diff options
author | Vladimír Čunát <vladimir.cunat@nic.cz> | 2018-12-10 17:06:37 +0100 |
---|---|---|
committer | Vladimír Čunát <vladimir.cunat@nic.cz> | 2018-12-10 17:15:47 +0100 |
commit | c0102bb90074c81e49c4b7368d8063f9a003c5f7 (patch) | |
tree | a21a33a93cb342319eee3d9c0bb593042eed47fc /daemon/main.c | |
parent | worker shutdown: close the leaking uv handle (diff) | |
download | knot-resolver-c0102bb90074c81e49c4b7368d8063f9a003c5f7.tar.xz knot-resolver-c0102bb90074c81e49c4b7368d8063f9a003c5f7.zip |
worker interactive mode: check stdin type
In particular, redirection from a file was leading to abort(),
so we provide an error message instead.
Diffstat (limited to 'daemon/main.c')
-rw-r--r-- | daemon/main.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/daemon/main.c b/daemon/main.c index 4e3e379c..5b212e78 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -414,8 +414,24 @@ static void help(int argc, char *argv[]) " [rundir] Path to the working directory (default: .)\n"); } +/** \return exit code for main() */ static int run_worker(uv_loop_t *loop, struct engine *engine, fd_array_t *ipc_set, bool leader, struct args *args) { + /* Only some kinds of stdin work with uv_pipe_t. + * Otherwise we would abort() from libuv e.g. with </dev/null */ + if (args->interactive) switch (uv_guess_handle(0)) { + case UV_TTY: /* standard terminal */ + case UV_NAMED_PIPE: /* echo 'quit()' | kresd ... */ + break; + default: + kr_log_error( + "[system] error: standard input is not a terminal or pipe; " + "use '-f 1' if you want non-interactive mode. " + "Commands can be simply added to your configuration file or sent over the tty/$PID control socket.\n" + ); + return 1; + } + /* Control sockets or TTY */ auto_free char *sock_file = NULL; uv_pipe_t pipe; @@ -462,7 +478,7 @@ static int run_worker(uv_loop_t *loop, struct engine *engine, fd_array_t *ipc_se unlink(sock_file); } uv_close((uv_handle_t *)&pipe, NULL); /* Seems OK even on the stopped loop. */ - return kr_ok(); + return 0; } #ifdef HAS_SYSTEMD @@ -807,11 +823,6 @@ int main(int argc, char **argv) /* Run the event loop */ ret = run_worker(loop, &engine, &ipc_set, fork_id == 0, &args); - if (ret != 0) { - perror("[system] worker failed"); - ret = EXIT_FAILURE; - goto cleanup; - } cleanup:/* Cleanup. */ engine_deinit(&engine); |