deliver_signal(struct monitor_closure *mc, int signo, bool from_parent)
{
char signame[SIG2STR_MAX];
- int status;
debug_decl(deliver_signal, SUDO_DEBUG_EXEC);
/* Avoid killing more than a single process or process group. */
break;
case SIGCONT_FG:
/* Continue in foreground, grant it controlling tty. */
- do {
- status = tcsetpgrp(io_fds[SFD_SLAVE], mc->cmnd_pgrp);
- } while (status == -1 && errno == EINTR);
+ if (tcsetpgrp(io_fds[SFD_SLAVE], mc->cmnd_pgrp) == -1) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+ "%s: unable to set foreground pgrp to %d (command)",
+ __func__, (int)mc->cmnd_pgrp);
+ }
killpg(mc->cmnd_pid, SIGCONT);
break;
case SIGCONT_BG:
/* Continue in background, I take controlling tty. */
- do {
- status = tcsetpgrp(io_fds[SFD_SLAVE], mc->mon_pgrp);
- } while (status == -1 && errno == EINTR);
+ if (tcsetpgrp(io_fds[SFD_SLAVE], mc->mon_pgrp) == -1) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+ "%s: unable to set foreground pgrp to %d (monitor)",
+ __func__, (int)mc->mon_pgrp);
+ }
killpg(mc->cmnd_pid, SIGCONT);
break;
case SIGKILL:
sudo_debug_printf(SUDO_DEBUG_INFO,
"sending status message to parent: [%d, %d]",
cstat->type, cstat->val);
- do {
- n = send(fd, cstat, sizeof(*cstat), 0);
- } while (n == -1 && errno == EINTR);
+ n = send(fd, cstat, sizeof(*cstat), 0);
if (n != sizeof(*cstat)) {
- sudo_debug_printf(SUDO_DEBUG_ERROR,
- "unable to send status to parent: %s", strerror(errno));
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+ "%s: unable to send status to parent", __func__);
}
cstat->type = CMD_INVALID; /* prevent re-sending */
}
mc->cstat->val = status;
if (WIFSTOPPED(status)) {
/* Save the foreground pgid so we can restore it later. */
- do {
- pid = tcgetpgrp(io_fds[SFD_SLAVE]);
- } while (pid == -1 && errno == EINTR);
+ pid = tcgetpgrp(io_fds[SFD_SLAVE]);
if (pid != mc->mon_pgrp)
mc->cmnd_pgrp = pid;
send_status(mc->backchannel, mc->cstat);
* Read errno from child or EOF when command is executed.
* Note that the error pipe is *blocking*.
*/
- do {
- nread = read(fd, &errval, sizeof(errval));
- } while (nread == -1 && errno == EINTR);
-
+ nread = read(fd, &errval, sizeof(errval));
switch (nread) {
case -1:
- if (errno != EAGAIN) {
+ if (errno != EAGAIN && errno != EINTR) {
if (mc->cstat->val == CMD_INVALID) {
/* XXX - need a way to distinguish non-exec error. */
mc->cstat->type = CMD_ERRNO;
/* setup tty and exec command */
exec_cmnd_pty(details, foreground, errpipe[1]);
- while (write(errpipe[1], &errno, sizeof(int)) == -1) {
- if (errno != EINTR)
- break;
- }
+ if (write(errpipe[1], &errno, sizeof(int)) == -1)
+ sudo_warn(U_("unable to execute %s"), details->command);
_exit(1);
}
close(errpipe[1]);
/* Make the command the foreground process for the pty slave. */
if (foreground && !ISSET(details->flags, CD_EXEC_BG)) {
- int n;
-
- do {
- n = tcsetpgrp(io_fds[SFD_SLAVE], mc.cmnd_pgrp);
- } while (n == -1 && errno == EINTR);
+ if (tcsetpgrp(io_fds[SFD_SLAVE], mc.cmnd_pgrp) == -1) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+ "%s: unable to set foreground pgrp to %d (command)",
+ __func__, (int)mc.cmnd_pgrp);
+ }
}
/*
case -1:
switch (errno) {
case EINTR:
- /* Should not happen now that we use SA_RESTART. */
- continue;
case EAGAIN:
/* Nothing ready. */
break;
"sending SIG%s to monitor over backchannel", signame);
cstat.type = CMD_SIGNO;
cstat.val = sigfwd->signo;
- do {
- nsent = send(sock, &cstat, sizeof(cstat), 0);
- } while (nsent == -1 && errno == EINTR);
TAILQ_REMOVE(&ec->sigfwd_list, sigfwd, entries);
free(sigfwd);
+ nsent = send(sock, &cstat, sizeof(cstat), 0);
if (nsent != sizeof(cstat)) {
if (errno == EPIPE) {
sudo_debug_printf(SUDO_DEBUG_ERROR,
exec_monitor(details, &oset, foreground && !pipeline, sv[1]);
cstat->type = CMD_ERRNO;
cstat->val = errno;
- while (send(sv[1], cstat, sizeof(*cstat), 0) == -1) {
- if (errno != EINTR)
- break;
+ if (send(sv[1], cstat, sizeof(*cstat), 0) == -1) {
+ sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+ "%s: unable to send status to parent", __func__);
}
_exit(1);
}