]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
engine: asynchronous start to prevent leaking of messages
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 12 Apr 2015 19:49:40 +0000 (21:49 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 12 Apr 2015 19:49:40 +0000 (21:49 +0200)
daemon/engine.c
daemon/main.c

index b1eea15d63887a5c31039de445a4df01965d6dcc..8b174a8096a37f398c0b20602493b0ad2515e89a 100644 (file)
@@ -251,7 +251,7 @@ int engine_start(struct engine *engine)
                return ret;
        }
 
-       return uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+       return kr_ok();
 }
 
 void engine_stop(struct engine *engine)
index 2cae4746e97317131d4a6e5b2ff4a84fb14c29ed..1f9906f0baf642916329d645d8464b72cf7dcb8f 100644 (file)
@@ -150,31 +150,39 @@ int main(int argc, char **argv)
        loop->data = &worker;
 
        /* Bind to sockets. */
-       ret = network_listen(&engine.net, addr, (uint16_t)port, NET_UDP|NET_TCP);
-       if (ret != 0) {
-               fprintf(stderr, "[system] bind to '%s#%d' %s\n", addr, port, knot_strerror(ret));
-               ret = EXIT_FAILURE;
-       } else {
-               /* Allocate TTY */
-               uv_pipe_t pipe;
-               uv_pipe_init(loop, &pipe, 0);
-               uv_pipe_open(&pipe, 0);
-               pipe.data = &engine;
+       if (addr != NULL) {
+               ret = network_listen(&engine.net, addr, (uint16_t)port, NET_UDP|NET_TCP);
+               if (ret != 0) {
+                       fprintf(stderr, "[system] bind to '%s#%d' %s\n", addr, port, knot_strerror(ret));
+                       ret = EXIT_FAILURE;
+               }
+       }
 
+       if (ret == 0) {
                /* Interactive stdin */
+               uv_pipe_t pipe;
                if (!feof(stdin)) {
-                       printf("[system] listening on '%s#%d'\n", addr, port);
                        printf("[system] started in interactive mode, type 'help()'\n");
+                       uv_pipe_init(loop, &pipe, 0);
+                       uv_pipe_open(&pipe, 0);
+                       pipe.data = &engine;
                        tty_read(NULL, 0, NULL);
                        uv_read_start((uv_stream_t*) &pipe, tty_alloc, tty_read);
                }
+
                /* Run the event loop. */
                ret = engine_start(&engine);
+               if (ret == 0) {
+                       ret = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+               }
        }
 
        /* Cleanup. */
        fprintf(stderr, "\n[system] quitting\n");
        engine_deinit(&engine);
 
+       if (ret != 0) {
+               ret = EXIT_FAILURE;
+       }
        return ret;
 }