aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-11-24 22:03:01 +0100
committerFederico Angelilli <code@fedang.net>2024-11-24 22:03:01 +0100
commitb5c06f76b9a7cbc64590ec247778704459efb3ea (patch)
tree0aa922a2af11fcf53d64ca8ae30ebe5ddce90f84
parent21fb9be7b28843d9232803b90137c7251fe9194e (diff)
Implement action run-script
-rw-r--r--comet.conf6
-rw-r--r--src/action.c27
2 files changed, 30 insertions, 3 deletions
diff --git a/comet.conf b/comet.conf
index c27d1c0..e77cddb 100644
--- a/comet.conf
+++ b/comet.conf
@@ -124,6 +124,8 @@
target = block.next
set-text = "ciao"
- target = block.mus
- set-blocks = bogus
+ run-script = echo works
+
+ ;target = block.mus
+ ;set-blocks = bogus
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;
}