summaryrefslogtreecommitdiffstats
path: root/src/fastd.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-02-25 04:48:11 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-02-25 04:48:11 +0100
commit698ede3ce4ab7ff88e5c69b3910544094c7f9814 (patch)
treed3a7bd1835ecf25e16c35ab658e7d56cc2c69ad2 /src/fastd.c
parentb3ba14d47370e156ef7366954c1160e088e92b49 (diff)
downloadfastd-698ede3ce4ab7ff88e5c69b3910544094c7f9814.tar
fastd-698ede3ce4ab7ff88e5c69b3910544094c7f9814.zip
Get rid of some duplicate code for calling shell commands
Diffstat (limited to 'src/fastd.c')
-rw-r--r--src/fastd.c46
1 files changed, 4 insertions, 42 deletions
diff --git a/src/fastd.c b/src/fastd.c
index 8b6ea94..ce297f7 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -563,56 +563,18 @@ void fastd_handle_receive(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer
}
}
-static void on_up(fastd_context_t *ctx) {
+static inline void on_up(fastd_context_t *ctx) {
if (!ctx->conf->on_up)
return;
- char *cwd = get_current_dir_name();
-
- if (!chdir(ctx->conf->on_up_dir)) {
- setenv("INTERFACE", ctx->ifname, 1);
-
- int ret = system(ctx->conf->on_up);
-
- if (WIFSIGNALED(ret))
- pr_error(ctx, "on-up command exited with signal %i", WTERMSIG(ret));
- else if(ret)
- pr_warn(ctx, "on-up command exited with status %i", WEXITSTATUS(ret));
-
- if (chdir(cwd))
- pr_error(ctx, "can't chdir to `%s': %s", cwd, strerror(errno));
- }
- else {
- pr_error(ctx, "can't chdir to `%s': %s", ctx->conf->on_up_dir, strerror(errno));
- }
-
- free(cwd);
+ fastd_shell_exec(ctx, NULL, ctx->conf->on_up, ctx->conf->on_up_dir, NULL);
}
-static void on_down(fastd_context_t *ctx) {
+static inline void on_down(fastd_context_t *ctx) {
if (!ctx->conf->on_down)
return;
- char *cwd = get_current_dir_name();
-
- if(!chdir(ctx->conf->on_down_dir)) {
- setenv("INTERFACE", ctx->ifname, 1);
-
- int ret = system(ctx->conf->on_down);
-
- if (WIFSIGNALED(ret))
- pr_error(ctx, "on-down command exited with signal %i", WTERMSIG(ret));
- else if(ret)
- pr_warn(ctx, "on-down command exited with status %i", WEXITSTATUS(ret));
-
- if (chdir(cwd))
- pr_error(ctx, "can't chdir to `%s': %s", cwd, strerror(errno));
- }
- else {
- pr_error(ctx, "can't chdir to `%s': %s", ctx->conf->on_down_dir, strerror(errno));
- }
-
- free(cwd);
+ fastd_shell_exec(ctx, NULL, ctx->conf->on_down, ctx->conf->on_down_dir, NULL);
}
static fastd_peer_group_t* init_peer_group(const fastd_peer_group_config_t *config, fastd_peer_group_t *parent) {