#include "conf.h" #include #include #include #include void daemonize() { gchar *pidfile = conf_get_string("audist", "pidfile"); if(pidfile == NULL) { g_warning("pidfile not set - can't daemonize"); return; } FILE *f = fopen(pidfile, "w"); if(f == NULL) { g_warning("pidfile \"%s\" not writeable - can't daemonize", pidfile); return; } switch(fork()) { case 0: break; case -1: g_error("fork() failed"); default: _exit(0); } fprintf(f, "%d\n", getpid()); fclose(f); g_free(pidfile); } void daemonize_finished() { gchar *pidfile = conf_get_string("audist", "pidfile"); if(pidfile == NULL) { g_warning("pidfile not set"); return; } g_unlink(pidfile); g_free(pidfile); }