]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
tun: Kill the tunnel script's process group
authorKevin Cernekee <cernekee@gmail.com>
Wed, 14 Nov 2012 03:00:25 +0000 (19:00 -0800)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Wed, 14 Nov 2012 10:09:33 +0000 (10:09 +0000)
When invoked with --script-tun, openconnect starts the tunnel script
via "/bin/sh -c 'SCRIPT'", then sends SIGHUP to the shell's PID when
shutting down.  However, non-interactive shells are not guaranteed to
send SIGHUP to any running jobs¹; indeed, the observed behavior on
Linux is that only the shell process receives SIGHUP, and the tunnel
script continues running after openconnect exits.

A quick fix is to set the child's pgid == pid, then send SIGHUP to the
entire process group when we want to shut down.

¹ http://www.gnu.org/software/bash/manual/html_node/Signals.html

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
tun.c

diff --git a/tun.c b/tun.c
index 831c11eb565fa645d2dd0583481fa9137932b94d..5c0417764b749c91945813d58c0e87fa809b77c7 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -652,6 +652,8 @@ int setup_tun(struct openconnect_info *vpninfo)
                        perror(_("fork"));
                        exit(1);
                } else if (!child) {
+                       if (setpgid(0, getpid()) < 0)
+                               perror(_("setpgid"));
                        close(tun_fd);
                        setenv_int("VPNFD", fds[1]);
                        execl("/bin/sh", "/bin/sh", "-c", vpninfo->vpnc_script, NULL);
@@ -786,7 +788,8 @@ int tun_mainloop(struct openconnect_info *vpninfo, int *timeout)
 void shutdown_tun(struct openconnect_info *vpninfo)
 {      
        if (vpninfo->script_tun) {
-               kill(vpninfo->script_tun, SIGHUP);
+               /* nuke the whole process group */
+               kill(-vpninfo->script_tun, SIGHUP);
        } else {
                script_config_tun(vpninfo, "disconnect");
 #ifdef __sun__