From: Aleš Křenek Date: Mon, 22 Mar 2010 13:40:41 +0000 (+0000) Subject: safer signal handling X-Git-Tag: glite-jobid-api-c_R_1_0_2_1~20 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=8d8d2936797429ce0492f1ec96fab44bdcf7e173;p=jra1mw.git safer signal handling --- diff --git a/org.glite.lb.logger/src/il_master.c b/org.glite.lb.logger/src/il_master.c index 6f57c80..2ea66b1 100644 --- a/org.glite.lb.logger/src/il_master.c +++ b/org.glite.lb.logger/src/il_master.c @@ -424,6 +424,7 @@ loop() long offset; int ret; + do_handle_signal(); if(killflg) return (0); diff --git a/org.glite.lb.logger/src/interlogd.c b/org.glite.lb.logger/src/interlogd.c index 572ff60..b7219ad 100644 --- a/org.glite.lb.logger/src/interlogd.c +++ b/org.glite.lb.logger/src/interlogd.c @@ -356,12 +356,21 @@ char *load_conf_file(char *filename) return s; } +static int received_signal = 0; -void handle_signal(int num) { +static void handle_signal(int num) +{ + received_signal = num; +} + + +void do_handle_signal() { - glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Received signal %d\n", num); + if (received_signal == 0) return; - switch(num) { + glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Received signal %d\n", received_signal); + + switch(received_signal) { case SIGHUP: /* TODO: reload all external configurations, see https://rt3.cesnet.cz/rt/Ticket/Display.html?id=24879 */ @@ -399,9 +408,12 @@ void handle_signal(int num) { break; } + + received_signal = 0; } + int main (int argc, char **argv) { diff --git a/org.glite.lb.logger/src/interlogd.h b/org.glite.lb.logger/src/interlogd.h index c13f585..60ddd7b 100644 --- a/org.glite.lb.logger/src/interlogd.h +++ b/org.glite.lb.logger/src/interlogd.h @@ -312,6 +312,7 @@ struct il_output_plugin *plugin_get(const char *); /* master main loop */ int loop(); +void do_handle_signal(); /* recover thread */ void *recover_thread(void*); diff --git a/org.glite.lb.logger/src/logd.c b/org.glite.lb.logger/src/logd.c index 50198ff..d2aaf76 100644 --- a/org.glite.lb.logger/src/logd.c +++ b/org.glite.lb.logger/src/logd.c @@ -123,7 +123,6 @@ static logd_handler_t mysignal(int num,logd_handler_t handler) memset(&sa,0,sizeof(sa)); sa.sa_handler = handler; - sa.sa_flags = SA_RESTART; return sigaction(num,&sa,&osa) ? SIG_ERR : osa.sa_handler; } @@ -137,9 +136,20 @@ static logd_handler_t mysignal(int num,logd_handler_t handler) * *---------------------------------------------------------------------- */ -void handle_signal(int num) { - if (num != SIGCHLD) glite_common_log(LOG_CATEGORY_CONTROL,LOG_PRIORITY_INFO,"Received signal %d\n", num); - switch (num) { + +static int received_signal = 0; + +static void handle_signal(int num) +{ + received_signal = num; +} + +void do_handle_signal() { + + if (received_signal == 0) return; + + if (received_signal != SIGCHLD) glite_common_log(LOG_CATEGORY_CONTROL,LOG_PRIORITY_INFO,"Received signal %d\n", received_signal); + switch (received_signal) { case SIGHUP: /* TODO: reload all external configurations, see https://rt3.cesnet.cz/rt/Ticket/Display.html?id=24879 */ @@ -182,6 +192,8 @@ void handle_signal(int num) { break; default: break; } + + received_signal = 0; } /* @@ -495,12 +507,15 @@ This is LocalLogger, part of Workload Management System in EU DataGrid & EGEE.\n * Main loop */ while (1) { - int opt; + int opt,my_errno; glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Accepting incomming connections...\n"); client_fd = accept(listener_fd, (struct sockaddr *) &client_addr, &client_addr_len); + my_errno = errno; + do_handle_signal(); if (client_fd < 0) { + if (my_errno == EINTR) continue; close(listener_fd); glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_FATAL,"Failed to accept incomming connections\n"); glite_common_log_SYS_ERROR("accept");