forked from lix-project/lix
* Use setsid instead of setpgrp in child processes. This not only
creates a new process group but also a new session. New sessions have no controlling tty, so child processes like ssh cannot open /dev/tty (which is bad).
This commit is contained in:
parent
b90daaaf6c
commit
81de538e46
|
@ -276,17 +276,19 @@ void Goal::trace(const format & f)
|
||||||
/* Common initialisation performed in child processes. */
|
/* Common initialisation performed in child processes. */
|
||||||
void commonChildInit(Pipe & logPipe)
|
void commonChildInit(Pipe & logPipe)
|
||||||
{
|
{
|
||||||
/* Put the child in a separate process group so that it doesn't
|
/* Put the child in a separate session (and thus a separate
|
||||||
receive terminal signals. */
|
process group) so that it has no controlling terminal (meaning
|
||||||
if (setpgid(0, 0) == -1)
|
that e.g. ssh cannot open /dev/tty) and it doesn't receive
|
||||||
throw SysError(format("setting process group"));
|
terminal signals. */
|
||||||
|
if (setsid() == -1)
|
||||||
|
throw SysError(format("creating a new session"));
|
||||||
|
|
||||||
/* Dup the write side of the logger pipe into stderr. */
|
/* Dup the write side of the logger pipe into stderr. */
|
||||||
if (dup2(logPipe.writeSide, STDERR_FILENO) == -1)
|
if (dup2(logPipe.writeSide, STDERR_FILENO) == -1)
|
||||||
throw SysError("cannot pipe standard error into log file");
|
throw SysError("cannot pipe standard error into log file");
|
||||||
logPipe.readSide.close();
|
logPipe.readSide.close();
|
||||||
|
|
||||||
/* Dup stderr to stdin. */
|
/* Dup stderr to stdout. */
|
||||||
if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1)
|
if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1)
|
||||||
throw SysError("cannot dup stderr into stdout");
|
throw SysError("cannot dup stderr into stdout");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue