diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-09-04 13:16:45 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-09-04 13:16:45 +0200 |
commit | f7d8db93610a13cb44d5a51c391049e84f670e0e (patch) | |
tree | f102245c59b5b39bcd7ee507eac583469ae01c5b /daemon.c | |
parent | d7c16ed5027b806600fd65300cd32d813b69afca (diff) |
Added kill switch.
Diffstat (limited to 'daemon.c')
-rw-r--r-- | daemon.c | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -5,21 +5,23 @@ #include <stdlib.h> #include <stdio.h> #include <unistd.h> +#include <sys/types.h> +#include <signal.h> void daemonize() { gchar *pidfile = conf_get_string("audist", "pidfile"); if(pidfile == NULL) { - g_warning("pidfile not set - can't daemonize"); - return; + g_error("pidfile not set - can't daemonize"); } FILE *f = fopen(pidfile, "w"); if(f == NULL) { - g_warning("pidfile \"%s\" not writeable - can't daemonize", pidfile); - return; + g_error("pidfile \"%s\" not writeable - can't daemonize", pidfile); } + g_free(pidfile); + switch(fork()) { case 0: break; @@ -31,8 +33,26 @@ void daemonize() { fprintf(f, "%d\n", getpid()); fclose(f); +} + +void daemon_kill() { + gchar *pidfile = conf_get_string("audist", "pidfile"); + if(pidfile == NULL) { + g_error("pidfile not set"); + } + + FILE *f = fopen(pidfile, "r"); g_free(pidfile); + if(f == NULL) { + g_error("can't read pidfile"); + } + + int pid; + fscanf(f, "%d", &pid); + fclose(f); + + kill(pid, SIGTERM); } void daemonize_finished() { |