summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-02-23 15:42:38 +0000
committerChristian Pointner <equinox@anytun.org>2009-02-23 15:42:38 +0000
commit4104fb9b38c22e7cb7d1a72e293742095f914a3e (patch)
tree05c31b8e61b08041891e095094999f59cc4e5828 /src
parentadded command line parameters for new logging (diff)
fixed cleanup at errors in main
Diffstat (limited to 'src')
-rw-r--r--src/uanytun.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/uanytun.c b/src/uanytun.c
index 57c52f1..7ac7c44 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -374,8 +374,11 @@ int main(int argc, char* argv[])
priv_info_t priv;
if(opt.username_)
- if(priv_init(&priv, opt.username_, opt.groupname_))
+ if(priv_init(&priv, opt.username_, opt.groupname_)) {
+ options_clear(&opt);
+ log_close();
exit(-1);
+ }
#ifndef NO_CRYPT
#ifndef USE_SSL_CRYPTO
@@ -383,6 +386,7 @@ int main(int argc, char* argv[])
if(ret) {
log_printf(ERROR, "error on libgcrpyt initialization, exitting");
options_clear(&opt);
+ log_close();
exit(ret);
}
#endif
@@ -393,6 +397,7 @@ int main(int argc, char* argv[])
if(ret) {
log_printf(ERROR, "error on tun_init, exitting");
options_clear(&opt);
+ log_close();
exit(ret);
}
log_printf(NOTICE, "dev of type '%s' opened, actual name is '%s'", tun_get_type_string(&dev), dev.actual_name_);
@@ -407,8 +412,9 @@ int main(int argc, char* argv[])
ret = udp_init(&sock, opt.local_addr_, opt.local_port_);
if(ret) {
log_printf(ERROR, "error on udp_init, exitting");
- options_clear(&opt);
tun_close(&dev);
+ options_clear(&opt);
+ log_close();
exit(ret);
}
char* local_string = udp_get_local_end_string(&sock);
@@ -432,12 +438,22 @@ int main(int argc, char* argv[])
}
if(opt.chroot_dir_)
- if(do_chroot(opt.chroot_dir_))
+ if(do_chroot(opt.chroot_dir_)) {
+ tun_close(&dev);
+ udp_close(&sock);
+ options_clear(&opt);
+ log_close();
exit(-1);
+ }
if(opt.username_)
- if(priv_drop(&priv))
+ if(priv_drop(&priv)) {
+ tun_close(&dev);
+ udp_close(&sock);
+ options_clear(&opt);
+ log_close();
exit(-1);
-
+ }
+
if(opt.daemonize_) {
pid_t oldpid = getpid();
daemonize();