Revision 09b72783 lib/utils/process.py

b/lib/utils/process.py
142 142

  
143 143
def RunCmd(cmd, env=None, output=None, cwd="/", reset_env=False,
144 144
           interactive=False, timeout=None, noclose_fds=None,
145
           input_fd=None, _postfork_fn=None):
145
           input_fd=None, postfork_fn=None):
146 146
  """Execute a (shell) command.
147 147

  
148 148
  The command should not read from its standard input, as it will be
......
172 172
                      open for the child process
173 173
  @type input_fd: C{file}-like object or numeric file descriptor
174 174
  @param input_fd: File descriptor for process' standard input
175
  @param _postfork_fn: Callback run after fork but before timeout (unittest)
175
  @type postfork_fn: Callable receiving PID as parameter
176
  @param postfork_fn: Callback run after fork but before timeout
176 177
  @rtype: L{RunResult}
177 178
  @return: RunResult instance
178 179
  @raise errors.ProgrammerError: if we call this when forks are disabled
......
211 212
      out, err, status, timeout_action = _RunCmdPipe(cmd, cmd_env, shell, cwd,
212 213
                                                     interactive, timeout,
213 214
                                                     noclose_fds, input_fd,
214
                                                     _postfork_fn=_postfork_fn)
215
                                                     postfork_fn=postfork_fn)
215 216
    else:
216
      assert _postfork_fn is None, \
217
          "_postfork_fn not supported if output provided"
217
      if postfork_fn:
218
        raise errors.ProgrammerError("postfork_fn is not supported if output"
219
                                     " should be captured")
218 220
      assert input_fd is None
219 221
      timeout_action = _TIMEOUT_NONE
220 222
      status = _RunCmdFile(cmd, cmd_env, shell, output, cwd, noclose_fds)
......
490 492

  
491 493

  
492 494
def _RunCmdPipe(cmd, env, via_shell, cwd, interactive, timeout, noclose_fds,
493
                input_fd,
494
                _linger_timeout=constants.CHILD_LINGER_TIMEOUT,
495
                _postfork_fn=None):
495
                input_fd, postfork_fn=None,
496
                _linger_timeout=constants.CHILD_LINGER_TIMEOUT):
496 497
  """Run a command and return its output.
497 498

  
498 499
  @type  cmd: string or list
......
512 513
                      open for the child process
513 514
  @type input_fd: C{file}-like object or numeric file descriptor
514 515
  @param input_fd: File descriptor for process' standard input
515
  @param _postfork_fn: Function run after fork but before timeout (unittest)
516
  @type postfork_fn: Callable receiving PID as parameter
517
  @param postfork_fn: Function run after fork but before timeout
516 518
  @rtype: tuple
517 519
  @return: (out, err, status)
518 520

  
......
548 550
                           cwd=cwd,
549 551
                           preexec_fn=preexec_fn)
550 552

  
551
  if _postfork_fn:
552
    _postfork_fn(child.pid)
553
  if postfork_fn:
554
    postfork_fn(child.pid)
553 555

  
554 556
  out = StringIO()
555 557
  err = StringIO()

Also available in: Unified diff