diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2011-07-08 09:41:37 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2011-07-08 09:41:37 +0200 |
commit | 5174b6a2330a93f183bc63894131fdc1b9ff4603 (patch) | |
tree | 225b000ee921cdf57881a20388a91fd1e89a0737 | |
parent | 2c89e23c5b4d874b7b56c50b1f3ba1a4d0a1189e (diff) | |
download | pingu-5174b6a2330a93f183bc63894131fdc1b9ff4603.tar.bz2 pingu-5174b6a2330a93f183bc63894131fdc1b9ff4603.tar.xz |
pingu_host: execute the action
-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) |