[OpenAFS-devel] new bos syslog diff - with -syslog=FACILITY

Nathan Neulinger nneul@umr.edu
Thu, 15 Mar 2001 10:50:28 -0600


--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Adds requested support for configuring the facility code.

-- Nathan

------------------------------------------------------------
Nathan Neulinger                       EMail:  nneul@umr.edu
University of Missouri - Rolla         Phone: (573) 341-4841
Computing Services                       Fax: (573) 341-4216

--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="bos-syslog-2.diff"

Index: bozo/bosserver.c
===================================================================
RCS file: /cvs/openafs/src/bozo/bosserver.c,v
retrieving revision 1.6
diff -u -r1.6 bosserver.c
--- bozo/bosserver.c	2001/03/05 19:13:24	1.6
+++ bozo/bosserver.c	2001/03/15 16:49:36
@@ -24,6 +24,7 @@
 #else
 #include <unistd.h>
 #include <netinet/in.h>
+#include <syslog.h>
 #endif /* AFS_NT40_ENV */
 #include <afs/cellconfig.h>
 #include <rx/rx.h>
@@ -55,6 +56,10 @@
 extern int rx_stackSize;    /* for rx_SetStackSize macro */
 
 int DoLogging = 0;
+int DoSyslog = 0;
+#ifndef AFS_NT40_EnV
+int DoSyslogFacility = LOG_DAEMON;
+#endif
 static afs_int32 nextRestart;
 static afs_int32 nextDay;
 
@@ -116,6 +121,19 @@
 	argv[i] = "-log";
 	i++;
     }
+#ifndef AFS_NT40_ENV
+    /* if syslog logging is on, pass "-syslog" to new bosserver */
+    if (DoSyslog) {
+		static char arg[40];
+		if ( DoSyslogFacility != LOG_DAEMON ) {
+			snprintf(arg, 40, "-syslog=%d", DoSyslogFacility);
+		} else {
+			strcpy(arg, "-syslog");
+		}
+		argv[i] = arg;
+		i++;
+    }
+#endif
 
     /* null-terminate argument list */
     argv[i] = NULL;
@@ -714,6 +732,16 @@
 	    /* set extra logging flag */
 	    DoLogging = 1;
 	}
+#ifndef AFS_NT40_ENV
+	else if (strcmp(argv[code], "-syslog")==0) {
+	    /* set syslog logging flag */
+	    DoSyslog = 1;
+	} 
+	else if (strncmp(argv[code], "-syslog=",8)==0) {
+		DoSyslog = 1;
+		DoSyslogFacility = atoi(argv[code]+8);
+	}
+#endif
 	else if (strcmp(argv[code], "-enable_peer_stats")==0) {
 	    rx_enablePeerRPCStats();
 	}
@@ -730,6 +758,9 @@
 	    /* hack to support help flag */
 
 	    printf("Usage: bosserver [-noauth] [-log] "
+#ifndef AFS_NT40_ENV
+			"[-syslog[=FACILITY]] "
+#endif
 		   /* "[-enable_peer_stats] [-enable_process_stats] " */
 		   "[-help]\n");
 	    fflush(stdout);
@@ -773,19 +804,27 @@
 #endif /* ! AFS_NT40_ENV */
 
     /* switch to logging information to the BosLog file */
-    strcpy(namebuf, AFSDIR_BOZLOG_FILE);
-    strcat(namebuf, ".old");
-    renamefile(AFSDIR_BOZLOG_FILE, namebuf);	/* try rename first */
-    bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
-    if (!bozo_logFile) {
-	printf("bosserver: can't initialize log file (%s).\n",
-	       AFSDIR_SERVER_BOZLOG_FILEPATH);
-	exit(1);
-    }
-
-    /* keep log closed normally, so can be removed */
+	if ( ! DoSyslog )
+	{
+	    strcpy(namebuf, AFSDIR_BOZLOG_FILE);
+	    strcat(namebuf, ".old");
+	    renamefile(AFSDIR_BOZLOG_FILE, namebuf);	/* try rename first */
+	    bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
+	    if (!bozo_logFile) {
+		printf("bosserver: can't initialize log file (%s).\n",
+		       AFSDIR_SERVER_BOZLOG_FILEPATH);
+		exit(1);
+  	    }
 
-    fclose(bozo_logFile);
+        /* keep log closed normally, so can be removed */
+        fclose(bozo_logFile);
+	}
+	else
+	{
+#ifndef AFS_NT40_ENV
+		openlog("bosserver", LOG_PID, DoSyslogFacility);
+#endif
+	}
 
     /* Write current state of directory permissions to log file */
     DirAccessOK ();
@@ -881,6 +920,15 @@
     char tdate[26];
     time_t myTime;
 
+	if ( DoSyslog )
+	{
+#ifndef AFS_NT40_ENV
+		syslog(LOG_INFO, a, b, c, d, e, f);
+#endif
+	}
+	else
+	{
+
     myTime = time(0);
     strcpy(tdate, ctime(&myTime));	/* copy out of static area asap */
     tdate[24] = ':';
@@ -907,4 +955,6 @@
     /* close so rm BosLog works */
 
     fclose(bozo_logFile);
+
+	}
 }

--a8Wt8u1KmwUX3Y2C--