From 829e484371a49b05707c31cd044d65e7d0bf76d5 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Thu, 7 Nov 2019 17:28:59 -0600 Subject: [PATCH] bozo: Use ViceLog-based logging Get rid of our custom bozo_Log() logging interface, and use the ViceLog/OpenLog logging function that the rest of the tree uses. This has a side effect of the log now staying open between logging messages. Previously, the log was open and closed every time we called bozo_Log(), so log rotations would take effect almost immediately. With this commit, we now reopen the log about every 5 minutes by BozoDaemon (BOZO_LOGOPEN_INT). Change-Id: I35545e4ac067a3339893d31e301e2cdfd5fefec0 Reviewed-on: https://gerrit.openafs.org/14582 Reviewed-by: Michael Meffie Tested-by: BuildBot Reviewed-by: Cheyenne Wills --- src/bozo/bnode.c | 67 +++++++-------- src/bozo/bosoprocs.c | 79 +++++++++--------- src/bozo/bosprototypes.h | 1 - src/bozo/bosserver.c | 170 ++++++++++++++------------------------- src/bozo/cronbnodeops.c | 18 ++--- src/bozo/ezbnodeops.c | 6 +- src/bozo/fsbnodeops.c | 82 +++++++++---------- 7 files changed, 188 insertions(+), 235 deletions(-) diff --git a/src/bozo/bnode.c b/src/bozo/bnode.c index 7214326a8e..0341911f5e 100644 --- a/src/bozo/bnode.c +++ b/src/bozo/bnode.c @@ -438,14 +438,14 @@ bnode_Create(char *atype, char *ainstance, struct bnode ** abp, char *ap1, if (notifier && strcmp(notifier, NONOTIFIER)) { /* construct local path from canonical (wire-format) path */ if (ConstructLocalBinPath(notifier, ¬ifierpath)) { - bozo_Log("BNODE-Create: Notifier program path invalid '%s'\n", - notifier); + ViceLog(0, ("BNODE-Create: Notifier program path invalid '%s'\n", + notifier)); return BZNOCREATE; } if (stat(notifierpath, &tstat)) { - bozo_Log("BNODE-Create: Notifier program '%s' not found\n", - notifierpath); + ViceLog(0, ("BNODE-Create: Notifier program '%s' not found\n", + notifierpath)); free(notifierpath); return BZNOCREATE; } @@ -722,11 +722,11 @@ bproc(void *unused) tb->errorSignal = 0; } if (tp->coreName) - bozo_Log("%s:%s exited with code %d\n", tb->name, - tp->coreName, tp->lastExit); + ViceLog(0, ("%s:%s exited with code %d\n", tb->name, + tp->coreName, tp->lastExit)); else - bozo_Log("%s exited with code %d\n", tb->name, - tp->lastExit); + ViceLog(0, ("%s exited with code %d\n", tb->name, + tp->lastExit)); } else { /* Signal occurred, perhaps spurious due to shutdown request. * If due to a shutdown request, don't overwrite last error @@ -742,22 +742,22 @@ bproc(void *unused) RememberProcName(tp); } if (tp->coreName) - bozo_Log("%s:%s exited on signal %d%s\n", - tb->name, tp->coreName, tp->lastSignal, - WCOREDUMP(status) ? " (core dumped)" : - ""); + ViceLog(0, ("%s:%s exited on signal %d%s\n", + tb->name, tp->coreName, tp->lastSignal, + WCOREDUMP(status) ? " (core dumped)" : + "")); else - bozo_Log("%s exited on signal %d%s\n", tb->name, - tp->lastSignal, - WCOREDUMP(status) ? " (core dumped)" : - ""); + ViceLog(0, ("%s exited on signal %d%s\n", tb->name, + tp->lastSignal, + WCOREDUMP(status) ? " (core dumped)" : + "")); SaveCore(tb, tp); } tb->lastAnyExit = FT_ApproxTime(); if (tb->notifier) { - bozo_Log("BNODE: Notifier %s will be called\n", - tb->notifier); + ViceLog(0, ("BNODE: Notifier %s will be called\n", + tb->notifier)); hdl_notifier(tp); } @@ -778,9 +778,9 @@ bproc(void *unused) } tb->flags |= BNODE_ERRORSTOP; bnode_SetGoal(tb, BSTAT_SHUTDOWN); - bozo_Log - ("BNODE '%s' repeatedly failed to start, perhaps missing executable.\n", - tb->name); + ViceLog(0, ("BNODE '%s' repeatedly failed to start, " + "perhaps missing executable.\n", + tb->name)); } BOP_PROCEXIT(tb, tp); bnode_Check(tb); @@ -844,8 +844,8 @@ hdl_notifier(struct bnode_proc *tp) BNODE_ASSERT_LOCK(); if (stat(tp->bnode->notifier, &tstat)) { - bozo_Log("BNODE: Failed to find notifier '%s'; ignored\n", - tp->bnode->notifier); + ViceLog(0, ("BNODE: Failed to find notifier '%s'; ignored\n", + tp->bnode->notifier)); return (1); } if ((pid = fork()) == 0) { @@ -863,21 +863,21 @@ hdl_notifier(struct bnode_proc *tp) #endif fout = popen(tb->notifier, "w"); if (fout == NULL) { - bozo_Log("BNODE: Failed to find notifier '%s'; ignored\n", - tb->notifier); + ViceLog(0, ("BNODE: Failed to find notifier '%s'; ignored\n", + tb->notifier)); perror(tb->notifier); exit(1); } if (SendNotifierData(fout, tp) != 0) - bozo_Log("BNODE: Failed to send notifier data to '%s'\n", - tb->notifier); + ViceLog(0, ("BNODE: Failed to send notifier data to '%s'\n", + tb->notifier)); if (pclose(fout) < 0) - bozo_Log("BNODE: Failed to close notifier pipe to '%s', %d\n", - tb->notifier, errno); + ViceLog(0, ("BNODE: Failed to close notifier pipe to '%s', %d\n", + tb->notifier, errno)); exit(0); } else if (pid < 0) { - bozo_Log("Failed to fork creating process to handle notifier '%s'\n", - tp->bnode->notifier); + ViceLog(0, ("Failed to fork creating process to handle notifier '%s'\n", + tp->bnode->notifier)); return -1; } #endif /* AFS_NT40_ENV */ @@ -1127,12 +1127,13 @@ bnode_NewProc(struct bnode *abnode, char *aexecString, char *coreName, osi_audit(BOSSpawnProcEvent, 0, AUD_STR, aexecString, AUD_END); if (cpid == (pid_t) - 1) { - bozo_Log("Failed to spawn process for bnode '%s'\n", abnode->name); + ViceLog(0, ("Failed to spawn process for bnode '%s'\n", abnode->name)); bnode_FreeTokens(tlist); free(tp); return errno; } - bozo_Log("%s started pid %ld: %s\n", abnode->name, cpid, aexecString); + ViceLog(0, ("%s started pid %d: %s\n", abnode->name, (int)cpid, + aexecString)); bnode_FreeTokens(tlist); opr_queue_Prepend(&allProcs, &tp->q); diff --git a/src/bozo/bosoprocs.c b/src/bozo/bosoprocs.c index 6c3508aadb..5ada424a11 100644 --- a/src/bozo/bosoprocs.c +++ b/src/bozo/bosoprocs.c @@ -80,7 +80,7 @@ SBOZO_SetRestartTime(struct rx_call *acall, afs_int32 atype, struct bozo_netKTim goto fail; } if (DoLogging) - bozo_Log("%s is executing SetRestartTime\n", caller); + ViceLog(0, ("%s is executing SetRestartTime\n", caller)); code = 0; /* assume success */ switch (atype) { @@ -125,7 +125,7 @@ SBOZO_Exec(struct rx_call *acall, char *acmd) goto fail; } if (DoLogging) - bozo_Log("%s is executing the shell command '%s'\n", caller, acmd); + ViceLog(0, ("%s is executing the shell command '%s'\n", caller, acmd)); /* should copy output to acall, but don't yet cause its hard */ /* hard... NOT! Nnow _at least_ return the exit status */ @@ -202,7 +202,7 @@ SBOZO_UnInstall(struct rx_call *acall, char *aname) } if (DoLogging) - bozo_Log("%s is executing UnInstall '%s'\n", caller, filepath); + ViceLog(0, ("%s is executing UnInstall '%s'\n", caller, filepath)); if (asprintf(&fpBak, "%s.BAK", filepath) < 0) { code = BZIO; @@ -323,7 +323,7 @@ SBOZO_Install(struct rx_call *acall, char *aname, afs_int32 asize, afs_int32 mod } if (DoLogging) - bozo_Log("%s is executing Install '%s'\n", caller, filepath); + ViceLog(0, ("%s is executing Install '%s'\n", caller, filepath)); /* open file */ fd = open(fpNew, O_CREAT | O_RDWR | O_TRUNC, 0777); @@ -402,7 +402,7 @@ SBOZO_SetCellName(struct rx_call *acall, char *aname) goto fail; } if (DoLogging) - bozo_Log("%s is executing SetCellName '%s'\n", caller, aname); + ViceLog(0, ("%s is executing SetCellName '%s'\n", caller, aname)); code = afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell, @@ -412,9 +412,9 @@ SBOZO_SetCellName(struct rx_call *acall, char *aname) /* Check that tcell has enough space for the new cellname. */ if (strlen(aname) > sizeof tcell.name - 1) { - bozo_Log + ViceLog(0, ("ERROR: SetCellName: cell name '%s' exceeds %ld bytes (cell name not changed)\n", - aname, (long)(sizeof tcell.name - 1)); + aname, (long)(sizeof tcell.name - 1))); code = BZDOM; goto fail; } @@ -499,7 +499,7 @@ SBOZO_DeleteCellHost(struct rx_call *acall, char *aname) goto fail; } if (DoLogging) - bozo_Log("%s is executing DeleteCellHost '%s'\n", caller, aname); + ViceLog(0, ("%s is executing DeleteCellHost '%s'\n", caller, aname)); code = afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell, @@ -548,7 +548,7 @@ SBOZO_AddCellHost(struct rx_call *acall, char *aname) goto fail; } if (DoLogging) - bozo_Log("%s is executing AddCellHost '%s'\n", caller, aname); + ViceLog(0, ("%s is executing AddCellHost '%s'\n", caller, aname)); code = afsconf_GetExtendedCellInfo(bozo_confdir, NULL, NULL, &tcell, @@ -582,19 +582,19 @@ SBOZO_AddCellHost(struct rx_call *acall, char *aname) */ if (tcell.numServers > sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]) { - bozo_Log + ViceLog(0, ("ERROR: AddCellHost: attempt to add more than %ld database servers (database server '%s' not added)\n", (long)(sizeof tcell.hostAddr / sizeof tcell.hostAddr[0]), - aname); + aname)); code = BZDOM; goto fail; } /* Check that tcell has enough space for the new hostname. */ if (strlen(aname) > sizeof tcell.hostName[0] - 1) { - bozo_Log + ViceLog(0, ("ERROR: AddCellHost: host name '%s' exceeds %ld bytes (not added)\n", - aname, (long)(sizeof tcell.hostName[0] - 1)); + aname, (long)(sizeof tcell.hostName[0] - 1))); code = BZDOM; goto fail; } @@ -628,7 +628,7 @@ SBOZO_ListKeys(struct rx_call *acall, afs_int32 an, afs_int32 *akvno, goto fail; } if (DoLogging) - bozo_Log("%s is executing ListKeys\n", caller); + ViceLog(0, ("%s is executing ListKeys\n", caller)); code = afsconf_GetKeys(bozo_confdir, &tkeys); if (code) @@ -688,7 +688,7 @@ SBOZO_AddKey(struct rx_call *acall, afs_int32 an, struct bozo_key *akey) goto fail; } if (DoLogging) - bozo_Log("%s is executing AddKey\n", caller); + ViceLog(0, ("%s is executing AddKey\n", caller)); code = afsconf_AddKey(bozo_confdir, an, akey->data, 0); if (code == AFSCONF_KEYINUSE) @@ -709,7 +709,7 @@ SBOZO_SetNoAuthFlag(struct rx_call *acall, afs_int32 aflag) goto fail; } if (DoLogging) - bozo_Log("%s is executing Set No Authentication\n", caller); + ViceLog(0, ("%s is executing Set No Authentication\n", caller)); afsconf_SetNoAuthFlag(bozo_confdir, aflag); @@ -729,7 +729,7 @@ SBOZO_DeleteKey(struct rx_call *acall, afs_int32 an) goto fail; } if (DoLogging) - bozo_Log("%s is executing DeleteKey\n", caller); + ViceLog(0, ("%s is executing DeleteKey\n", caller)); code = afsconf_DeleteKey(bozo_confdir, an); @@ -765,7 +765,7 @@ SBOZO_AddSUser(struct rx_call *acall, char *aname) goto fail; } if (DoLogging) - bozo_Log("%s is executing Add SuperUser '%s'\n", caller, aname); + ViceLog(0, ("%s is executing Add SuperUser '%s'\n", caller, aname)); code = afsconf_AddUser(bozo_confdir, aname); @@ -786,7 +786,7 @@ SBOZO_DeleteSUser(struct rx_call *acall, char *aname) } if (DoLogging) - bozo_Log("%s is executing Delete SuperUser '%s'\n", caller, aname); + ViceLog(0, ("%s is executing Delete SuperUser '%s'\n", caller, aname)); code = afsconf_DeleteUser(bozo_confdir, aname); @@ -852,7 +852,7 @@ SBOZO_WaitAll(struct rx_call *acall) } if (DoLogging) - bozo_Log("%s is executing Wait for All\n", caller); + ViceLog(0, ("%s is executing Wait for All\n", caller)); code = bnode_WaitAll(); @@ -879,7 +879,7 @@ SBOZO_DeleteBnode(struct rx_call *acall, char *ainstance) goto fail; } if (DoLogging) - bozo_Log("%s is executing DeleteBnode '%s'\n", caller, ainstance); + ViceLog(0, ("%s is executing DeleteBnode '%s'\n", caller, ainstance)); code = bnode_DeleteName(ainstance); @@ -940,7 +940,7 @@ SBOZO_ShutdownAll(struct rx_call *acall) goto fail; } if (DoLogging) - bozo_Log("%s is executing ShutdownAll\n", caller); + ViceLog(0, ("%s is executing ShutdownAll\n", caller)); code = bnode_ApplyInstance(sdproc, NULL); @@ -964,7 +964,7 @@ SBOZO_RestartAll(struct rx_call *acall) goto fail; } if (DoLogging) - bozo_Log("%s is executing RestartAll\n", caller); + ViceLog(0, ("%s is executing RestartAll\n", caller)); /* start shutdown of all processes */ code = bnode_ApplyInstance(sdproc, NULL); @@ -999,7 +999,7 @@ SBOZO_ReBozo(struct rx_call *acall) goto fail; } if (DoLogging) - bozo_Log("%s is executing ReBozo\n", caller); + ViceLog(0, ("%s is executing ReBozo\n", caller)); /* start shutdown of all processes */ code = bnode_ApplyInstance(sdproc, NULL); @@ -1047,7 +1047,7 @@ SBOZO_StartupAll(struct rx_call *acall) goto fail; } if (DoLogging) - bozo_Log("%s is executing StartupAll\n", caller); + ViceLog(0, ("%s is executing StartupAll\n", caller)); code = bnode_ApplyInstance(stproc, NULL); fail: @@ -1070,7 +1070,7 @@ SBOZO_Restart(struct rx_call *acall, char *ainstance) goto fail; } if (DoLogging) - bozo_Log("%s is executing Restart '%s'\n", caller, ainstance); + ViceLog(0, ("%s is executing Restart '%s'\n", caller, ainstance)); tb = bnode_FindInstance(ainstance); if (!tb) { @@ -1106,7 +1106,7 @@ SBOZO_SetTStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus) goto fail; } if (DoLogging) - bozo_Log("%s is executing SetTempStatus '%s'\n", caller, ainstance); + ViceLog(0, ("%s is executing SetTempStatus '%s'\n", caller, ainstance)); tb = bnode_FindInstance(ainstance); if (!tb) { @@ -1139,8 +1139,8 @@ SBOZO_SetStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus) goto fail; } if (DoLogging) - bozo_Log("%s is executing SetStatus '%s' (status = %d)\n", caller, - ainstance, astatus); + ViceLog(0, ("%s is executing SetStatus '%s' (status = %d)\n", caller, + ainstance, astatus)); tb = bnode_FindInstance(ainstance); if (!tb) { @@ -1232,7 +1232,7 @@ SBOZO_Prune(struct rx_call *acall, afs_int32 aflags) goto fail; } if (DoLogging) - bozo_Log("%s is executing Prune (flags=%d)\n", caller, aflags); + ViceLog(0, ("%s is executing Prune (flags=%d)\n", caller, aflags)); /* first scan AFS binary directory */ dirp = opendir(AFSDIR_SERVER_BIN_DIRPATH); @@ -1390,18 +1390,19 @@ DirAccessOK(void) for (i = 0; i < bozo_nbosEntryStats; i++) { struct bozo_bosEntryStats *e = &bozo_bosEntryStats[i]; if (!StatEachEntry(e)) { - bozo_Log("unhappy with %s which is a %s that should " + ViceLog(0, + ("unhappy with %s which is a %s that should " "have at least rights %o, at most rights %o %s\n", e->path, e->dir ? "dir" : "file", e->reqPerm, (~e->proPerm & 0777), - e->rootOwner ? ", owned by root" : ""); + e->rootOwner ? ", owned by root" : "")); result = 0; } } if (result != lastResult) { /* log changes */ - bozo_Log("Server directory access is %sokay\n", - (result ? "" : "not ")); + ViceLog(0, ("Server directory access is %sokay\n", + (result ? "" : "not "))); } lastResult = result; return lastResult; @@ -1518,7 +1519,7 @@ SBOZO_GetLog(struct rx_call *acall, char *aname) return BZNOENT; } if (DoLogging) - bozo_Log("%s is executing GetLog '%s'\n", caller, logpath); + ViceLog(0, ("%s is executing GetLog '%s'\n", caller, logpath)); tfile = fopen(logpath, "r"); free(logpath); @@ -1632,9 +1633,9 @@ bozo_ShutdownAndExit(void *param) BNODE_LOCK(); - bozo_Log + ViceLog(0, ("Shutdown of BOS server and processes in response to signal %d\n", - asignal); + asignal)); /* start shutdown of all processes */ if ((code = bnode_ApplyInstance(sdproc, NULL)) == 0) { @@ -1643,8 +1644,8 @@ bozo_ShutdownAndExit(void *param) } if (code) { - bozo_Log("Shutdown incomplete (code = %d); manual cleanup required\n", - code); + ViceLog(0, ("Shutdown incomplete (code = %d); manual cleanup required\n", + code)); } BNODE_UNLOCK(); diff --git a/src/bozo/bosprototypes.h b/src/bozo/bosprototypes.h index 4d6e64fce9..d8323da65c 100644 --- a/src/bozo/bosprototypes.h +++ b/src/bozo/bosprototypes.h @@ -38,7 +38,6 @@ int bnode_NewProc(struct bnode *abnode, char *aexecString, char *coreName, int bnode_StopProc(struct bnode_proc *aproc, int asignal); /* bosserver.c */ -void bozo_Log(const char *format, ... ); int bozo_ReBozo(void); int WriteBozoFile(char *aname); int bozo_CreatePidFile(char *ainst, char *aname, pid_t apid); diff --git a/src/bozo/bosserver.c b/src/bozo/bosserver.c index e675e0a099..4d1b52dcb4 100644 --- a/src/bozo/bosserver.c +++ b/src/bozo/bosserver.c @@ -73,11 +73,6 @@ const char *bozo_fileName; /* Protects the entire bnode subsystem. */ opr_mutex_t bnode_glock; -#ifdef AFS_PTHREAD_ENV -/* Protects writing to the log file. */ -static opr_mutex_t bozo_logLock; -#endif - #ifndef AFS_NT40_ENV static int bozo_argc = 0; static char** bozo_argv = NULL; @@ -87,9 +82,6 @@ char *DoCore; int DoLogging = 0; int DoSyslog = 0; char *DoPidFiles = NULL; -#ifndef AFS_NT40_ENV -int DoSyslogFacility = LOG_DAEMON; -#endif int DoTransarcLogs = 0; struct ktime bozo_nextRestartKT, bozo_nextDayKT; @@ -145,8 +137,8 @@ bozo_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell) code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell); if (code) { - bozo_Log("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n", - code, name, inst, cell); + ViceLog(0, ("Failed local realm check; code=%d, name=%s, inst=%s, cell=%s\n", + code, name, inst, cell)); } return islocal; } @@ -621,7 +613,8 @@ bdrestart(struct bnode *abnode, void *arock) return 0; /* keep trying all bnodes */ } -#define BOZO_MINSKIP 3600 /* minimum to advance clock */ +#define BOZO_MINSKIP 3600 /* minimum to advance clock */ +#define BOZO_LOGOPEN_INT 300 /* reopen our log file every 5 minutes */ /* lwp to handle system restarts */ static void * BozoDaemon(void *unused) @@ -629,6 +622,7 @@ BozoDaemon(void *unused) afs_int32 now; afs_int32 nextRestart = 0; afs_int32 nextDay = 0; + afs_int32 last_reopen = FT_ApproxTime(); while (1) { #ifdef AFS_PTHREAD_ENV @@ -642,7 +636,7 @@ BozoDaemon(void *unused) now = FT_ApproxTime(); if (rx_atomic_read(&bozo_restricted_disabled)) { - bozo_Log("Restricted mode disabled by signal\n"); + ViceLog(0, ("Restricted mode disabled by signal\n")); rx_atomic_set(&bozo_restricted_disabled, 0); } @@ -668,6 +662,12 @@ BozoDaemon(void *unused) } BNODE_UNLOCK(); + + if (now < last_reopen || now - last_reopen >= BOZO_LOGOPEN_INT) { + /* Reopen logs to allow for log rotation. */ + last_reopen = now; + ReOpenLog(); + } } AFS_UNREACHED(return(NULL)); } @@ -714,12 +714,13 @@ make_pid_filename(char *ainst, char *aname) if (aname && *aname) { r = asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname); if (r < 0 || buffer == NULL) - bozo_Log("Failed to alloc pid filename buffer for %s.%s.\n", - ainst, aname); + ViceLog(0, ("Failed to alloc pid filename buffer for %s.%s.\n", + ainst, aname)); } else { r = asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst); if (r < 0 || buffer == NULL) - bozo_Log("Failed to alloc pid filename buffer for %s.\n", ainst); + ViceLog(0, ("Failed to alloc pid filename buffer for %s.\n", + ainst)); } return buffer; @@ -746,7 +747,7 @@ bozo_CreatePidFile(char *ainst, char *aname, pid_t apid) return ENOMEM; } if ((fp = fopen(pidfile, "w")) == NULL) { - bozo_Log("Failed to open pidfile %s; errno=%d\n", pidfile, errno); + ViceLog(0, ("Failed to open pidfile %s; errno=%d\n", pidfile, errno)); free(pidfile); return errno; } @@ -794,10 +795,10 @@ bozo_CreateRxBindFile(afs_uint32 host) FILE *fp; afs_inet_ntoa_r(host, buffer); - bozo_Log("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT); + ViceLog(0, ("Listening on %s:%d\n", buffer, AFSCONF_NANNYPORT)); if ((fp = fopen(AFSDIR_SERVER_BOZRXBIND_FILEPATH, "w")) == NULL) { - bozo_Log("Unable to open rxbind address file: %s, code=%d\n", - AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno); + ViceLog(0, ("Unable to open rxbind address file: %s, code=%d\n", + AFSDIR_SERVER_BOZRXBIND_FILEPATH, errno)); } else { /* If listening on any interface, write the loopback interface to the rxbind file to give local scripts a usable addresss. */ @@ -851,24 +852,24 @@ CreateLocalCellConfig(void) tcell.numServers = 1; code = gethostname(tcell.hostName[0], MAXHOSTCHARS); if (code) { - bozo_Log("failed to get hostname, code %d\n", errno); + ViceLog(0, ("failed to get hostname, code %d\n", errno)); exit(1); } if (tcell.hostName[0][0] == 0) { - bozo_Log("host name not set, can't start\n"); - bozo_Log("try the 'hostname' command\n"); + ViceLog(0, ("host name not set, can't start\n")); + ViceLog(0, ("try the 'hostname' command\n")); exit(1); } code = afsconf_SetCellInfo(NULL, AFSDIR_SERVER_ETC_DIRPATH, &tcell); if (code) { - bozo_Log + ViceLog(0, ("could not create cell database in '%s' (code %d), quitting\n", - AFSDIR_SERVER_ETC_DIRPATH, code); + AFSDIR_SERVER_ETC_DIRPATH, code)); exit(1); } tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH); if (!tdir) { - bozo_Log("failed to open newly-created cell database, quitting\n"); + ViceLog(0, ("failed to open newly-created cell database, quitting\n")); exit(1); } return tdir; @@ -902,13 +903,12 @@ int main(int argc, char **argv, char **envp) { struct cmd_syndesc *opts; - + struct logOptions logopts; struct rx_service *tservice; afs_int32 code; struct afsconf_dir *tdir; int noAuth = 0; int i; - char *oldlog; int rxMaxMTU = -1; afs_uint32 host = htonl(INADDR_ANY); char *auditIface = NULL; @@ -917,7 +917,6 @@ main(int argc, char **argv, char **envp) afs_int32 numClasses; int DoPeerRPCStats = 0; int DoProcessRPCStats = 0; - struct stat sb; struct afsconf_bsso_info bsso; int restricted = 0; #ifdef AFS_PTHREAD_ENV @@ -951,6 +950,7 @@ main(int argc, char **argv, char **envp) sigaction(SIGABRT, &nsa, NULL); #endif osi_audit_init(); + memset(&logopts, 0, sizeof(logopts)); memset(&bsso, 0, sizeof(bsso)); @@ -963,7 +963,6 @@ main(int argc, char **argv, char **envp) } #endif - opr_mutex_init(&bozo_logLock); opr_mutex_init(&bnode_glock); /* Initialize dirpaths */ @@ -1096,11 +1095,20 @@ main(int argc, char **argv, char **envp) cmd_OptionAsList(opts, OPT_auditlog, &auditLogList); cmd_OptionAsFlag(opts, OPT_transarc_logs, &DoTransarcLogs); + if (DoTransarcLogs) { + logopts.lopt_rotateOnOpen = 1; + logopts.lopt_rotateStyle = logRotate_old; + } #ifndef AFS_NT40_ENV if (cmd_OptionPresent(opts, OPT_syslog)) { DoSyslog = 1; - cmd_OptionAsInt(opts, OPT_syslog, &DoSyslogFacility); + + logopts.lopt_dest = logDest_syslog; + logopts.lopt_facility = LOG_DAEMON; + logopts.lopt_tag = "bosserver"; + + cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility); } #endif @@ -1128,30 +1136,14 @@ main(int argc, char **argv, char **envp) } if (!DoSyslog) { - FILE *bozo_logFile; - /* Support logging to named pipes by not renaming. */ - if (DoTransarcLogs - && (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); - } - bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "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 */ - fclose(bozo_logFile); - } else { -#ifndef AFS_NT40_ENV - openlog("bosserver", LOG_PID, DoSyslogFacility); -#endif + logopts.lopt_dest = logDest_file; + logopts.lopt_filename = AFSDIR_SERVER_BOZLOG_FILEPATH; + } + + code = OpenLog(&logopts); + if (code != 0) { + printf("bosserver: can't initialize logs.\n"); + exit(1); } /* @@ -1226,25 +1218,26 @@ main(int argc, char **argv, char **envp) rlp.rlim_max = rlp.rlim_cur = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &rlp); getrlimit(RLIMIT_CORE, &rlp); - bozo_Log("Core limits now %d %d\n",(int)rlp.rlim_cur,(int)rlp.rlim_max); + ViceLog(0, ("Core limits now %d %d\n", + (int)rlp.rlim_cur,(int)rlp.rlim_max)); } #endif /* Read init file, starting up programs. Also starts watcher threads. */ if ((code = ReadBozoFile(0))) { - bozo_Log + ViceLog(0, ("bosserver: Something is wrong (%d) with the bos configuration file %s; aborting\n", - code, AFSDIR_SERVER_BOZCONF_FILEPATH); + code, AFSDIR_SERVER_BOZCONF_FILEPATH)); exit(code); } if (bozo_IsRestricted()) { - bozo_Log("NOTICE: bosserver is running in restricted mode.\n"); + ViceLog(0, ("NOTICE: bosserver is running in restricted mode.\n")); } else { - bozo_Log("WARNING: bosserver is not running in restricted mode.\n"); - bozo_Log("WARNING: Superusers have unrestricted access to this host via bos.\n"); - bozo_Log("WARNING: Use 'bos setrestricted' or restart with the -restricted option\n"); - bozo_Log("WARNING: to enable restricted mode.\n"); + ViceLog(0, ("WARNING: bosserver is not running in restricted mode.\n")); + ViceLog(0, ("WARNING: Superusers have unrestricted access to this host via bos.\n")); + ViceLog(0, ("WARNING: Use 'bos setrestricted' or restart with the -restricted option\n")); + ViceLog(0, ("WARNING: to enable restricted mode.\n")); } if (rxBind) { @@ -1253,13 +1246,13 @@ main(int argc, char **argv, char **envp) for (i = 0; i < 10; i++) { code = rx_InitHost(host, htons(AFSCONF_NANNYPORT)); if (code) { - bozo_Log("can't initialize rx: code=%d\n", code); + ViceLog(0, ("can't initialize rx: code=%d\n", code)); sleep(3); } else break; } if (i >= 10) { - bozo_Log("Bos giving up, can't initialize rx\n"); + ViceLog(0, ("Bos giving up, can't initialize rx\n")); exit(code); } @@ -1274,7 +1267,7 @@ main(int argc, char **argv, char **envp) if (rxMaxMTU != -1) { if (rx_SetMaxMTU(rxMaxMTU) != 0) { - bozo_Log("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU); + ViceLog(0, ("bosserver: rxMaxMTU %d is invalid\n", rxMaxMTU)); exit(1); } } @@ -1289,7 +1282,7 @@ main(int argc, char **argv, char **envp) /* param */ NULL , "bozo-the-clown", &bozo_pid); #endif if (code) { - bozo_Log("Failed to create daemon thread\n"); + ViceLog(0, ("Failed to create daemon thread\n")); exit(1); } @@ -1307,7 +1300,7 @@ main(int argc, char **argv, char **envp) afsconf_SetNoAuthFlag(tdir, noAuth); bsso.dir = tdir; - bsso.logger = bozo_Log; + bsso.logger = FSLog; afsconf_BuildServerSecurityObjects_int(&bsso, &securityClasses, &numClasses); if (DoPidFiles) { @@ -1326,7 +1319,7 @@ main(int argc, char **argv, char **envp) code = rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS, (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK); if (code) { - bozo_Log("Failed to allow dotted principals: code %d\n", code); + ViceLog(0, ("Failed to allow dotted principals: code %d\n", code)); exit(1); } } @@ -1339,44 +1332,3 @@ main(int argc, char **argv, char **envp) rx_StartServer(1); /* donate this process */ return 0; } - -void -bozo_Log(const char *format, ...) -{ - char tdate[27]; - time_t myTime; - va_list ap; - - va_start(ap, format); - - if (DoSyslog) { -#ifndef AFS_NT40_ENV - vsyslog(LOG_INFO, format, ap); -#endif - } else { - FILE *bozo_logFile; - opr_mutex_enter(&bozo_logLock); - myTime = time(0); - strcpy(tdate, ctime(&myTime)); /* copy out of static area asap */ - tdate[24] = ':'; - - /* log normally closed, so can be removed */ - - bozo_logFile = fopen(AFSDIR_SERVER_BOZLOG_FILEPATH, "a"); - if (bozo_logFile == NULL) { - printf("bosserver: WARNING: problem with %s\n", - AFSDIR_SERVER_BOZLOG_FILEPATH); - printf("%s ", tdate); - vprintf(format, ap); - fflush(stdout); - } else { - fprintf(bozo_logFile, "%s ", tdate); - vfprintf(bozo_logFile, format, ap); - - /* close so rm BosLog works */ - fclose(bozo_logFile); - } - opr_mutex_exit(&bozo_logLock); - } - va_end(ap); -} diff --git a/src/bozo/cronbnodeops.c b/src/bozo/cronbnodeops.c index 7a76e51743..1752bd9ba2 100644 --- a/src/bozo/cronbnodeops.c +++ b/src/bozo/cronbnodeops.c @@ -111,8 +111,8 @@ ScheduleCronBnode(struct cronbnode *abnode) abnode->lastStart = FT_ApproxTime(); code = bnode_NewProc((struct bnode *)abnode, abnode->command, NULL, &tp); if (code) { - bozo_Log("cron bnode %s failed to start (code %d)\n", - abnode->b.name, code); + ViceLog(0, ("cron bnode %s failed to start (code %d)\n", + abnode->b.name, code)); return code; } abnode->everRun = 1; @@ -159,7 +159,7 @@ cron_create(char *ainstance, char *acommand, char *awhen, /* construct local path from canonical (wire-format) path */ if (ConstructLocalBinPath(acommand, &cmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", acommand); + ViceLog(0, ("BNODE: command path invalid '%s'\n", acommand)); return NULL; } @@ -195,8 +195,8 @@ cron_timeout(struct bnode *bn) bnode_SetTimeout((struct bnode *)abnode, 0); code = bnode_NewProc((struct bnode *)abnode, abnode->command, NULL, &tp); if (code) { - bozo_Log("cron failed to start bnode %s (code %d)\n", - abnode->b.name, code); + ViceLog(0, ("cron failed to start bnode %s (code %d)\n", + abnode->b.name, code)); return code; } abnode->everRun = 1; @@ -284,11 +284,11 @@ cron_procexit(struct bnode *bn, struct bnode_proc *aproc) /* log interesting errors for folks */ if (aproc->lastSignal) - bozo_Log("cron job %s exited due to signal %d\n", abnode->b.name, - aproc->lastSignal); + ViceLog(0, ("cron job %s exited due to signal %d\n", abnode->b.name, + aproc->lastSignal)); else if (aproc->lastExit) - bozo_Log("cron job %s exited with non-zero code %d\n", abnode->b.name, - aproc->lastExit); + ViceLog(0, ("cron job %s exited with non-zero code %d\n", + abnode->b.name, aproc->lastExit)); abnode->waitingForShutdown = 0; abnode->running = 0; diff --git a/src/bozo/ezbnodeops.c b/src/bozo/ezbnodeops.c index 6046b450a5..87a64aebb5 100644 --- a/src/bozo/ezbnodeops.c +++ b/src/bozo/ezbnodeops.c @@ -110,7 +110,7 @@ ez_create(char *ainstance, char *acommand, char *unused1, char *unused2, char *cmdpath; if (ConstructLocalBinPath(acommand, &cmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", acommand); + ViceLog(0, ("BNODE: command path invalid '%s'\n", acommand)); return NULL; } @@ -226,8 +226,8 @@ ez_procexit(struct bnode *bn, struct bnode_proc *aproc) if (abnode->b.goal) code = ez_setstat((struct bnode *) abnode, BSTAT_NORMAL); else if (abnode->b.flags & BNODE_ERRORSTOP && abnode->b.errorStopDelay) { - bozo_Log("%s will retry start in %d seconds\n", abnode->b.name, - abnode->b.errorStopDelay); + ViceLog(0, ("%s will retry start in %d seconds\n", abnode->b.name, + abnode->b.errorStopDelay)); bnode_SetTimeout(bn, abnode->b.errorStopDelay); } return code; diff --git a/src/bozo/fsbnodeops.c b/src/bozo/fsbnodeops.c index c6bcef9c61..8e1c15e6be 100644 --- a/src/bozo/fsbnodeops.c +++ b/src/bozo/fsbnodeops.c @@ -420,24 +420,24 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd, /* construct local paths from canonical (wire-format) paths */ if (ConstructLocalBinPath(afilecmd, &fileCmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", afilecmd); + ViceLog(0, ("BNODE: command path invalid '%s'\n", afilecmd)); bailout = 1; goto done; } if (ConstructLocalBinPath(avolcmd, &volCmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", avolcmd); + ViceLog(0, ("BNODE: command path invalid '%s'\n", avolcmd)); bailout = 1; goto done; } if (ConstructLocalBinPath(asalcmd, &salCmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", asalcmd); + ViceLog(0, ("BNODE: command path invalid '%s'\n", asalcmd)); bailout = 1; goto done; } if (ascancmd && strlen(ascancmd)) { if (ConstructLocalBinPath(ascancmd, &scanCmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", ascancmd); + ViceLog(0, ("BNODE: command path invalid '%s'\n", ascancmd)); bailout = 1; goto done; } @@ -446,12 +446,12 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd, if (!bailout) { cmdname = PathToExecutable(fileCmdpath); if (cmdname == NULL) { - bozo_Log("Out of memory constructing binary filename\n"); + ViceLog(0, ("Out of memory constructing binary filename\n")); bailout = 1; goto done; } if (stat(cmdname, &tstat)) { - bozo_Log("BNODE: file server binary '%s' not found\n", cmdname); + ViceLog(0, ("BNODE: file server binary '%s' not found\n", cmdname)); bailout = 1; goto done; } @@ -459,12 +459,12 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd, cmdname = PathToExecutable(volCmdpath); if (cmdname == NULL) { - bozo_Log("Out of memory constructing binary filename\n"); + ViceLog(0, ("Out of memory constructing binary filename\n")); bailout = 1; goto done; } if (stat(cmdname, &tstat)) { - bozo_Log("BNODE: volume server binary '%s' not found\n", cmdname); + ViceLog(0, ("BNODE: volume server binary '%s' not found\n", cmdname)); bailout = 1; goto done; } @@ -472,12 +472,12 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd, cmdname = PathToExecutable(salCmdpath); if (cmdname == NULL) { - bozo_Log("Out of memory constructing binary filename\n"); + ViceLog(0, ("Out of memory constructing binary filename\n")); bailout = 1; goto done; } if (stat(cmdname, &tstat)) { - bozo_Log("BNODE: salvager binary '%s' not found\n", cmdname); + ViceLog(0, ("BNODE: salvager binary '%s' not found\n", cmdname)); bailout = 1; goto done; } @@ -486,12 +486,12 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd, free(cmdname); cmdname = PathToExecutable(scanCmdpath); if (cmdname == NULL) { - bozo_Log("Out of memory constructing binary filename\n"); + ViceLog(0, ("Out of memory constructing binary filename\n")); bailout = 1; goto done; } if (stat(cmdname, &tstat)) { - bozo_Log("BNODE: scanner binary '%s' not found\n", cmdname); + ViceLog(0, ("BNODE: scanner binary '%s' not found\n", cmdname)); bailout = 1; goto done; } @@ -555,29 +555,29 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd, /* construct local paths from canonical (wire-format) paths */ if (ConstructLocalBinPath(afilecmd, &fileCmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", afilecmd); + ViceLog(0, ("BNODE: command path invalid '%s'\n", afilecmd)); bailout = 1; goto done; } if (ConstructLocalBinPath(avolcmd, &volCmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", avolcmd); + ViceLog(0, ("BNODE: command path invalid '%s'\n", avolcmd)); bailout = 1; goto done; } if (ConstructLocalBinPath(asalsrvcmd, &salsrvCmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", asalsrvcmd); + ViceLog(0, ("BNODE: command path invalid '%s'\n", asalsrvcmd)); bailout = 1; goto done; } if (ConstructLocalBinPath(asalcmd, &salCmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", asalcmd); + ViceLog(0, ("BNODE: command path invalid '%s'\n", asalcmd)); bailout = 1; goto done; } if (ascancmd && strlen(ascancmd)) { if (ConstructLocalBinPath(ascancmd, &scanCmdpath)) { - bozo_Log("BNODE: command path invalid '%s'\n", ascancmd); + ViceLog(0, ("BNODE: command path invalid '%s'\n", ascancmd)); bailout = 1; goto done; } @@ -586,12 +586,12 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd, if (!bailout) { cmdname = PathToExecutable(fileCmdpath); if (cmdname == NULL) { - bozo_Log("Out of memory constructing binary filename\n"); + ViceLog(0, ("Out of memory constructing binary filename\n")); bailout = 1; goto done; } if (stat(cmdname, &tstat)) { - bozo_Log("BNODE: file server binary '%s' not found\n", cmdname); + ViceLog(0, ("BNODE: file server binary '%s' not found\n", cmdname)); bailout = 1; goto done; } @@ -599,12 +599,12 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd, cmdname = PathToExecutable(volCmdpath); if (cmdname == NULL) { - bozo_Log("Out of memory constructing binary filename\n"); + ViceLog(0, ("Out of memory constructing binary filename\n")); bailout = 1; goto done; } if (stat(cmdname, &tstat)) { - bozo_Log("BNODE: volume server binary '%s' not found\n", cmdname); + ViceLog(0, ("BNODE: volume server binary '%s' not found\n", cmdname)); bailout = 1; goto done; } @@ -612,12 +612,12 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd, cmdname = PathToExecutable(salsrvCmdpath); if (cmdname == NULL) { - bozo_Log("Out of memory constructing binary filename\n"); + ViceLog(0, ("Out of memory constructing binary filename\n")); bailout = 1; goto done; } if (stat(cmdname, &tstat)) { - bozo_Log("BNODE: salvageserver binary '%s' not found\n", cmdname); + ViceLog(0, ("BNODE: salvageserver binary '%s' not found\n", cmdname)); bailout = 1; goto done; } @@ -625,12 +625,12 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd, cmdname = PathToExecutable(salCmdpath); if (cmdname == NULL) { - bozo_Log("Out of memory constructing binary filename\n"); + ViceLog(0, ("Out of memory constructing binary filename\n")); bailout = 1; goto done; } if (stat(cmdname, &tstat)) { - bozo_Log("BNODE: salvager binary '%s' not found\n", cmdname); + ViceLog(0, ("BNODE: salvager binary '%s' not found\n", cmdname)); bailout = 1; goto done; } @@ -639,12 +639,12 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd, free(cmdname); cmdname = PathToExecutable(scanCmdpath); if (cmdname == NULL) { - bozo_Log("Out of memory constructing binary filename\n"); + ViceLog(0, ("Out of memory constructing binary filename\n")); bailout = 1; goto done; } if (stat(cmdname, &tstat)) { - bozo_Log("BNODE: scanner binary '%s' not found\n", cmdname); + ViceLog(0, ("BNODE: scanner binary '%s' not found\n", cmdname)); bailout = 1; goto done; } @@ -708,45 +708,45 @@ fs_timeout(struct bnode *bn) if (!abnode->volKillSent && now - abnode->timeSDStarted > SDTIME) { bnode_StopProc(abnode->volProc, SIGKILL); abnode->volKillSent = 1; - bozo_Log + ViceLog(0, ("bos shutdown: volserver failed to shutdown within %d seconds\n", - SDTIME); + SDTIME)); } } if (abnode->salSDW) { if (!abnode->salKillSent && now - abnode->timeSDStarted > SDTIME) { bnode_StopProc(abnode->salProc, SIGKILL); abnode->salKillSent = 1; - bozo_Log + ViceLog(0, ("bos shutdown: salvager failed to shutdown within %d seconds\n", - SDTIME); + SDTIME)); } } if (abnode->fileSDW) { if (!abnode->fileKillSent && now - abnode->timeSDStarted > FSSDTIME) { bnode_StopProc(abnode->fileProc, SIGKILL); abnode->fileKillSent = 1; - bozo_Log + ViceLog(0, ("bos shutdown: fileserver failed to shutdown within %d seconds\n", - FSSDTIME); + FSSDTIME)); } } if (abnode->salsrvSDW) { if (!abnode->salsrvKillSent && now - abnode->timeSDStarted > SDTIME) { bnode_StopProc(abnode->salsrvProc, SIGKILL); abnode->salsrvKillSent = 1; - bozo_Log + ViceLog(0, ("bos shutdown: salvageserver failed to shutdown within %d seconds\n", - SDTIME); + SDTIME)); } } if (abnode->scanSDW) { if (!abnode->scanKillSent && now - abnode->timeSDStarted > SDTIME) { bnode_StopProc(abnode->scanProc, SIGKILL); abnode->scanKillSent = 1; - bozo_Log + ViceLog(0, ("bos shutdown: scanner failed to shutdown within %d seconds\n", - SDTIME); + SDTIME)); } } @@ -882,8 +882,8 @@ SetNeedsClock(struct fsbnode *ab) } else if ((ab->b.goal == 0) && !ab->fileRunning && !ab->volRunning && !ab->salRunning && !ab->scanRunning && !ab->salsrvRunning) { if (ab->b.flags & BNODE_ERRORSTOP && ab->b.errorStopDelay) { - bozo_Log("%s will retry start in %d seconds\n", ab->b.name, - ab->b.errorStopDelay); + ViceLog(0, ("%s will retry start in %d seconds\n", ab->b.name, + ab->b.errorStopDelay)); ab->needsClock = 1; /* halted for errors, retry later */ timeout = ab->b.errorStopDelay; } else { @@ -913,8 +913,8 @@ NudgeProcs(struct fsbnode *abnode) * tells us if we need to run the salvager or not */ if (abnode->fileRunning) { if (abnode->salRunning) { - bozo_Log("Salvager running along with file server!\n"); - bozo_Log("Emergency shutdown\n"); + ViceLog(0, ("Salvager running along with file server!\n")); + ViceLog(0, ("Emergency shutdown\n")); emergency = 1; bnode_SetGoal(fsbnode2bnode(abnode), BSTAT_SHUTDOWN); bnode_StopProc(abnode->salProc, SIGKILL);