diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cli/stasis/stasis_main.c | 3 | ||||
| -rw-r--r-- | src/lib/core/multiprocessing.c | 35 |
2 files changed, 27 insertions, 11 deletions
diff --git a/src/cli/stasis/stasis_main.c b/src/cli/stasis/stasis_main.c index 2ce6831..967ecaf 100644 --- a/src/cli/stasis/stasis_main.c +++ b/src/cli/stasis/stasis_main.c @@ -586,6 +586,9 @@ int main(int argc, char *argv[]) { case OPT_NO_PARALLEL: globals.enable_parallel = false; break; + case OPT_NO_TASK_LOGGING: + globals.enable_task_logging = false; + break; case '?': default: exit(1); diff --git a/src/lib/core/multiprocessing.c b/src/lib/core/multiprocessing.c index c9d22a1..69719e8 100644 --- a/src/lib/core/multiprocessing.c +++ b/src/lib/core/multiprocessing.c @@ -27,8 +27,11 @@ int child(struct MultiProcessingPool *pool, struct MultiProcessingTask *task) { // Redirect stdout and stderr to the log file fflush(stdout); fflush(stderr); + // Set log file name - sprintf(task->log_file + strlen(task->log_file), "task-%zu-%d.log", mp_global_task_count, task->parent_pid); + if (globals.enable_task_logging) { + sprintf(task->log_file + strlen(task->log_file), "task-%zu-%d.log", mp_global_task_count, task->parent_pid); + } 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)); @@ -118,8 +121,12 @@ struct MultiProcessingTask *mp_pool_task(struct MultiProcessingPool *pool, const // Set log file path memset(slot->log_file, 0, sizeof(*slot->log_file)); - strcat(slot->log_file, pool->log_root); - strcat(slot->log_file, "/"); + if (globals.enable_task_logging) { + strcat(slot->log_file, pool->log_root); + strcat(slot->log_file, "/"); + } else { + strcpy(slot->log_file, "/dev/stdout"); + } // Set working directory if (isempty(working_dir)) { @@ -251,9 +258,11 @@ int mp_pool_kill(struct MultiProcessingPool *pool, int signum) { } } } - if (!access(slot->log_file, F_OK)) { - SYSDEBUG("Removing log file: %s", slot->log_file); - remove(slot->log_file); + if (globals.enable_task_logging) { + if (!access(slot->log_file, F_OK)) { + SYSDEBUG("Removing log file: %s", slot->log_file); + remove(slot->log_file); + } } if (!access(slot->parent_script, F_OK)) { SYSDEBUG("Removing runner script: %s", slot->parent_script); @@ -340,9 +349,11 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { fprintf(stderr, "%s Task state is unknown (0x%04X)\n", progress, status); } - // Show the log (always) - if (show_log_contents(stdout, slot)) { - perror(slot->log_file); + if (globals.enable_task_logging) { + // Show the log (always) + if (show_log_contents(stdout, slot)) { + perror(slot->log_file); + } } // Record the task stop time @@ -364,8 +375,10 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { } // Clean up logs and scripts left behind by the task - if (remove(slot->log_file)) { - fprintf(stderr, "%s Unable to remove log file: '%s': %s\n", progress, slot->parent_script, strerror(errno)); + if (globals.enable_task_logging) { + if (remove(slot->log_file)) { + fprintf(stderr, "%s Unable to remove log file: '%s': %s\n", progress, slot->parent_script, strerror(errno)); + } } if (remove(slot->parent_script)) { fprintf(stderr, "%s Unable to remove temporary script '%s': %s\n", progress, slot->parent_script, strerror(errno)); |
