Can anybody please post some example code on how I can reread a configuration file and restart my daemon after the daemon receives a SIGHUP signal. The daemon is a user spac
I found this page as I was looking for an example myself to make sure I'm doing it correctly. Since there is no example for this I'll post my attempt and let others comment on it:
volatile sig_atomic_t g_eflag = 0;
volatile sig_atomic_t g_hupflag = 1;
static void signal_handler(int sig)
{
switch(sig)
{
case SIGHUP:
g_hupflag = 1;
break;
case SIGINT:
case SIGTERM:
g_eflag = 1;
break;
}
}
int main(int argc, char **argv)
{
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
signal(SIGHUP, signal_handler);
signal(SIGPIPE, SIG_IGN);
while(!g_eflag)
{
if(g_hupflag)
{
g_hupflag = 0;
load_config();
}
// ... do daemon work ...
}
return 0;
}