bozo: create a syslog connection only if the -syslog option is given
authorMichael Meffie <mmeffie@sinenomine.net>
Wed, 21 Jan 2015 19:42:47 +0000 (14:42 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Wed, 18 Nov 2015 05:03:58 +0000 (00:03 -0500)
Fix a minor bug in which an unnecessary syslog connection is opened when
the BosLog is not present (typically, the first time the bosserver is
started) or when the BosLog is a named pipe, even if the -syslog option
was not given.

This bug was introduced in commit bdc7e43117706d0aa46d3b6435489e9d4c2b0888,
which added checks to avoid renaming logs when they are named pipes.

lstat() and S_ISFIFO are provided by libroken, so do not need to be hidden
behind conditional compilation.

Change-Id: I828534be69949fe017cc7dbed1b6798aa4c0ba17
Reviewed-on: http://gerrit.openafs.org/11686
Reviewed-by: Perry Ruiter <pruiter@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/bozo/bosserver.c

index 76f866a..f3be7aa 100644 (file)
@@ -857,9 +857,9 @@ main(int argc, char **argv, char **envp)
     afs_int32 numClasses;
     int DoPeerRPCStats = 0;
     int DoProcessRPCStats = 0;
+    struct stat sb;
 #ifndef AFS_NT40_ENV
     int nofork = 0;
-    struct stat sb;
 #endif
 #ifdef AFS_AIX32_ENV
     struct sigaction nsa;
@@ -1045,18 +1045,17 @@ main(int argc, char **argv, char **envp)
        exit(1);
     }
 
-    if ((!DoSyslog)
-#ifndef AFS_NT40_ENV
-       && ((lstat(AFSDIR_SERVER_BOZLOG_FILEPATH, &sb) == 0) &&
-       !(S_ISFIFO(sb.st_mode)))
-#endif
-       ) {
-       if (asprintf(&oldlog, "%s.old", AFSDIR_SERVER_BOZLOG_FILEPATH) < 0) {
-           printf("bosserver: out of memory\n");
-           exit(1);
+    if (!DoSyslog) {
+       /* Support logging to named pipes by not renaming. */
+       if ((lstat(AFSDIR_SERVER_BOZLOG_FILEPATH, &sb) == 0)
+           && !(S_ISFIFO(sb.st_mode))) {
+           if (asprintf(&oldlog, "%s.old", AFSDIR_SERVER_BOZLOG_FILEPATH) < 0) {
+               printf("bosserver: out of memory\n");
+               exit(1);
+           }
+           rk_rename(AFSDIR_SERVER_BOZLOG_FILEPATH, oldlog);
+           free(oldlog);
        }
-       rk_rename(AFSDIR_SERVER_BOZLOG_FILEPATH, oldlog);       /* try rename first */
-       free(oldlog);
        bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
        if (!bozo_logFile) {
            printf("bosserver: can't initialize log file (%s).\n",