aboutsummaryrefslogtreecommitdiff
path: root/src/action.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/action.c')
-rw-r--r--src/action.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/action.c b/src/action.c
index 590eac8..1ea7d7f 100644
--- a/src/action.c
+++ b/src/action.c
@@ -8,7 +8,7 @@
#include "block.h"
#include "any_log.h"
-void action_perform(action_t *action, block_t *block, config_t *config)
+bool action_perform(action_t *action, block_t *block, config_t *config)
{
block_t *target = block;
bool warned = false;
@@ -38,10 +38,8 @@ void action_perform(action_t *action, block_t *block, config_t *config)
assert(target->scheme->validate_fn != NULL);
int errors = target->scheme->validate_fn(target, config);
- if (config->action_failfast && errors) {
- log_debug("Aborted action '%s' for %d errors", action->label, errors);
- return;
- }
+ if (config->action_failfast && errors)
+ goto error;
}
notify = false;
@@ -60,24 +58,21 @@ void action_perform(action_t *action, block_t *block, config_t *config)
// Skip "set-" in key
bool success = block_change(target, config, key + 4, value);
- if (config->action_failfast && !success) {
- log_debug("Aborted action '%s'", action->label);
- return;
- }
+ if (config->action_failfast && !success)
+ goto error;
notify = true;
break;
}
- case ACTION_RUN_SCRIPT: {
+ case ACTION_RUN_SYNC: {
// 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;
+ log_trace("Failed to fork");
+ goto error;
}
} else if (pid == 0) {
execl("/bin/sh", "sh", "-c", value, (char *)NULL);
@@ -88,15 +83,18 @@ void action_perform(action_t *action, block_t *block, config_t *config)
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;
- }
+ if (config->action_failfast)
+ goto error;
}
}
break;
}
+ case ACTION_RUN_ASYNC: {
+ log_panic("Async not implemented");
+ break;
+ }
+
default:
unreachable();
}
@@ -110,15 +108,18 @@ void action_perform(action_t *action, block_t *block, config_t *config)
if (notify && target->scheme->validate_change) {
assert(target->scheme->validate_fn != NULL);
- int errors = target->scheme->validate_fn(target, config);
- if (config->action_failfast && errors) {
- log_debug("Aborted action '%s' for %d errors", action->label, errors);
- return;
- }
+ int errors = target->scheme->validate_fn(target, config);
+ if (config->action_failfast && errors != 0)
+ goto error;
}
log_debug("Performed action '%s'", action->label);
+ return true;
+
+error:
+ log_debug("Aborted action '%s'", action->label);
+ return false;
}
int action_validate(action_t *action, config_t *config)