lib/log: Cleanup log API
[petitboot] / discover / pb-discover.c
index a0535c2f5e6639a423ffba3bcd534aae408ba8fc..c16d6903ed5c1da180dfd615beed1950c824b20b 100644 (file)
@@ -12,6 +12,7 @@
 #include <waiter/waiter.h>
 #include <log/log.h>
 #include <pb-config/pb-config.h>
+#include <process/process.h>
 
 #include "udev.h"
 #include "user-event.h"
@@ -118,9 +119,11 @@ int main(int argc, char *argv[])
        struct discover_server *server;
        struct network *network;
        struct waitset *waitset;
+       struct procset *procset;
        struct opts opts;
        struct pb_udev *udev;
        struct user_event *uev;
+       FILE *log;
 
        if (opts_parse(&opts, argc, argv)) {
                print_usage();
@@ -137,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 */
@@ -166,6 +169,10 @@ int main(int argc, char *argv[])
        if (!server)
                return EXIT_FAILURE;
 
+       procset = process_init(server, waitset, opts.dry_run == opt_yes);
+       if (!procset)
+               return EXIT_FAILURE;
+
        network = network_init(server, waitset, opts.dry_run == opt_yes);
        if (!network)
                return EXIT_FAILURE;