aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2026-05-10 21:44:15 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2026-05-11 15:56:09 -0400
commit3eddcfe9d11e6feba000fab54288124cb24f1899 (patch)
tree586b8fecaddcd0d0f8bfaa4b97cdebaad2c2709c /src/lib
parentb5bda9c367d78a28c6523071d6c8c8e7b6551f02 (diff)
downloadstasis-3eddcfe9d11e6feba000fab54288124cb24f1899.tar.gz
Use semaphore to lock the child process up to the point of execvp
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/core/multiprocessing.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/lib/core/multiprocessing.c b/src/lib/core/multiprocessing.c
index 2fe02bb..5a6767f 100644
--- a/src/lib/core/multiprocessing.c
+++ b/src/lib/core/multiprocessing.c
@@ -62,6 +62,7 @@ int child(struct MultiProcessingPool *pool, struct MultiProcessingTask *task) {
(void) pool;
FILE *fp_log = NULL;
+ semaphore_wait(&pool->semaphore);
// The task starts inside the requested working directory
if (chdir(task->working_dir)) {
perror(task->working_dir);
@@ -77,11 +78,13 @@ int child(struct MultiProcessingPool *pool, struct MultiProcessingTask *task) {
snprintf(task->log_file + strlen(task->log_file), sizeof(task->log_file) - strlen(task->log_file),
"task-%zu-%d.log", mp_global_task_count, task->parent_pid);
SYSDEBUG("using log file: %s", task->log_file);
+ semaphore_post(&pool->semaphore);
}
fp_log = freopen(task->log_file, "w+", stdout);
if (!fp_log) {
fprintf(stderr, "unable to open '%s' for writing: %s\n", task->log_file, strerror(errno));
SYSERROR("unable to open '%s' for writing: %s", task->log_file, strerror(errno));
+ semaphore_post(&pool->semaphore);
return -1;
}
@@ -90,6 +93,7 @@ int child(struct MultiProcessingPool *pool, struct MultiProcessingTask *task) {
SYSERROR("%s", "Unable to redirect stderr to stdout");
SYSERROR("Unable to redirect stderr to stdout");
fclose(fp_log);
+ semaphore_post(&pool->semaphore);
return -1;
}