diff options
Diffstat (limited to 'src/action.c')
| -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; } |
