Call tcgetpgrp() in the parent, not the child and have the child spin
until it is granted. Fixes a race on darwin.
This commit is contained in:
13
script.c
13
script.c
@@ -523,8 +523,10 @@ script_child(path, argv)
|
|||||||
warning("unable to execute %s", path);
|
warning("unable to execute %s", path);
|
||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
/* Also set grandchild process group here to avoid a race condition. */
|
/* Set grandchild process group and grant it the controlling tty. */
|
||||||
setpgid(grandchild, grandchild);
|
setpgid(grandchild, grandchild);
|
||||||
|
if (tcsetpgrp(script_fds[SFD_SLAVE], grandchild) != 0)
|
||||||
|
warning("tcsetpgrp");
|
||||||
|
|
||||||
gettimeofday(&then, NULL);
|
gettimeofday(&then, NULL);
|
||||||
|
|
||||||
@@ -724,14 +726,9 @@ script_grandchild(path, argv, rbac_enabled)
|
|||||||
{
|
{
|
||||||
pid_t self = getpid();
|
pid_t self = getpid();
|
||||||
|
|
||||||
/* Also set our process group here to avoid a race condition. */
|
|
||||||
setpgid(0, self);
|
|
||||||
|
|
||||||
dup2(script_fds[SFD_SLAVE], STDIN_FILENO);
|
dup2(script_fds[SFD_SLAVE], STDIN_FILENO);
|
||||||
dup2(script_fds[SFD_SLAVE], STDOUT_FILENO);
|
dup2(script_fds[SFD_SLAVE], STDOUT_FILENO);
|
||||||
dup2(script_fds[SFD_SLAVE], STDERR_FILENO);
|
dup2(script_fds[SFD_SLAVE], STDERR_FILENO);
|
||||||
if (tcsetpgrp(STDIN_FILENO, self) != 0)
|
|
||||||
warning("tcsetpgrp");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close old fds and exec command.
|
* Close old fds and exec command.
|
||||||
@@ -742,6 +739,10 @@ script_grandchild(path, argv, rbac_enabled)
|
|||||||
close(script_fds[SFD_OUTPUT]);
|
close(script_fds[SFD_OUTPUT]);
|
||||||
close(script_fds[SFD_TIMING]);
|
close(script_fds[SFD_TIMING]);
|
||||||
|
|
||||||
|
/* Spin until parent grants us the controlling pty */
|
||||||
|
while (tcgetpgrp(STDIN_FILENO) != self)
|
||||||
|
continue;
|
||||||
|
|
||||||
#ifdef HAVE_SELINUX
|
#ifdef HAVE_SELINUX
|
||||||
if (rbac_enabled)
|
if (rbac_enabled)
|
||||||
selinux_execv(path, argv);
|
selinux_execv(path, argv);
|
||||||
|
Reference in New Issue
Block a user