Add device handler cleanup
[petitboot] / discover / pb-discover.c
index d2ea7ae1e7b075691e708d4b72f8d94a6557050a..024cb303fb9f6da4dfb4dd0204c59d12425a213a 100644 (file)
@@ -8,6 +8,13 @@
 #include "waiter.h"
 #include "log.h"
 
 #include "waiter.h"
 #include "log.h"
 
+static int running;
+
+void sigint_handler(int signum)
+{
+       running = 0;
+}
+
 int main(void)
 {
        struct device_handler *handler;
 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);
 
        /* 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;
        server = discover_server_init();
        if (!server)
                return EXIT_FAILURE;
@@ -31,11 +40,13 @@ int main(void)
        if (!udev)
                return EXIT_FAILURE;
 
        if (!udev)
                return EXIT_FAILURE;
 
-       for (;;) {
+       for (running = 1; running;) {
                if (waiter_poll())
                if (waiter_poll())
-                       return EXIT_FAILURE;
+                       break;
        }
 
        }
 
+       device_handler_destroy(handler);
+
 
        return EXIT_SUCCESS;
 }
 
        return EXIT_SUCCESS;
 }