Ignore SIGINT to allow proper cleanup on Ctrl-C

This commit is contained in:
Johan Ström
2018-09-06 15:12:50 +02:00
parent 9a0ec161de
commit 4660d48151
+5 -1
View File
@@ -24,7 +24,7 @@
THE SOFTWARE. THE SOFTWARE.
""" """
from __future__ import print_function from __future__ import print_function
import io, os, sys, re, json, base64, getpass, subprocess, shlex import io, os, sys, re, json, base64, getpass, subprocess, shlex, signal
from lxml import etree from lxml import etree
import requests import requests
@@ -363,6 +363,10 @@ def main():
pp = subprocess.Popen(shlex.split(pcmd), stdout=subprocess.PIPE) pp = subprocess.Popen(shlex.split(pcmd), stdout=subprocess.PIPE)
cp = subprocess.Popen(cmd, stdin=pp.stdout, stdout=sys.stdout) cp = subprocess.Popen(cmd, stdin=pp.stdout, stdout=sys.stdout)
pp.stdout.close() pp.stdout.close()
# Do not abort on SIGINT. openconnect will see it, and perform proper exit & cleanup
signal.signal(signal.SIGINT, signal.SIG_IGN)
cp.communicate() cp.communicate()
else: else:
print('{0} | {1}'.format(pcmd, cmd)) print('{0} | {1}'.format(pcmd, cmd))