From 8ea1f9664abdb24e92f6337fa7b98587129bb716 Mon Sep 17 00:00:00 2001 From: "Manuel Amador (Rudd-O)" Date: Mon, 23 Apr 2012 17:55:35 -0700 Subject: [PATCH] Handle errors in tcollector related to failure to spawn collectors. Change-Id: Ia27a4b528eac99e5d4f2ddc35c503d470eeaee37 Reviewed-on: https://review.stumble.net/11428 Reviewed-by: Dave Barr Tested-by: Benoit Sigoure Reviewed-by: Benoit Sigoure --- tcollector.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tcollector.py b/tcollector.py index 04d7dba4..b943132c 100755 --- a/tcollector.py +++ b/tcollector.py @@ -993,9 +993,23 @@ def spawn_collector(col): # FIXME: do custom integration of Python scripts into memory/threads # if re.search('\.py$', col.name) is not None: # ... load the py module directly instead of using a subprocess ... - col.lastspawn = int(time.time()) - col.proc = subprocess.Popen(col.filename, stdout=subprocess.PIPE, + try: + col.proc = subprocess.Popen(col.filename, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + except OSError, e: + if e.errno == 13: + LOG.error('failed to spawn collector %s: permission denied' % + col.filename) + return + elif e.errno == 2: + LOG.error('failed to spawn collector %s: no such file or directory' % + col.filename) + else: + raise + # the following line needs to move below this line because it is used in + # other logic and it makes no sense to update the last spawn time if the + # collector didn't actually spam + col.lastspawn = int(time.time()) set_nonblocking(col.proc.stdout.fileno()) set_nonblocking(col.proc.stderr.fileno()) if col.proc.pid > 0: