-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.
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);
int child_status;
int error;
+ child_status = 0;
error = create_dir_recursive(uri);
if (error)
return error;
/* 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). */
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;
}
/**
#include <errno.h>
#include <netdb.h>
#include <pthread.h>
-#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "rtr/pdu.h"
#include "rtr/db/vrps.h"
-struct sigaction act;
-
struct thread_param {
int fd;
pthread_t tid;
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
*/
int server_fd; /* "file descriptor" */
int error;
- error = init_signal_handler();
- if (error)
- return error;
-
error = clients_db_init();
if (error)
return error;
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);