These files are part of a library now so they should report errors back to the caller. Signed-off-by: Kevin Cernekee <cernekee at gmail.com> --- cstp.c | 9 +++++---- tun.c | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cstp.c b/cstp.c index 71fde30..4c15d0d 100644 --- a/cstp.c +++ b/cstp.c @@ -196,8 +196,9 @@ static int start_cstp_connection(struct openconnect_info *vpninfo) if (vpninfo->dtls_times.last_rekey + vpninfo->dtls_times.rekey < time(NULL) + 300 && openconnect_random(vpninfo->dtls_secret, sizeof(vpninfo->dtls_secret))) { - fprintf(stderr, _("Failed to initialise DTLS secret\n")); - exit(1); + vpn_progress(vpninfo, PRG_ERR, + _("Failed to initialise DTLS secret\n")); + return -EIO; } retry: @@ -238,7 +239,7 @@ static int start_cstp_connection(struct openconnect_info *vpninfo) vpn_progress(vpninfo, PRG_ERR, _("Failed to open HTTPS connection to %s\n"), vpninfo->hostname); - exit(1); + return -EIO; } goto retry; } @@ -264,7 +265,7 @@ static int start_cstp_connection(struct openconnect_info *vpninfo) _("Got inappropriate HTTP CONNECT response: %s\n"), buf); if (!strncmp(buf, "HTTP/1.1 401 ", 13)) - exit(2); + return -EPERM; return -EINVAL; } diff --git a/tun.c b/tun.c index e4f7a5e..2edb8d9 100644 --- a/tun.c +++ b/tun.c @@ -508,7 +508,7 @@ static int os_setup_tun(struct openconnect_info *vpninfo) vpn_progress(vpninfo, PRG_ERR, _("Failed to open tun device: %s\n"), strerror(tunerr)); - exit(1); + return -EIO; } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN | IFF_NO_PI; @@ -519,7 +519,7 @@ static int os_setup_tun(struct openconnect_info *vpninfo) vpn_progress(vpninfo, PRG_ERR, _("TUNSETIFF failed: %s\n"), strerror(errno)); - exit(1); + return -EIO; } if (!vpninfo->ifname) vpninfo->ifname = strdup(ifr.ifr_name); @@ -615,8 +615,10 @@ static int os_setup_tun(struct openconnect_info *vpninfo) break; } if (tun_fd < 0) { - perror(_("open tun")); - exit(1); + vpn_progress(vpninfo, PRG_ERR, + _("Failed to open tun device: %s\n"), + strerror(errno)); + return -EIO; } vpninfo->ifname = strdup(tun_name + 5); } @@ -624,7 +626,7 @@ static int os_setup_tun(struct openconnect_info *vpninfo) i = 1; if (ioctl(tun_fd, TUNSIFHEAD, &i) < 0) { perror(_("TUNSIFHEAD")); - exit(1); + return -EIO; } #endif #endif @@ -657,13 +659,13 @@ int openconnect_setup_tun_script(struct openconnect_info *vpninfo, char *tun_scr set_script_env(vpninfo); if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds)) { - perror(_("socketpair")); - exit(1); + vpn_progress(vpninfo, PRG_ERR, _("socketpair failed: %s\n"), strerror(errno)); + return -EIO; } child = fork(); if (child < 0) { - perror(_("fork")); - exit(1); + vpn_progress(vpninfo, PRG_ERR, _("fork failed: %s\n"), strerror(errno)); + return -EIO; } else if (!child) { if (setpgid(0, getpid()) < 0) perror(_("setpgid")); -- 1.7.9.5