From: pcarana Date: Wed, 14 Aug 2019 22:10:25 +0000 (-0500) Subject: Fix #14, remove SIGINT handler and adequate rsync return status. X-Git-Tag: v1.0.0^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afcad9c95cb0843dbf5647cd7bf2361d493d9a42;p=thirdparty%2FFORT-validator.git Fix #14, remove SIGINT handler and adequate rsync return status. -The SIGINT handler wasn't terminating the process as it should be, so let the signal be handled as default (like SIGTERM). -Update the rsync (do_rsync) function to read the returned pid status and know how did the process was terminated; in case of interruption, use the returned value to terminate the validation cycle as well. --- diff --git a/src/object/tal.c b/src/object/tal.c index 92bb48e4..d395f855 100644 --- a/src/object/tal.c +++ b/src/object/tal.c @@ -402,8 +402,9 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, void *arg) error = download_files(uri, true, false); if (error) { - return pr_warn("TAL '%s' could not be RSYNC'd.", + pr_warn("TAL '%s' could not be RSYNC'd.", uri_get_printable(uri)); + return ENSURE_NEGATIVE(error); } error = validation_prepare(&state, tal, arg); diff --git a/src/rsync/rsync.c b/src/rsync/rsync.c index 5065dcea..5e7e2449 100644 --- a/src/rsync/rsync.c +++ b/src/rsync/rsync.c @@ -304,6 +304,7 @@ do_rsync(struct rpki_uri *uri, bool is_ta) int child_status; int error; + child_status = 0; error = create_dir_recursive(uri); if (error) return error; @@ -318,12 +319,16 @@ do_rsync(struct rpki_uri *uri, bool is_ta) /* This code is run by us. */ error = waitpid(child_pid, &child_status, 0); - if (error == -1) { - error = errno; - pr_err("The rsync sub-process returned error %d (%s)", - error, strerror(error)); - return error; - } + do { + if (error == -1) { + error = errno; + pr_err("The rsync sub-process returned error %d (%s)", + error, strerror(error)); + if (child_status > 0) + break; + return error; + } + } while (0); if (WIFEXITED(child_status)) { /* Happy path (but also sad path sometimes). */ @@ -347,11 +352,11 @@ do_rsync(struct rpki_uri *uri, bool is_ta) pr_err("The RSYNC was terminated by a signal I don't have a handler for. Dunno; guess I'll just die."); break; } - exit(-EINTR); /* Meh? */ + return -EINTR; /* Meh? */ } pr_err("The RSYNC command died in a way I don't have a handler for. Dunno; guess I'll die as well."); - exit(-EINVAL); + return -EINVAL; } /** diff --git a/src/rtr/rtr.c b/src/rtr/rtr.c index c1487349..9fdb1308 100644 --- a/src/rtr/rtr.c +++ b/src/rtr/rtr.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -19,8 +18,6 @@ #include "rtr/pdu.h" #include "rtr/db/vrps.h" -struct sigaction act; - struct thread_param { int fd; pthread_t tid; @@ -329,30 +326,6 @@ handle_client_connections(int server_fd) return 0; /* Unreachable. */ } -static void -signal_handler(int signal, siginfo_t *info, void *param) -{ - /* Empty handler */ -} - -static int -init_signal_handler(void) -{ - int error; - - memset(&act, 0, sizeof act); - sigemptyset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; - act.sa_sigaction = signal_handler; - - error = sigaction(SIGINT, &act, NULL); - if (error) { - pr_errno(errno, "Error initializing signal handler"); - error = -errno; - } - return error; -} - /* * Receive @arg to be called as a clients_foreach_cb */ @@ -393,10 +366,6 @@ rtr_listen(void) int server_fd; /* "file descriptor" */ int error; - error = init_signal_handler(); - if (error) - return error; - error = clients_db_init(); if (error) return error; diff --git a/src/updates_daemon.c b/src/updates_daemon.c index 7868ff27..622c8bb1 100644 --- a/src/updates_daemon.c +++ b/src/updates_daemon.c @@ -21,6 +21,9 @@ check_vrps_updates(void *param_void) do { error = vrps_update(&changed); + if (error == -EINTR) + break; /* Process interrupted, terminate thread */ + if (error) { pr_err("Error code %d while trying to update the ROA database. Sleeping...", error);