char pidfile[FILENAME_MAX + 1] = "";
-void sig_handler(int signo)
+void sig_handler_exit(int signo)
{
if(signo) {
error_log_limit_unlimited();
}
}
+void sig_handler_save(int signo)
+{
+ if(signo) {
+ info("Received signal %d to save the database...", signo);
+ rrdset_save_all();
+ }
+}
+
static void properly_chown_netdata_generated_file(int fd, uid_t uid, gid_t gid) {
if(fd == -1) return;
#ifndef NETDATA_DAEMON_H
#define NETDATA_DAEMON_H 1
-extern void sig_handler(int signo);
+extern void sig_handler_exit(int signo);
+extern void sig_handler_save(int signo);
extern int become_user(const char *username, int access_fd, int output_fd, int error_fd, int pid_fd);
sigaddset(&sa.sa_mask, SIGHUP);
sigaddset(&sa.sa_mask, SIGINT);
sigaddset(&sa.sa_mask, SIGTERM);
- sa.sa_handler = sig_handler;
+ sa.sa_handler = sig_handler_exit;
sa.sa_flags = 0;
if(sigaction(SIGHUP, &sa, NULL) == -1) {
error("Failed to change signal handler for SIGHUP");
if(sigaction(SIGTERM, &sa, NULL) == -1) {
error("Failed to change signal handler for SIGTERM");
}
+
+ // save database on SIGUSR1
+ sa.sa_handler = sig_handler_save;
+ if(sigaction(SIGUSR1, &sa, NULL) == -1) {
+ error("Failed to change signal handler for SIGUSR1");
+ }
+
// Ignore SIGPIPE completely.
// INFO: If we add signals here we have to unblock them
// at popen.c when running a external plugin.
sa.sa_handler = SIG_IGN;
if(sigaction(SIGPIPE, &sa, NULL) == -1) {
- error("Failed to change signal handler for SIGTERM");
+ error("Failed to change signal handler for SIGPIPE");
}
// --------------------------------------------------------------------
sigemptyset(&sa.sa_mask);
sa.sa_handler = SIG_DFL;
sa.sa_flags = 0;
+
+ if(sigaction(SIGUSR1, &sa, NULL) == -1)
+ error("pre-execution of command '%s' on pid %d: failed to set default signal handler for SIGUSR1.", command, getpid());
+
if(sigaction(SIGPIPE, &sa, NULL) == -1)
error("pre-execution of command '%s' on pid %d: failed to set default signal handler for SIGPIPE.", command, getpid());
}