X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=powersensordaemon%2Fautosample.c;h=bcba8c232e116faaa73084e17e8811e7cd747245;hb=4e1a804cee8f1349967d65118bed03af60c6abdd;hp=24edfc67d314768d30115dd777e99374d66299d4;hpb=ed84246e82295c574998450115a98565814ac2b2;p=svn42.git diff --git a/powersensordaemon/autosample.c b/powersensordaemon/autosample.c index 24edfc6..bcba8c2 100644 --- a/powersensordaemon/autosample.c +++ b/powersensordaemon/autosample.c @@ -51,21 +51,54 @@ int start_autosample_process(options_t* opt) } if (cpid == 0) { - close(pipefd[1]); - return autosample_process(opt, pipefd[0]); + close(pipefd[0]); + return autosample_process(opt, pipefd[1]); } - close(pipefd[0]); - return pipefd[1]; + close(pipefd[1]); + return pipefd[0]; } 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; + + 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... + write(pipefd, "sample temp0", 12); + char c = '\n'; + write(pipefd, &c, 1); + } + + if(FD_ISSET(sig_fd, &readfds)) { + if(signal_handle()) { + return_value = -2; + break; + } + } + } - return 0; + signal_stop(); + return return_value; }