lib/log: Cleanup log API
[petitboot] / discover / pb-discover.c
index 61da5097035ff6aedf12f6ba2c3b6692a790c170..c16d6903ed5c1da180dfd615beed1950c824b20b 100644 (file)
@@ -123,6 +123,7 @@ int main(int argc, char *argv[])
        struct opts opts;
        struct pb_udev *udev;
        struct user_event *uev;
+       FILE *log;
 
        if (opts_parse(&opts, argc, argv)) {
                print_usage();
@@ -139,17 +140,17 @@ int main(int argc, char *argv[])
                return EXIT_SUCCESS;
        }
 
+       log = stderr;
        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);
+               log = fopen(opts.log_file, "a");
+               if (!log) {
+                       fprintf(stderr, "can't open log file %s, logging to "
+                                       "stderr\n", opts.log_file);
+                       log = stderr;
+               }
+       }
+       pb_log_init(log);
 
-#if defined(DEBUG)
-       pb_log_always_flush(1);
-#endif
        pb_log("--- pb-discover ---\n");
 
        /* we look for closed sockets when we write, so ignore SIGPIPE */
@@ -168,7 +169,7 @@ int main(int argc, char *argv[])
        if (!server)
                return EXIT_FAILURE;
 
-       procset = process_init(server, waitset);
+       procset = process_init(server, waitset, opts.dry_run == opt_yes);
        if (!procset)
                return EXIT_FAILURE;