• L
    Add virFork() function to utils · b4584612
    Laine Stump 提交于
    virFork() contains bookkeeping that must be done any time a process
    forks. Currently this includes:
    
    1) Call virLogLock() prior to fork() and virLogUnlock() just after,
       to avoid a deadlock if some other thread happens to hold that lock
       during the fork.
    
    2) Reset the logging hooks and send all child process log messages to
       stderr.
    
    3) Block all signals prior to fork(), then either a) reset the signal
       mask for the parent process, or b) clear the signal mask for the
       child process.
    
    Note that the signal mask handling in __virExec erroneously fails to
    restore the signal mask when fork() fails. virFork() fixes this
    problem.
    
    Other than this, it attempts to behave as closely to fork() as
    possible (including preserving errno for the caller), with a couple
    exceptions:
    
    1) The return value is 0 (success) or -1 (failure), while the pid is
       returned via the pid_t* argument. Like fork(), if pid < 0 there is
       no child process, otherwise both the child and the parent will
       return to the caller, and both should look at the return value,
       which will indicate if some of the extra processing outlined above
       encountered an error.
    
    2) If virFork() returns with pid < 0 or with a return value < 0
       indicating an error condition, the error has already been
       reported. You can log an additional message if you like, but it
       isn't necessary, and may be awkwardly extraneous.
    
    Note that virFork()'s child process will *never* call _exit() - if a
    child process is created, it will return to the caller.
    
    * util.c util.h: add virFork() function, based on what is currently
                     done in __virExec().
    b4584612
util.h 9.1 KB