summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sysexec.h13
-rw-r--r--src/uanytun.c2
2 files changed, 13 insertions, 2 deletions
diff --git a/src/sysexec.h b/src/sysexec.h
index 2b01bc8..04226a1 100644
--- a/src/sysexec.h
+++ b/src/sysexec.h
@@ -56,11 +56,22 @@ int exec_script(const char* script, const char* ifname)
if(dup(fd) == -1) // stderr
log_printf(WARNING, "can't open stderr");
}
- return execl("/bin/sh", "/bin/sh", script, ifname, NULL);
+ execl("/bin/sh", "/bin/sh", script, ifname, NULL);
+ // if execl return, an error occurred
+ log_printf(ERR, "error on executing script: %m");
+ return -1;
}
int status = 0;
waitpid(pid, &status, 0);
+ if(WIFEXITED(status))
+ log_printf(NOTICE, "script '%s' returned %d", script, WEXITSTATUS(status));
+ else if(WIFSIGNALED(status))
+ log_printf(NOTICE, "script '%s' terminated after signal %d", script, WTERMSIG(status));
+ else
+ log_printf(ERR, "executing script: unkown error");
+
return status;
+
}
#endif
diff --git a/src/uanytun.c b/src/uanytun.c
index c4a4f1b..d1919d6 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -362,8 +362,8 @@ int main(int argc, char* argv[])
log_printf(NOTICE, "dev of type '%s' opened, actual name is '%s'", tun_get_type_string(&dev), dev.actual_name_);
if(opt.post_up_script_) {
+ log_printf(NOTICE, "executing post-up script '%s'", opt.post_up_script_);
int ret = exec_script(opt.post_up_script_, dev.actual_name_);
- log_printf(NOTICE, "post-up script returned %d", ret);
}