10
volatile sig_atomic_t keep_going = 1; /* controls program termination */
12
/* Function prototypes: */
13
void termination_handler (int signum); /* clean up before termination */
20
if (chdir (HOME_DIR)) /* change to directory containing data
23
fprintf (stderr, "%s': ", HOME_DIR);
28
/* Become a daemon: */
31
case -1: /* can't fork */
34
case 0: /* child, process becomes a daemon: */
36
close (STDOUT_FILENO);
37
close (STDERR_FILENO);
38
if (setsid () == -1) /* request a new session (job control) */
43
default: /* parent returns to calling process: */
47
/* Establish signal handler to clean up before termination: */
48
if (signal (SIGTERM, termination_handler) == SIG_IGN)
49
signal (SIGTERM, SIG_IGN);
50
signal (SIGINT, SIG_IGN);
51
signal (SIGHUP, SIG_IGN);
53
/* Main program loop */
62
termination_handler (int signum)
65
signal (signum, termination_handler);