"""Detects whether or not an argument list invokes a Python program."""
return args[0] == "python" or args[0] == "wizard"
-def drop_priviledges(dir, options):
+def drop_priviledges(dir, log_file):
"""
Checks if we are running as root. If we are, attempt to drop
priviledges to the user who owns ``dir``, by re-calling
itself using sudo with exec, such that the new process subsumes our
- current one.
+ current one. If ``log_file`` is passed, the file is chown'ed
+ to the user we are dropping priviledges to, so the subprocess
+ can write to it.
"""
if os.getuid():
return
args.append("%s=%s" % (k,v))
args += sys.argv
logging.debug("Dropping priviledges")
- if options.log_file: os.chown(options.log_file, uid, -1)
+ if log_file: os.chown(log_file, uid, -1)
os.execlp('sudo', 'sudo', '-u', '#' + str(uid), *args)
class Shell(object):
specify this if you are using another wrapper around this function).
:param log: if True, we log the call as INFO, if False, we log the call
as DEBUG, otherwise, we detect based on ``strip``.
+ :param stdout:
+ :param stderr:
+ :param stdin: a file-type object that will be written to or read from as a pipe.
:returns: a tuple of strings ``(stdout, stderr)``, or a string ``stdout``
if ``strip`` is specified.
kwargs.setdefault("strip", False)
kwargs.setdefault("python", None)
kwargs.setdefault("log", None)
+ kwargs.setdefault("stdout", subprocess.PIPE)
+ kwargs.setdefault("stdin", subprocess.PIPE)
+ kwargs.setdefault("stderr", subprocess.PIPE)
msg = "Running `" + ' '.join(args) + "`"
if kwargs["strip"] and not kwargs["log"] is True or kwargs["log"] is False:
logging.debug(msg)
stdin=sys.stdin
stderr=sys.stderr
else:
- stdout=subprocess.PIPE
- stdin=subprocess.PIPE
- stderr=subprocess.PIPE
+ stdout=kwargs["stdout"]
+ stdin=kwargs["stdin"]
+ stderr=kwargs["stderr"]
# XXX: There is a possible problem here where we can fill up
# the kernel buffer if we have 64KB of data. This shouldn't
# be a problem, and the fix for such case would be to write to