Use special values SIGCONT_FG and SIGCONT_BG instead of SIGUSR1 and

SIGUSR2 to indicate whether the child should be continued in the
foreground or background.
This commit is contained in:
Todd C. Miller
2011-02-03 09:59:41 -05:00
parent 34a087acf6
commit 2959d5dadd
2 changed files with 12 additions and 5 deletions

View File

@@ -271,7 +271,8 @@ check_foreground(void)
/* /*
* Suspend sudo if the underlying command is suspended. * Suspend sudo if the underlying command is suspended.
* Returns SIGUSR1 if the child should be resume in foreground else SIGUSR2. * Returns SIGCONT_FG if the child should be resume in the
* foreground or SIGCONT_BG if it is a background process.
*/ */
int int
suspend_parent(int signo) suspend_parent(int signo)
@@ -295,7 +296,7 @@ suspend_parent(int signo)
} while (!n && errno == EINTR); } while (!n && errno == EINTR);
ttymode = TERM_RAW; ttymode = TERM_RAW;
} }
rval = SIGUSR1; /* resume child in foreground */ rval = SIGCONT_FG; /* resume child in foreground */
break; break;
} }
ttymode = TERM_RAW; ttymode = TERM_RAW;
@@ -342,7 +343,7 @@ suspend_parent(int signo)
} }
sigaction(signo, &osa, NULL); sigaction(signo, &osa, NULL);
rval = ttymode == TERM_RAW ? SIGUSR1 : SIGUSR2; rval = ttymode == TERM_RAW ? SIGCONT_FG : SIGCONT_BG;
break; break;
} }
@@ -709,14 +710,14 @@ deliver_signal(pid_t pid, int signo)
case SIGALRM: case SIGALRM:
terminate_child(pid, TRUE); terminate_child(pid, TRUE);
break; break;
case SIGUSR1: case SIGCONT_FG:
/* foreground process, grant it controlling tty. */ /* foreground process, grant it controlling tty. */
do { do {
status = tcsetpgrp(io_fds[SFD_SLAVE], pid); status = tcsetpgrp(io_fds[SFD_SLAVE], pid);
} while (status == -1 && errno == EINTR); } while (status == -1 && errno == EINTR);
killpg(pid, SIGCONT); killpg(pid, SIGCONT);
break; break;
case SIGUSR2: case SIGCONT_BG:
/* background process, I take controlling tty. */ /* background process, I take controlling tty. */
do { do {
status = tcsetpgrp(io_fds[SFD_SLAVE], getpid()); status = tcsetpgrp(io_fds[SFD_SLAVE], getpid());

View File

@@ -17,6 +17,12 @@
#ifndef _SUDO_EXEC_H #ifndef _SUDO_EXEC_H
#define _SUDO_EXEC_H #define _SUDO_EXEC_H
/*
* Special values to indicate whether continuing in foreground or background.
*/
#define SIGCONT_FG -2
#define SIGCONT_BG -3
/* /*
* Symbols shared between exec.c and exec_pty.c * Symbols shared between exec.c and exec_pty.c
*/ */