]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Improve log initialization
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 10 May 2010 16:30:17 +0000 (18:30 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 10 May 2010 16:30:17 +0000 (18:30 +0200)
ccache.h
util.c

index be9ec41470412c7e008b5647fec16eed2c7131fe..7d50b2dd2002ac44b574c07df5d7a341b4f257c6 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -65,9 +65,9 @@ char *hash_result(struct mdfour *md);
 void hash_result_as_bytes(struct mdfour *md, unsigned char *out);
 void hash_buffer(struct mdfour *md, const void *s, size_t len);
 
-int cc_log_no_newline(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
-int cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
-int cc_log_executed_command(char **argv);
+void cc_log_no_newline(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
+void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
+void cc_log_executed_command(char **argv);
 void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
 
 void copy_fd(int fd_in, int fd_out);
diff --git a/util.c b/util.c
index 4a6195d79359b0e3cf8d5f5082173bfa5604ff7e..0aef7f972d11f33eef25bc8d3ead8d159ab5a683 100644 (file)
--- a/util.c
+++ b/util.c
 
 static FILE *logfile;
 
-static int cc_log_va_list(const char *format, va_list ap)
+static int init_log()
 {
        extern char *cache_logfile;
 
+       if (logfile) {
+               return 1;
+       }
        if (!cache_logfile) {
                return 0;
        }
+       logfile = fopen(cache_logfile, "a");
+       if (logfile) {
+               return 1;
+       } else {
+               return 0;
+       }
+}
 
-       if (!logfile) {
-               logfile = fopen(cache_logfile, "a");
-               if (!logfile) {
-                       return 0;
-               }
+static void log_va_list(const char *format, va_list ap)
+{
+       if (!init_log()) {
+               return;
        }
 
        fprintf(logfile, "[%-5d] ", getpid());
        vfprintf(logfile, format, ap);
-
-       return 1;
 }
 
 /*
  * Log a message to the CCACHE_LOGFILE location without newline and without
  * flushing.
  */
-int cc_log_no_newline(const char *format, ...)
+void cc_log_no_newline(const char *format, ...)
 {
-       int logged;
+       if (!init_log()) {
+               return;
+       }
+
        va_list ap;
        va_start(ap, format);
-       logged = cc_log_va_list(format, ap);
+       log_va_list(format, ap);
        va_end(ap);
-       return logged;
 }
 
 /*
  * Log a message to the CCACHE_LOGFILE location adding a newline and flushing.
  */
-int cc_log(const char *format, ...)
+void cc_log(const char *format, ...)
 {
-       int logged;
+       if (!init_log()) {
+               return;
+       }
+
        va_list ap;
        va_start(ap, format);
-       logged = cc_log_va_list(format, ap);
-       if (logged) {
-               fprintf(logfile, "\n");
-               fflush(logfile);
-       }
+       log_va_list(format, ap);
        va_end(ap);
-       return logged;
+       fprintf(logfile, "\n");
+       fflush(logfile);
 }
 
-int cc_log_executed_command(char **argv)
+void cc_log_executed_command(char **argv)
 {
-       if (cc_log_no_newline("Executing ")) {
-               print_command(logfile, argv);
-               fflush(logfile);
-               return 1;
-       } else {
-               return 0;
+       if (!init_log()) {
+               return;
        }
+
+       cc_log_no_newline("Executing ");
+       print_command(logfile, argv);
+       fflush(logfile);
 }
 
 /* something went badly wrong! */