2 * cleanup.c - Cleanup and shutdown framework.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2004 Project Purple
18 static bool should_cleanup = false;
21 * trytocleanup - say we should try to cleanup.
23 * This function sets the cleanup flag indicating we want to try and
26 void trytocleanup(void)
28 logthing(LOGTHING_INFO, "Setting cleanup flag.");
29 should_cleanup = true;
35 * cleanup - indicate if we should try to cleanup.
37 * This function returns a bool which indicates if we want to cleanup and
42 return(should_cleanup);
46 * sig_cleanup - set the cleanup flag when we receive a signal
48 * This is our signal handler; all it does it log the fact we got a signal
49 * and set the cleanup flag.
51 void sig_cleanup(int signal)
53 logthing(LOGTHING_INFO, "Got signal %d.", signal);
60 * catchsignals - Register signal handlers for various signals.
62 * This function registers a signal handler for various signals (PIPE,
63 * ALRM, INT, TERM, HUP) that sets the cleanup flag so we try to exit
66 void catchsignals(void)
68 logthing(LOGTHING_INFO, "Catching signals");
70 signal(SIGALRM, &sig_cleanup);
71 signal(SIGPIPE, &sig_cleanup);
72 signal(SIGTERM, &sig_cleanup);
73 signal(SIGINT, &sig_cleanup);
74 signal(SIGHUP, &sig_cleanup);