1 --- apmd/apmd.c~ 2006-04-10 20:10:42.787178752 +0100
2 +++ apmd/apmd.c 2006-04-17 20:16:25.984067744 +0100
7 + struct timeval timeout;
12 /* Capture the child's output, if any, but only until it terminates */
14 fcntl(fds[0], F_SETFL, O_RDONLY|O_NONBLOCK);
15 - countdown = proxy_timeout;
18 - while ((len = read(fds[0], line, sizeof(line)-1)) > 0) {
20 - APMD_SYSLOG(LOG_INFO, "+ %s", line);
23 - retval = waitpid(pid, &status, WNOHANG);
27 - APMD_TRACE1(LOG_ERR, "waitpid() failed: %s", strerror(errno));
28 - status = __W_EXITCODE(0, SIGTERM) | __WCOREFLAG;
32 - while (sleep(1) > 0) ;
35 - || (proxy_timeout < 0)
38 - APMD_SYSLOG(LOG_NOTICE, "Proxy has been running more than %d seconds; killing it", proxy_timeout);
43 - retval = waitpid(pid, &status, WNOHANG);
47 - APMD_TRACE1(LOG_ERR, "waitpid() failed: %s", strerror(errno));
48 - status = __W_EXITCODE(0, SIGTERM) | __WCOREFLAG;
50 + timeout.tv_sec = proxy_timeout;
51 + timeout.tv_usec = 0;
56 + FD_SET (fds[0], &rfds);
57 + r = select (fds[0] + 1, &rfds, NULL, NULL, &timeout);
59 + APMD_SYSLOG(LOG_NOTICE, "Proxy has been running more than %d seconds; killing it", proxy_timeout);
64 + retval = waitpid(pid, &status, WNOHANG);
68 + APMD_TRACE1(LOG_ERR, "waitpid() failed: %s", strerror(errno));
69 + status = __W_EXITCODE(0, SIGTERM) | __WCOREFLAG;
72 + while (sleep(1) > 0) ;
73 + } while (countdown-- >= 0);
82 + len = read(fds[0], line, sizeof(line)-1);
85 + APMD_SYSLOG(LOG_INFO, "+ %s", line);
91 - while (sleep(1) > 0) ;
93 - } while (countdown >= 0);
96 - status = __W_EXITCODE(0, SIGKILL);
97 + retval = waitpid(pid, &status, 0);
100 - /* Flush any remaining data */
101 - while ((len = read(fds[0], line, sizeof(line)-1)) > 0) {
103 - APMD_SYSLOG(LOG_INFO, "+ %s", line);
107 /* Collect the exit code */