From: Geoff Levand Date: Tue, 27 Mar 2012 02:23:17 +0000 (-0700) Subject: Log to stderr, allow --log=- X-Git-Tag: v1.0.0~766 X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=commitdiff_plain;h=09cc1ef3d7e2c1dab6648aceb24dd33e7897f998 Log to stderr, allow --log=- Signed-off-by: Geoff Levand --- diff --git a/discover/pb-discover.c b/discover/pb-discover.c index fa1c28e..aac50df 100644 --- a/discover/pb-discover.c +++ b/discover/pb-discover.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -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); diff --git a/lib/log/log.c b/lib/log/log.c index 697af6c..ecbd714 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -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) diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index 6b8f5ba..4d154ee 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -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); diff --git a/ui/ncurses/ps3-main.c b/ui/ncurses/ps3-main.c index 890e47b..69913ed 100644 --- a/ui/ncurses/ps3-main.c +++ b/ui/ncurses/ps3-main.c @@ -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); diff --git a/ui/twin/main-generic.c b/ui/twin/main-generic.c index ce6a573..7cf510a 100644 --- a/ui/twin/main-generic.c +++ b/ui/twin/main-generic.c @@ -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); diff --git a/ui/twin/main-ps3.c b/ui/twin/main-ps3.c index 66ba561..138cd28 100644 --- a/ui/twin/main-ps3.c +++ b/ui/twin/main-ps3.c @@ -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);