From a74f1b80779263c9074ba975357064332bcd4730 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Mon, 13 Jun 2016 09:43:18 -0700 Subject: [PATCH] ZD 762 (#33942) * Initial debugging * Replace the old child jid tracking with psutil investigation of children * Remove debugging --- salt/modules/cmdmod.py | 21 --------------------- salt/modules/saltutil.py | 7 ++++--- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index daee9392fc..00c0a8e4c1 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -816,27 +816,6 @@ def run(cmd, log_callback = _check_cb(log_callback) - if 'pid' in ret and '__pub_jid' in kwargs: - # Stuff the child pid in the JID file - try: - proc_dir = os.path.join(__opts__['cachedir'], 'proc') - jid_file = os.path.join(proc_dir, kwargs['__pub_jid']) - if os.path.isfile(jid_file): - serial = salt.payload.Serial(__opts__) - with salt.utils.fopen(jid_file, 'rb') as fn_: - jid_dict = serial.load(fn_) - - if 'child_pids' in jid_dict: - jid_dict['child_pids'].append(ret['pid']) - else: - jid_dict['child_pids'] = [ret['pid']] - # Rewrite file - with salt.utils.fopen(jid_file, 'w+b') as fn_: - fn_.write(serial.dumps(jid_dict)) - except (NameError, TypeError): - # Avoids errors from msgpack not being loaded in salt-ssh - pass - lvl = _check_loglevel(output_loglevel) if lvl is not None: if not ignore_retcode and ret['retcode'] != 0: diff --git a/salt/modules/saltutil.py b/salt/modules/saltutil.py index 61b5be9f15..394da2d786 100644 --- a/salt/modules/saltutil.py +++ b/salt/modules/saltutil.py @@ -51,6 +51,8 @@ import salt.utils.event import salt.utils.url import salt.transport import salt.wheel +import salt.utils.psutil_compat as psutil + from salt.exceptions import ( SaltReqTimeoutError, SaltRenderError, CommandExecutionError, SaltInvocationError ) @@ -856,10 +858,9 @@ def signal_job(jid, sig): for data in running(): if data['jid'] == jid: try: + for proc in psutil.Process(pid=data['pid']).children(recursive=True): + proc.send_signal(sig) os.kill(int(data['pid']), sig) - if 'child_pids' in data: - for pid in data['child_pids']: - os.kill(int(pid), sig) return 'Signal {0} sent to job {1} at pid {2}'.format( int(sig), jid,