]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Remove server logging globals
authorMichael Meffie <mmeffie@sinenomine.net>
Wed, 6 Jan 2016 22:06:54 +0000 (17:06 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Mon, 25 Apr 2016 04:47:15 +0000 (00:47 -0400)
Remove the global variables used to setup server logging and replace
with an argument to OpenLog.

Keep the LogLevel variable as a global for use by the logging macros,
but provide an inline function for applications which check the log
level to dump more information when the log level is increased.

Provide consistency by adding syslog tags to processes that did not
previously set one (salvageserver, salvager, and volserver).

[kaduk@mit.edu: update commit message, use old-style log rotation for
kalog, minor commenting fixes]

Change-Id: I11cffbdd1418304d33f0be02dd7e600955c4a8bb
Reviewed-on: https://gerrit.openafs.org/12168
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
24 files changed:
acinclude.m4
src/budb/server.c
src/kauth/kalog.c
src/kauth/kaserver.c
src/ptserver/ptserver.c
src/util/afsutil.h
src/util/afsutil_prototypes.h
src/util/liboafs_util.la.sym
src/util/serverLog.c
src/viced/afsfileprocs.c
src/viced/host.c
src/viced/viced.c
src/viced/viced_prototypes.h
src/vlserver/vlserver.c
src/vol/fssync-client.c
src/vol/fssync-server.c
src/vol/salvaged.c
src/vol/salvager.c
src/vol/salvsync-client.c
src/vol/salvsync-server.c
src/vol/vnode.c
src/vol/vol-salvage.c
src/vol/volume.c
src/volser/volmain.c

index 67fa158db7645984276773489d3138a225ed37b5..38da5e5cb1553f1a7e80c9673634e522e95bb1ba 100644 (file)
@@ -1602,6 +1602,7 @@ AC_SUBST(INSTALL_KAUTH)
 
 AC_CHECK_FUNCS([ \
        arc4random \
+       closelog \
        fcntl \
        fseeko64 \
        ftello64 \
@@ -1613,6 +1614,7 @@ AC_CHECK_FUNCS([ \
        getrlimit \
        issetugid \
        mkstemp \
+       openlog \
        poll \
        pread \
        preadv \
@@ -1630,6 +1632,7 @@ AC_CHECK_FUNCS([ \
        strerror \
        sysconf \
        sysctl \
+       syslog \
        tdestroy \
        timegm \
 ])
index c8dd504f1b336ab8c0bc3ec9600aff2c10b8c4d2..5ba95d18ad4283007bec50994d173225ea641a73 100644 (file)
@@ -371,6 +371,7 @@ main(int argc, char **argv)
     afs_int32 numClasses;
 
     extern int rx_stackSize;
+    struct logOptions logopts;
 
 #ifdef AFS_NT40_ENV
     /* initialize winsock */
@@ -400,6 +401,12 @@ main(int argc, char **argv)
     memset(&cellinfo_s, 0, sizeof(cellinfo_s));
     memset(clones, 0, sizeof(clones));
 
+    memset(&logopts, 0, sizeof(logopts));
+    logopts.lopt_dest = logDest_file;
+    logopts.lopt_filename = AFSDIR_SERVER_BUDBLOG_FILEPATH;
+    logopts.lopt_rotateOnOpen = 1;
+    logopts.lopt_rotateStyle = logRotate_old;
+
     osi_audit_init();
     osi_audit(BUDB_StartEvent, 0, AUD_END);
 
@@ -442,7 +449,7 @@ main(int argc, char **argv)
        BUDB_EXIT(0);
 
     /* open the log file */
-    OpenLog(AFSDIR_SERVER_BUDBLOG_FILEPATH);
+    OpenLog(&logopts);
 
     /* open the cell's configuration directory */
     LogDebug(4, "opening %s\n", globalConfPtr->cellConfigdir);
index 8f0cd16117501fc481097461de34233b04fd0d2c..70967d50a7d7a5c740dac1cbfb2f3ff2608c4abe 100644 (file)
@@ -34,7 +34,14 @@ DBM *kalog_db;
 void
 kalog_Init(void)
 {
-    OpenLog(AFSDIR_SERVER_KALOGDB_FILEPATH);   /* set up logging */
+    struct logOptions logopts;
+
+    memset(&logopts, 0, sizeof(logopts));
+    logopts.lopt_dest = logDest_file;
+    logopts.lopt_filename = AFSDIR_SERVER_KALOGDB_FILEPATH;
+    logopts.lopt_rotateOnOpen = 1;
+    logopts.lopt_rotateStyle = logRotate_old;
+    OpenLog(&logopts);
     SetupLogSignals();
     kalog_db =
        dbm_open(AFSDIR_SERVER_KALOG_FILEPATH, O_WRONLY | O_CREAT,
index c402df2a2d8efb0664688128ede1f9dcd455e054..da824bc771410069f3a540e28dc3b93599c22365 100644 (file)
@@ -171,6 +171,7 @@ main(int argc, char *argv[])
     char clones[MAXHOSTSPERCELL];
     afs_uint32 host = ntohl(INADDR_ANY);
     char *auditFileName = NULL;
+    struct logOptions logopts;
 
     struct rx_service *tservice;
     struct rx_securityClass *sca[1];
@@ -195,6 +196,8 @@ main(int argc, char *argv[])
 #endif
     osi_audit_init();
 
+    memset(&logopts, 0, sizeof(logopts));
+
     if (argc == 0) {
       usage:
        printf("Usage: kaserver [-noAuth] [-database <dbpath>] "
@@ -321,7 +324,12 @@ main(int argc, char *argv[])
      * text logging. So open the AuthLog file for logging and redirect
      * stdin and stdout to it
      */
-    OpenLog(AFSDIR_SERVER_KALOG_FILEPATH);
+    logopts.lopt_dest = logDest_file;
+    logopts.lopt_filename = AFSDIR_SERVER_KALOG_FILEPATH;
+    logopts.lopt_rotateOnOpen = 1;
+    logopts.lopt_rotateStyle = logRotate_old;
+
+    OpenLog(&logopts);
     SetupLogSignals();
 #endif
 
index fdf37c1b2dd8e2613b40b579c8aad858c1a76030..9dfd7c1944560e041c21a8ad13d9011b1fbc1b08 100644 (file)
@@ -226,7 +226,9 @@ enum optionsList {
     OPT_debug,
     OPT_logfile,
     OPT_threads,
+#ifdef HAVE_SYSLOG
     OPT_syslog,
+#endif
     OPT_peer,
     OPT_process,
     OPT_rxbind,
@@ -252,7 +254,7 @@ main(int argc, char **argv)
 
     char *pr_dbaseName;
     char *configDir;
-    char *logFile;
+    struct logOptions logopts;
     char *whoami = "ptserver";
 
     char *auditFileName = NULL;
@@ -288,7 +290,7 @@ main(int argc, char **argv)
 
     pr_dbaseName = strdup(AFSDIR_SERVER_PRDB_FILEPATH);
     configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
-    logFile = strdup(AFSDIR_SERVER_PTLOG_FILEPATH);
+    memset(&logopts, 0, sizeof(logopts));
 
 #if defined(SUPERGROUPS)
     /* make sure the structures for database records are the same size */
@@ -338,7 +340,7 @@ main(int argc, char **argv)
                        CMD_OPTIONAL, "location of logfile");
     cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE,
                        CMD_OPTIONAL, "number of threads");
-#if !defined(AFS_NT40_ENV)
+#ifdef HAVE_SYSLOG
     cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG, 
                        CMD_OPTIONAL, "log to syslog");
 #endif
@@ -397,9 +399,7 @@ main(int argc, char **argv)
        free(interface);
     }
 
-    cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
     cmd_OptionAsString(opts, OPT_database, &pr_dbaseName);
-    cmd_OptionAsString(opts, OPT_logfile, &logFile);
 
     if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
        if (lwps > 64) {        /* maximum of 64 */
@@ -413,12 +413,29 @@ main(int argc, char **argv)
        }
     }
 
-#ifndef AFS_NT40_ENV
+#ifdef HAVE_SYSLOG
     if (cmd_OptionPresent(opts, OPT_syslog)) {
-       serverLogSyslog = 1;
-       cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
-    }
+       if (cmd_OptionPresent(opts, OPT_logfile)) {
+           fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.");
+           PT_EXIT(1);
+       }
+       logopts.lopt_dest = logDest_syslog;
+       logopts.lopt_facility = LOG_DAEMON;
+       logopts.lopt_tag = "ptserver";
+       cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility);
+    } else
 #endif
+    {
+       logopts.lopt_dest = logDest_file;
+       logopts.lopt_rotateOnOpen = 1;
+       logopts.lopt_rotateStyle = logRotate_old;
+
+       if (cmd_OptionPresent(opts, OPT_logfile))
+           cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
+       else
+           logopts.lopt_filename = AFSDIR_SERVER_PTLOG_FILEPATH;
+    }
+    cmd_OptionAsInt(opts, OPT_debug, &logopts.lopt_logLevel);
 
     /* rx options */
     if (cmd_OptionPresent(opts, OPT_peer))
@@ -441,10 +458,7 @@ main(int argc, char **argv)
        osi_audit(PTS_StartEvent, 0, AUD_END);
     }
 
-#ifndef AFS_NT40_ENV
-    serverLogSyslogTag = "ptserver";
-#endif
-    OpenLog(logFile);  /* set up logging */
+    OpenLog(&logopts);
 #ifdef AFS_PTHREAD_ENV
     opr_softsig_Init();
     SetupLogSoftSignals();
index 53db42a3d961535a30666f85a29a22ce2003d963..bd78946b4eb20247fa8d417b619a7e37fef5585b 100644 (file)
 #include <stdarg.h>
 #include <string.h>
 
-extern int LogLevel;
-extern int mrafsStyleLogs;
-#ifndef AFS_NT40_ENV
-extern int serverLogSyslog;
-extern int serverLogSyslogFacility;
-extern char *serverLogSyslogTag;
+enum logDest {
+    logDest_file,
+#ifdef HAVE_SYSLOG
+    logDest_syslog,
+#endif
+};
+
+enum logRotateStyle {
+    logRotate_none = 0,
+    logRotate_old,        /**< Rename log file by adding .old to the file name. */
+    logRotate_timestamp,  /**< Rename log file to a timestamped file name. */
+};
+
+struct logOptions {
+    int logLevel;                  /**< The initial log level. */
+    enum logDest dest;             /**< Log destination */
+    union {
+       struct fileOptions {
+           const char *filename;  /**< Log filename (may be a named pipe). */
+           int rotateOnOpen;      /**< Rotate the log file during OpenLog. */
+           int rotateOnReset;     /**< Rotate the log file when the SIGHUP is caught. */
+           enum logRotateStyle rotateStyle; /**< Specifies how logs are renamed. */
+       } fileOpts;
+#ifdef HAVE_SYSLOG
+       struct syslogOptions {
+           int facility;          /**< The syslog facility. */
+           char *tag;             /**< The syslog identification. */
+       } syslogOpts;
 #endif
+    } opts;
+};
+#define lopt_logLevel logLevel
+#define lopt_dest dest
+#define lopt_filename  opts.fileOpts.filename
+#define lopt_rotateOnOpen opts.fileOpts.rotateOnOpen
+#define lopt_rotateOnReset opts.fileOpts.rotateOnReset
+#define lopt_rotateStyle opts.fileOpts.rotateStyle
+#define lopt_facility opts.syslogOpts.facility
+#define lopt_tag opts.syslogOpts.tag
+
 extern void vFSLog(const char *format, va_list args)
        AFS_ATTRIBUTE_FORMAT(__printf__, 1, 0);
 
@@ -48,16 +81,22 @@ extern void SetLogThreadNumProgram(int (*func) (void) );
 extern void FSLog(const char *format, ...)
        AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2);
 
+
+extern int LogLevel; /* For logging macros only. */
+
 #define ViceLog(level, str)  do { if ((level) <= LogLevel) (FSLog str); } while (0)
 #define vViceLog(level, str) do { if ((level) <= LogLevel) (vFSLog str); } while (0)
 #define ViceLogThenPanic(level, str) \
     do { ViceLog(level, str); osi_Panic str; } while(0);
 
-extern int OpenLog(const char *filename);
+extern int OpenLog(struct logOptions *opts);
 extern int ReOpenLog(void);
 extern void SetupLogSignals(void);
 extern void CloseLog(void);
 extern void SetupLogSoftSignals(void);
+extern int GetLogLevel(void);
+extern enum logDest GetLogDest(void);
+extern const char *GetLogFilename(void);
 
 #ifdef AFS_NT40_ENV
 #ifndef _MFC_VER
index beb03f331fe822a665b7e104b37bd920494fd699..b91e6fb7f25ca829275a1a3966ca31ae35b21156 100644 (file)
@@ -125,17 +125,21 @@ extern void afs_pthread_setname_self(const char *threadname);
 
 
 /* serverLog.c */
+struct logOptions;
 extern void WriteLogBuffer(char *buf, afs_uint32 len);
 extern void SetDebug_Signal(int signo);
 extern void ResetDebug_Signal(int signo);
 extern void SetupLogSignals(void);
-extern int OpenLog(const char *fileName);
+extern int OpenLog(struct logOptions *opts);
 extern int ReOpenLog(void);
 extern int LogThreadNum(void);
 extern void LogCommandLine(int argc, char **argv, const char *progname,
                           const char *version, const char *logstring,
                           void (*log) (const char *format, ...));
 extern void LogDesWarning(void);
+extern int GetLogLevel(void);
+extern enum logDest GetLogDest(void);
+extern const char *GetLogFilename(void);
 
 /* snprintf.c */
 
index d3a5793ef2ecc688b9e4fef2a9f0927d569a98ab..98fad699dc9882f326de02fee9601bf61d87c837 100644 (file)
@@ -35,14 +35,10 @@ hostutil_GetNameByINet
 initAFSDirPath
 int64_to_flipbase64
 ktime_DateToInt32
-mrafsStyleLogs
 pthread_recursive_mutex_lock
 pthread_recursive_mutex_lock
 pthread_recursive_mutex_unlock
 pthread_recursive_mutex_unlock
-serverLogSyslog
-serverLogSyslogFacility
-serverLogSyslogTag
 util_GetHumanInt32
 util_GetInt32
 util_GetInt64
index 5cb08791bddc52f45077833fd41f376e59bb4f7b..bfb2803f374c7f411a61569a919d67699dc82db9 100644 (file)
@@ -65,19 +65,14 @@ static int (*threadNumProgram) (void) = dummyThreadNum;
 /* After single-threaded startup, accesses to serverlogFD and
  * serverLogSyslog* are protected by LOCK_SERVERLOG(). */
 static int serverLogFD = -1;
-
-#ifndef AFS_NT40_ENV
-int serverLogSyslog = 0;
-int serverLogSyslogFacility = LOG_DAEMON;
-char *serverLogSyslogTag = 0;
-#endif
+static struct logOptions serverLogOpts;
 
 int LogLevel;
-int mrafsStyleLogs = 0;
 static int threadIdLogs = 0;
 static int resetSignals = 0;
 static char *ourName = NULL;
 
+static int OpenLogFile(const char *fileName);
 static void RotateLogFile(void);
 
 /*!
@@ -97,6 +92,37 @@ IsFIFO(const char *fileName)
     return (lstat(fileName, &statbuf) == 0) && (S_ISFIFO(statbuf.st_mode));
 }
 
+/*!
+ * Return the current logging level.
+ */
+int
+GetLogLevel(void)
+{
+    return LogLevel;
+}
+
+/*!
+ * Return the log destination.
+ */
+enum logDest
+GetLogDest(void)
+{
+    return serverLogOpts.lopt_dest;
+}
+
+/*!
+ * Get the log filename for file based logging.
+ *
+ * An empty string is returned if the log destination is not
+ * file based.  The caller must make a copy of the string
+ * if it is accessed after the CloseLog.
+ */
+const char *
+GetLogFilename(void)
+{
+    return serverLogOpts.lopt_dest == logDest_file ? (const char*)ourName : "";
+}
+
 void
 SetLogThreadNumProgram(int (*func) (void) )
 {
@@ -148,8 +174,8 @@ vFSLog(const char *format, va_list args)
 
     len = strlen(tbuffer);
     LOCK_SERVERLOG();
-#ifndef AFS_NT40_ENV
-    if (serverLogSyslog) {
+#ifdef HAVE_SYSLOG
+    if (serverLogOpts.dest == logDest_syslog) {
        syslog(LOG_INFO, "%s", info);
     } else
 #endif
@@ -160,7 +186,7 @@ vFSLog(const char *format, va_list args)
     UNLOCK_SERVERLOG();
 
 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
-    if (!serverLogSyslog) {
+    if (serverLogOpts.dest == logDest_file) {
        fflush(stdout);
        fflush(stderr);         /* in case they're sharing the same FD */
     }
@@ -239,13 +265,21 @@ RenameLogFile(const char *fileName)
 {
     int code;
     char *nextName = NULL;
-
-    if (mrafsStyleLogs) {
-       int tries;
-       time_t t;
-       struct stat buf;
-       struct tm *timeFields;
-
+    int tries;
+    time_t t;
+    struct stat buf;
+    struct tm *timeFields;
+
+    switch (serverLogOpts.lopt_rotateStyle) {
+    case logRotate_none:
+       break;
+    case logRotate_old:
+       code = asprintf(&nextName, "%s.old", fileName);
+       if (code < 0) {
+           nextName = NULL;
+       }
+       break;
+    case logRotate_timestamp:
        time(&t);
        for (tries = 0; nextName == NULL && tries < 100; t++, tries++) {
            timeFields = localtime(&t);
@@ -264,11 +298,9 @@ RenameLogFile(const char *fileName)
                nextName = NULL;
            }
        }
-    } else {
-       code = asprintf(&nextName, "%s.old", fileName);
-       if (code < 0) {
-           nextName = NULL;
-       }
+       break;
+    default:
+       opr_Assert(0);
     }
     if (nextName != NULL) {
        rk_rename(fileName, nextName);  /* Don't check the error code. */
@@ -343,7 +375,7 @@ ResetDebug_Signal(int signo)
     if (threadIdLogs == 1)
         threadIdLogs = 0;
 #endif
-    if (mrafsStyleLogs) {
+    if (serverLogOpts.lopt_rotateOnReset) {
        RotateLogFile();
     }
 }                              /*ResetDebug_Signal */
@@ -415,33 +447,33 @@ RedirectStdStreams(const char *fileName)
     }
 }
 
-int
-OpenLog(const char *fileName)
+/*!
+ * Open the log file.
+ *
+ * Open the log file using the options given in OpenLog().
+ *
+ * \returns 0 on success
+ */
+static int
+OpenLogFile(const char *fileName)
 {
     /*
      * This function should allow various libraries that inconsistently
      * use stdout/stderr to all go to the same place
      */
     int tempfd;
-    int flags = O_WRONLY | O_TRUNC | O_CREAT | O_APPEND;
+    int flags = O_WRONLY | O_CREAT | O_APPEND;
 
-#if defined(AFS_PTHREAD_ENV)
-    opr_Verify(pthread_once(&serverLogOnce, InitServerLogMutex) == 0);
-#endif /* AFS_PTHREAD_ENV */
-
-#ifndef AFS_NT40_ENV
-    if (serverLogSyslog) {
-       openlog(serverLogSyslogTag, LOG_PID, serverLogSyslogFacility);
-       return (0);
-    }
-#endif
+    opr_Assert(serverLogOpts.dest == logDest_file);
 
     opr_Assert(fileName != NULL);
 
     if (IsFIFO(fileName)) {
        /* Support named pipes as logs by not rotating them. */
        flags |= O_NONBLOCK;
-    } else {
+    } else if (serverLogOpts.lopt_rotateOnOpen) {
+       /* Old style logging always started a new log file. */
+       flags |= O_TRUNC;
        RenameLogFile(fileName);
     }
 
@@ -460,6 +492,103 @@ OpenLog(const char *fileName)
     serverLogFD = tempfd;
 
     return 0;
+}
+
+/*!
+ * Open the log file descriptor or a connection to the system log.
+ *
+ * This function should be called once during program initialization and
+ * must be called before calling FSLog() or WriteLogBuffer().  The
+ * fields of the given argument specify the logging destination and
+ * various optional features.
+ *
+ * The lopt_logLevel value specifies the initial logging level.
+ *
+ * The lopt_dest enum specifies the logging destination; either
+ * file based (logDest_file) or the system log (logDest_syslog).
+ *
+ * File Based Logging
+ * ------------------
+ *
+ * A file will be opened for log messages when the lopt_dest enum is set
+ * to logDest_file.  The file specified by lopt_filename will be opened
+ * for appending log messages.  A new file will be created if the log
+ * file does not exist.
+ *
+ * The lopt_rotateOnOpen flag specifies whether an existing log file is
+ * to be renamed and a new log file created during the call to OpenLog.
+ * The lopt_rotateOnOpen flag has no effect if the file given by
+ * lopt_filename is a named pipe (fifo).
+ *
+ * The lopt_rotateOnReset flag specifies whether the log file is renamed
+ * and then reopened when the reset signal (SIGHUP) is caught.
+ *
+ * The lopt_rotateStyle enum specifies how the new log file is renamed when
+ * lopt_rotateOnOpen or lopt_rotateOnReset are set. The lopt_rotateStyle
+ * may be the traditional Transarc style (logRotate_old) or the MR-AFS
+ * style (logRotate_timestamp).
+ *
+ * When lopt_rotateStyle is set to logRotate_old, the suffix ".old" is
+ * appended to the log file name. The existing ".old" log file is
+ * removed.
+ *
+ * When lopt_rotateStyle is set to logRotate_timestamp, a timestamp
+ * string is appended to the log file name and existing files are not
+ * removed.
+ *
+ * \note  Messages written to stdout and stderr are redirected to the log
+ *        file when file-based logging is in effect.
+ *
+ * System Logging
+ * --------------
+ *
+ * A connection to the system log (syslog) will be established for log
+ * messages when the lopt_dest enum is set to logDest_syslog.
+ *
+ * The lopt_facility specifies the system log facility to be used when
+ * writing messages to the system log.
+ *
+ * The lopt_tag string specifies the indentification string to be used
+ * when writing messages to the system log.
+ *
+ * \param opts  logging options. A copy of the logging
+ *              options will be made before returning to
+ *              the caller.
+ *
+ * \returns 0 on success
+ */
+int
+OpenLog(struct logOptions *opts)
+{
+    int code;
+
+#if defined(AFS_PTHREAD_ENV)
+    opr_Verify(pthread_once(&serverLogOnce, InitServerLogMutex) == 0);
+#endif /* AFS_PTHREAD_ENV */
+
+    LogLevel = serverLogOpts.logLevel = opts->logLevel;
+    serverLogOpts.dest = opts->dest;
+    switch (serverLogOpts.dest) {
+    case logDest_file:
+       serverLogOpts.lopt_rotateOnOpen = opts->lopt_rotateOnOpen;
+       serverLogOpts.lopt_rotateOnReset = opts->lopt_rotateOnReset;
+       serverLogOpts.lopt_rotateStyle = opts->lopt_rotateStyle;
+       /* OpenLogFile() sets ourName; don't cache filename here. */
+       code = OpenLogFile(opts->lopt_filename);
+       break;
+#ifdef HAVE_SYSLOG
+    case logDest_syslog:
+       serverLogOpts.lopt_rotateOnOpen = 0;
+       serverLogOpts.lopt_rotateOnReset = 0;
+       serverLogOpts.lopt_rotateStyle = logRotate_none;
+       openlog(opts->lopt_tag, LOG_PID, opts->lopt_facility);
+       code = 0;
+       break;
+#endif
+    default:
+       opr_Assert(0);
+    }
+    return code;
 }                              /*OpenLog */
 
 /*!
@@ -475,8 +604,8 @@ ReOpenLog(void)
 {
     int flags = O_WRONLY | O_APPEND | O_CREAT;
 
-#if !defined(AFS_NT40_ENV)
-    if (serverLogSyslog) {
+#ifdef HAVE_SYSLOG
+    if (serverLogOpts.dest == logDest_syslog) {
        return 0;
     }
 #endif
@@ -511,7 +640,7 @@ RotateLogFile(void)
            close(serverLogFD);
            serverLogFD = -1;
        }
-       OpenLog(ourName);
+       OpenLogFile(ourName);
     }
     UNLOCK_SERVERLOG();
 }
@@ -525,8 +654,9 @@ void
 CloseLog(void)
 {
     LOCK_SERVERLOG();
-#ifndef AFS_NT40_ENV
-    if (serverLogSyslog) {
+
+#ifdef HAVE_SYSLOG
+    if (serverLogOpts.dest == logDest_syslog) {
        closelog();
     } else
 #endif
index 5a9e0fa4e168317fdef0bf4a20ff739df6697f0f..ea1164092eeb74b191de3ca3782f107e9dd6aa1b 100644 (file)
@@ -173,7 +173,6 @@ struct afs_FSStats {
 
 struct afs_FSStats afs_fsstats;
 
-int LogLevel = 0;
 int supported = 1;
 int Console = 0;
 afs_int32 BlocksSpare = 1024;  /* allow 1 MB overruns */
index e44bdb0eed8eb3747caf1d6defd2a35a2d031d1d..f53a415f491a448222bfd57cb59cd73212814236 100644 (file)
@@ -53,7 +53,6 @@ extern int CurrentConnections;
 extern int SystemId;
 extern int AnonymousID;
 extern prlist AnonCPS;
-extern int LogLevel;
 extern struct afsconf_dir *confDir;    /* config dir object */
 extern int lwps;               /* the max number of server threads */
 extern afsUUID FS_HostUUID;
@@ -1128,7 +1127,7 @@ h_AddHostToUuidHashTable_r(struct afsUUID *uuid, struct host *host)
 
        if (chain->hostPtr->z.interface &&
            afs_uuid_equal(&chain->hostPtr->z.interface->uuid, uuid)) {
-           if (LogLevel >= 125) {
+           if (GetLogLevel() >= 125) {
                afsUUID_to_string(&chain->hostPtr->z.interface->uuid, uuid1,
                                  127);
                afsUUID_to_string(uuid, uuid2, 127);
@@ -1149,7 +1148,7 @@ h_AddHostToUuidHashTable_r(struct afsUUID *uuid, struct host *host)
     chain->hostPtr = host;
     chain->next = hostUuidHashTable[index];
     hostUuidHashTable[index] = chain;
-         if (LogLevel < 125)
+         if (GetLogLevel() < 125)
               return;
      afsUUID_to_string(uuid, uuid2, 127);
      ViceLog(125,
@@ -1173,7 +1172,7 @@ h_DeleteHostFromUuidHashTable_r(struct host *host)
      /* hash into proper bucket */
      index = h_UuidHashIndex(&host->z.interface->uuid);
 
-     if (LogLevel >= 125)
+     if (GetLogLevel() >= 125)
         afsUUID_to_string(&host->z.interface->uuid, uuid1, 127);
      for (uhp = &hostUuidHashTable[index]; (uth = *uhp); uhp = &uth->next) {
          opr_Assert(uth->hostPtr);
@@ -4259,7 +4258,7 @@ initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf)
 
     h_AddHostToUuidHashTable_r(&interface->uuid, host);
 
-    if (LogLevel >= 125) {
+    if (GetLogLevel() >= 125) {
        afsUUID_to_string(&interface->uuid, uuidstr, 127);
 
        ViceLog(125, ("--- uuid %s\n", uuidstr));
index cbfa01c7bbf9910b106e29b6a8a183e3d6c76fd2..03bf03220dfb43cf25e6b554d3e55a4fa74d5d8e 100644 (file)
@@ -71,6 +71,7 @@
 #include <afs/audit.h>
 #include <afs/partition.h>
 #include <afs/dir.h>
+#include <afs/afsutil.h>
 #include "viced_prototypes.h"
 #include "viced.h"
 #include "host.h"
@@ -89,7 +90,7 @@ static afs_int32 Do_VLRegisterRPC(void);
 
 int eventlog = 0, rxlog = 0;
 FILE *debugFile;
-char *logFile = NULL;
+static struct logOptions logopts;
 
 pthread_mutex_t fsync_glock_mutex;
 pthread_cond_t fsync_cond;
@@ -115,7 +116,6 @@ int restartMode = RESTART_ORDINARY;
  */
 struct afs_PerfStats afs_perfstats;
 
-extern int LogLevel;
 extern int Statistics;
 
 int busyonrst = 1;
@@ -629,9 +629,9 @@ PrintCounters(void)
     ViceLog(0, ("Vice was last started at %s\n", tbuffer));
 
 #ifdef AFS_DEMAND_ATTACH_FS
-    if (LogLevel >= 125) {
+    if (GetLogLevel() >= 125) {
        stats_flags = VOL_STATS_PER_CHAIN2;
-    } else if (LogLevel >= 25) {
+    } else if (GetLogLevel() >= 25) {
        stats_flags = VOL_STATS_PER_CHAIN;
     }
     VPrintExtendedCacheStats(stats_flags);
@@ -912,7 +912,9 @@ enum optionsList {
     OPT_logfile,
     OPT_mrafslogs,
     OPT_threads,
+#ifdef HAVE_SYSLOG
     OPT_syslog,
+#endif
     OPT_peer,
     OPT_process,
     OPT_nojumbo,
@@ -1065,7 +1067,7 @@ ParseArgs(int argc, char *argv[])
                        CMD_OPTIONAL, "enable MRAFS style logging");
     cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
                        "number of threads");
-#if !defined(AFS_NT40_ENV)
+#ifdef HAVE_SYSLOG
     cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
                        CMD_OPTIONAL, "log to syslog");
 #endif
@@ -1300,9 +1302,6 @@ ParseArgs(int argc, char *argv[])
        optstring = NULL;
     }
 
-    cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
-    cmd_OptionAsFlag(opts, OPT_mrafslogs, &mrafsStyleLogs);
-
     if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
        lwps_max = max_fileserver_thread() - FILESERVER_HELPER_THREADS;
        if (lwps > lwps_max)
@@ -1311,12 +1310,40 @@ ParseArgs(int argc, char *argv[])
            lwps = 6;
     }
 
-#ifndef AFS_NT40_ENV
+    /* Logging options. */
+#ifdef HAVE_SYSLOG
     if (cmd_OptionPresent(opts, OPT_syslog)) {
-       serverLogSyslog = 1;
-       cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
-    }
+       if (cmd_OptionPresent(opts, OPT_logfile)) {
+           fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.\n");
+           return -1;
+       }
+       if (cmd_OptionPresent(opts, OPT_mrafslogs)) {
+           fprintf(stderr, "Invalid options: -syslog and -mrafslogs are exclusive.\n");
+           return -1;
+       }
+
+       logopts.lopt_dest = logDest_syslog;
+       logopts.lopt_facility = LOG_DAEMON;
+       logopts.lopt_tag = "fileserver";
+       cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility);
+    } else
 #endif
+    {
+       logopts.lopt_dest = logDest_file;
+       logopts.lopt_rotateOnOpen = 1;
+       logopts.lopt_rotateStyle = logRotate_old;
+
+       if (cmd_OptionPresent(opts, OPT_logfile))
+           cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
+       else
+           logopts.lopt_filename = AFSDIR_SERVER_FILELOG_FILEPATH;
+
+       if (cmd_OptionPresent(opts, OPT_mrafslogs)) {
+           logopts.lopt_rotateOnReset = 1;
+           logopts.lopt_rotateStyle = logRotate_timestamp;
+       }
+    }
+    cmd_OptionAsInt(opts, OPT_debug, &logopts.lopt_logLevel);
 
     if (cmd_OptionPresent(opts, OPT_peer))
        rx_enablePeerRPCStats();
@@ -1368,7 +1395,6 @@ ParseArgs(int argc, char *argv[])
        busy_threshold = 3 * rxpackets / 2;
     }
 
-    cmd_OptionAsString(opts, OPT_logfile, &logFile);
     cmd_OptionAsString(opts, OPT_config, &FS_configPath);
 
 
@@ -1809,7 +1835,7 @@ main(int argc, char *argv[])
     CheckParms();
 
     FS_configPath = strdup(AFSDIR_SERVER_ETC_DIRPATH);
-    logFile = strdup(AFSDIR_SERVER_FILELOG_FILEPATH);
+    memset(&logopts, 0, sizeof(logopts));
 
     if (ParseArgs(argc, argv)) {
        exit(-1);
@@ -1834,11 +1860,7 @@ main(int argc, char *argv[])
     /* initialize audit user check */
     osi_audit_set_user_check(confDir, fs_IsLocalRealmMatch);
 
-    /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
-#ifndef AFS_NT40_ENV
-    serverLogSyslogTag = "fileserver";
-#endif
-    OpenLog(logFile);
+    OpenLog(&logopts);
 
     LogCommandLine(argc, argv, "starting", "", "File server", FSLog);
     if (afsconf_GetLatestKey(confDir, NULL, NULL) == 0) {
index 544bde310db73f129f5d18e8ac5daedfd2e4e9d0..2b34d98bd46f916e6104d98d4ef77b7241f5b8e8 100644 (file)
@@ -15,7 +15,6 @@ afs_int32 sys_error_to_et(afs_int32 in);
 void init_sys_error_to_et(void);
 
 /* afsfileprocs.c */
-extern int LogLevel;
 extern afs_int32 BlocksSpare;
 extern afs_int32 PctSpare;
 
index f64f97e71d457713b5489e1e74ac0d639d05ad8b..9137deb731fab06a7c3e6f87f129c261b78bb821 100644 (file)
@@ -52,7 +52,6 @@ afs_uint32 rd_HostAddress[MAXSERVERID + 1];
 afs_uint32 wr_HostAddress[MAXSERVERID + 1];
 
 static void *CheckSignal(void*);
-int LogLevel = 0;
 int smallMem = 0;
 int restrictedQueryLevel = RESTRICTED_QUERY_ANYUSER;
 int rxJumbograms = 0;          /* default is to not send and receive jumbo grams */
@@ -147,7 +146,9 @@ enum optionsList {
     OPT_database,
     OPT_logfile,
     OPT_threads,
+#ifdef HAVE_SYSLOG
     OPT_syslog,
+#endif
     OPT_peer,
     OPT_process,
     OPT_nojumbo,
@@ -176,10 +177,10 @@ main(int argc, char **argv)
     char clones[MAXHOSTSPERCELL];
     afs_uint32 host = ntohl(INADDR_ANY);
     struct cmd_syndesc *opts;
+    struct logOptions logopts;
 
     char *vl_dbaseName;
     char *configDir;
-    char *logFile;
 
     char *auditFileName = NULL;
     char *interface = NULL;
@@ -205,6 +206,8 @@ main(int argc, char **argv)
 #endif
     osi_audit_init();
 
+    memset(&logopts, 0, sizeof(logopts));
+
     /* Initialize dirpaths */
     if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
 #ifdef AFS_NT40_ENV
@@ -217,7 +220,6 @@ main(int argc, char **argv)
 
     vl_dbaseName = strdup(AFSDIR_SERVER_VLDB_FILEPATH);
     configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
-    logFile = strdup(AFSDIR_SERVER_VLOG_FILEPATH);
 
     cmd_DisableAbbreviations();
     cmd_DisablePositionalCommands();
@@ -245,7 +247,7 @@ main(int argc, char **argv)
                        CMD_OPTIONAL, "location of logfile");
     cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL,
                        "number of threads");
-#if !defined(AFS_NT40_ENV)
+#ifdef HAVE_SYSLOG
     cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
                        CMD_OPTIONAL, "log to syslog");
 #endif
@@ -308,9 +310,7 @@ main(int argc, char **argv)
        free(interface);
     }
 
-    cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
     cmd_OptionAsString(opts, OPT_database, &vl_dbaseName);
-    cmd_OptionAsString(opts, OPT_logfile, &logFile);
 
     if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) {
        if (lwps > MAXLWP) {
@@ -319,12 +319,32 @@ main(int argc, char **argv)
             lwps = MAXLWP;
        }
     }
-#ifndef AFS_NT40_ENV
+
+    cmd_OptionAsInt(opts, OPT_debug, &logopts.lopt_logLevel);
+#ifdef HAVE_SYSLOG
     if (cmd_OptionPresent(opts, OPT_syslog)) {
-        serverLogSyslog = 1;
-        cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
-    }
+       if (cmd_OptionPresent(opts, OPT_logfile)) {
+           fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.\n");
+           return -1;
+       }
+
+       logopts.lopt_dest = logDest_syslog;
+       logopts.lopt_facility = LOG_DAEMON; /* default value */
+       logopts.lopt_tag = "vlserver";
+       cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility);
+    } else
 #endif
+    {
+       logopts.lopt_dest = logDest_file;
+       logopts.lopt_rotateOnOpen = 1;
+       logopts.lopt_rotateStyle = logRotate_old;
+
+       if (cmd_OptionPresent(opts, OPT_logfile))
+           cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
+       else
+           logopts.lopt_filename = AFSDIR_SERVER_VLOG_FILEPATH;
+    }
+
 
     /* rx options */
     if (cmd_OptionPresent(opts, OPT_peer))
@@ -362,10 +382,7 @@ main(int argc, char **argv)
        osi_audit_file(auditFileName);
     }
 
-#ifndef AFS_NT40_ENV
-    serverLogSyslogTag = "vlserver";
-#endif
-    OpenLog(logFile);  /* set up logging */
+    OpenLog(&logopts);
 #ifdef AFS_PTHREAD_ENV
     opr_softsig_Init();
     SetupLogSoftSignals();
index 46b44deb9216985546a04f5368d1775a796822c4..02559222e7c09304fb628d80a8ee619e4f33cf2b 100644 (file)
@@ -60,8 +60,6 @@
 
 #ifdef FSSYNC_BUILD_CLIENT
 
-extern int LogLevel;
-
 static SYNC_client_state fssync_state =
     { -1,                    /* file descriptor */
       FSSYNC_ENDPOINT_DECL,  /* server endpoint */
index 8ede22b0bb5ce0eb43971f3b326d5b25c1f47d55..cd15e2d7c3d7eee287a7f802b2d20363edf0b289 100644 (file)
@@ -143,7 +143,6 @@ static void GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds);
 static void CallHandler(fd_set * fdsetp);
 static void GetHandler(fd_set * fdsetp, int *maxfdp);
 #endif
-extern int LogLevel;
 
 static afs_int32 FSYNC_com_VolOp(osi_socket fd, SYNC_command * com, SYNC_response * res);
 
@@ -1063,7 +1062,7 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
     if (vp) {
        if (VVolOpLeaveOnline_r(vp, &info)) {
            VUpdateVolume_r(&error, vp, VOL_UPDATE_WAIT);       /* At least get volume stats right */
-           if (LogLevel) {
+           if (GetLogLevel() > 0) {
                Log("FSYNC: Volume %" AFS_VOLID_FMT " (%s) was left on line for an external %s request\n",
                    afs_printable_VolumeId_lu(V_id(vp)), V_name(vp),
                    vcom->hdr->reason == V_CLONE ? "clone" :
index 6464ef6d811606393afbfba82fdfa32a8fb2f59a..8edf1b31f6d09037b1bff4302119315dea1467ce 100644 (file)
@@ -138,7 +138,7 @@ static pthread_cond_t worker_cv;
 static void * SalvageChildReaperThread(void *);
 static int DoSalvageVolume(struct SalvageQueueNode * node, int slot);
 
-static void SalvageServer(int argc, char **argv);
+static void SalvageServer(int argc, char **argv, struct logOptions *logopts);
 static void SalvageClient(VolumeId vid, char * pname);
 
 static int Reap_Child(char * prog, int * pid, int * status);
@@ -194,6 +194,9 @@ handleit(struct cmd_syndesc *opts, void *arock)
     VolumeId vid = 0;
     struct cmdline_rock *rock = (struct cmdline_rock *)arock;
     char *optstring = NULL;
+    struct logOptions logopts;
+
+    memset(&logopts, 0, sizeof(logopts));
 
 #ifdef AFS_SGI_VNODE_GLUE
     if (afs_init_kernel_config(-1) < 0) {
@@ -253,12 +256,30 @@ handleit(struct cmd_syndesc *opts, void *arock)
        free(optstring);
        optstring = NULL;
     }
-#ifndef AFS_NT40_ENV           /* ignore options on NT */
+
+#ifdef HAVE_SYSLOG
     if (cmd_OptionPresent(opts, OPT_syslog)) {
-       serverLogSyslog = 1;
-    }
-    cmd_OptionAsInt(opts, OPT_syslogfacility, &serverLogSyslogFacility);
+       if (cmd_OptionPresent(opts, OPT_logfile)) {
+           fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.\n");
+           return -1;
+       }
+
+       logopts.lopt_dest = logDest_syslog;
+       logopts.lopt_facility = LOG_DAEMON;
+       logopts.lopt_tag = "salvageserver";
+       cmd_OptionAsInt(opts, OPT_syslogfacility, &logopts.lopt_facility);
+    } else
 #endif
+    {
+       logopts.lopt_dest = logDest_file;
+       logopts.lopt_rotateOnOpen = 1;
+       logopts.lopt_rotateStyle = logRotate_old;
+
+       if (cmd_OptionPresent(opts, OPT_logfile))
+           cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
+       else
+           logopts.lopt_filename = AFSDIR_SERVER_SALSRVLOG_FILEPATH;
+    }
 
     if (cmd_OptionPresent(opts, OPT_client)) {
        if (cmd_OptionAsString(opts, OPT_partition, &optstring) == 0) {
@@ -287,7 +308,7 @@ handleit(struct cmd_syndesc *opts, void *arock)
        SalvageClient(vid, pname);
 
     } else {  /* salvageserver mode */
-       SalvageServer(rock->argc, rock->argv);
+       SalvageServer(rock->argc, rock->argv, &logopts);
     }
     return (0);
 }
@@ -393,7 +414,7 @@ main(int argc, char **argv)
     cmd_AddParmAtOffset(ts, OPT_orphans, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
            "ignore | remove | attach");
 
-#if !defined(AFS_NT40_ENV)
+#ifdef HAVE_SYSLOG
     cmd_AddParmAtOffset(ts, OPT_syslog, "-syslog", CMD_FLAG, CMD_OPTIONAL,
            "Write salvage log to syslogs");
     cmd_AddParmAtOffset(ts, OPT_syslogfacility, "-syslogfacility", CMD_SINGLE,
@@ -474,7 +495,7 @@ SalvageClient(VolumeId vid, char * pname)
 static int * child_slot;
 
 static void
-SalvageServer(int argc, char **argv)
+SalvageServer(int argc, char **argv, struct logOptions *logopts)
 {
     int pid, ret;
     struct SalvageQueueNode * node;
@@ -486,7 +507,7 @@ SalvageServer(int argc, char **argv)
     /* All entries to the log will be appended.  Useful if there are
      * multiple salvagers appending to the log.
      */
-    OpenLog(AFSDIR_SERVER_SALSRVLOG_FILEPATH);
+    OpenLog(logopts);
     SetupLogSignals();
 
     Log("%s\n", cml_version_number);
@@ -580,7 +601,8 @@ SalvageServer(int argc, char **argv)
 static int
 DoSalvageVolume(struct SalvageQueueNode * node, int slot)
 {
-    char *childLog;
+    char *filename = NULL;
+    struct logOptions logopts;
     struct DiskPartition64 * partP;
 
     /* do not allow further forking inside salvager */
@@ -591,13 +613,17 @@ DoSalvageVolume(struct SalvageQueueNode * node, int slot)
      * another thread may have held the lock when fork was
      * called!
      */
-    if (asprintf(&childLog, "%s.%d",
+    memset(&memset, 0, sizeof(logopts));
+    logopts.lopt_dest = logDest_file;
+    logopts.lopt_rotateStyle = logRotate_none;
+    if (asprintf(&filename, "%s.%d",
                 AFSDIR_SERVER_SLVGLOG_FILEPATH, getpid()) < 0) {
        fprintf(stderr, "out of memory\n");
        return ENOMEM;
     }
-    OpenLog(childLog);
-    free(childLog);
+    logopts.lopt_filename = filename;
+    OpenLog(&logopts);
+    free(filename);
 
     if (node->command.sop.parent <= 0) {
        Log("salvageServer: invalid volume id specified; salvage aborted\n");
index 532e7b896c8a73559a028ddce004a269c7ce738e..3bc9351ffdee75c1e29591df0bd966340203aeab 100644 (file)
 pthread_t main_thread;
 #endif
 
-extern char *ShowLogFilename;
 extern char cml_version_number[];
 static int get_salvage_lock = 0;
 
@@ -120,7 +119,6 @@ struct CmdLine {
    char **argv;
 };
 
-#ifndef AFS_NT40_ENV
 static int
 TimeStampLogFile(char **logfile)
 {
@@ -137,11 +135,9 @@ TimeStampLogFile(char **logfile)
                 lt->tm_min, lt->tm_sec) < 0) {
        return ENOMEM;
     }
-    free(*logfile); /* free the default name */
     *logfile = stampSlvgLog;
     return 0;
 }
-#endif
 
 static int
 handleit(struct cmd_syndesc *as, void *arock)
@@ -152,15 +148,18 @@ handleit(struct cmd_syndesc *as, void *arock)
     afs_int32 seenpart = 0, seenvol = 0;
     VolumeId vid = 0;
     ProgramType pt;
-    char *logfile = strdup(AFSDIR_SERVER_SLVGLOG_FILEPATH);
 
 #ifdef FAST_RESTART
     afs_int32  seenany = 0;
 #endif
 
+    char *filename = NULL;
+    struct logOptions logopts;
     VolumePackageOptions opts;
     struct DiskPartition64 *partP;
 
+    memset(&logopts, 0, sizeof(logopts));
+
 #ifdef AFS_SGI_VNODE_GLUE
     if (afs_init_kernel_config(-1) < 0) {
        printf
@@ -274,30 +273,47 @@ handleit(struct cmd_syndesc *as, void *arock)
                 || strcmp(ti->data, "a") == 0)
            orphans = ORPH_ATTACH;
     }
-#ifndef AFS_NT40_ENV           /* ignore options on NT */
+
     if ((ti = as->parms[16].items)) {  /* -syslog */
        if (ShowLog) {
            fprintf(stderr, "Invalid options: -syslog and -showlog are exclusive.\n");
            Exit(1);
        }
-       serverLogSyslog = 1;
-    }
-    if ((ti = as->parms[17].items)) {  /* -syslogfacility */
-       serverLogSyslogFacility = atoi(ti->data);
-    }
+       if ((ti = as->parms[18].items)) {       /* -datelogs */
+           fprintf(stderr, "Invalid option: -syslog and -datelogs are exclusive.\n");
+           Exit(1);
+       }
+#ifndef HAVE_SYSLOG
+       /* Do not silently ignore. */
+       fprintf(stderr, "Invalid option: -syslog is not available on this platform.\n");
+       Exit(1);
+#else
+       logopts.lopt_dest = logDest_syslog;
+       logopts.lopt_tag = "salvager";
+
+       if ((ti = as->parms[17].items))  /* -syslogfacility */
+           logopts.lopt_facility = atoi(ti->data);
+       else
+           logopts.lopt_facility = LOG_DAEMON; /* default value */
+#endif
+    } else {
+       logopts.lopt_dest = logDest_file;
 
-    if ((ti = as->parms[18].items)) {  /* -datelogs */
-       int code = TimeStampLogFile(&logfile);
-       if (code != 0) {
-           fprintf(stderr, "Failed to format log file name for -datelogs; code=%d\n", code);
-           Exit(code);
+       if ((ti = as->parms[18].items)) {       /* -datelogs */
+           int code = TimeStampLogFile(&filename);
+           if (code != 0) {
+               fprintf(stderr, "Failed to format log file name for -datelogs; code=%d\n", code);
+               Exit(code);
+           }
+           logopts.lopt_filename = filename;
+       } else {
+           logopts.lopt_filename = AFSDIR_SERVER_SLVGLOG_FILEPATH;
        }
-       ShowLogFilename = logfile;
     }
-#endif
 
-    OpenLog(logfile);
+    OpenLog(&logopts);
     SetupLogSignals();
+    free(filename); /* Free string created by -datelogs, if one. */
 
     Log("%s\n", cml_version_number);
     LogCommandLine(cmdline->argc, cmdline->argv, "SALVAGER", SalvageVersion, "STARTING AFS", Log);
index 641f2414c40d949c829601ce538e208bd7c477a5..3e0b1398c136d81ee41d8ea4d99bcf8cd9452151 100644 (file)
@@ -40,7 +40,6 @@
  * SALVSYNC is a feature specific to the demand attach fileserver
  */
 
-extern int LogLevel;
 extern int VInit;
 extern pthread_mutex_t vol_salvsync_mutex;
 
index 14027dbef89c95b314098cb34422ecf1d8bf6b31..b399d8164940f00f472315bcc1278f52bc0b54d9 100644 (file)
@@ -115,7 +115,6 @@ static afs_int32 SALVSYNC_com_CancelAll(SALVSYNC_command * com, SALVSYNC_respons
 static afs_int32 SALVSYNC_com_Link(SALVSYNC_command * com, SALVSYNC_response * res);
 
 
-extern int LogLevel;
 extern int VInit;
 extern pthread_mutex_t vol_salvsync_mutex;
 
index ab1c349adc820161d8cca5d4e9579fb0e68a112a..472e2e42880877553860ea30f7328c2ae76b76f6 100644 (file)
@@ -54,8 +54,6 @@ struct VnodeClassInfo VnodeClassInfo[nVNODECLASSES];
 
 void VNLog(afs_int32 aop, afs_int32 anparms, ... );
 
-extern int LogLevel;
-
 /* logging stuff for finding bugs */
 #define        THELOGSIZE      5120
 static afs_int32 theLog[THELOGSIZE];
@@ -951,7 +949,7 @@ VnLoad(Error * ec, Volume * vp, Vnode * vnp,
            Log("VnLoad: Couldn't read vnode %u, volume %" AFS_VOLID_FMT " (%s); volume needs salvage\n", Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
        } else {
            /* vnode is not allocated */
-           if (LogLevel >= 5)
+           if (GetLogLevel() >= 5)
                Log("VnLoad: Couldn't read vnode %u, volume %" AFS_VOLID_FMT " (%s); read %d bytes, errno %d\n",
                    Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp), (int)nBytes, errno);
            *ec = VNOVNODE;
index 190bf963ab2135dcf0dab4dbec804fdeabb1c7bb..87e265d3b6b406feb5a83da1fcefebd203385ede 100644 (file)
@@ -603,7 +603,11 @@ SalvageFileSysParallel(struct DiskPartition64 *partP)
                numjobs++;
            } else {
                int fd;
-               char *logFileName;
+               char *filename;
+               struct logOptions logopts;
+
+               memset(&logopts, 0, sizeof(logopts));
+               logopts.lopt_dest = logDest_file;
 
                for (fd = 0; fd < 16; fd++)
                    close(fd);
@@ -612,11 +616,12 @@ SalvageFileSysParallel(struct DiskPartition64 *partP)
                dup2(0, 2);
 
                ShowLog = 0; /* Child processes do not display. */
-               if (asprintf(&logFileName, "%s.%d",
+               if (asprintf(&filename, "%s.%d",
                             AFSDIR_SERVER_SLVGLOG_FILEPATH,
                             jobs[startjob]->jobnumb) >= 0) {
-                   OpenLog(logFileName);
-                   free(logFileName);
+                   logopts.lopt_filename = filename;
+                   OpenLog(&logopts);
+                   free(filename);
                }
 
                SalvageFileSys1(jobs[startjob]->partP, 0);
@@ -626,10 +631,11 @@ SalvageFileSysParallel(struct DiskPartition64 *partP)
        }
     }                          /* while ( thisjob || (!partP && numjobs > 0) ) */
 
-    /* If waited for all jobs to complete, now collect log files and return */
-#ifndef AFS_NT40_ENV
-    if (!serverLogSyslog)              /* if syslogging - no need to collect */
-#endif
+    /*
+     * If waited for all jobs to complete, now collect log files and return.
+     * No files can be collected when logging to the system log (syslog).
+     */
+    if (GetLogDest() == logDest_file) {
        if (!partP) {
            char *buf = calloc(1, SALV_BUFFER_SIZE);
            char *logFileName;
@@ -655,7 +661,7 @@ SalvageFileSysParallel(struct DiskPartition64 *partP)
                free(buf);
            }
        }
-
+    }
     return;
 }
 
@@ -4842,17 +4848,17 @@ static void
 SalvageShowLog(void)
 {
     char line[256];
+    char *filename;
     FILE *logFile;
 
     if (ShowLog == 0 || ClientMode) {
-       return;
-    }
-
-    if (ShowLogFilename == NULL) {
-       ShowLogFilename = strdup(AFSDIR_SERVER_SLVGLOG_FILEPATH);
+       return; /* nothing to do */
     }
+    filename = strdup(GetLogFilename());
+    opr_Assert(filename != NULL);
     CloseLog();
-    logFile = afs_fopen(ShowLogFilename, "r");
+
+    logFile = afs_fopen(filename, "r");
     if (!logFile)
        printf("Can't read %s, exiting\n", ShowLogFilename);
     else {
@@ -4860,6 +4866,7 @@ SalvageShowLog(void)
            printf("%s", line);
        fflush(stdout);
     }
+    free(filename);
 }
 
 static void
index 88e355f551693e6e248360fea29711d09a248af5..202bdcc6cefb25c67390f8ff4f9341c3330a9d17 100644 (file)
@@ -176,8 +176,6 @@ static int VCheckDetach(Volume * vp);
 static Volume * GetVolume(Error * ec, Error * client_ec, VolumeId volumeId,
                           Volume * hint, const struct timespec *ts);
 
-int LogLevel;                  /* Vice loglevel--not defined as extern so that it will be
-                                * defined when not linked with vice, XXXX */
 ProgramType programType;       /* The type of program using the package */
 static VolumePackageOptions vol_opts;
 
@@ -1125,7 +1123,7 @@ VAttachVolumesByPartition(struct DiskPartition64 *diskP, int * nAttached, int *
       (*(vp ? nAttached : nUnattached))++;
       if (error == VOFFLINE)
        Log("Volume %d stays offline (/vice/offline/%s exists)\n", VolumeNumber(dp->d_name), dp->d_name);
-      else if (LogLevel >= 5) {
+      else if (GetLogLevel() >= 5) {
        Log("Partition %s: attached volume %d (%s)\n",
            diskP->name, VolumeNumber(dp->d_name),
            dp->d_name);
@@ -1356,7 +1354,7 @@ VShutdown_r(void)
        for (queue_Scan(&VolumeHashTable.Table[i],vp,np,Volume)) {
            code = VHold_r(vp);
            if (code == 0) {
-               if (LogLevel >= 5)
+               if (GetLogLevel() >= 5)
                    Log("VShutdown:  Attempting to take volume %" AFS_VOLID_FMT " offline.\n",
                        afs_printable_VolumeId_lu(vp->hashid));
 
@@ -1844,7 +1842,7 @@ VShutdownVolume_r(Volume * vp)
 
     VCreateReservation_r(vp);
 
-    if (LogLevel >= 5) {
+    if (GetLogLevel() >= 5) {
        Log("VShutdownVolume_r:  vid=%" AFS_VOLID_FMT ", device=%d, state=%u\n",
            afs_printable_VolumeId_lu(vp->hashid), vp->partition->device,
            (unsigned int) V_attachState(vp));
@@ -1872,7 +1870,7 @@ VShutdownVolume_r(Volume * vp)
     case VOL_STATE_ATTACHED:
        code = VHold_r(vp);
        if (!code) {
-           if (LogLevel >= 5)
+           if (GetLogLevel() >= 5)
                Log("VShutdown:  Attempting to take volume %" AFS_VOLID_FMT " offline.\n",
                    afs_printable_VolumeId_lu(vp->hashid));
 
@@ -2299,7 +2297,7 @@ VPreAttachVolumeByVp_r(Error * ec,
     VLRU_Init_Node_r(vp);
     VChangeState_r(vp, VOL_STATE_PREATTACHED);
 
-    if (LogLevel >= 5)
+    if (GetLogLevel() >= 5)
        Log("VPreAttachVolumeByVp_r:  volume %" AFS_VOLID_FMT " pre-attached\n", afs_printable_VolumeId_lu(vp->hashid));
 
   done:
@@ -2578,7 +2576,7 @@ VAttachVolumeByName_r(Error * ec, char *partition, char *name, int mode)
                goto done;
            }
        }
-       if (LogLevel)
+       if (GetLogLevel() != 0)
          Log("VOnline:  volume %" AFS_VOLID_FMT " (%s) attached and online\n", afs_printable_VolumeId_lu(V_id(vp)),
                V_name(vp));
     }
@@ -2728,7 +2726,7 @@ VAttachVolumeByVp_r(Error * ec, Volume * vp, int mode)
            goto done;
        }
     }
-    if (LogLevel)
+    if (GetLogLevel() != 0)
        Log("VOnline:  volume %" AFS_VOLID_FMT " (%s) attached and online\n",
            afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
   done:
@@ -4233,7 +4231,7 @@ GetVolume(Error * ec, Error * client_ec, VolumeId volumeId, Volume * hint,
            VGET_CTR_INC(V6);
            /* Only log the error if it was a totally unexpected error.  Simply
             * a missing inode is likely to be caused by the volume being deleted */
-           if (errno != ENXIO || LogLevel)
+           if (errno != ENXIO || GetLogLevel() != 0)
                Log("Volume %" AFS_VOLID_FMT ": couldn't reread volume header\n",
                    afs_printable_VolumeId_lu(vp->hashid));
 #ifdef AFS_DEMAND_ATTACH_FS
@@ -4481,7 +4479,7 @@ VScanCalls_r(struct Volume *vp)
 #endif /* AFS_DEMAND_ATTACH_FS */
 
     for(queue_Scan(&vp->rx_call_list, cbv, ncbv, VCallByVol)) {
-       if (LogLevel > 0) {
+       if (GetLogLevel() != 0) {
            struct rx_peer *peer;
            char hoststr[16];
            peer = rx_PeerOf(rx_ConnectionOf(cbv->call));
@@ -5172,7 +5170,7 @@ VCheckOffline(Volume * vp)
        VUpdateVolume_r(&error, vp, 0);
        VCloseVolumeHandles_r(vp);
 
-       if (LogLevel) {
+       if (GetLogLevel() != 0) {
            if (V_offlineMessage(vp)[0]) {
                Log("VOffline: Volume %lu (%s) is now offline (%s)\n",
                    afs_printable_uint32_lu(V_id(vp)), V_name(vp),
@@ -5211,7 +5209,7 @@ VCheckOffline(Volume * vp)
        V_inUse(vp) = 0;
        VUpdateVolume_r(&error, vp, 0);
        VCloseVolumeHandles_r(vp);
-       if (LogLevel) {
+       if (GetLogLevel() != 0) {
            if (V_offlineMessage(vp)[0]) {
                Log("VOffline: Volume %lu (%s) is now offline (%s)\n",
                    afs_printable_uint32_lu(V_id(vp)), V_name(vp),
@@ -7218,7 +7216,7 @@ VInitVLRU(void)
     /* setup the timing constants */
     VLRU_ComputeConstants();
 
-    /* XXX put inside LogLevel check? */
+    /* XXX put inside log level check? */
     Log("VLRU: starting scanner with the following configuration parameters:\n");
     Log("VLRU:  offlining volumes after minimum of %d seconds of inactivity\n", VLRU_offline_thresh);
     Log("VLRU:  running VLRU soft detach pass every %d seconds\n", VLRU_offline_interval);
index 33f8b56a454d998c0aba77708e1b4cab5f0db17e..b70f6434f3f5401592e5b2e247474ee8dbad133a 100644 (file)
@@ -80,7 +80,7 @@ int DoPreserveVolumeStats = 0;
 int rxJumbograms = 0;  /* default is to not send and receive jumbograms. */
 int rxMaxMTU = -1;
 char *auditFileName = NULL;
-char *logFile = NULL;
+static struct logOptions logopts;
 char *configDir = NULL;
 
 #define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */
@@ -236,7 +236,9 @@ enum optionsList {
     OPT_process,
     OPT_preserve_vol_stats,
     OPT_sync,
+#ifdef HAVE_SYSLOG
     OPT_syslog,
+#endif
     OPT_logfile,
     OPT_config,
     OPT_restricted_query
@@ -283,7 +285,7 @@ ParseArgs(int argc, char **argv) {
            CMD_OPTIONAL, "enable RX RPC statistics");
     cmd_AddParmAtOffset(opts, OPT_preserve_vol_stats, "-preserve-vol-stats", CMD_FLAG,
            CMD_OPTIONAL, "preserve volume statistics");
-#if !defined(AFS_NT40_ENV)
+#ifdef HAVE_SYSLOG
     cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG,
            CMD_OPTIONAL, "log to syslog");
 #endif
@@ -307,7 +309,6 @@ ParseArgs(int argc, char **argv) {
     cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind);
     cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck);
     cmd_OptionAsFlag(opts, OPT_preserve_vol_stats, &DoPreserveVolumeStats);
-    cmd_OptionAsInt(opts, OPT_debug, &LogLevel);
     if (cmd_OptionPresent(opts, OPT_peer))
        rx_enablePeerRPCStats();
     if (cmd_OptionPresent(opts, OPT_process))
@@ -316,12 +317,31 @@ ParseArgs(int argc, char **argv) {
        rxJumbograms = 0;
     if (cmd_OptionPresent(opts, OPT_jumbo))
        rxJumbograms = 1;
-#ifndef AFS_NT40_ENV
+
+#ifdef HAVE_SYSLOG
     if (cmd_OptionPresent(opts, OPT_syslog)) {
-       serverLogSyslog = 1;
-       cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility);
-    }
+       if (cmd_OptionPresent(opts, OPT_logfile)) {
+           fprintf(stderr, "Invalid options: -syslog and -logfile are exclusive.\n");
+           return -1;
+       }
+       logopts.lopt_dest = logDest_syslog;
+       logopts.lopt_facility = LOG_DAEMON;
+       logopts.lopt_tag = "volserver";
+       cmd_OptionAsInt(opts, OPT_syslog, &logopts.lopt_facility);
+    } else
 #endif
+    {
+       logopts.lopt_dest = logDest_file;
+       logopts.lopt_rotateOnOpen = 1;
+       logopts.lopt_rotateStyle = logRotate_old;
+
+       if (cmd_OptionPresent(opts, OPT_logfile))
+           cmd_OptionAsString(opts, OPT_logfile, (char**)&logopts.lopt_filename);
+       else
+           logopts.lopt_filename = AFSDIR_SERVER_VOLSERLOG_FILEPATH;
+    }
+    cmd_OptionAsInt(opts, OPT_debug, &logopts.lopt_logLevel);
+
     cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU);
     if (cmd_OptionAsInt(opts, OPT_udpsize, &optval) == 0) {
        if (optval < rx_GetMinUdpBufSize()) {
@@ -355,7 +375,6 @@ ParseArgs(int argc, char **argv) {
            return -1;
        }
     }
-    cmd_OptionAsString(opts, OPT_logfile, &logFile);
     cmd_OptionAsString(opts, OPT_config, &configDir);
     if (cmd_OptionAsString(opts, OPT_restricted_query,
                           &restricted_query_parameter) == 0) {
@@ -415,7 +434,6 @@ main(int argc, char **argv)
     }
 
     configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH);
-    logFile = strdup(AFSDIR_SERVER_VOLSERLOG_FILEPATH);
 
     if (ParseArgs(argc, argv)) {
        exit(1);
@@ -445,9 +463,8 @@ main(int argc, char **argv)
        exit(1);
     }
 #endif
-    /* Open VolserLog and map stdout, stderr into it; VInitVolumePackage2 can
-       log, so we need to do this here */
-    OpenLog(logFile);
+
+    OpenLog(&logopts);
 
     VOptDefaults(volumeServer, &opts);
     if (VInitVolumePackage2(volumeServer, &opts)) {