Advertisement
yaneurabeya

Untitled

Mar 26th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. Index: gui/middleware/notifier.py
  2. ===================================================================
  3. --- gui/middleware/notifier.py (revision 10844)
  4. +++ gui/middleware/notifier.py (working copy)
  5. @@ -122,7 +122,6 @@
  6. from pwd import getpwnam as ___getpwnam
  7. IDENTIFIER = 'notifier'
  8. def __system(self, command):
  9. - log.debug("Executing: %s", command)
  10. # TODO: python's signal class should be taught about sigprocmask(2)
  11. # This is hacky hack to work around this issue.
  12. libc = ctypes.cdll.LoadLibrary("libc.so.7")
  13. @@ -132,14 +131,13 @@
  14. pomask = ctypes.pointer(omask)
  15. libc.sigprocmask(signal.SIGQUIT, pmask, pomask)
  16. try:
  17. - self.___system("(" + command + ") 2>&1 | logger -p daemon.notice -t %s"
  18. - % (self.IDENTIFIER, ))
  19. + p = self.__pipeopen('(%s 2>&1 | logger -p daemon.notice -t %s)'
  20. + % (command, self.IDENTIFIER, ))
  21. + p.wait()
  22. finally:
  23. libc.sigprocmask(signal.SIGQUIT, pomask, None)
  24. - log.debug("Executed: %s", command)
  25.  
  26. def __system_nolog(self, command):
  27. - log.debug("Executing: %s", command)
  28. # TODO: python's signal class should be taught about sigprocmask(2)
  29. # This is hacky hack to work around this issue.
  30. libc = ctypes.cdll.LoadLibrary("libc.so.7")
  31. @@ -148,16 +146,35 @@
  32. pmask = ctypes.pointer(mask)
  33. pomask = ctypes.pointer(omask)
  34. libc.sigprocmask(signal.SIGQUIT, pmask, pomask)
  35. + err = ''
  36. try:
  37. - retval = self.___system("(" + command + ") >/dev/null 2>&1")
  38. + p = self.__pipeopen(command)
  39. + __, err = p.communicate()
  40. + retval = p.returncode
  41. finally:
  42. libc.sigprocmask(signal.SIGQUIT, pomask, None)
  43. - log.debug("Executed: %s; returned %d", command, retval >> 8)
  44. + log.debug("Executed: %s; returned %d", command, retval)
  45. + if retval and err:
  46. + log.debug('Error output:\n%s', err)
  47. return retval
  48.  
  49. def __pipeopen(self, command):
  50. + """Create a subprocess.Popen object based on ``command``
  51. +
  52. + Notes:
  53. + - File descriptors are closed prior to execution.
  54. + - A full shell environment is instantiated.
  55. + - The command is sanitized properly (run through shlex.split(..)).
  56. +
  57. + Arguments:
  58. + command - a string to execute via subprocess
  59. + """
  60. log.debug("Popen()ing: %s", command)
  61. - return Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)
  62. + return subprocess.Popen(shlex.split(command),
  63. + stdout=subprocess.PIPE,
  64. + stderr=subprocess.PIPE,
  65. + shell=True,
  66. + close_fds=True)
  67.  
  68. def _do_nada(self):
  69. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement