]> git.ozlabs.org Git - petitboot/blobdiff - discover/pb-discover.c
Log to stderr, allow --log=-
[petitboot] / discover / pb-discover.c
index bd515e327cc9c94d75cd0c9ec3eb9de622a553ca..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>
@@ -58,7 +59,7 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
        };
        static const char short_options[] = "hl:V";
        static const struct opts default_values = {
-               .log_file = "pb-discover.log",
+               .log_file = "/var/log/petitboot/pb-discover.log",
        };
 
        *opts = default_values;
@@ -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);