* New server command-line option "-l" to send log output to the host
authorArt Cancro <ajc@citadel.org>
Sat, 17 Jan 2004 03:17:35 +0000 (03:17 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 17 Jan 2004 03:17:35 +0000 (03:17 +0000)
  computer's syslog facility instead of to a trace file.

14 files changed:
citadel/ChangeLog
citadel/citserver.c
citadel/control.c
citadel/docs/citadel.html
citadel/html.c
citadel/msgbase.c
citadel/serv_chat.c
citadel/serv_expire.c
citadel/serv_extensions.c
citadel/server_main.c
citadel/sysdep.c
citadel/sysdep_decls.h
citadel/user_ops.c
citadel/vcard.c

index 8f15d916eba61f436d2ca17657e2fe4738b996ba..f2123543524b908b0dac27e7bd357e9054f7d8fb 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 614.2  2004/01/17 03:17:34  ajc
+ * New server command-line option "-l" to send log output to the host
+   computer's syslog facility instead of to a trace file.
+
  Revision 614.1  2004/01/02 22:13:59  ajc
  * Link to OpenLDAP client library (-lldap) and set HAVE_LDAP if present.
 
@@ -5213,3 +5217,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 6b8c3936925b5673f19d0c8787030f730676f7d1..7c6492a2ab823d53dca5d4fe299c33f708aeb272 100644 (file)
@@ -34,7 +34,6 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
-#include <syslog.h>
 /* #include <dlfcn.h> */
 #include <netdb.h>
 #include <sys/types.h>
@@ -229,8 +228,7 @@ void RemoveContext (struct CitContext *con)
        logout(con);
 
        unlink(con->temp);
-       lprintf(3, "Session ended.\n");
-       syslog(LOG_NOTICE,"Session %d: ended.", con->cs_pid);
+       lprintf(3, "Session %d: ended.\n", con->cs_pid);
 
        /* Deallocate any user-data attached to this session */
        deallocate_user_data(con);
@@ -507,14 +505,7 @@ void cmd_iden(char *argbuf)
                }
        }
 
-       lprintf(7, "Client %d/%d/%01d.%02d (%s)\n",
-               dev_code,
-               cli_code,
-               (rev_level / 100),
-               (rev_level % 100),
-               desc);
-
-       syslog(LOG_NOTICE,"Session %d: Client %d/%d/%01d.%02d (%s) from %s\n",
+       lprintf(3,"Session %d: Client %d/%d/%01d.%02d (%s) from %s\n",
                CC->cs_pid,
                dev_code,
                cli_code,
@@ -907,8 +898,7 @@ void begin_session(struct CitContext *con)
        if ((config.c_maxsessions > 0)&&(num_sessions > config.c_maxsessions))
                con->nologin = 1;
 
-       lprintf(3, "Session started.\n");
-       syslog(LOG_NOTICE, "Session %d: started.", con->cs_pid);
+       lprintf(3, "Session %d: started.\n", con->cs_pid);
 
        /* Run any session startup routines registered by loadable modules */
        PerformSessionHooks(EVT_START);
index f582c4aa64ca25c71d0aff3c1a173268253c7fad..01d2e9d80e568601f837e51232589d2bdf6f8624 100644 (file)
@@ -31,7 +31,6 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
-#include <syslog.h>
 #include <sys/types.h>
 #include "citadel.h"
 #include "server.h"
index cfc410408bd44deb4623d73688990dd998ff9492..2d0dba4f78d36818f3dcb43d6c65ab2a885d8487 100644 (file)
@@ -836,7 +836,7 @@ a different port for each one.</p>
 <p>The next step is to arrange for the server to start. The <tt>citserver</tt>
 program is the main Citadel server. Before we cover the recommended
 method of starting the server, let's examine its usage options:</p>
-<pre>citserver [-hHomeDir] [-xDebugLevel] [-tTraceFile] [-d] [-f]<br></pre>
+<pre>citserver [-hHomeDir] [-xDebugLevel] [-tTraceFile] [-lLogFacility] [-d] [-f]<br></pre>
 <p>The options are as follows:</p>
 <p><tt>-hHomeDir</tt> - the directory your Citadel data files live in.
 This should, of course, be a directory that you've run the <tt>setup</tt>
@@ -857,6 +857,14 @@ etc.) </li>
 </ul>
 <p><tt>-tTraceFile</tt> - Tell the server where to send its debug/trace
 output. Normally it is sent to stdout.</p>
+<p><tt>-lLogFacility</tt> - Tell the server to send its debug/trace output
+to the <tt>syslog</tt> service on the host system <i>instead of</i> to a
+trace file.  <tt>LogFacility</tt> must be one of: <tt><i>kern, user, mail,
+daemon, auth, syslog, lpr, news, uucp, local0, local1, local2, local3,
+local4, local5, local6, local7</i></tt>.  Please note that use of the
+<tt>-l</tt> option will cancel any use of the <tt>-t</tt> option; that is,
+if you specify a trace file <i>and</i> a syslog facility, log output will
+only go to the syslog facility.
 <p><tt>-d</tt> - Run as a daemon; i.e. in the background. This switch
 would be necessary if you were starting the Citadel server, for
 example, from an rc.local script (which is not recommended, because
index ea72a5906ff83e46a3164699db0b71612a7c7090..697547a14fd70061d766a5f0d1ef86b3658fd60f 100644 (file)
@@ -32,7 +32,6 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
-#include <syslog.h>
 #include "citadel.h"
 #include "server.h"
 #include "serv_extensions.h"
index 52d5cb2b74bdc586a0c1461317b3a3bde43373e4..71dc3fc2acbfe7abac81b4a5a1fc59c902bf9f6c 100644 (file)
@@ -29,7 +29,6 @@
 
 #include <ctype.h>
 #include <string.h>
-#include <syslog.h>
 #include <limits.h>
 #include <errno.h>
 #include <stdarg.h>
index c7c7a00652bdebcda876bdf0032ce6b57b8ff762..acd867e0f8782973067427b18a46d4b17f44caf8 100644 (file)
@@ -32,7 +32,6 @@
 #include "citadel.h"
 #include "server.h"
 #include "serv_extensions.h"
-#include <syslog.h>
 #include "serv_chat.h"
 #include "sysdep_decls.h"
 #include "citserver.h"
index a67222173acae01af4d15296d683678693b57161..d29220bf3dd427fb2cd311c2ddc0725dd35b0e3c 100644 (file)
@@ -51,7 +51,6 @@
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include <syslog.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
index 286fe5b32407bb2b9d76ef1142736a0b4674f155..29c92587ea847e2d8fa876dec54f350c9b68411d 100644 (file)
@@ -13,7 +13,6 @@
 #include <sys/types.h>
 #include <dirent.h>
 #include <string.h>
-#include <syslog.h>
 #include <limits.h>
 #include <ctype.h>
 #include "citadel.h"
index 10b61cf590ed3251e1898e19f7ecd11eff16f7a2..94ee493ff340281bdbe39fb0dbd658e922205a20 100644 (file)
@@ -15,6 +15,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
+#include <syslog.h>
 
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
@@ -35,7 +36,6 @@
 #include <pwd.h>
 #include <errno.h>
 #include <stdarg.h>
-#include <syslog.h>
 #include <grp.h>
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
@@ -90,6 +90,15 @@ int main(int argc, char **argv)
                        chmod(tracefile, 0600);
                }
 
+               else if (!strncmp(argv[a], "-l", 2)) {
+                       safestrncpy(tracefile, argv[a], sizeof tracefile);
+                       strcpy(tracefile, &tracefile[2]);
+                       syslog_facility = SyslogFacility(tracefile);
+                       if (syslog_facility >= 0) {
+                               openlog("citadel", LOG_PID, syslog_facility);
+                       }
+               }
+
                /* run in the background if -d was specified */
                else if (!strcmp(argv[a], "-d")) {
                        start_daemon( (strlen(tracefile) > 0) ? 0 : 1 ) ;
@@ -119,7 +128,9 @@ int main(int argc, char **argv)
                /* any other parameter makes it crash and burn */
                else {
                        lprintf(1,      "citserver: usage: "
-                                       "citserver [-tTraceFile] [-d] [-f]"
+                                       "citserver [-tTraceFile] "
+                                       "[-lLogFacility] "
+                                       "[-d] [-f]"
                                        " [-xLogLevel] [-hHomeDir]\n");
                        exit(1);
                }
@@ -138,7 +149,6 @@ int main(int argc, char **argv)
 
        /* Initialize... */
        init_sysdep();
-       openlog("citserver", LOG_PID, LOG_USER);
 
        /* Load site-specific parameters, and set the ipgm secret */
        lprintf(7, "Loading citadel.config\n");
index 0eba07f384a777a8419752189bf903cbf76846d0..930e8cf71be1335110f442f84cc4c62ab0933918 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
+#include <sys/syslog.h>
 
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
@@ -47,7 +48,6 @@
 #include <pwd.h>
 #include <errno.h>
 #include <stdarg.h>
-#include <syslog.h>
 #include <grp.h>
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
@@ -92,6 +92,8 @@ int masterhighest;
 
 pthread_t initial_thread;              /* tid for main() thread */
 
+int syslog_facility = (-1);
+
 
 /*
  * lprintf()  ...   Write logging information
@@ -107,7 +109,12 @@ void lprintf(int loglevel, const char *format, ...) {
         vsnprintf(buf, sizeof(buf), format, arg_ptr);   
         va_end(arg_ptr);   
 
-       if (loglevel <= verbosity) { 
+       if (syslog_facility >= 0) {
+               if (loglevel <= verbosity) {
+                       syslog(LOG_NOTICE, buf);
+               }
+       }
+       else if (loglevel <= verbosity) { 
                struct timeval tv;
                struct tm *tim;
                time_t unixtime;
@@ -1141,3 +1148,46 @@ SETUP_FD:        memcpy(&readfds, &masterfds, sizeof masterfds);
        --num_threads;
        return NULL;
 }
+
+
+
+
+/*
+ * SyslogFacility()
+ * Translate text facility name to syslog.h defined value.
+ */
+int SyslogFacility(char *name)
+{
+       int i;
+       struct
+       {
+               int facility;
+               char *name;
+       }   facTbl[] =
+       {
+               {   LOG_KERN,   "kern"          },
+               {   LOG_USER,   "user"          },
+               {   LOG_MAIL,   "mail"          },
+               {   LOG_DAEMON, "daemon"        },
+               {   LOG_AUTH,   "auth"          },
+               {   LOG_SYSLOG, "syslog"        },
+               {   LOG_LPR,    "lpr"           },
+               {   LOG_NEWS,   "news"          },
+               {   LOG_UUCP,   "uucp"          },
+               {   LOG_LOCAL0, "local0"        },
+               {   LOG_LOCAL1, "local1"        },
+               {   LOG_LOCAL2, "local2"        },
+               {   LOG_LOCAL3, "local3"        },
+               {   LOG_LOCAL4, "local4"        },
+               {   LOG_LOCAL5, "local5"        },
+               {   LOG_LOCAL6, "local6"        },
+               {   LOG_LOCAL7, "local7"        },
+               {   0,            NULL          }
+       };
+       for(i = 0; facTbl[i].name != NULL; i++) {
+               if(!strcasecmp(name, facTbl[i].name))
+                       return facTbl[i].facility;
+       }
+       return -1;
+}
+
index 9b7483ed8d771afb2eeddb6c2b5d7ccecaeaf664..37ee0769fa1c53b14d501e4b9198fed5765a5c70 100644 (file)
@@ -49,3 +49,7 @@ extern struct worker_node {
         pthread_t tid;
         struct worker_node *next;
 } *worker_list;
+
+
+extern int SyslogFacility(char *name);
+extern int syslog_facility;
index 0a3ff2e8c6be5fadd1500773ecc79a58d5a64b35..43deedcef6ec3a00421edc64149cdd546d996270 100644 (file)
@@ -33,7 +33,6 @@
 #endif
 
 #include <string.h>
-#include <syslog.h>
 #include <limits.h>
 #ifndef ENABLE_CHKPWD
 #include "auth.h"
@@ -437,7 +436,7 @@ void session_startup(void)
 {
        int i;
 
-       syslog(LOG_NOTICE, "Session %d: %s logged in",
+       lprintf(3, "Session %d: %s logged in",
               CC->cs_pid, CC->curr_user);
 
        lgetuser(&CC->user, CC->curr_user);
index 3906c4c22daf58490937c1ed6094f5163eb08f21..1898516da0b34d0873b1ed9fdeb1dab258f148bb 100644 (file)
@@ -30,7 +30,6 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
-#include <syslog.h>
 
 #include "citadel.h"
 #include "server.h"