Log server messages to file
[petitboot] / discover / pb-discover.c
1
2 #include <assert.h>
3 #include <stdlib.h>
4 #include <signal.h>
5
6 #include <waiter/waiter.h>
7 #include <log/log.h>
8
9 #include "udev.h"
10 #include "discover-server.h"
11 #include "device-handler.h"
12
13 static int running;
14
15 static void sigint_handler(int __attribute__((unused)) signum)
16 {
17         running = 0;
18 }
19
20 int main(void)
21 {
22         struct device_handler *handler;
23         struct discover_server *server;
24         struct udev *udev;
25         FILE *log;
26
27         log = fopen("pb-discover.log", "a");
28         assert(log);
29         pb_log_set_stream(log);
30
31 #if defined(DEBUG)
32         pb_log_always_flush(1);
33 #endif
34         pb_log("--- pb-discover ---\n");
35
36         /* we look for closed sockets when we write, so ignore SIGPIPE */
37         signal(SIGPIPE, SIG_IGN);
38
39         signal(SIGINT, sigint_handler);
40
41         server = discover_server_init();
42         if (!server)
43                 return EXIT_FAILURE;
44
45         handler = device_handler_init(server);
46         if (!handler)
47                 return EXIT_FAILURE;
48
49         discover_server_set_device_source(server, handler);
50
51         udev = udev_init(handler);
52         if (!udev)
53                 return EXIT_FAILURE;
54
55         for (running = 1; running;) {
56                 if (waiter_poll())
57                         break;
58         }
59
60         device_handler_destroy(handler);
61
62         pb_log("--- end ---\n");
63
64         return EXIT_SUCCESS;
65 }