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