56602d95d015b24b74c6976b60099993823ef745
[petitboot] / discover / pb-discover.c
1
2 #include <stdlib.h>
3 #include <signal.h>
4
5 #include "udev.h"
6 #include "discover-server.h"
7 #include "device-handler.h"
8 #include "waiter.h"
9 #include "log.h"
10
11 static int running;
12
13 static void sigint_handler(int __attribute__((unused)) signum)
14 {
15         running = 0;
16 }
17
18 int main(void)
19 {
20         struct device_handler *handler;
21         struct discover_server *server;
22         struct udev *udev;
23
24         /* we look for closed sockets when we write, so ignore SIGPIPE */
25         signal(SIGPIPE, SIG_IGN);
26
27         signal(SIGINT, sigint_handler);
28
29         server = discover_server_init();
30         if (!server)
31                 return EXIT_FAILURE;
32
33         handler = device_handler_init(server);
34         if (!handler)
35                 return EXIT_FAILURE;
36
37         discover_server_set_device_source(server, handler);
38
39         udev = udev_init(handler);
40         if (!udev)
41                 return EXIT_FAILURE;
42
43         for (running = 1; running;) {
44                 if (waiter_poll())
45                         break;
46         }
47
48         device_handler_destroy(handler);
49
50
51         return EXIT_SUCCESS;
52 }