Remove discover sd to ps3d hack
[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 "user-event.h"
11 #include "discover-server.h"
12 #include "device-handler.h"
13
14 static int running;
15
16 static void sigint_handler(int __attribute__((unused)) signum)
17 {
18         running = 0;
19 }
20
21 int main(void)
22 {
23         struct device_handler *handler;
24         struct discover_server *server;
25         struct udev *udev;
26         struct user_event *uev;
27         FILE *log;
28
29         log = fopen("pb-discover.log", "a");
30         assert(log);
31         pb_log_set_stream(log);
32
33 #if defined(DEBUG)
34         pb_log_always_flush(1);
35 #endif
36         pb_log("--- pb-discover ---\n");
37
38         /* we look for closed sockets when we write, so ignore SIGPIPE */
39         signal(SIGPIPE, SIG_IGN);
40
41         signal(SIGINT, sigint_handler);
42
43         server = discover_server_init();
44         if (!server)
45                 return EXIT_FAILURE;
46
47         handler = device_handler_init(server);
48         if (!handler)
49                 return EXIT_FAILURE;
50
51         discover_server_set_device_source(server, handler);
52
53         udev = udev_init(handler);
54         if (!udev)
55                 return EXIT_FAILURE;
56
57         uev = user_event_init(handler);
58         if (!uev)
59                 return EXIT_FAILURE;
60
61         udev_trigger(udev);
62         user_event_trigger(uev);
63
64         for (running = 1; running;) {
65                 if (waiter_poll())
66                         break;
67         }
68
69         device_handler_destroy(handler);
70
71         pb_log("--- end ---\n");
72
73         return EXIT_SUCCESS;
74 }