PATCH: Options for more log-output (BUGFIX)
Mattias.Gronlund
Mattias.Gronlund at sa.erisoft.se
Mon Aug 30 19:07:42 GMT 1999
Sorry,
There had snneked in bugs in the patch, I'm sorry, but this version
should be better tested.
/Mattias
"Mattias.Gronlund" wrote:
>
> Hi,
>
> I have made a patch that adds three new options to smb.conf:
>
> debug hires timestamp:
> Sometimes the timestamps in the log messages are needed with a
> resolution of higher that seconds, this boolean parameter adds
> microsecond resolution to the message header when turned on.
>
> debug pid:
> When using only one log file for more then one forked smbd-process
> there may be hard to follow which process outputs which message.
> This boolean parameter is adds the process-id to the messageheaders
> in the logfile when turned on.
>
> debug uid:
> Samba is sometimes run as root and sometime run as the connected
> user, this boolean parameter inserts the current euid, egid, uid
> and gid to the message headers in the log file if turned on.
>
> They all give us a much better chance to understand why some strange
> errors have occured.
>
> The patch is against 2.0.5a, and if this code make it into the
> mainstream
> I will create patches for the head branch to.
>
> The options defaults to off so that the log-format does not change for
> users that does not enable any of them.
>
> Pleas give me some feedback if you do not think this patch should go
> into
> mainstream.
>
> /Mattias
>
-------------- next part --------------
diff -ru samba-2.0.5a/source/include/proto.h samba-2.0.5a-mgr/source/include/proto.h
--- samba-2.0.5a/source/include/proto.h Thu Jul 22 04:00:26 1999
+++ samba-2.0.5a-mgr/source/include/proto.h Tue Aug 24 21:46:53 1999
@@ -1045,6 +1045,9 @@
BOOL lp_encrypted_passwords(void);
BOOL lp_update_encrypted(void);
BOOL lp_syslog_only(void);
+BOOL lp_debug_hires_timestamp(void);
+BOOL lp_debug_pid(void);
+BOOL lp_debug_uid(void);
BOOL lp_timestamp_logs(void);
BOOL lp_browse_list(void);
BOOL lp_unix_realname(void);
diff -ru samba-2.0.5a/source/lib/debug.c samba-2.0.5a-mgr/source/lib/debug.c
--- samba-2.0.5a/source/lib/debug.c Tue Feb 16 20:20:55 1999
+++ samba-2.0.5a-mgr/source/lib/debug.c Mon Aug 30 20:59:58 1999
@@ -515,6 +515,9 @@
*/
BOOL dbghdr( int level, char *file, char *func, int line )
{
+ #define HEADER_SIZE 100
+ char header_str[HEADER_SIZE];
+
if( format_pos )
{
/* This is a fudge. If there is stuff sitting in the format_bufr, then
@@ -543,9 +546,18 @@
*/
if( lp_timestamp_logs() || !(lp_loaded()) )
{
+ header_str[0] = '\0';
+ if( lp_debug_pid())
+ slprintf(header_str, sizeof(header_str)-1, ", %d", getpid());
+ if( lp_debug_uid())
+ slprintf(header_str+strlen(header_str), sizeof(header_str)-1-strlen( header_str ),
+ ", e(%d, %d), r(%d, %d)", geteuid(), getegid(),
+ getuid(), getgid());
+
/* Print it all out at once to prevent split syslog output. */
- (void)Debug1( "[%s, %d] %s:%s(%d)\n",
- timestring(), level, file, func, line );
+ (void)Debug1( "[%s, %d%s] %s:%s(%d)\n",
+ timestring(), level,
+ header_str, file, func, line );
}
return( True );
diff -ru samba-2.0.5a/source/lib/time.c samba-2.0.5a-mgr/source/lib/time.c
--- samba-2.0.5a/source/lib/time.c Mon Jan 4 20:21:50 1999
+++ samba-2.0.5a-mgr/source/lib/time.c Tue Aug 24 21:46:53 1999
@@ -509,16 +509,51 @@
char *timestring(void )
{
static fstring TimeBuf;
- time_t t = time(NULL);
- struct tm *tm = LocalTime(&t);
+ struct timeval tp;
+ time_t t;
+ struct tm *tm;
+ if (lp_debug_hires_timestamp()) {
+ GetTimeOfDay(&tp);
+ t = (time_t)tp.tv_sec;
+ } else {
+ t = time(NULL);
+ }
+ tm = LocalTime(&t);
if (!tm) {
- slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t);
+ if (lp_debug_hires_timestamp()) {
+ slprintf(TimeBuf,
+ sizeof(TimeBuf)-1,
+ "%ld.%06ld seconds since the Epoch",
+ (long)tp.tv_sec,
+ (long)tp.tv_usec);
+ } else {
+ slprintf(TimeBuf,
+ sizeof(TimeBuf)-1,
+ "%ld seconds since the Epoch",
+ (long)t);
+ }
} else {
#ifdef HAVE_STRFTIME
- strftime(TimeBuf,100,"%Y/%m/%d %H:%M:%S",tm);
+ if (lp_debug_hires_timestamp()) {
+ strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
+ slprintf(TimeBuf+strlen(TimeBuf),
+ sizeof(TimeBuf)-1 - strlen(TimeBuf),
+ ".%06ld",
+ (long)tp.tv_usec);
+ } else {
+ strftime(TimeBuf,100,"%Y/%m/%d %H:%M:%S",tm);
+ }
#else
- fstrcpy(TimeBuf, asctime(tm));
+ if (lp_debug_hires_timestamp)() {
+ slprintf(TimeBuf,
+ sizeof(TimeBuf)-1,
+ "%s.%06ld",
+ asctime(tm),
+ (long)tp.tv_usec);
+ } else {
+ fstrcpy(TimeBuf, asctime(tm));
+ }
#endif
}
return(TimeBuf);
diff -ru samba-2.0.5a/source/param/loadparm.c samba-2.0.5a-mgr/source/param/loadparm.c
--- samba-2.0.5a/source/param/loadparm.c Wed Jul 21 03:25:12 1999
+++ samba-2.0.5a-mgr/source/param/loadparm.c Tue Aug 24 21:46:53 1999
@@ -240,6 +240,9 @@
BOOL bKernelOplocks;
BOOL bAllowTrustedDomains;
BOOL bRestrictAnonymous;
+ BOOL bDebugHiresTimestamp;
+ BOOL bDebugPid;
+ BOOL bDebugUid;
} global;
static global Globals;
@@ -626,6 +629,9 @@
{"max log size", P_INTEGER, P_GLOBAL, &Globals.max_log_size, NULL, NULL, 0},
{"timestamp logs", P_BOOL, P_GLOBAL, &Globals.bTimestampLogs, NULL, NULL, 0},
{"debug timestamp", P_BOOL, P_GLOBAL, &Globals.bTimestampLogs, NULL, NULL, 0},
+ {"debug hires timestamp", P_BOOL, P_GLOBAL, &Globals.bDebugHiresTimestamp, NULL, NULL, 0},
+ {"debug pid", P_BOOL, P_GLOBAL, &Globals.bDebugPid, NULL, NULL, 0},
+ {"debug uid", P_BOOL, P_GLOBAL, &Globals.bDebugUid, NULL, NULL, 0},
{"status", P_BOOL, P_LOCAL, &sDefault.status, NULL, NULL, FLAG_GLOBAL|FLAG_SHARE|FLAG_PRINT},
{"Protocol Options", P_SEP, P_SEPARATOR},
@@ -907,6 +913,9 @@
Globals.syslog = 1;
Globals.bSyslogOnly = False;
Globals.bTimestampLogs = True;
+ Globals.bDebugHiresTimestamp = False;
+ Globals.bDebugPid = False;
+ Globals.bDebugUid = False;
Globals.os_level = 0;
Globals.max_ttl = 60*60*24*3; /* 3 days default. */
Globals.max_wins_ttl = 60*60*24*6; /* 6 days default. */
@@ -1229,6 +1238,9 @@
FN_GLOBAL_BOOL(lp_update_encrypted,&Globals.bUpdateEncrypt)
FN_GLOBAL_BOOL(lp_syslog_only,&Globals.bSyslogOnly)
FN_GLOBAL_BOOL(lp_timestamp_logs,&Globals.bTimestampLogs)
+FN_GLOBAL_BOOL(lp_debug_hires_timestamp,&Globals.bDebugHiresTimestamp)
+FN_GLOBAL_BOOL(lp_debug_pid,&Globals.bDebugPid)
+FN_GLOBAL_BOOL(lp_debug_uid,&Globals.bDebugUid)
FN_GLOBAL_BOOL(lp_browse_list,&Globals.bBrowseList)
FN_GLOBAL_BOOL(lp_unix_realname,&Globals.bUnixRealname)
FN_GLOBAL_BOOL(lp_nis_home_map,&Globals.bNISHomeMap)
More information about the samba-technical
mailing list