Pass sudo's process ID to suspend_sudo_nopty() since we already know it.
Saves an unnecessary getpid(2) call.
This commit is contained in:
@@ -757,8 +757,10 @@ handle_sigchld_nopty(struct exec_closure *ec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If the main command is suspended, suspend sudo too. */
|
/* If the main command is suspended, suspend sudo too. */
|
||||||
if (pid == ec->cmnd_pid)
|
if (pid == ec->cmnd_pid) {
|
||||||
suspend_sudo_nopty(ec, signo, ec->ppgrp, ec->cmnd_pid);
|
suspend_sudo_nopty(ec, signo, ec->sudo_pid, ec->ppgrp,
|
||||||
|
ec->cmnd_pid);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (WIFSIGNALED(status)) {
|
if (WIFSIGNALED(status)) {
|
||||||
if (sig2str(WTERMSIG(status), signame) == -1) {
|
if (sig2str(WTERMSIG(status), signame) == -1) {
|
||||||
|
@@ -121,7 +121,7 @@ main(int argc, char *argv[])
|
|||||||
const char *errstr;
|
const char *errstr;
|
||||||
sigset_t blocked, empty;
|
sigset_t blocked, empty;
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
pid_t child, pid, ppgrp;
|
pid_t child, my_pid, pid, my_pgrp;
|
||||||
int ch, status;
|
int ch, status;
|
||||||
debug_decl_vars(main, SUDO_DEBUG_MAIN);
|
debug_decl_vars(main, SUDO_DEBUG_MAIN);
|
||||||
|
|
||||||
@@ -173,7 +173,8 @@ main(int argc, char *argv[])
|
|||||||
sigaction(SIGUSR1, &sa, NULL);
|
sigaction(SIGUSR1, &sa, NULL);
|
||||||
|
|
||||||
/* Fork a shell. */
|
/* Fork a shell. */
|
||||||
ppgrp = getpgrp();
|
my_pid = getpid();
|
||||||
|
my_pgrp = getpgrp();
|
||||||
child = fork();
|
child = fork();
|
||||||
switch (child) {
|
switch (child) {
|
||||||
case -1:
|
case -1:
|
||||||
@@ -227,7 +228,8 @@ main(int argc, char *argv[])
|
|||||||
} else if (WIFSTOPPED(status)) {
|
} else if (WIFSTOPPED(status)) {
|
||||||
if (exec_ptrace_stopped(pid, status, &closure)) {
|
if (exec_ptrace_stopped(pid, status, &closure)) {
|
||||||
if (pid == child) {
|
if (pid == child) {
|
||||||
suspend_sudo_nopty(NULL, WSTOPSIG(status), ppgrp, child);
|
suspend_sudo_nopty(NULL, WSTOPSIG(status), my_pid,
|
||||||
|
my_pgrp, child);
|
||||||
if (kill(child, SIGCONT) != 0)
|
if (kill(child, SIGCONT) != 0)
|
||||||
sudo_warn("kill(%d, SIGCONT)", (int)child);
|
sudo_warn("kill(%d, SIGCONT)", (int)child);
|
||||||
}
|
}
|
||||||
|
@@ -233,6 +233,6 @@ bool set_exec_filter(void);
|
|||||||
int exec_ptrace_seize(pid_t child);
|
int exec_ptrace_seize(pid_t child);
|
||||||
|
|
||||||
/* suspend_nopty.c */
|
/* suspend_nopty.c */
|
||||||
void suspend_sudo_nopty(struct exec_closure *ec, int signo, pid_t ppgrp, pid_t cmnd_pid);
|
void suspend_sudo_nopty(struct exec_closure *ec, int signo, pid_t my_pid, pid_t my_pgrp, pid_t cmnd_pid);
|
||||||
|
|
||||||
#endif /* SUDO_EXEC_H */
|
#endif /* SUDO_EXEC_H */
|
||||||
|
@@ -34,8 +34,8 @@
|
|||||||
#include "sudo_exec.h"
|
#include "sudo_exec.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
suspend_sudo_nopty(struct exec_closure *ec, int signo, pid_t ppgrp,
|
suspend_sudo_nopty(struct exec_closure *ec, int signo, pid_t my_pid,
|
||||||
pid_t cmnd_pid)
|
pid_t my_pgrp, pid_t cmnd_pid)
|
||||||
{
|
{
|
||||||
struct sigaction sa, osa;
|
struct sigaction sa, osa;
|
||||||
pid_t saved_pgrp = -1;
|
pid_t saved_pgrp = -1;
|
||||||
@@ -67,9 +67,9 @@ suspend_sudo_nopty(struct exec_closure *ec, int signo, pid_t ppgrp,
|
|||||||
* pgrp and let it continue.
|
* pgrp and let it continue.
|
||||||
*/
|
*/
|
||||||
if (signo == SIGTTOU || signo == SIGTTIN) {
|
if (signo == SIGTTOU || signo == SIGTTIN) {
|
||||||
if (saved_pgrp == ppgrp) {
|
if (saved_pgrp == my_pgrp) {
|
||||||
pid_t cmnd_pgrp = getpgid(cmnd_pid);
|
pid_t cmnd_pgrp = getpgid(cmnd_pid);
|
||||||
if (cmnd_pgrp != ppgrp) {
|
if (cmnd_pgrp != my_pgrp) {
|
||||||
if (tcsetpgrp_nobg(fd, cmnd_pgrp) == 0) {
|
if (tcsetpgrp_nobg(fd, cmnd_pgrp) == 0) {
|
||||||
if (killpg(cmnd_pgrp, SIGCONT) != 0)
|
if (killpg(cmnd_pgrp, SIGCONT) != 0)
|
||||||
sudo_warn("kill(%d, SIGCONT)", (int)cmnd_pgrp);
|
sudo_warn("kill(%d, SIGCONT)", (int)cmnd_pgrp);
|
||||||
@@ -92,8 +92,8 @@ suspend_sudo_nopty(struct exec_closure *ec, int signo, pid_t ppgrp,
|
|||||||
if (sudo_sigaction(SIGTSTP, &sa, &osa) != 0)
|
if (sudo_sigaction(SIGTSTP, &sa, &osa) != 0)
|
||||||
sudo_warn(U_("unable to set handler for signal %d"), SIGTSTP);
|
sudo_warn(U_("unable to set handler for signal %d"), SIGTSTP);
|
||||||
}
|
}
|
||||||
if (kill(getpid(), signo) != 0)
|
if (kill(my_pid, signo) != 0)
|
||||||
sudo_warn("kill(%d, %d)", (int)getpid(), signo);
|
sudo_warn("kill(%d, %d)", (int)my_pid, signo);
|
||||||
if (signo == SIGTSTP) {
|
if (signo == SIGTSTP) {
|
||||||
if (sudo_sigaction(SIGTSTP, &osa, NULL) != 0)
|
if (sudo_sigaction(SIGTSTP, &osa, NULL) != 0)
|
||||||
sudo_warn(U_("unable to restore handler for signal %d"), SIGTSTP);
|
sudo_warn(U_("unable to restore handler for signal %d"), SIGTSTP);
|
||||||
@@ -110,7 +110,7 @@ suspend_sudo_nopty(struct exec_closure *ec, int signo, pid_t ppgrp,
|
|||||||
* It is possible that we are no longer the foreground process,
|
* It is possible that we are no longer the foreground process,
|
||||||
* use tcsetpgrp_nobg() to prevent sudo from receiving SIGTTOU.
|
* use tcsetpgrp_nobg() to prevent sudo from receiving SIGTTOU.
|
||||||
*/
|
*/
|
||||||
if (saved_pgrp != ppgrp)
|
if (saved_pgrp != my_pgrp)
|
||||||
tcsetpgrp_nobg(fd, saved_pgrp);
|
tcsetpgrp_nobg(fd, saved_pgrp);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user