Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1168 → Rev 1169

/rebootd/trunk/rebootd.c
73,6 → 73,7
#define PARAM_PORT "--port"
#define PARAM_CONFIG "--config"
#define PARAM_PID_FILE "--pid"
#define PARAM_DEBUG "--debug"
#define CONFIG_INTERFACE "interface"
#define CONFIG_PORT "port"
#define CONFIG_PASSWORD "password"
94,11 → 95,13
char password_prio;
char pid_file[FILENAME_MAX];
char pid_file_prio;
char debug_mode;
};
static struct config global_cfg;
static int daemonized = 0; /* we are already a daemon */
volatile static int reconfig_needed = 0; /* we have to stop socket listening and reread config */
static int daemonized = 0; /* we are already a daemon */
volatile static int reconfig_required = 0; /* we have to stop socket listening and reread config */
volatile static int quit_required = 0; /* we have to stop socket listening and exit */
 
static int parse_cmd_line(struct config *cfg, int argc, const char* argv[]);
static int parse_config_file(struct config *cfg, const char *config_name);
143,14 → 146,16
ss_size = sizeof(ss);
br = recvfrom(soc, buf, sizeof(buf)-1, 0, (struct sockaddr *)&ss, &ss_size);
 
if(br == 0) {
if(reconfig_needed) return;
if(br < 0) {
if(errno == EINTR) {
if(reconfig_required || quit_required) break;
}
else {
syslog(LOG_INFO, "cannot receive: %s", strerror(errno));
}
 
continue;
}
else if(br < 0) {
syslog(LOG_INFO, "cannot receive: %s", strerror(errno));
continue;
}
 
buf[br] = '\0';
sleep(1);
157,11 → 162,16
syslog(LOG_INFO, "got command");
if(0 == strncmp(buf, cfg->password, sizeof(buf))) {
syslog(LOG_EMERG, "REBOOT");
sleep(5);
if(reboot(RB_AUTOBOOT) < 0) {
syslog(LOG_ERR, "cannot reboot, %s", strerror(errno));
if(cfg->debug_mode) {
syslog(LOG_INFO, "REBOOT, debug mode");
}
else {
syslog(LOG_EMERG, "REBOOT");
sleep(5);
if(reboot(RB_AUTOBOOT) < 0) {
syslog(LOG_ERR, "cannot reboot, %s", strerror(errno));
}
}
}
}
}
307,6 → 317,8
strncpy(cfg->password, file_cfg.password, sizeof(cfg->password));
cfg->password_prio = CFG_PRIO_CONFIG;
 
cfg->debug_mode = cmd_cfg.debug_mode;
 
return RESULT_OK;
}
 
432,6 → 444,9
return print_cmd_error(argc, argv, "PID file name expected", NULL);
}
}
else if(0 == strcmp(argv[i], PARAM_DEBUG)) {
cfg->debug_mode = 1;
}
else if(0 == strcmp(argv[i], PARAM_VERSION)) {
print_version();
return RESULT_EXIT;
689,12 → 704,6
return RESULT_OK;
}
 
static void reconfig_signal(void)
{
syslog(LOG_INFO, "reconfig");
reconfig_needed = 1;
}
 
static void delete_pid_file(void)
{
if(global_cfg.pid_file && global_cfg.pid_file[0] != '\0') {
705,11 → 714,16
}
}
 
static void reconfig_signal(void)
{
syslog(LOG_INFO, "reconfig");
reconfig_required = 1;
}
 
static void quit_signal(void)
{
delete_pid_file();
syslog(LOG_WARNING, "quit");
exit(0);
quit_required = 1;
}
 
static void signal_handler(int sig)
817,8 → 831,11
syslog(LOG_INFO, "listen on %d", global_cfg.port);
listen_socket(&global_cfg, soc);
 
if(reconfig_needed) {
reconfig_needed = 0;
if(quit_required) {
break;
}
else if(reconfig_required) {
reconfig_required = 0;
check_return(reread_config(&global_cfg, &reinit_needed));
if(reinit_needed) {
close(soc);
831,6 → 848,7
}
}
 
return EXIT_OK; /* unreacheable */
delete_pid_file();
return EXIT_OK;
}
 
/rebootd/trunk/TODO
1,7 → 1,6
rebootd todo
============
 
- debug mode (no real reboot)
- quit_sig & co set flag only, exit in main code
- update revision number for any changed file
- split code to several files