From 637d958bd868f35cfac1170354921792bbf91899 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 10 Jul 2017 16:52:10 +0200 Subject: xe: keep track of our own children Note that we could have children already upon our execve, there were false positives before. Also allows us to spawn our own helper processes now. --- xe.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/xe.c b/xe.c index 7e2a468..2b6bf68 100644 --- a/xe.c +++ b/xe.c @@ -45,6 +45,8 @@ static size_t argslen; static size_t argscap; static size_t argsresv; +static pid_t *children; + static char **inargs; static char *line = 0; @@ -85,7 +87,17 @@ mywait() return 0; // no other error possible? } - + + int i; + for (i = 0; i < maxjobs; i++) + if (children[i] == pid) { + children[i] = 0; + goto my_child; + } + + return 1; + +my_child: if (WIFEXITED(status)) { if (WEXITSTATUS(status) >= 1 && WEXITSTATUS(status) <= 125) { if (Fflag) { @@ -193,7 +205,7 @@ run() { pid_t pid; - if (runjobs >= maxjobs) + while (runjobs >= maxjobs) mywait(); runjobs++; iterations++; @@ -234,6 +246,13 @@ run() trace(); } + int i; + for (i = 0; i < maxjobs; i++) + if (!children[i]) { + children[i] = pid; + break; + } + return 0; } @@ -335,6 +354,10 @@ main(int argc, char *argv[], char *envp[]) exit(1); } + children = calloc(sizeof (pid_t), maxjobs); + if (!children) + exit(1); + if (aflag || Aflag) { input = 0; } else if (!fflag || strcmp("-", fflag) == 0) { -- cgit 1.4.1