Add process group support to init and sh.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-06-12 00:59:19 +02:00
parent 938f722dcb
commit c8f302df1a
2 changed files with 15 additions and 0 deletions

View File

@ -39,6 +39,8 @@ int child()
snprintf(init_pid_str, sizeof(pid_t)*3, "%ju", (uintmax_t) init_pid);
setenv("INIT_PID", init_pid_str, 1);
setpgid(0, 0);
const char* programname = "sh";
const char* newargv[] = { programname, NULL };

View File

@ -83,6 +83,7 @@ int runcommandline(const char** tokens, bool* exitexec)
const char* execmode;
const char* outputfile;
pid_t childpid;
pid_t pgid = -1;
bool internal;
int internalresult;
readcmd:
@ -166,6 +167,13 @@ readcmd:
if ( childpid < 0 ) { perror("fork"); goto out; }
if ( childpid )
{
if ( !internal )
{
if ( pgid == -1 )
pgid = childpid;
setpgid(childpid, pgid);
}
if ( pipein != 0 ) { close(pipein); pipein = 0; }
if ( pipeout != 1 ) { close(pipeout); pipeout = 1; }
if ( pipeinnext != 0 ) { pipein = pipeinnext; pipeinnext = 0; }
@ -175,6 +183,9 @@ readcmd:
result = 0; goto out;
}
if ( strcmp(execmode, "&") == 0 )
pgid = -1;
if ( strcmp(execmode, "&") == 0 || strcmp(execmode, "|") == 0 )
{
goto readcmd;
@ -205,6 +216,8 @@ readcmd:
goto out;
}
setpgid(0, pgid != -1 ? pgid : 0);
if ( pipeinnext != 0 ) { close(pipeinnext); }
if ( pipein != 0 )