0,0 → 1,80 |
/****************************************************************** |
* rebootd. |
* |
* A daemon which waits on specified UDP port for special string |
* (password) and reboots the computer. |
* |
* Run "./rebootd --help" to see options and parameters. |
* |
* Copyleft 2005 Anatoli Klassen |
* |
******************************************************************/ |
|
#include <stdlib.h> |
#include <stdio.h> |
#include <string.h> |
#include <errno.h> |
#include <signal.h> |
#include <unistd.h> |
#include <syslog.h> |
|
#include "common.h" |
#include "signals.h" |
|
static void reconfig_signal(void) |
{ |
syslog(LOG_INFO, "reconfig"); |
reconfig_required = 1; |
} |
|
static void quit_signal(void) |
{ |
syslog(LOG_WARNING, "quit"); |
quit_required = 1; |
} |
|
static void signal_handler(int sig) |
{ |
int saved_errno = errno; |
|
switch(sig) { |
case SIGHUP: |
reconfig_signal(); |
break; |
|
case SIGINT: |
case SIGTERM: |
case SIGQUIT: |
quit_signal(); |
break; |
} |
|
errno = saved_errno; |
} |
|
static int init_signal_handler(int sig) |
{ |
struct sigaction sa; |
|
sa.sa_flags = 0; |
sa.sa_handler = signal_handler; |
sigemptyset(&sa.sa_mask); |
|
if(sigaction(sig, &sa, (struct sigaction *)NULL) != 0) { |
syslog(LOG_ERR, "Cannot register handler for signal %d: %s\n", sig, strerror(errno)); |
return RESULT_UNEXPECTED; |
} |
|
return RESULT_OK; |
} |
|
int init_signals(void) |
{ |
if(init_signal_handler(SIGHUP) != RESULT_OK) return RESULT_UNEXPECTED; |
if(init_signal_handler(SIGINT) != RESULT_OK) return RESULT_UNEXPECTED; |
if(init_signal_handler(SIGTERM) != RESULT_OK) return RESULT_UNEXPECTED; |
if(init_signal_handler(SIGQUIT) != RESULT_OK) return RESULT_UNEXPECTED; |
|
return RESULT_OK; |
} |
|