[PATCH 3/3] Optional Logfile Timestamp Functionality.

0 views
Skip to first unread message

Ian....@cern.ch

unread,
Feb 3, 2009, 5:29:54 AM2/3/09
to distcc-...@googlegroups.com
distcc_filelog_timestamp_trace.patch

Fergus Henderson

unread,
Mar 11, 2009, 1:53:31 PM3/11/09
to distcc-...@googlegroups.com
Looks good to me!
Please feel free to commit this patch to the svn repository.

Cheers,
  Fergus.

On Tue, Feb 3, 2009 at 6:29 AM, <Ian....@cern.ch> wrote:

This patch is used to implement optional logfile entry timestamps.
This option is specified through an environment variable.

Index: quilt-distcc-3.1/distcc-3.1/src/trace.c
===================================================================
--- quilt-distcc-3.1.orig/distcc-3.1/src/trace.c
+++ quilt-distcc-3.1/distcc-3.1/src/trace.c
@@ -38,6 +38,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <syslog.h>
+#include <time.h>

 #include "trace.h"
 #include "snprintf.h"
@@ -319,6 +320,26 @@ rs_logger_file(int flags, const char *fn
    /* NOTE NO TRAILING NUL */
    char buf[4090];
    size_t len;
+    char timebuf[128];
+    size_t timebuflen;
+    time_t now;
+    struct tm *timestamp;
+    char *timestamp_opt;
+
+    if ((timestamp_opt = getenv("DISTCC_TIMESTAMP"))) {
+       if (*timestamp_opt == '1') {
+            now = time(NULL);
+
+           if ((timestamp = localtime(&now)) != NULL) {
+               timebuflen = strftime(timebuf, 128, "%F %T ", timestamp);
+           } else {
+                strcpy(timebuf, "localtime() NULL??? ");
+               timebuflen = strlen(timebuf);
+           }
+
+           (void) write(log_fd, timebuf, timebuflen);
+       }
+    }

    rs_format_msg(buf, sizeof buf, flags, fn, fmt, va);

Index: quilt-distcc-3.1/distcc-3.1/man/distcc.1
===================================================================
--- quilt-distcc-3.1.orig/distcc-3.1/man/distcc.1
+++ quilt-distcc-3.1/distcc-3.1/man/distcc.1
@@ -820,6 +820,9 @@ If set to 1, peform GSS-API based mutual
 .B "DISTCC_PRINCIPAL"
 If set, specifies the name of the principal that distccd runs under, and is used
 to authenticate the server to the client.
+.TP
+.B "DISTCC_TIMESTAMP"
+If set to 1, include timestamps for logfile entries.
 .SH "CROSS COMPILING"
 Cross compilation means building programs to run on a
 machine with a different processor, architecture, or
Index: quilt-distcc-3.1/distcc-3.1/man/distccd.1
===================================================================
--- quilt-distcc-3.1.orig/distcc-3.1/man/distccd.1
+++ quilt-distcc-3.1/distcc-3.1/man/distccd.1
@@ -301,6 +301,9 @@ Directory for temporary files such as pr
 .B "DISTCCD_PRINCIPAL"
 If set, specifies the name of the principal that distccd runs under, and is used
 to authenticate with the client.
+.TP
+.B "DISTCC_TIMESTAMP"
+If set to 1, include timestamps for logfile entries.
 .SH "SEE ALSO"
 \fBdistcc\fR(1), \fBpump\fR(1), \fBinclude_server\fR(1), \fBgcc\fR(1),
 \fBmake\fR(1), and  \fBccache\fR(1)






--
Fergus Henderson <fer...@google.com>
Reply all
Reply to author
Forward
0 new messages