Add device handler cleanup
[petitboot] / discover / pb-discover.c
index 45b6ba1c7207c62a870a73fe3d22c317bf418326..024cb303fb9f6da4dfb4dd0204c59d12425a213a 100644 (file)
@@ -4,31 +4,49 @@
 
 #include "udev.h"
 #include "discover-server.h"
+#include "device-handler.h"
 #include "waiter.h"
 #include "log.h"
 
+static int running;
+
+void sigint_handler(int signum)
+{
+       running = 0;
+}
 
 int main(void)
 {
+       struct device_handler *handler;
        struct discover_server *server;
        struct udev *udev;
 
        /* we look for closed sockets when we write, so ignore SIGPIPE */
        signal(SIGPIPE, SIG_IGN);
 
-       udev = udev_init();
-       if (!udev)
-               return EXIT_FAILURE;
+       signal(SIGINT, sigint_handler);
 
        server = discover_server_init();
        if (!server)
                return EXIT_FAILURE;
 
-       for (;;) {
+       handler = device_handler_init(server);
+       if (!handler)
+               return EXIT_FAILURE;
+
+       discover_server_set_device_source(server, handler);
+
+       udev = udev_init(handler);
+       if (!udev)
+               return EXIT_FAILURE;
+
+       for (running = 1; running;) {
                if (waiter_poll())
-                       return EXIT_FAILURE;
+                       break;
        }
 
+       device_handler_destroy(handler);
+
 
        return EXIT_SUCCESS;
 }