bozo: use the full path when renaming BosLog to BosLog.old
authorMichael Meffie <mmeffie@sinenomine.net>
Wed, 21 Jan 2015 19:31:51 +0000 (14:31 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 28 Aug 2015 01:34:20 +0000 (21:34 -0400)
Use the full path when renaming the BosLog file to BosLog.old and when
checking whether the BosLog file can be opened, otherwise the rename
will fail (and go unnoticed), and the initial BosLog check opens a
handle to a file in the wrong directory.

Create the server directories, including the logs directory, before
forking and log file initialization.

Change-Id: I3733d64335f348190572f6278086b634641f2754
Reviewed-on: http://gerrit.openafs.org/11685
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams <3chas3@gmail.com>
Reviewed-by: Perry Ruiter <pruiter@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/bozo/bosserver.c

index 9f5b74e..19db559 100644 (file)
@@ -976,19 +976,26 @@ main(int argc, char **argv, char **envp)
     }
 #endif
 
+    /* create useful dirs */
+    i = CreateDirs(DoCore);
+    if (i) {
+       printf("bosserver: could not set up directories, code %d\n", i);
+       exit(1);
+    }
+
     if ((!DoSyslog)
 #ifndef AFS_NT40_ENV
-       && ((lstat(AFSDIR_BOZLOG_FILE, &sb) == 0) &&
+       && ((lstat(AFSDIR_SERVER_BOZLOG_FILEPATH, &sb) == 0) &&
        !(S_ISFIFO(sb.st_mode)))
 #endif
        ) {
-       if (asprintf(&oldlog, "%s.old", AFSDIR_BOZLOG_FILE) < 0) {
+       if (asprintf(&oldlog, "%s.old", AFSDIR_SERVER_BOZLOG_FILEPATH) < 0) {
            printf("bosserver: out of memory\n");
            exit(1);
        }
-       rk_rename(AFSDIR_BOZLOG_FILE, oldlog);  /* try rename first */
+       rk_rename(AFSDIR_SERVER_BOZLOG_FILEPATH, oldlog);       /* try rename first */
        free(oldlog);
-       bozo_logFile = fopen(AFSDIR_BOZLOG_FILE, "a");
+       bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a");
        if (!bozo_logFile) {
            printf("bosserver: can't initialize log file (%s).\n",
                   AFSDIR_SERVER_BOZLOG_FILEPATH);
@@ -1014,13 +1021,6 @@ main(int argc, char **argv, char **envp)
     }
 #endif /* ! AFS_NT40_ENV */
 
-    /* create useful dirs */
-    i = CreateDirs(DoCore);
-    if (i) {
-       printf("bosserver: could not set up directories, code %d\n", i);
-       exit(1);
-    }
-
     /* Write current state of directory permissions to log file */
     DirAccessOK();