From 4050134067b948953758b2bad2702211e1dd46fd Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 17 Jan 2004 03:17:35 +0000 Subject: [PATCH] * New server command-line option "-l" to send log output to the host computer's syslog facility instead of to a trace file. --- citadel/ChangeLog | 5 ++++ citadel/citserver.c | 16 +++--------- citadel/control.c | 1 - citadel/docs/citadel.html | 10 +++++++- citadel/html.c | 1 - citadel/msgbase.c | 1 - citadel/serv_chat.c | 1 - citadel/serv_expire.c | 1 - citadel/serv_extensions.c | 1 - citadel/server_main.c | 16 +++++++++--- citadel/sysdep.c | 54 +++++++++++++++++++++++++++++++++++++-- citadel/sysdep_decls.h | 4 +++ citadel/user_ops.c | 3 +-- citadel/vcard.c | 1 - 14 files changed, 87 insertions(+), 28 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 8f15d916e..f21235435 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/citserver.c b/citadel/citserver.c index 6b8c39369..7c6492a2a 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -34,7 +34,6 @@ #include #include #include -#include /* #include */ #include #include @@ -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); diff --git a/citadel/control.c b/citadel/control.c index f582c4aa6..01d2e9d80 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include "citadel.h" #include "server.h" diff --git a/citadel/docs/citadel.html b/citadel/docs/citadel.html index cfc410408..2d0dba4f7 100644 --- a/citadel/docs/citadel.html +++ b/citadel/docs/citadel.html @@ -836,7 +836,7 @@ a different port for each one.

The next step is to arrange for the server to start. The citserver program is the main Citadel server. Before we cover the recommended method of starting the server, let's examine its usage options:

-
citserver [-hHomeDir] [-xDebugLevel] [-tTraceFile] [-d] [-f]
+
citserver [-hHomeDir] [-xDebugLevel] [-tTraceFile] [-lLogFacility] [-d] [-f]

The options are as follows:

-hHomeDir - the directory your Citadel data files live in. This should, of course, be a directory that you've run the setup @@ -857,6 +857,14 @@ etc.)

-tTraceFile - Tell the server where to send its debug/trace output. Normally it is sent to stdout.

+

-lLogFacility - Tell the server to send its debug/trace output +to the syslog service on the host system instead of to a +trace file. LogFacility must be one of: kern, user, mail, +daemon, auth, syslog, lpr, news, uucp, local0, local1, local2, local3, +local4, local5, local6, local7. Please note that use of the +-l option will cancel any use of the -t option; that is, +if you specify a trace file and a syslog facility, log output will +only go to the syslog facility.

-d - 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 diff --git a/citadel/html.c b/citadel/html.c index ea72a5906..697547a14 100644 --- a/citadel/html.c +++ b/citadel/html.c @@ -32,7 +32,6 @@ #include #include #include -#include #include "citadel.h" #include "server.h" #include "serv_extensions.h" diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 52d5cb2b7..71dc3fc2a 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -29,7 +29,6 @@ #include #include -#include #include #include #include diff --git a/citadel/serv_chat.c b/citadel/serv_chat.c index c7c7a0065..acd867e0f 100644 --- a/citadel/serv_chat.c +++ b/citadel/serv_chat.c @@ -32,7 +32,6 @@ #include "citadel.h" #include "server.h" #include "serv_extensions.h" -#include #include "serv_chat.h" #include "sysdep_decls.h" #include "citserver.h" diff --git a/citadel/serv_expire.c b/citadel/serv_expire.c index a67222173..d29220bf3 100644 --- a/citadel/serv_expire.c +++ b/citadel/serv_expire.c @@ -51,7 +51,6 @@ #include #include "citadel.h" #include "server.h" -#include #include "sysdep_decls.h" #include "citserver.h" #include "support.h" diff --git a/citadel/serv_extensions.c b/citadel/serv_extensions.c index 286fe5b32..29c92587e 100644 --- a/citadel/serv_extensions.c +++ b/citadel/serv_extensions.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include "citadel.h" diff --git a/citadel/server_main.c b/citadel/server_main.c index 10b61cf59..94ee493ff 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -15,6 +15,7 @@ #include #include #include +#include #if TIME_WITH_SYS_TIME # include @@ -35,7 +36,6 @@ #include #include #include -#include #include #ifdef HAVE_PTHREAD_H #include @@ -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"); diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 0eba07f38..930e8cf71 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -27,6 +27,7 @@ #include #include #include +#include #if TIME_WITH_SYS_TIME # include @@ -47,7 +48,6 @@ #include #include #include -#include #include #ifdef HAVE_PTHREAD_H #include @@ -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; +} + diff --git a/citadel/sysdep_decls.h b/citadel/sysdep_decls.h index 9b7483ed8..37ee0769f 100644 --- a/citadel/sysdep_decls.h +++ b/citadel/sysdep_decls.h @@ -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; diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 0a3ff2e8c..43deedcef 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -33,7 +33,6 @@ #endif #include -#include #include #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); diff --git a/citadel/vcard.c b/citadel/vcard.c index 3906c4c22..1898516da 100644 --- a/citadel/vcard.c +++ b/citadel/vcard.c @@ -30,7 +30,6 @@ #include #include #include -#include #include "citadel.h" #include "server.h" -- 2.39.2