/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
#include <afsconfig.h>
#include <afs/param.h>
+#include <afs/stds.h>
-
-#include <stdio.h>
-#ifdef AFS_NT40_ENV
-#include <io.h>
-#include <time.h>
-#else
-#ifdef AFS_AIX_ENV
-#include <time.h>
-#endif
-#include <sys/param.h>
-#include <sys/time.h>
-#include <syslog.h>
-#endif
#include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
-#include <fcntl.h>
-#include <afs/stds.h>
-#include <string.h>
-#include <sys/stat.h>
+
+#include <roken.h> /* Must come after procmgmt.h */
+#include <afs/opr.h>
+
+#include <afs/opr.h>
#include "afsutil.h"
#include "fileutil.h"
#include <lwp.h>
+
#if defined(AFS_PTHREAD_ENV)
-#include <assert.h>
#include <pthread.h>
static pthread_mutex_t serverLogMutex;
-#define LOCK_SERVERLOG() assert(pthread_mutex_lock(&serverLogMutex)==0)
-#define UNLOCK_SERVERLOG() assert(pthread_mutex_unlock(&serverLogMutex)==0)
+#define LOCK_SERVERLOG() opr_Verify(pthread_mutex_lock(&serverLogMutex) == 0);
+#define UNLOCK_SERVERLOG() opr_Verify(pthread_mutex_unlock(&serverLogMutex) == 0);
#ifdef AFS_NT40_ENV
#define NULLDEV "NUL"
char *serverLogSyslogTag = 0;
#endif
-#include <stdarg.h>
int LogLevel;
int mrafsStyleLogs = 0;
static int threadIdLogs = 0;
}
int
-LogThreadNum(void)
+LogThreadNum(void)
{
return (*threadNumProgram) ();
}
vFSLog(const char *format, va_list args)
{
time_t currenttime;
- char *timeStamp;
char tbuffer[1024];
char *info;
size_t len;
+ struct tm tm;
int num;
- currenttime = time(0);
- timeStamp = afs_ctime(¤ttime, tbuffer, sizeof(tbuffer));
- timeStamp[24] = ' '; /* ts[24] is the newline, 25 is the null */
- info = &timeStamp[25];
+ currenttime = time(NULL);
+ len = strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y ",
+ localtime_r(¤ttime, &tm));
+ info = &tbuffer[len];
if (mrafsStyleLogs || threadIdLogs) {
num = (*threadNumProgram) ();
if (num > -1) {
- (void)afs_snprintf(info, (sizeof tbuffer) - strlen(tbuffer), "[%d] ",
- num);
- info += strlen(info);
- }
+ snprintf(info, (sizeof tbuffer) - strlen(tbuffer), "[%d] ",
+ num);
+ info += strlen(info);
+ }
}
- (void)afs_vsnprintf(info, (sizeof tbuffer) - strlen(tbuffer), format,
- args);
+ vsnprintf(info, (sizeof tbuffer) - strlen(tbuffer), format, args);
len = strlen(tbuffer);
LOCK_SERVERLOG();
va_end(args);
} /*FSLog */
+void
+LogCommandLine(int argc, char **argv, const char *progname,
+ const char *version, const char *logstring,
+ void (*log) (const char *format, ...))
+{
+ int i, l;
+ char *commandLine, *cx;
+
+ opr_Assert(argc > 0);
+
+ for (l = i = 0; i < argc; i++)
+ l += strlen(argv[i]) + 1;
+ if ((commandLine = malloc(l))) {
+ for (cx = commandLine, i = 0; i < argc; i++) {
+ strcpy(cx, argv[i]);
+ cx += strlen(cx);
+ *(cx++) = ' ';
+ }
+ commandLine[l-1] = '\0';
+ (*log)("%s %s %s%s(%s)\n", logstring, progname,
+ version, strlen(version)>0?" ":"", commandLine);
+ free(commandLine);
+ } else {
+ /* What, we're out of memory already!? */
+ (*log)("%s %s%s%s\n", logstring,
+ progname, strlen(version)>0?" ":"", version);
+ }
+}
+
static void*
DebugOn(void *param)
{
- int loglevel = (int)param;
+ int loglevel = (intptr_t)param;
if (loglevel == 0) {
ViceLog(0, ("Reset Debug levels to 0\n"));
} else {
LogLevel *= 5;
#if defined(AFS_PTHREAD_ENV)
- if (LogLevel > 1 && threadNumProgram != NULL &&
+ if (LogLevel > 1 && threadNumProgram != NULL &&
threadIdLogs == 0) {
threadIdLogs = 1;
}
}
printLocks = 2;
#if defined(AFS_PTHREAD_ENV)
- DebugOn((void *) LogLevel);
+ DebugOn((void *)(intptr_t)LogLevel);
#else /* AFS_PTHREAD_ENV */
- IOMGR_SoftSig(DebugOn, (void *) LogLevel);
+ IOMGR_SoftSig(DebugOn, (void *)(intptr_t)LogLevel);
#endif /* AFS_PTHREAD_ENV */
(void)signal(signo, SetDebug_Signal); /* on some platforms, this
if (printLocks > 0)
--printLocks;
#if defined(AFS_PTHREAD_ENV)
- DebugOn((void *) LogLevel);
+ DebugOn((void *)(intptr_t)LogLevel);
#else /* AFS_PTHREAD_ENV */
- IOMGR_SoftSig(DebugOn, (void *) LogLevel);
+ IOMGR_SoftSig(DebugOn, (void *)(intptr_t)LogLevel);
#endif /* AFS_PTHREAD_ENV */
(void)signal(signo, ResetDebug_Signal); /* on some platforms,
if (mrafsStyleLogs) {
time_t t;
- FT_GetTimeOfDay(&Start, 0);
- t = Start.tv_sec;
+ struct stat buf;
+ gettimeofday(&Start, NULL);
+ t = Start.tv_sec;
TimeFields = localtime(&t);
if (fileName) {
if (strncmp(fileName, (char *)&ourName, strlen(fileName)))
strcpy((char *)&ourName, (char *)fileName);
}
- afs_snprintf(FileName, MAXPATHLEN, "%s.%d%02d%02d%02d%02d%02d",
- ourName, TimeFields->tm_year + 1900,
- TimeFields->tm_mon + 1, TimeFields->tm_mday,
- TimeFields->tm_hour, TimeFields->tm_min,
- TimeFields->tm_sec);
+ makefilename:
+ snprintf(FileName, MAXPATHLEN, "%s.%d%02d%02d%02d%02d%02d",
+ ourName, TimeFields->tm_year + 1900,
+ TimeFields->tm_mon + 1, TimeFields->tm_mday,
+ TimeFields->tm_hour, TimeFields->tm_min,
+ TimeFields->tm_sec);
+ if(lstat(FileName, &buf) == 0) {
+ /* avoid clobbering a log */
+ TimeFields->tm_sec++;
+ goto makefilename;
+ }
if (!isfifo)
- renamefile(fileName, FileName); /* don't check error code */
+ rk_rename(fileName, FileName); /* don't check error code */
tempfd = open(fileName, O_WRONLY | O_TRUNC | O_CREAT | (isfifo?O_NONBLOCK:0), 0666);
} else {
strcpy(oldName, fileName);
/* don't check error */
if (!isfifo)
- renamefile(fileName, oldName);
+ rk_rename(fileName, oldName);
tempfd = open(fileName, O_WRONLY | O_TRUNC | O_CREAT | (isfifo?O_NONBLOCK:0), 0666);
}
(void)freopen(fileName, "a", stdout);
(void)freopen(fileName, "a", stderr);
#ifdef HAVE_SETVBUF
-#ifdef SETVBUF_REVERSED
- setvbuf(stderr, _IONBF, NULL, 0);
-#else
setvbuf(stderr, NULL, _IONBF, 0);
-#endif
#else
setbuf(stderr, NULL);
#endif
#if defined(AFS_PTHREAD_ENV)
- assert(pthread_mutex_init(&serverLogMutex, NULL) == 0);
+ opr_Verify(pthread_mutex_init(&serverLogMutex, NULL) == 0);
#endif /* AFS_PTHREAD_ENV */
serverLogFD = tempfd;