]> git.ozlabs.org Git - petitboot/commitdiff
Log to stderr, allow --log=-
authorGeoff Levand <geoff@infradead.org>
Tue, 27 Mar 2012 02:23:17 +0000 (19:23 -0700)
committerGeoff Levand <geoff@infradead.org>
Tue, 27 Mar 2012 02:23:17 +0000 (19:23 -0700)
Signed-off-by: Geoff Levand <geoff@infradead.org>
discover/pb-discover.c
lib/log/log.c
ui/ncurses/generic-main.c
ui/ncurses/ps3-main.c
ui/twin/main-generic.c
ui/twin/main-ps3.c

index fa1c28ec75ca169f0690740d9358d4a394eff9b2..aac50df332d4c47b636909ae7b7c0afbf3310c4a 100644 (file)
@@ -7,6 +7,7 @@
 #include <getopt.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <string.h>
 
 #include <waiter/waiter.h>
 #include <log/log.h>
@@ -103,7 +104,6 @@ int main(int argc, char *argv[])
        struct opts opts;
        struct udev *udev;
        struct user_event *uev;
-       FILE *log;
 
        if (opts_parse(&opts, argc, argv)) {
                print_usage();
@@ -120,9 +120,13 @@ int main(int argc, char *argv[])
                return EXIT_SUCCESS;
        }
 
-       log = fopen(opts.log_file, "a");
-       assert(log);
-       pb_log_set_stream(log);
+       if (strcmp(opts.log_file, "-")) {
+               FILE *log = fopen(opts.log_file, "a");
+
+               assert(log);
+               pb_log_set_stream(log);
+       } else
+               pb_log_set_stream(stderr);
 
 #if defined(DEBUG)
        pb_log_always_flush(1);
index 697af6c0760ec612d328f03de59ee7be1a86b1a2..ecbd7142d2e5c14ce1f5847d2bb93a6e467790df 100644 (file)
@@ -11,7 +11,7 @@ void pb_log(const char *fmt, ...)
        va_list ap;
        FILE *stream;
 
-       stream = logf ? logf : stdout;
+       stream = logf ? logf : stderr;
 
        va_start(ap, fmt);
        vfprintf(stream, fmt, ap);
@@ -23,13 +23,13 @@ void pb_log(const char *fmt, ...)
 
 void pb_log_set_stream(FILE *stream)
 {
-       fflush(logf ? logf : stdout);
+       fflush(logf ? logf : stderr);
        logf = stream;
 }
 
 FILE * pb_log_get_stream(void)
 {
-       return logf;
+       return logf ? logf : stderr;
 }
 
 void pb_log_always_flush(int state)
index 6b8f5bacd92eb95c155727904d6bea5c7a910d8d..4d154eee067502cff1d93a4ee6ba44bc2cde31e1 100644 (file)
@@ -234,7 +234,6 @@ int main(int argc, char *argv[])
        static struct opts opts;
        int result;
        int cui_result;
-       FILE *log;
 
        result = opts_parse(&opts, argc, argv);
 
@@ -253,9 +252,13 @@ int main(int argc, char *argv[])
                return EXIT_SUCCESS;
        }
 
-       log = fopen(opts.log_file, "a");
-       assert(log);
-       pb_log_set_stream(log);
+       if (strcmp(opts.log_file, "-")) {
+               FILE *log = fopen(opts.log_file, "a");
+
+               assert(log);
+               pb_log_set_stream(log);
+       } else
+               pb_log_set_stream(stderr);
 
 #if defined(DEBUG)
        pb_log_always_flush(1);
index 890e47b852221a0c1b04e1519e838ac5a8bbb6e9..69913edc73910dcca30173649d6ceeb319b364e4 100644 (file)
@@ -597,7 +597,6 @@ int main(int argc, char *argv[])
        int result;
        int cui_result;
        unsigned int mode;
-       FILE *log;
 
        result = opts_parse(&opts, argc, argv);
 
@@ -616,9 +615,13 @@ int main(int argc, char *argv[])
                return EXIT_SUCCESS;
        }
 
-       log = fopen(opts.log_file, "a");
-       assert(log);
-       pb_log_set_stream(log);
+       if (strcmp(opts.log_file, "-")) {
+               FILE *log = fopen(opts.log_file, "a");
+
+               assert(log);
+               pb_log_set_stream(log);
+       } else
+               pb_log_set_stream(stderr);
 
 #if defined(DEBUG)
        pb_log_always_flush(1);
index ce6a5739e6f58351c5b47d10568cc56241537872..7cf510a44c2ebefebf485e3a6fb5f9f25bd5f158 100644 (file)
@@ -285,7 +285,6 @@ int main(int argc, char *argv[])
        static struct pbt_opts opts;
        int result;
        int ui_result;
-       FILE *log;
        struct pbt_client *client;
 
        result = pbt_opts_parse(&opts, argc, argv);
@@ -305,9 +304,13 @@ int main(int argc, char *argv[])
                return EXIT_SUCCESS;
        }
 
-       log = fopen(opts.log_file, "a");
-       assert(log);
-       pb_log_set_stream(log);
+       if (strcmp(opts.log_file, "-")) {
+               FILE *log = fopen(opts.log_file, "a");
+
+               assert(log);
+               pb_log_set_stream(log);
+       } else
+               pb_log_set_stream(stderr);
 
 #if defined(DEBUG)
        pb_log_always_flush(1);
index 66ba5613c05d46c0ba68784903c0205b24bdb186..138cd28f74f6eb2aaccfbb20f591f57f5a5447a0 100644 (file)
@@ -372,7 +372,6 @@ int main(int argc, char *argv[])
        int result;
        int ui_result = -1;
        unsigned int mode;
-       FILE *log;
 
        result = pbt_opts_parse(&opts, argc, argv);
 
@@ -391,9 +390,13 @@ int main(int argc, char *argv[])
                return EXIT_SUCCESS;
        }
 
-       log = fopen(opts.log_file, "a");
-       assert(log);
-       pb_log_set_stream(log);
+       if (strcmp(opts.log_file, "-")) {
+               FILE *log = fopen(opts.log_file, "a");
+
+               assert(log);
+               pb_log_set_stream(log);
+       } else
+               pb_log_set_stream(stderr);
 
 #if defined(DEBUG)
        pb_log_always_flush(1);