Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: gui/middleware/notifier.py
- ===================================================================
- --- gui/middleware/notifier.py (revision 10844)
- +++ gui/middleware/notifier.py (working copy)
- @@ -122,7 +122,6 @@
- from pwd import getpwnam as ___getpwnam
- IDENTIFIER = 'notifier'
- def __system(self, command):
- - log.debug("Executing: %s", command)
- # TODO: python's signal class should be taught about sigprocmask(2)
- # This is hacky hack to work around this issue.
- libc = ctypes.cdll.LoadLibrary("libc.so.7")
- @@ -132,14 +131,13 @@
- pomask = ctypes.pointer(omask)
- libc.sigprocmask(signal.SIGQUIT, pmask, pomask)
- try:
- - self.___system("(" + command + ") 2>&1 | logger -p daemon.notice -t %s"
- - % (self.IDENTIFIER, ))
- + p = self.__pipeopen('(%s 2>&1 | logger -p daemon.notice -t %s)'
- + % (command, self.IDENTIFIER, ))
- + p.wait()
- finally:
- libc.sigprocmask(signal.SIGQUIT, pomask, None)
- - log.debug("Executed: %s", command)
- def __system_nolog(self, command):
- - log.debug("Executing: %s", command)
- # TODO: python's signal class should be taught about sigprocmask(2)
- # This is hacky hack to work around this issue.
- libc = ctypes.cdll.LoadLibrary("libc.so.7")
- @@ -148,16 +146,35 @@
- pmask = ctypes.pointer(mask)
- pomask = ctypes.pointer(omask)
- libc.sigprocmask(signal.SIGQUIT, pmask, pomask)
- + err = ''
- try:
- - retval = self.___system("(" + command + ") >/dev/null 2>&1")
- + p = self.__pipeopen(command)
- + __, err = p.communicate()
- + retval = p.returncode
- finally:
- libc.sigprocmask(signal.SIGQUIT, pomask, None)
- - log.debug("Executed: %s; returned %d", command, retval >> 8)
- + log.debug("Executed: %s; returned %d", command, retval)
- + if retval and err:
- + log.debug('Error output:\n%s', err)
- return retval
- def __pipeopen(self, command):
- + """Create a subprocess.Popen object based on ``command``
- +
- + Notes:
- + - File descriptors are closed prior to execution.
- + - A full shell environment is instantiated.
- + - The command is sanitized properly (run through shlex.split(..)).
- +
- + Arguments:
- + command - a string to execute via subprocess
- + """
- log.debug("Popen()ing: %s", command)
- - return Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)
- + return subprocess.Popen(shlex.split(command),
- + stdout=subprocess.PIPE,
- + stderr=subprocess.PIPE,
- + shell=True,
- + close_fds=True)
- def _do_nada(self):
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement