]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Fix #14, remove SIGINT handler and adequate rsync return status.
authorpcarana <pc.moreno2099@gmail.com>
Wed, 14 Aug 2019 22:10:25 +0000 (17:10 -0500)
committerpcarana <pc.moreno2099@gmail.com>
Wed, 14 Aug 2019 22:10:25 +0000 (17:10 -0500)
-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.

src/object/tal.c
src/rsync/rsync.c
src/rtr/rtr.c
src/updates_daemon.c

index 92bb48e40b5b28057701e4297c3a6f5eaaa27516..d395f8559eba1f5173bd9c4a55dc502fa7715220 100644 (file)
@@ -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);
index 5065dcea07b683f80bd43169d4fa1461e2cc23a0..5e7e2449c8eedd5650b5eaadc8d4cfe92022f568 100644 (file)
@@ -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;
 }
 
 /**
index c148734927625a397a3542742671433ca0e45828..9fdb1308f4045185c5658b0bec7169e80d163e61 100644 (file)
@@ -3,7 +3,6 @@
 #include <errno.h>
 #include <netdb.h>
 #include <pthread.h>
-#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -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;
index 7868ff27cb0ff6f01783e88dc03021fcb7947621..622c8bb15d32e2d0d94afce9f62d01543685267f 100644 (file)
@@ -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);