bozo: use the full path when renaming BosLog to BosLog.old

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>
This commit is contained in:
Michael Meffie 2015-01-21 14:31:51 -05:00 committed by Benjamin Kaduk
parent df05a15ce3
commit 05e7c2f2fb

View 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();