diff options
| author | Federico Angelilli <code@fedang.net> | 2024-11-24 22:03:01 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-11-24 22:03:01 +0100 |
| commit | b5c06f76b9a7cbc64590ec247778704459efb3ea (patch) | |
| tree | 0aa922a2af11fcf53d64ca8ae30ebe5ddce90f84 /src | |
| parent | 21fb9be7b28843d9232803b90137c7251fe9194e (diff) | |
Implement action run-script
Diffstat (limited to 'src')
| -rw-r--r-- | src/action.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/action.c b/src/action.c index 65172f5..590eac8 100644 --- a/src/action.c +++ b/src/action.c @@ -1,6 +1,8 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <unistd.h> +#include <sys/wait.h> #include "action.h" #include "block.h" @@ -68,7 +70,30 @@ void action_perform(action_t *action, block_t *block, config_t *config) } case ACTION_RUN_SCRIPT: { - log_panic("TODO"); + // TODO: Pass information about the action/block to the script + // Also allow sync/async scripts + + pid_t pid = fork(); + if (pid == -1) { + if (config->action_failfast) { + log_debug("Aborted action '%s'", action->label); + return; + } + } else if (pid == 0) { + execl("/bin/sh", "sh", "-c", value, (char *)NULL); + unreachable(); + } else { + int status; + waitpid(pid, &status, 0); + + bool success = !WIFEXITED(status) || WEXITSTATUS(status) != 0; + if (config->action_strict_run && !success) { + if (config->action_failfast) { + log_debug("Aborted action '%s'", action->label); + return; + } + } + } break; } |
