]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Import Ksp's improved slapd logging & args/pid options
authorKurt Zeilenga <kurt@openldap.org>
Wed, 20 Jan 1999 01:26:03 +0000 (01:26 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 20 Jan 1999 01:26:03 +0000 (01:26 +0000)
CHANGES
doc/man/man8/slapd.8
include/ldapconfig.h.edit
include/ldapconfig.h.nt
servers/slapd/daemon.c
servers/slapd/main.c

diff --git a/CHANGES b/CHANGES
index e9e54e8212cb3561f966b99fa055da7155441da4..a094fe6c4b09a8efa89a50e0c1f01662cc92d80d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,8 @@ Changes included in OpenLDAP 1.2
        Add ldappasswd() tool
        Add salted MD5/SHA1 password support
        Add client/tools password prompting (-W)
+       Add slapd logging option
+       Add slapd alternative args/pid file locations
        Fix lber leaking ber_scanf
        Update client/tools Kerberos option handling
 
index be0c97d3bf58f2adacc9d61c4c04517bc4a287b6..85f3aa830ac2f7c2bf2a6493a6d360a231157242 100644 (file)
@@ -1,10 +1,10 @@
-.TH SLAPD 8C "6 November 1995" "U-M LDAP LDVERSION"
+.TH SLAPD 8C "22 September 1998" "OpenLDAP LDVERSION"
 .SH NAME
 slapd \- Stand-alone LDAP Daemon
 .SH SYNOPSIS
-.B ETCDIR/slapd [\-d debug\-level]
+.B LIBEXECDIR/slapd [\-d debug\-level]
 .B [\-f slapd\-config\-file] [\-p port\-number]
-.B [\-s syslog\-level] [\-i]
+.B [\-s syslog\-level] [\-l syslog\-local\-user] [\-i]
 .B 
 .SH DESCRIPTION
 .LP
@@ -18,6 +18,26 @@ is typically invoked at boot time, usually out of
 Upon startup,
 .B slapd
 normally forks and disassociates itself from the invoking tty.
+In this case, the
+.B slapd
+process will print its process ID to a 
+.B .pid
+file ( see
+.BR getpid (2)
+), as well as the command line options during invocation to an
+.B .args
+file. By default, these files are located in the directory 
+.B LOCALSTATEDIR.
+The files' base names are derived from the 
+.B slapd
+binary name, making it possible to run several 
+.B slapd
+servers with differet names on the same machine, with each having
+its own 
+.B .pid/.args 
+files. (Those 
+.B slapd
+names might be obtained via symbolic links to one binary file.)
 If the
 .B \-d
 flag is given and debugging is set to some non-zero
@@ -55,6 +75,21 @@ at what level debugging statements should be logged to the
 .BR syslog (8)
 facility.
 .TP
+.BI \-l " syslog\-local\-user"
+Selects the local user of the
+.BR syslog (8)
+facility. Values can be 
+.BR LOCAL0 , 
+.BR LOCAL1 , 
+and so on, up to 
+.BR LOCAL7 . 
+The default is
+.BR LOCAL4 .
+However, this option is only permitted on systems that support
+local users with the 
+.BR syslog (8)
+facility.
+.TP
 .BI \-f " slapd\-config\-file"
 Specifies the slapd configuration file. The default is
 .BR ETCDIR/slapd.conf .
@@ -78,7 +113,7 @@ the LDAP databases defined in the default config file, just type:
 .LP
 .nf
 .ft tt
-       ETCDIR/slapd
+       LIBEXECDIR/slapd
 .ft
 .fi
 .LP
@@ -89,7 +124,7 @@ on voluminous debugging which will be printed on standard error, type:
 .LP
 .nf
 .ft tt
-       ETCDIR/slapd -f /usr/local/slapd/slapd.conf -d 255
+       LIBEXECDIR/slapd -f ETCDIR/slapd.conf -d 255
 .ft
 .fi
 .LP
@@ -102,3 +137,8 @@ on voluminous debugging which will be printed on standard error, type:
 .SH BUGS
 When using the LDBM database backend, the Modify RDN operation does not
 update the attribute values in the entry that are affected by the change.
+.SH ACKNOWLEDGEMENTS
+.B     OpenLDAP
+is developed and maintained by The OpenLDAP Project (http://www.openldap.org/).
+.B     OpenLDAP
+is derived from University of Michigan LDAP 3.3 Release.  
index 4acdfd8cd406f04b7e59ff838793f8074dd52f7f..ff3233768aa72ae3e612ec9cc7a2eb983bb3a018 100644 (file)
 /*
  * SHARED DEFINITIONS - things you should change
  */
+#define DEFAULT_DIRSEP         "/"
 #define DEFAULT_BINDIR         "%BINDIR%"
 #define DEFAULT_SBINDIR                "%SBINDIR%"
 #define DEFAULT_DATADIR                "%DATADIR%"
 #define DEFAULT_SYSCONFDIR     "%SYSCONFDIR%"
 #define DEFAULT_LIBEXECDIR     "%LIBEXECDIR%"
+#define DEFAULT_RUNDIR         "%RUNDIR%"
 
 #define DEFAULT_LDAP_CONF_FILE "%SYSCONFDIR%/ldap.conf"
 #define DEFAULT_LDAP_USERRC_FILE "ldaprc"
@@ -213,10 +215,10 @@ Please try again later.\r\n"
 #define SLAPD_DEFAULT_SIZELIMIT                500
        /* default timelimit to spend on a search */
 #define SLAPD_DEFAULT_TIMELIMIT                3600
-       /* location of the slapd pid file */
-#define SLAPD_PIDFILE                  "%RUNDIR%/slapd.pid"
-       /* location of the slapd args file */
-#define SLAPD_ARGSFILE                 "%RUNDIR%/slapd.args"
+       /* extension of the slapd pid file */
+#define SLAPD_PIDEXT            ".pid"
+       /* extension of the slapd args file */
+#define SLAPD_ARGSEXT           ".args"
        /* dn of the special "monitor" entry */
 #define SLAPD_MONITOR_DN               "cn=monitor"
        /* dn of the special "config" entry */
index 94881f00823842312b319e42704c2503b732e652..4590031ed0e198f598935a82fe46488ae461c79f 100644 (file)
@@ -31,9 +31,7 @@
 /*
  * SHARED DEFINITIONS - things you should change
  */
-/*
- * SHARED DEFINITIONS - things you should change
- */
+#define DEFAULT_DIRSEP         "\\"
 #define DEFAULT_BINDIR         "C:\\OpenLDAP\\bin"
 #define DEFAULT_SBINDIR                "C:\\OpenLDAP\\sbin"
 #define DEFAULT_DATADIR                "C:\\OpenLDAP\\share"
@@ -217,10 +215,10 @@ Please try again later.\r\n"
 #define SLAPD_DEFAULT_SIZELIMIT                500
        /* default timelimit to spend on a search */
 #define SLAPD_DEFAULT_TIMELIMIT                3600
-       /* location of the slapd pid file */
-#define SLAPD_PIDFILE                  "C:\\OpenLDAP\\run\\slapd.pid"
-       /* location of the slapd args file */
-#define SLAPD_ARGSFILE                 "C:\\OpenLDAP\\run\\slapd.args"
+       /* extension of the slapd pid file */
+#define SLAPD_PIDEXT                   ".pid"
+       /* extension of the slapd args file */
+#define SLAPD_ARGSEXT                  ".args"
        /* dn of the special "monitor" entry */
 #define SLAPD_MONITOR_DN               "cn=monitor"
        /* dn of the special "config" entry */
index b03b80b9338a8ad6ad3f9609689d53d58e9eacf0..85954be7cb5d5fc386708502de145db3222ebd53 100644 (file)
@@ -40,6 +40,12 @@ static int slapd_shutdown = 0;
 static void    set_shutdown(int sig);
 static void    do_nothing  (int sig);
 
+/* we need the server's name for constructing the pid/args file names */
+#if defined( SLAPD_PIDEXT ) || defined( SLAPD_ARGSEXT )
+extern char  *serverName;
+#define DEFAULT_SERVERNAME  "slapd"
+#endif
+
 void *
 slapd_daemon(
     void *port
@@ -56,6 +62,13 @@ slapd_daemon(
        FILE                    *fp;
        int                     on = 1;
 
+#ifdef SLAPD_PIDEXT
+    char            pidFile[BUFSIZ];
+#endif
+#ifdef SLAPD_ARGSEXT
+    char            argsFile[BUFSIZ];
+#endif
+
 #ifdef HAVE_SYSCONF
        dtblsize = sysconf( _SC_OPEN_MAX );
 #elif HAVE_GETDTABLESIZE
@@ -135,14 +148,22 @@ slapd_daemon(
        (void) SIGNAL( SIGHUP, set_shutdown );
 
        Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
-#ifdef SLAPD_PIDFILE
-       if ( (fp = fopen( SLAPD_PIDFILE, "w" )) != NULL ) {
+
+#if defined( SLAPD_PIDEXT ) || defined( SLAPD_ARGSEXT )
+    if ( !serverName ) serverName = DEFAULT_SERVERNAME;
+
+#ifdef SLAPD_PIDEXT
+    sprintf( pidFile, "%s%s%s%s", DEFAULT_RUNDIR, DEFAULT_DIRSEP,
+               serverName, SLAPD_PIDEXT );
+       if ( (fp = fopen( pidFile, "w" )) != NULL ) {
                fprintf( fp, "%d\n", (int) getpid() );
                fclose( fp );
        }
 #endif
-#ifdef SLAPD_ARGSFILE
-       if ( (fp = fopen( SLAPD_ARGSFILE, "w" )) != NULL ) {
+#ifdef SLAPD_ARGSEXT
+    sprintf( argsFile, "%s%s%s%s", DEFAULT_RUNDIR, DEFAULT_DIRSEP,
+       serverName, SLAPD_ARGSEXT );
+       if ( (fp = fopen( argsFile, "w" )) != NULL ) {
                for ( i = 0; i < g_argc; i++ ) {
                        fprintf( fp, "%s ", g_argv[i] );
                }
@@ -150,6 +171,8 @@ slapd_daemon(
                fclose( fp );
        }
 #endif
+#endif
+
 
        while ( !slapd_shutdown ) {
                struct sockaddr_in      from;
index 4f8c778bcdb750d2055bbf7f816de3c9eea0f973..b19e290f7561a86dca1f0fd11062c10916da7d4a 100644 (file)
 #include "slap.h"
 #include "lutil.h"                     /* Get lutil_detach() */
 
+/*
+ * when more than one slapd is running on one machine, each one might have
+ * it's own LOCAL for syslogging and must have its own pid/args files
+ */
+
+#ifdef LOG_LOCAL4
+
+#define DEFAULT_SYSLOG_USER  LOG_LOCAL4
+
+typedef struct _str2intDispatch {
+
+        char    *stringVal;
+        int      abbr;
+        int      intVal;
+
+} STRDISP, *STRDISP_P;
+
+
+/* table to compute syslog-options to integer */
+static STRDISP  syslog_types[] = {
+
+    { "LOCAL0",         6, LOG_LOCAL0 },
+    { "LOCAL1",         6, LOG_LOCAL1 },
+    { "LOCAL2",         6, LOG_LOCAL2 },
+    { "LOCAL3",         6, LOG_LOCAL3 },
+    { "LOCAL4",         6, LOG_LOCAL4 },
+    { "LOCAL5",         6, LOG_LOCAL5 },
+    { "LOCAL6",         6, LOG_LOCAL6 },
+    { "LOCAL7",         6, LOG_LOCAL7 },
+    NULL
+
+};
+
+static int   cnvt_str2int();
+
+#endif  /* LOG_LOCAL4 */
+
+/*
+ * the server's name must be accessible from the daemon module,
+ * to construct the pid/args file names
+ */
+char  *serverName = NULL;
+
+
 static void
 usage( char *name )
 {
-       fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]\n", name );
+       fprintf( stderr, "usage: %s [-d ?|debuglevel] [-f configfile] [-p portnumber] [-s sysloglevel]", name );
+#ifdef LOG_LOCAL4
+    fprintf( stderr, " [-l sysloguser]" );
+#endif
+    fprintf( stderr, "\n" );
 }
 
 int
@@ -23,11 +71,13 @@ main( int argc, char **argv )
        int             i;
        int             inetd = 0;
        int             port;
-       char            *myname;
        int             udp;
        Backend         *be = NULL;
        FILE            *fp = NULL;
        char            *configfile;
+#ifdef LOG_LOCAL4
+       int     syslogUser = DEFAULT_SYSLOG_USER;
+#endif
 
        configfile = SLAPD_DEFAULT_CONFIGFILE;
        port = LDAP_PORT;
@@ -95,6 +145,15 @@ main( int argc, char **argv )
                        ldap_syslog = atoi( optarg );
                        break;
 
+#ifdef LOG_LOCAL4
+
+               case 'l':       /* set syslog local user */
+                       syslogUser = cnvt_str2int( optarg, syslog_types,
+                                           DEFAULT_SYSLOG_USER );
+                       break;
+
+#endif
+
                case 'u':       /* do udp */
                        udp = 1;
                        break;
@@ -107,10 +166,10 @@ main( int argc, char **argv )
 
        Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 );
 
-       if ( (myname = strrchr( argv[0], '/' )) == NULL ) {
-               myname = ch_strdup( argv[0] );
+       if ( (serverName = strrchr( argv[0], '/' )) == NULL ) {
+               serverName = ch_strdup( argv[0] );
        } else {
-               myname = ch_strdup( myname + 1 );
+               serverName = ch_strdup( serverName + 1 );
        }
 
        if ( ! inetd ) {
@@ -122,10 +181,11 @@ main( int argc, char **argv )
                lutil_detach( 0, 0 );
 #endif
        }
+
 #ifdef LOG_LOCAL4
-       openlog( myname, OPENLOG_OPTIONS, LOG_LOCAL4 );
+       openlog( serverName, OPENLOG_OPTIONS, syslogUser );
 #else
-       openlog( myname, OPENLOG_OPTIONS );
+       openlog( serverName, OPENLOG_OPTIONS );
 #endif
 
        init();
@@ -231,3 +291,37 @@ main( int argc, char **argv )
        }
        return 1;
 }
+
+
+#ifdef LOG_LOCAL4
+
+/*
+ *  Convert a string to an integer by means of a dispatcher table
+ *  if the string is not in the table return the default
+ */
+
+static int
+cnvt_str2int (stringVal, dispatcher, defaultVal)
+char      *stringVal;
+STRDISP_P  dispatcher;
+int        defaultVal;
+{
+    int        retVal = defaultVal;
+    STRDISP_P  disp;
+
+    for (disp = dispatcher; disp->stringVal; disp++) {
+
+        if (!strncasecmp (stringVal, disp->stringVal, disp->abbr)) {
+
+            retVal = disp->intVal;
+            break;
+
+        }
+    }
+
+    return (retVal);
+
+} /* cnvt_str2int */
+
+#endif  /* LOG_LOCAL4 */
+