mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add process group support to init and sh.
This commit is contained in:
parent
938f722dcb
commit
c8f302df1a
2 changed files with 15 additions and 0 deletions
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
Loading…
Add table
Reference in a new issue