diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-11 15:50:43 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-11 15:50:43 +0200 |
commit | a45a313422efa33f261cb1b53a08646a6b3ab947 (patch) | |
tree | abe0d81b6dba97106b1016722e210f02a0168733 /src/shell.c | |
parent | e5a8f900352b242860ac3dd4e3b39c7297169480 (diff) | |
download | fastd-a45a313422efa33f261cb1b53a08646a6b3ab947.tar fastd-a45a313422efa33f261cb1b53a08646a6b3ab947.zip |
Improve shell command config handling
Diffstat (limited to 'src/shell.c')
-rw-r--r-- | src/shell.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/shell.c b/src/shell.c index 7acfa48..6d60a07 100644 --- a/src/shell.c +++ b/src/shell.c @@ -24,6 +24,7 @@ */ +#include "shell.h" #include "peer.h" #include <arpa/inet.h> @@ -31,12 +32,16 @@ #include <sys/wait.h> -bool fastd_shell_exec(fastd_context_t *ctx, const char *command, const char *dir, const fastd_peer_t *peer, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *peer_addr, int *ret) { +bool fastd_shell_command_exec(fastd_context_t *ctx, const fastd_shell_command_t *command, const fastd_peer_t *peer, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *peer_addr, int *ret) { + if (!fastd_shell_command_isset(command)) + return true; + int result = -1; bool ok = false; char *cwd = get_current_dir_name(); - if(!chdir(dir)) { + + if(!chdir(command->dir)) { /* both INET6_ADDRSTRLEN and IFNAMESIZE already include space for the zero termination, so there is no need to add space for the '%' here. */ char buf[INET6_ADDRSTRLEN+IF_NAMESIZE]; @@ -128,7 +133,7 @@ bool fastd_shell_exec(fastd_context_t *ctx, const char *command, const char *dir ctx->conf->protocol->set_shell_env(ctx, peer); - result = system(command); + result = system(command->command); if (ret) { *ret = result; @@ -147,7 +152,7 @@ bool fastd_shell_exec(fastd_context_t *ctx, const char *command, const char *dir pr_error(ctx, "can't chdir to `%s': %s", cwd, strerror(errno)); } else { - pr_error(ctx, "can't chdir to `%s': %s", dir, strerror(errno)); + pr_error(ctx, "can't chdir to `%s': %s", command->dir, strerror(errno)); } free(cwd); |