From: Christian Pointner Date: Sun, 7 Mar 2010 17:24:25 +0000 (+0000) Subject: signal handler for autosample process X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=d1d4f8e2439fbe19fca819e9b81ef1e0451dc4c5;p=svn42.git signal handler for autosample process --- diff --git a/powersensordaemon/autosample.c b/powersensordaemon/autosample.c index 24edfc6..63dd5c8 100644 --- a/powersensordaemon/autosample.c +++ b/powersensordaemon/autosample.c @@ -63,9 +63,39 @@ int autosample_process(options_t *opt, int pipefd) { log_printf(NOTICE, "autosample process just started"); - sleep(5); + int sig_fd = signal_init(); + if(sig_fd < 0) + return -3; - return 0; + fd_set readfds; + struct timeval timeout; + int return_value = 0; + while(!return_value) { + FD_SET(sig_fd, &readfds); + timeout.tv_sec = 0; + timeout.tv_usec = 1000000; + int ret = select(sig_fd+1, &readfds, NULL, NULL, &timeout); + if(ret == -1 && errno != EINTR) { + log_printf(ERROR, "autosample process select returned with error: %s", strerror(errno)); + return_value = -3; + break; + } + if(ret == -1) + continue; +// if(!ret) { + // timout has expired... +// } + + if(FD_ISSET(sig_fd, &readfds)) { + if(signal_handle()) { + return_value = -2; + break; + } + } + } + + signal_stop(); + return return_value; }