diff --git a/daemon/core/misc/utils.py b/daemon/core/misc/utils.py index 634a0425..52b18c45 100644 --- a/daemon/core/misc/utils.py +++ b/daemon/core/misc/utils.py @@ -15,11 +15,28 @@ import subprocess, os, ast def checkexec(execlist): for bin in execlist: - # note that os.access() uses real uid/gid; that should be okay - # here - if not os.access(bin, os.X_OK): + if which(bin) is None: raise EnvironmentError, "executable not found: %s" % bin +def which(program): + ''' From: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python + ''' + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + return None + def ensurepath(pathlist): searchpath = os.environ["PATH"].split(":") for p in set(pathlist):