[daemon_base] fix to not reregister signal handler (#4998)
* [daemon_base] fix to not reregister signal handler -src/sonic-daemon-base/sonic_daemon_base/daemon_base.py Problem: Currently all daemons inherit from daemon_base class, and for signal handling functionality they register the signal_handler() by overriding the siganl_handler() in daemon_base by their own implmentation. But some sonic_platform instances also can invoke the daemon_base constructor while trying to instantiate the common utilities for example platform_chassis = sonic_platform.platform.Platform().get_chassis() This will cause the re registration of signal_handler which will cause base class signal_handler() to be invoked when the daemon gets a signal, whereas their own signal_handler should have been invoked. Fix: We only register the siganl_handler once, and if signal_handler has been registered, not re register it. Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com> * [daemon_base] fix to not reregister signal handler Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
This commit is contained in:
parent
aa9e1e2f43
commit
c9983df062
@ -90,8 +90,24 @@ class Logger(object):
|
|||||||
class DaemonBase(object):
|
class DaemonBase(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Register our signal handlers
|
# Register our signal handlers
|
||||||
|
'''all daemons inherit from daemon_base class, and for
|
||||||
|
signal handling functionality they register the signal_handler() by
|
||||||
|
overriding the siganl_handler() in daemon_base by their own
|
||||||
|
implmentation.
|
||||||
|
But some sonic_platform instances also can invoke the daemon_base
|
||||||
|
constructor while trying to instantiate the common utilities
|
||||||
|
for example
|
||||||
|
platform_chassis = sonic_platform.platform.Platform().get_chassis()
|
||||||
|
This will cause the re registration of signal_handler which will
|
||||||
|
cause base class signal_handler() to be invoked when the daemon
|
||||||
|
gets a signal, whereas the derived class signal_handler should have
|
||||||
|
been invoked. The if checks will not allow the re registration
|
||||||
|
of signal handler '''
|
||||||
|
if not signal.getsignal(signal.SIGHUP):
|
||||||
signal.signal(signal.SIGHUP, self.signal_handler)
|
signal.signal(signal.SIGHUP, self.signal_handler)
|
||||||
|
if not signal.getsignal(signal.SIGINT):
|
||||||
signal.signal(signal.SIGINT, self.signal_handler)
|
signal.signal(signal.SIGINT, self.signal_handler)
|
||||||
|
if not signal.getsignal(signal.SIGTERM):
|
||||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||||
|
|
||||||
# Signal handler
|
# Signal handler
|
||||||
|
Loading…
Reference in New Issue
Block a user