Skip to content

Commit

Permalink
Split out os_shutdown_tun() for Windows vs. sane platforms
Browse files Browse the repository at this point in the history
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Feb 13, 2014
1 parent 4b3317e commit 761832f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mainloop.c
Expand Up @@ -219,7 +219,7 @@ int openconnect_mainloop(struct openconnect_info *vpninfo,

cstp_bye(vpninfo, vpninfo->quit_reason);

shutdown_tun(vpninfo);
os_shutdown_tun(vpninfo);
return ret < 0 ? ret : -EIO;
}

Expand Down
2 changes: 1 addition & 1 deletion openconnect-internal.h
Expand Up @@ -454,7 +454,7 @@ void set_script_env(struct openconnect_info *vpninfo);
int script_config_tun(struct openconnect_info *vpninfo, const char *reason);

/* tun.c */
void shutdown_tun(struct openconnect_info *vpninfo);
void os_shutdown_tun(struct openconnect_info *vpninfo);
int os_read_tun(struct openconnect_info *vpninfo, struct pkt *pkt, int new_pkt);
int os_write_tun(struct openconnect_info *vpninfo, struct pkt *pkt);

Expand Down
9 changes: 9 additions & 0 deletions tun-win32.c
Expand Up @@ -264,3 +264,12 @@ int os_write_tun(struct openconnect_info *vpninfo, struct pkt *pkt)
_("Failed to write to TAP device: %lx\n"), err);
return -1;
}

void os_shutdown_tun(struct openconnect_info *vpninfo)
{
script_config_tun(vpninfo, "disconnect");
CloseHandle(vpninfo->tun_fh);
vpninfo->tun_fh = NULL;
CloseHandle(vpninfo->tun_rd_overlap.hEvent);
vpninfo->tun_rd_overlap.hEvent = NULL;
}
12 changes: 3 additions & 9 deletions tun.c
Expand Up @@ -467,15 +467,9 @@ int openconnect_setup_tun_device(struct openconnect_info *vpninfo, char *vpnc_sc
return openconnect_setup_tun_fd(vpninfo, tun_fd);
}

void shutdown_tun(struct openconnect_info *vpninfo)
#ifndef _WIN32
void os_shutdown_tun(struct openconnect_info *vpninfo)
{
#ifdef _WIN32
script_config_tun(vpninfo, "disconnect");
CloseHandle(vpninfo->tun_fh);
vpninfo->tun_fh = NULL;
CloseHandle(vpninfo->tun_rd_overlap.hEvent);
vpninfo->tun_rd_overlap.hEvent = NULL;
#else
if (vpninfo->script_tun) {
/* nuke the whole process group */
kill(-vpninfo->script_tun, SIGHUP);
Expand All @@ -494,5 +488,5 @@ void shutdown_tun(struct openconnect_info *vpninfo)
if (vpninfo->vpnc_script)
close(vpninfo->tun_fd);
vpninfo->tun_fd = -1;
#endif
}
#endif

0 comments on commit 761832f

Please sign in to comment.