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);
|
snprintf(init_pid_str, sizeof(pid_t)*3, "%ju", (uintmax_t) init_pid);
|
||||||
setenv("INIT_PID", init_pid_str, 1);
|
setenv("INIT_PID", init_pid_str, 1);
|
||||||
|
|
||||||
|
setpgid(0, 0);
|
||||||
|
|
||||||
const char* programname = "sh";
|
const char* programname = "sh";
|
||||||
const char* newargv[] = { programname, NULL };
|
const char* newargv[] = { programname, NULL };
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,7 @@ int runcommandline(const char** tokens, bool* exitexec)
|
||||||
const char* execmode;
|
const char* execmode;
|
||||||
const char* outputfile;
|
const char* outputfile;
|
||||||
pid_t childpid;
|
pid_t childpid;
|
||||||
|
pid_t pgid = -1;
|
||||||
bool internal;
|
bool internal;
|
||||||
int internalresult;
|
int internalresult;
|
||||||
readcmd:
|
readcmd:
|
||||||
|
@ -166,6 +167,13 @@ readcmd:
|
||||||
if ( childpid < 0 ) { perror("fork"); goto out; }
|
if ( childpid < 0 ) { perror("fork"); goto out; }
|
||||||
if ( childpid )
|
if ( childpid )
|
||||||
{
|
{
|
||||||
|
if ( !internal )
|
||||||
|
{
|
||||||
|
if ( pgid == -1 )
|
||||||
|
pgid = childpid;
|
||||||
|
setpgid(childpid, pgid);
|
||||||
|
}
|
||||||
|
|
||||||
if ( pipein != 0 ) { close(pipein); pipein = 0; }
|
if ( pipein != 0 ) { close(pipein); pipein = 0; }
|
||||||
if ( pipeout != 1 ) { close(pipeout); pipeout = 1; }
|
if ( pipeout != 1 ) { close(pipeout); pipeout = 1; }
|
||||||
if ( pipeinnext != 0 ) { pipein = pipeinnext; pipeinnext = 0; }
|
if ( pipeinnext != 0 ) { pipein = pipeinnext; pipeinnext = 0; }
|
||||||
|
@ -175,6 +183,9 @@ readcmd:
|
||||||
result = 0; goto out;
|
result = 0; goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( strcmp(execmode, "&") == 0 )
|
||||||
|
pgid = -1;
|
||||||
|
|
||||||
if ( strcmp(execmode, "&") == 0 || strcmp(execmode, "|") == 0 )
|
if ( strcmp(execmode, "&") == 0 || strcmp(execmode, "|") == 0 )
|
||||||
{
|
{
|
||||||
goto readcmd;
|
goto readcmd;
|
||||||
|
@ -205,6 +216,8 @@ readcmd:
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setpgid(0, pgid != -1 ? pgid : 0);
|
||||||
|
|
||||||
if ( pipeinnext != 0 ) { close(pipeinnext); }
|
if ( pipeinnext != 0 ) { close(pipeinnext); }
|
||||||
|
|
||||||
if ( pipein != 0 )
|
if ( pipein != 0 )
|
||||||
|
|
Loading…
Add table
Reference in a new issue