summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Straz <nstraz@redhat.com>2013-10-04 12:21:34 -0400
committerNathan Straz <nstraz@redhat.com>2013-10-04 12:21:34 -0400
commit76def9a53192c9748808616eaf49f6a476385f17 (patch)
treeabac5377a1c622bd0a2d9efa06f3fe579040dcd3
parent4fe61ef380ae7cadc207faea9a13d76028cc47a5 (diff)
downloadqarsh-76def9a53192c9748808616eaf49f6a476385f17.tar.gz
qarsh-76def9a53192c9748808616eaf49f6a476385f17.tar.xz
qarsh-76def9a53192c9748808616eaf49f6a476385f17.zip
Remove child signal handling
Instead of moving the setup for SIGCHLD handling, I'm removing it. waitpid() isn't that expensive and we know the pid we are waiting for.
-rw-r--r--qarshd.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/qarshd.c b/qarshd.c
index dc53d21..255defe 100644
--- a/qarshd.c
+++ b/qarshd.c
@@ -53,7 +53,6 @@ int dopause = 0;
/* Globals */
const int qinfd = 0; /* qarshd in file descriptor */
const int qoutfd = 1; /* qarshd out file descriptor */
-int child_exitted = 0;
pid_t child_pid;
sigset_t orig_sigmask;
int childfds[3] = { -1, -1, -1 }; /* pipes to child for stdin/stdout/stderr */
@@ -103,7 +102,6 @@ setup_user(char *user, char *group)
void
sig_handler(int sig)
{
- if (sig == SIGCHLD) child_exitted++;
}
pid_t
@@ -129,7 +127,6 @@ run_cmd(const char *cmd)
if (pid == 0) { /* child */
setpgrp();
- sigprocmask(SIG_SETMASK, &orig_sigmask, NULL);
/* Connect stdin, stdout, and stderr to parent's pipes */
dup2(parentfds[0], fileno(stdin));
@@ -240,9 +237,7 @@ handle_qarsh()
{
fd_set rfds, wfds;
int nfd, maxfd;
- struct timespec timeout;
- sigset_t sigmask;
- struct sigaction sa;
+ struct timeval timeout;
int child_status;
struct qa_packet *qp = NULL, *rp = NULL;
int allowed_out = 0, allowed_err = 0; /* number of bytes we can send to client */
@@ -252,13 +247,6 @@ handle_qarsh()
int eof_in = 0; /* Have we seen EOF on stdin yet? */
int nbytes;
- sigemptyset(&sigmask);
- sigaddset(&sigmask, SIGCHLD);
- sigprocmask(SIG_BLOCK, &sigmask, &orig_sigmask);
- sa.sa_handler = sig_handler;
- sa.sa_mask = sigmask;
- sa.sa_flags = SA_RESTART;
- sigaction(SIGCHLD, &sa, NULL);
signal(SIGPIPE, SIG_IGN);
qp = make_qp_data_allow(0, QARSHD_BUFSIZE);
@@ -268,7 +256,7 @@ handle_qarsh()
for (;;) {
timeout.tv_sec = 3;
- timeout.tv_nsec = 0;
+ timeout.tv_usec = 0;
FD_ZERO(&rfds); FD_ZERO(&wfds);
FD_SET(qinfd, &rfds);
maxfd = qinfd;
@@ -285,15 +273,13 @@ handle_qarsh()
maxfd = childfds[2] > maxfd ? childfds[2] : maxfd;
}
- nfd = pselect(maxfd+1, &rfds, &wfds, NULL, &timeout, &orig_sigmask);
+ nfd = select(maxfd+1, &rfds, &wfds, NULL, &timeout);
- if (child_exitted) {
- waitpid(child_pid, &child_status, 0);
- child_exitted--;
- child_pid = 0;
+ if (child_pid && waitpid(child_pid, &child_status, WNOHANG) == child_pid) {
rp = make_qp_cmdexit(child_pid, child_status);
send_packet(qoutfd, rp);
qpfree(rp);
+ child_pid = 0;
}
if (nfd < 0) {
if (errno == EINTR) {