diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-07-10 16:52:10 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-07-10 16:52:10 +0200 |
commit | 637d958bd868f35cfac1170354921792bbf91899 (patch) | |
tree | 7597420f5d0383732d727c145c9fbe3da846774a /xe.c | |
parent | 8fa2e549cbf181a7552ac8833c1aec56d80c335b (diff) | |
download | xe-637d958bd868f35cfac1170354921792bbf91899.tar.gz xe-637d958bd868f35cfac1170354921792bbf91899.tar.xz xe-637d958bd868f35cfac1170354921792bbf91899.zip |
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.
Diffstat (limited to 'xe.c')
-rw-r--r-- | xe.c | 27 |
1 files 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) { |