add-server-syslog-logging-capabilities-20010326
authorNathan Neulinger <nneul@umr.edu>
Mon, 26 Mar 2001 20:26:17 +0000 (20:26 +0000)
committerDerrick Brashear <shadow@dementia.org>
Mon, 26 Mar 2001 20:26:17 +0000 (20:26 +0000)
Add support for syslogging server log messages

====================
This delta was composed from multiple commits as part of the CVS->Git migration.
The checkin message with each commit was inconsistent.
The following are the additional commit messages.
====================
Add syslogging capability to ptserver

====================
add syslog capability to fileserver

====================
Add syslog capability to the volserver

====================
Add syslog capability to the vlserver

====================
fix my own error when hand-applying nathan's patch

====================
remove unused function

src/ptserver/ptserver.c
src/util/afsutil.h
src/util/serverLog.c
src/viced/viced.c
src/vlserver/vlserver.c
src/volser/volmain.c

index e29fe7c..56371f6 100644 (file)
@@ -143,13 +143,26 @@ void main (argc, argv)
        else if (strncmp (arg, "-enable_process_stats", alen) == 0) {
            rx_enableProcessRPCStats();
        }
+#ifndef AFS_NT40_ENV
+       else if (strncmp(arg, "-syslog", alen)==0) {
+           /* set syslog logging flag */
+           serverLogSyslog = 1;
+       } 
+       else if (strncmp(arg, "-syslog=", MIN(8,alen))==0) {
+           serverLogSyslog = 1;
+           serverLogSyslogFacility = atoi(arg+8);
+       }
+#endif
        else if (*arg == '-') {
          usage:
 
                /* hack in help flag support */
 
                printf ("Usage: ptserver [-database <db path>] "
-                       "[-p <number of processes>] [-rebuildDB] "
+#ifndef AFS_NT40_ENV
+                       "[-syslog[=FACILITY]] "
+#endif
+                       "[-p <number of processes>] [-rebuild] "
                        /* "[-enable_peer_stats] [-enable_process_stats] " */
                        "[-help]\n");
                fflush(stdout);
index c152a65..e3fecc6 100644 (file)
 #include <stdio.h>
 #include <stdarg.h>
 extern int LogLevel;
+#ifndef AFS_NT40_ENV
+extern int serverLogSyslog;
+extern int serverLogSyslogFacility;
+#endif
 extern void FSLog(const char *format, ...);
 #define ViceLog(level, str)  if ((level) <= LogLevel) (FSLog str)
 
index 3d3ed3e..5d0f024 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 #include <sys/param.h>
 #include <sys/time.h>
+#include <syslog.h>
 #endif
 #include <afs/procmgmt.h>  /* signal(), kill(), wait(), etc. */
 #include <fcntl.h>
@@ -64,22 +65,17 @@ char *threadname();
 
 static int serverLogFD = -1;
 
+#ifndef AFS_NT40_ENV
+int serverLogSyslog = 0;
+int serverLogSyslogFacility = LOG_DAEMON;
+#endif
+
 #include <stdarg.h>
 int LogLevel;
 int mrafsStyleLogs = 0;
 int printLocks = 0;
 static char ourName[MAXPATHLEN];
 
-void WriteLogBuffer(buf,len)
-    char *buf;
-    afs_uint32 len;
-{
-    LOCK_SERVERLOG();
-    if (serverLogFD > 0)
-        write(serverLogFD, buf, len);
-    UNLOCK_SERVERLOG();
-}
-
 /* VARARGS1 */
 void FSLog (const char *format, ...)
 {
@@ -110,8 +106,13 @@ void FSLog (const char *format, ...)
 
     len = strlen(tbuffer);
     LOCK_SERVERLOG();
-    if (serverLogFD > 0)
-       write(serverLogFD, tbuffer, len);
+#ifndef AFS_NT40_ENV
+    if ( serverLogSyslog ){
+       syslog(LOG_INFO, "%s", info);
+    } else 
+#endif
+       if (serverLogFD > 0)
+           write(serverLogFD, tbuffer, len);
     UNLOCK_SERVERLOG();
 
 #if !defined(AFS_PTHREAD_ENV)
@@ -189,6 +190,13 @@ int OpenLog(const char *fileName)
     struct tm *TimeFields;
     char FileName[MAXPATHLEN]; 
 
+    if ( serverLogSyslog ) {
+#ifndef AFS_NT40_ENV
+       openlog(NULL, LOG_PID, serverLogSyslogFacility);
+       return;
+#endif
+    }
+
     if (mrafsStyleLogs) {
         TM_GetTimeOfDay(&Start, 0);
         TimeFields = localtime(&Start.tv_sec);
@@ -244,6 +252,10 @@ int ReOpenLog(const char *fileName)
     if (access(fileName, F_OK)==0)
        return 0; /* exists, no need to reopen. */
 
+    if ( serverLogSyslog ) {
+       return 0;
+    }
+
 #if defined(AFS_PTHREAD_ENV)
     LOCK_SERVERLOG();
     if (serverLogFD > 0)
index add63db..34a3250 100644 (file)
@@ -1177,6 +1177,18 @@ static ParseArgs(argc, argv)
            if (!strcmp(argv[i], "-enable_process_stats")) {
                rx_enableProcessRPCStats();
            }
+#ifndef AFS_NT40_ENV
+        else 
+           if (strcmp(argv[i], "-syslog")==0) {
+               /* set syslog logging flag */
+               serverLogSyslog = 1;
+           } 
+       else 
+           if (strncmp(argv[i], "-syslog=", 8)==0) {
+               serverLogSyslog = 1;
+               serverLogSyslogFacility = atoi(argv[i]+8);
+           }
+#endif
        else {
            return(-1);
        }
index 6f17df5..2ca6796 100644 (file)
@@ -164,9 +164,20 @@ char       **argv;
            rx_enablePeerRPCStats();
        } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
            rx_enableProcessRPCStats();
+#ifndef AFS_NT40_ENV
+       } else if (strcmp(argv[index], "-syslog")==0) {
+           /* set syslog logging flag */
+           serverLogSyslog = 1;
+       } else if (strncmp(argv[index], "-syslog=", 8)==0) {
+           serverLogSyslog = 1;
+           serverLogSyslogFacility = atoi(argv[index]+8);
+#endif
        } else {
            /* support help flag */
            printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
+#ifndef AFS_NT40_ENV
+                  "[-syslog[=FACILITY]] "
+#endif
                   /*" [-enable_peer_stats] [-enable_process_stats] " */
                   "[-help]\n");
            fflush(stdout);
index 0ae13bb..bdddc9c 100644 (file)
@@ -274,11 +274,24 @@ char **argv; {
        else if (strcmp(argv[code], "-enable_process_stats")==0) {
            rx_enableProcessRPCStats();
        }
+#ifndef AFS_NT40_ENV
+       else if (strcmp(argv[code], "-syslog")==0) {
+           /* set syslog logging flag */
+           serverLogSyslog = 1;
+       } 
+       else if (strncmp(argv[code], "-syslog=", 8)==0) {
+           serverLogSyslog = 1;
+           serverLogSyslogFacility = atoi(argv[code]+8);
+       }
+#endif
        else {
            printf("volserver: unrecognized flag '%s'\n", argv[code]);
 usage:
            printf("Usage: volserver [-log] [-p <number of processes>] "
                   "[-udpsize <size of socket buffer in bytes>] "
+#ifndef AFS_NT40_ENV
+                  "[-syslog[=FACILITY]] "
+#endif
                   /* "[-enable_peer_stats] [-enable_process_stats] " */
                   "[-help]\n");
            VS_EXIT(1);