diff options
-rw-r--r-- | pingu_host.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/pingu_host.c b/pingu_host.c index 26b4d83..a7640ed 100644 --- a/pingu_host.c +++ b/pingu_host.c @@ -1,3 +1,6 @@ + +#include <stdlib.h> +#include <unistd.h> #include <ev.h> #include "log.h" @@ -5,6 +8,26 @@ #include "pingu_host.h" #include "pingu_ping.h" +static void execute_action(const char *action) +{ + pid_t pid; + const char *shell = getenv("SHELL"); + if (shell == NULL) + shell = "/bin/sh"; + + log_debug("executing '%s'", action); + pid = fork(); + if (pid < 0) { + log_perror("fork"); + return; + } + if (pid == 0) { + execl(shell, shell, "-c", action, NULL); + log_perror(action); + exit(1); + } +} + void pingu_host_set_status(struct pingu_host *host, int status) { const char *action; @@ -23,7 +46,8 @@ void pingu_host_set_status(struct pingu_host *host, int status) action = host->up_action; break; } - log_debug("TODO: execute %s", action); + if (action != NULL) + execute_action(action); } int pingu_host_verify_status(struct ev_loop *loop, struct pingu_host *host) |