diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-04-06 00:55:59 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-04-06 00:55:59 +0200 |
commit | 1ed4ac93ae35534397bc8267f255c380ef3193c4 (patch) | |
tree | 1ac441024715ace282ef52587ddcfec678f4d8ed /src/fastd.c | |
parent | a6a5b5e00e98aa27644a1afa4a461819221b758d (diff) | |
download | fastd-1ed4ac93ae35534397bc8267f255c380ef3193c4.tar fastd-1ed4ac93ae35534397bc8267f255c380ef3193c4.zip |
Add some missing error handling
Diffstat (limited to 'src/fastd.c')
-rw-r--r-- | src/fastd.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/src/fastd.c b/src/fastd.c index ca4edb8..b2cc196 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -191,22 +191,28 @@ static void on_up(fastd_context *ctx) { return; char *cwd = get_current_dir_name(); - chdir(ctx->conf->on_up_dir); - setenv("INTERFACE", ctx->ifname, 1); + if (!chdir(ctx->conf->on_up_dir)) { + setenv("INTERFACE", ctx->ifname, 1); - char buf[6]; - snprintf(buf, 6, "%u", ctx->conf->mtu); - setenv("MTU", buf, 1); + char buf[6]; + snprintf(buf, 6, "%u", ctx->conf->mtu); + setenv("MTU", buf, 1); - int ret = system(ctx->conf->on_up); + 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 (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)); + } - chdir(cwd); free(cwd); } @@ -215,22 +221,28 @@ static void on_down(fastd_context *ctx) { return; char *cwd = get_current_dir_name(); - chdir(ctx->conf->on_down_dir); - setenv("INTERFACE", ctx->ifname, 1); + if(!chdir(ctx->conf->on_down_dir)) { + setenv("INTERFACE", ctx->ifname, 1); - char buf[6]; - snprintf(buf, 6, "%u", ctx->conf->mtu); - setenv("MTU", buf, 1); + char buf[6]; + snprintf(buf, 6, "%u", ctx->conf->mtu); + setenv("MTU", buf, 1); - int ret = system(ctx->conf->on_down); + 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 (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)); + } - chdir(cwd); free(cwd); } @@ -306,7 +318,8 @@ static void handle_tasks(fastd_context *ctx) { fastd_peer_eth_addr_add(ctx, task->peer, src_addr); } - write(ctx->tunfd, task->handle_recv.buffer.data, task->handle_recv.buffer.len); + if (write(ctx->tunfd, task->handle_recv.buffer.data, task->handle_recv.buffer.len) < 0) + warn_errno(ctx, "write"); if (ctx->conf->mode == MODE_TAP && ctx->conf->peer_to_peer) { const fastd_eth_addr *dest_addr = fastd_get_dest_address(ctx, task->handle_recv.buffer); |