]> git.sur5r.net Git - openldap/commitdiff
allow descriptions in -d for tools as well; test as much as possible about pid/args...
authorPierangelo Masarati <ando@openldap.org>
Mon, 31 Oct 2005 18:48:12 +0000 (18:48 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 31 Oct 2005 18:48:12 +0000 (18:48 +0000)
servers/slapd/slapcommon.c
servers/slapd/slaptest.c

index 0cf108c72c0afb49d940983db44d4f7ee224b363..f0fe956ad7d1e1ff6052a364cf60e559e4d9c025 100644 (file)
@@ -245,7 +245,38 @@ slap_tool_init(
                        break;
 
                case 'd':       /* turn on debugging */
-                       ldap_debug += atoi( optarg );
+#ifdef LDAP_DEBUG
+                       if ( optarg != NULL && optarg[ 0 ] != '-' && !isdigit( optarg[ 0 ] ) )
+                       {
+                               int     level;
+
+                               if ( str2loglevel( optarg, &level ) ) {
+                                       fprintf( stderr,
+                                               "unrecognized log level "
+                                               "\"%s\"\n", optarg );
+                                       exit( EXIT_FAILURE );
+                               }
+
+                               ldap_debug |= level;
+
+                       } else {
+                               int     level;
+                               char    *next = NULL;
+
+                               level = strtol( optarg, &next, 0 );
+                               if ( next == NULL || next[ 0 ] != '\0' ) {
+                                       fprintf( stderr,
+                                               "unrecognized log level "
+                                               "\"%s\"\n", optarg );
+                                       exit( EXIT_FAILURE );
+                               }
+                               ldap_debug |= level;
+                       }
+#else
+                       if ( atoi( optarg ) != 0 )
+                               fputs( "must compile with LDAP_DEBUG for debugging\n",
+                                      stderr );
+#endif
                        break;
 
                case 'D':
index 2bd5d1b0f383b2b3aadcbbca57d4da7df2dfa487..245389223006170efbd49f1d80876b6e30ad5955 100644 (file)
 #include <ac/ctype.h>
 #include <ac/string.h>
 #include <ac/socket.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <ac/unistd.h>
+#include <ac/errno.h>
 
 #include <lber.h>
 #include <ldif.h>
 
 #include "slapcommon.h"
 
+static int
+test_file( const char *fname, const char *ftype )
+{
+       struct stat     st;
+       int             save_errno;
+
+       switch ( stat( fname, &st ) ) {
+       case 0:
+               if ( !( st.st_mode & S_IWUSR ) ) {
+                       Debug( LDAP_DEBUG_ANY, "%s file "
+                               "\"%s\" exists, but user does not have access\n",
+                               ftype, fname, 0 );
+                       return -1;
+               }
+               break;
+
+       case -1:
+       default:
+               save_errno = errno;
+               if ( save_errno == ENOENT ) {
+                       FILE            *fp = fopen( fname, "w" );
+
+                       if ( fp == NULL ) {
+                               save_errno = errno;
+
+                               Debug( LDAP_DEBUG_ANY, "unable to open file "
+                                       "\"%s\": %d (%s)\n",
+                                       fname,
+                                       save_errno, strerror( save_errno ) );
+
+                               return -1;
+                       }
+                       unlink( fname );
+                       break;
+               }
+
+               Debug( LDAP_DEBUG_ANY, "unable to stat file "
+                       "\"%s\": %d (%s)\n",
+                       slapd_pid_file,
+                       save_errno, strerror( save_errno ) );
+               return -1;
+       }
+}
+
 int
 slaptest( int argc, char **argv )
 {
@@ -42,6 +89,18 @@ slaptest( int argc, char **argv )
 
        slap_tool_init( progname, SLAPTEST, argc, argv );
 
+       if ( slapd_pid_file != NULL ) {
+               if ( test_file( slapd_pid_file, "pid" ) ) {
+                       return EXIT_FAILURE;
+               }
+       }
+
+       if ( slapd_args_file != NULL ) {
+               if ( test_file( slapd_args_file, "args" ) ) {
+                       return EXIT_FAILURE;
+               }
+       }
+
        fprintf( stderr, "config file testing succeeded\n");
 
        slap_tool_destroy();