summaryrefslogtreecommitdiff
path: root/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon.c')
-rw-r--r--daemon.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/daemon.c b/daemon.c
index 0de94fa..3cccedd 100644
--- a/daemon.c
+++ b/daemon.c
@@ -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() {