Skip to content

Commit

Permalink
Merge pull request saltstack#36184 from DSRCorporation/bugs/35480_mas…
Browse files Browse the repository at this point in the history
…ter_shutdown

Disable signal handling while handling signal
  • Loading branch information
Mike Place authored Sep 11, 2016
2 parents f11f093 + 229504e commit 6ebe655
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 0 additions & 1 deletion salt/log/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

# Import python libs
import sys
import atexit
import logging
import threading
import logging.handlers
Expand Down
13 changes: 11 additions & 2 deletions salt/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ def kill_children(self, *args, **kwargs):
'''
Kill all of the children
'''
# first lets reset signal handlers to default one to prevent running this twice
signal.signal(signal.SIGTERM, signal.SIG_IGN)
signal.signal(signal.SIGINT, signal.SIG_IGN)

# check that this is the correct process, children inherit this
# handler, if we are in a child lets just run the original handler
if os.getpid() != self._pid:
Expand All @@ -433,7 +437,10 @@ def kill_children(self, *args, **kwargs):
log.trace('Terminating pid {0}: {1}'.format(pid, p_map['Process']))
if args:
# escalate the signal to the process
os.kill(pid, args[0])
try:
os.kill(pid, args[0])
except OSError:
pass
try:
p_map['Process'].terminate()
except OSError as exc:
Expand Down Expand Up @@ -477,7 +484,7 @@ def kill_children(self, *args, **kwargs):
continue
log.trace('Killing pid {0}: {1}'.format(pid, p_map['Process']))
try:
os.kill(signal.SIGKILL, pid)
os.kill(pid, signal.SIGKILL)
except OSError:
# in case the process has since decided to die, os.kill returns OSError
if not p_map['Process'].is_alive():
Expand Down Expand Up @@ -648,6 +655,8 @@ def __setup_signals(self):
signal.signal(signal.SIGTERM, self._handle_signals)

def _handle_signals(self, signum, sigframe):
signal.signal(signal.SIGTERM, signal.SIG_IGN)
signal.signal(signal.SIGINT, signal.SIG_IGN)
msg = '{0} received a '.format(self.__class__.__name__)
if signum == signal.SIGINT:
msg += 'SIGINT'
Expand Down

0 comments on commit 6ebe655

Please sign in to comment.