Skip to content

Commit

Permalink
handle non-working pwd and grp gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
jhjaggars authored and n1hility committed May 25, 2012
1 parent d7a2fd0 commit e27da18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 2 additions & 3 deletions jdr/jboss-as-sos/src/main/resources/sos/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,12 @@ def addCopySpec(self, copyspec, sub=None):
if filespec not in self.copyPaths:
self.copyPaths.append((filespec, sub))

def callExtProg(self, prog):
def callExtProg(self, prog, timeout=300):
"""Execute a command independantly of the output gathering part of
sosreport.
"""
# pylint: disable-msg = W0612
status, shout, runtime = sosGetCommandOutput(prog)
return (status, shout, runtime)
return sosGetCommandOutput(prog, timeout)

def checkExtprog(self, prog):
"""Execute a command independently of the output gathering part of
Expand Down
13 changes: 8 additions & 5 deletions jdr/jboss-as-sos/src/main/resources/sos/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ def sosGetCommandOutput(command, timeout=300):
cmdfile = command.strip("(").split()[0]

if is_executable(cmdfile):

# use /usr/bin/timeout to implement a timeout
if timeout and is_executable("/usr/bin/timeout"):
command = "/usr/bin/timeout %ds %s" % (timeout, command)

p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, bufsize=-1)
stdout, stderr = p.communicate()
return (p.returncode, stdout.strip(), 0)
Expand All @@ -173,9 +178,7 @@ def import_module(module_fqname, superclasses=None):
def shell_out(cmd):
"""Uses subprocess.Popen to make a system call and returns stdout.
Does not handle exceptions."""
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
return p.communicate()[0]

return sosGetCommandOutput(cmd)[1]

class Archive(object):

Expand Down Expand Up @@ -378,14 +381,14 @@ def _get_user(self, stats):
try:
import pwd
return pwd.getpwuid(stats.st_uid)[0]
except ImportError:
except:
return str(stats.st_uid)

def _get_group(self, stats):
try:
import grp
return grp.getgrgid(stats.st_gid)[0]
except ImportError:
except:
return str(stats.st_uid)

def _format(self, path):
Expand Down

0 comments on commit e27da18

Please sign in to comment.