From: Ondrej Lichtner <olichtne(a)redhat.com>
This commit modifies signal handling for lnst-slave processes running in
non-root network namespaces to:
* when a SIGHUP, SIGTERM or SIGINT is recieved resend this signal to the
parent process that is running in the root netns and it will
coordinate deconfiguration
* when SIGUSR1 is recieved the main server loop will be interrupted like
it would with the previous signal handling
This solves the issue of deconfiguration races and crashes happening
when doing Ctrl-C from the terminal after lnst-ctl config-only was
called.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Slave/NetTestSlave.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index c63c719..8eb1f99 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -516,6 +516,7 @@ class SlaveMethods:
self._server_handler.add_netns(netns, read_pipe)
return None
elif pid == 0:
+ self._slave_server.set_netns_sighandlers()
#create new network namespace
libc_name = ctypes.util.find_library("c")
#from sched.h
@@ -564,7 +565,7 @@ class SlaveMethods:
return False
else:
netns_pid = self._net_namespaces[netns]["pid"]
- os.kill(netns_pid, signal.SIGTERM)
+ os.kill(netns_pid, signal.SIGUSR1)
os.waitpid(netns_pid, 0)
logging.debug("Network namespace %s removed." % netns)
@@ -859,3 +860,13 @@ class NetTestSlave:
def _signal_die_handler(self, signum, frame):
logging.info("Caught signal %d -> dying" % signum)
self._finished = True
+
+ def _parent_resend_signal_handler(self, signum, frame):
+ logging.info("Caught signal %d -> resending to parent" % signum)
+ os.kill(os.getppid(), signum)
+
+ def set_netns_sighandlers(self):
+ signal.signal(signal.SIGHUP, self._parent_resend_signal_handler)
+ signal.signal(signal.SIGINT, self._parent_resend_signal_handler)
+ signal.signal(signal.SIGTERM, self._parent_resend_signal_handler)
+ signal.signal(signal.SIGUSR1, self._signal_die_handler)
--
2.1.0
_______________________________________________
LNST-developers mailing list
LNST-developers(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/lnst-developers