Commit c3198437 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add HUP/INT/TERM signal handlers, primarily to avoid non-zero exit

status when we kill them off intentionally.
parent 25c8fde9
......@@ -26,6 +26,10 @@ struct in_addr mcastif;
char *filename;
struct timeval IdleTimeStamp;
/* Forward decls */
void quit(int);
void reinit(int);
/*
* This structure defines the file we are spitting back.
*/
......@@ -379,10 +383,14 @@ main(int argc, char **argv)
if (!portnum || ! mcastaddr.s_addr)
usage();
signal(SIGINT, quit);
signal(SIGTERM, quit);
signal(SIGHUP, reinit);
ServerLogInit();
WorkQueueInit();
ServerNetInit();
filename = argv[0];
if (access(filename, R_OK) < 0)
pfatal("Cannot read %s", filename);
......@@ -419,3 +427,24 @@ main(int argc, char **argv)
exit(0);
}
/*
* We catch the signals, but do not do anything. We exit with 0 status
* for these, since it indicates a desired shutdown.
*/
void
quit(int sig)
{
log("Caught signal %d. Exiting ...", sig);
exit(0);
}
/*
* We cannot reinit, so exit with non-zero to indicate it was unexpected.
*/
void
reinit(int sig)
{
log("Caught signal %d. Exiting ...", sig);
exit(1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment