diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-20 00:34:09 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-20 01:13:46 +0100 |
| commit | 99be43e366b5c4d9dbaeaad9d885ff6d7f3aec4d (patch) | |
| tree | cb391a27d2e348fb7a8754e841c110d9ed359758 /src/util.c | |
| parent | Fix year (diff) | |
| download | blind-99be43e366b5c4d9dbaeaad9d885ff6d7f3aec4d.tar.gz blind-99be43e366b5c4d9dbaeaad9d885ff6d7f3aec4d.tar.bz2 blind-99be43e366b5c4d9dbaeaad9d885ff6d7f3aec4d.tar.xz | |
Fix and improve blind-gauss-blur, and fix new bug in blind-from-image
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 37 |
1 files changed, 29 insertions, 8 deletions
@@ -167,35 +167,56 @@ enfork(int status) } +/* If <() is used in Bash (possibily other shells), that process becomes + * child of the process for each <() is used. Therefore, we cannot simply + * wait until the last child has been reaped, or even the expected number + * of children has been reaped, we must instead remember the PID of each + * child we created and wait for all of them to be reaped. { */ + int -enfork_jobs(int status, size_t *start, size_t *end, size_t jobs) +enfork_jobs(int status, size_t *start, size_t *end, size_t jobs, pid_t **pids) { size_t j, s = *start, n = *end - *start; - if (jobs < 2) + pid_t pid; + if (jobs < 2) { + *pids = NULL; return 1; + } *end = n / jobs + s; + *pids = enmalloc(status, jobs * sizeof(**pids)); for (j = 1; j < jobs; j++) { - if (!enfork(status)) { + pid = enfork(status); + if (!pid) { #if defined(HAVE_PRCTL) && defined(PR_SET_PDEATHSIG) prctl(PR_SET_PDEATHSIG, SIGKILL); #endif *start = n * (j + 0) / jobs + s; *end = n * (j + 1) / jobs + s; return 0; + } else { + (*pids)[j - 1] = pid; } } + (*pids)[jobs - 1] = -1; return 1; } void -enjoin_jobs(int status, int is_master) +enjoin_jobs(int status, int is_master, pid_t *pids) { int stat; + size_t i; if (!is_master) exit(0); - while (wait(&stat) != -1) - if (!stat) + if (!pids) + return; + for (i = 0; pids[i] != -1; i++) { + if (waitpid(pids[i], &stat, 0) == -1) + enprintf(status, "waitpid:"); + if (stat) exit(status); - if (errno != ECHILD) - enprintf(status, "wait:"); + } + free(pids); } + +/* } */ |
