diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2025-12-30 11:28:36 -0500 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2025-12-30 11:28:36 -0500 |
| commit | 18b29bd58d1daa1752e981488445e0fcb100f2a7 (patch) | |
| tree | 0f4f2a5f62536ea80c7cd50801bc06d916e5c165 /src/lib | |
| parent | 67c290158cdb12b755c17b404f0eb63bc40eac73 (diff) | |
| download | stasis-18b29bd58d1daa1752e981488445e0fcb100f2a7.tar.gz | |
Implement task timeout
* Add argument: --task-timeout=1[s,m,h]
* Timed out tasks are SIGKILL'd
* If killing a task fails, the entire program ends
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/core/globals.c | 1 | ||||
| -rw-r--r-- | src/lib/core/include/core.h | 1 | ||||
| -rw-r--r-- | src/lib/core/include/multiprocessing.h | 1 | ||||
| -rw-r--r-- | src/lib/core/multiprocessing.c | 3 |
4 files changed, 6 insertions, 0 deletions
diff --git a/src/lib/core/globals.c b/src/lib/core/globals.c index a262d6c..834213b 100644 --- a/src/lib/core/globals.c +++ b/src/lib/core/globals.c @@ -44,6 +44,7 @@ struct STASIS_GLOBAL globals = { .enable_task_logging = true, ///< Toggle logging for multiprocess tasks .parallel_fail_fast = false, ///< Kill ALL multiprocessing tasks immediately on error .pool_status_interval = 30, ///< Report "Task is running" + .task_timeout = 0, ///< Time in seconds before task is terminated }; void globals_free() { diff --git a/src/lib/core/include/core.h b/src/lib/core/include/core.h index e96e010..5a3fa85 100644 --- a/src/lib/core/include/core.h +++ b/src/lib/core/include/core.h @@ -51,6 +51,7 @@ struct STASIS_GLOBAL { char *tmpdir; //!< Path to temporary storage directory char *conda_install_prefix; //!< Path to install conda char *sysconfdir; //!< Path where STASIS reads its configuration files (mission directory, etc) + int task_timeout; ///< Time in seconds before task is terminated struct { char *tox_posargs; char *conda_reactivate; diff --git a/src/lib/core/include/multiprocessing.h b/src/lib/core/include/multiprocessing.h index 6477818..ab7b416 100644 --- a/src/lib/core/include/multiprocessing.h +++ b/src/lib/core/include/multiprocessing.h @@ -15,6 +15,7 @@ struct MultiProcessingTask { pid_t parent_pid; ///< Program PID (parent process) int status; ///< Child process exit status int signaled_by; ///< Last signal received, if any + int timeout; ///< Seconds to elapse before killing the process time_t _now; ///< Current time time_t _seconds; ///< Time elapsed since status interval (used by MultiprocessingPool.status_interval) time_t _startup; ///< Time elapsed since task started diff --git a/src/lib/core/multiprocessing.c b/src/lib/core/multiprocessing.c index 69719e8..ff4453c 100644 --- a/src/lib/core/multiprocessing.c +++ b/src/lib/core/multiprocessing.c @@ -167,6 +167,9 @@ struct MultiProcessingTask *mp_pool_task(struct MultiProcessingPool *pool, const memset(slot->cmd, 0, slot->cmd_len); strncpy(slot->cmd, cmd, slot->cmd_len); + // Set task timeout + slot->timeout = globals.task_timeout; + return slot; } |
