lib/daemon-windows.c
/* If one of the command line option is "--detach", creates
 * a new process in case of parent, waits for child to start and exits.
 * In case of the child, returns. */
If one of the command line option is "--detach", creates
a new process in case of parent, waits for child to start and exits.
In case of the child, returns.
If one of the command line option is " -- detach " creates a new process in case of parent waits for child to start and exits . In case of the child returns .
static bool
detach_process(int argc, char *argv[])
{
    SECURITY_ATTRIBUTES sa;
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    HANDLE read_pipe, write_pipe;
    char *buffer;
    int error, i;
    char ch;
    for (i = 0; i < argc; i ++) {
        if (!detach && !strcmp(argv[i], "--detach")) {
            detach = true;
        } else if (!strncmp(argv[i], "--pipe-handle", 13)) {
            detached = true;
            return true;
        }
    }
    if (!detach) {
        return false;
    }
    sa.nLength = sizeof(sa);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE;
    error = CreatePipe(&read_pipe, &write_pipe, &sa, 0);
    if (!error) {
        VLOG_FATAL("CreatePipe failed (%s)", ovs_lasterror_to_string());
    }
    GetStartupInfo(&si);
    buffer = xasprintf("%s %s=%ld", GetCommandLine(), "--pipe-handle",
                       write_pipe);
    error = CreateProcess(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS,
                          NULL, NULL, &si, &pi);
    if (!error) {
        VLOG_FATAL("CreateProcess failed (%s)", ovs_lasterror_to_string());
    }
    CloseHandle(write_pipe);
    error = ReadFile(read_pipe, &ch, 1, NULL, NULL);
    if (!error) {
        VLOG_FATAL("Failed to read from child (%s)",
                   ovs_lasterror_to_string());
    }
    exit(0);
}
static bool detach_process ( int argc , char * argv [ ] ) { SECURITY_ATTRIBUTES sa ; STARTUPINFO si ; PROCESS_INFORMATION pi ; HANDLE read_pipe , write_pipe ; char * buffer ; int error , i ; char ch ; for ( i = 0 ; i < argc ; i ++ ) { if ( ! detach && ! strcmp ( argv [ i ] , " " ) ) { detach = true ; } else if ( ! strncmp ( argv [ i ] , " " , 13 ) ) { detached = true ; return true ; } } if ( ! detach ) { return false ; } sa . nLength = sizeof ( sa ) ; sa . lpSecurityDescriptor = NULL ; sa . bInheritHandle = TRUE ; error = CreatePipe ( & read_pipe , & write_pipe , & sa , 0 ) ; if ( ! error ) { VLOG_FATAL ( " " , ovs_lasterror_to_string ( ) ) ; } GetStartupInfo ( & si ) ; buffer = xasprintf ( " " , GetCommandLine ( ) , " " , write_pipe ) ; error = CreateProcess ( NULL , buffer , NULL , NULL , TRUE , DETACHED_PROCESS , NULL , NULL , & si , & pi ) ; if ( ! error ) { VLOG_FATAL ( " " , ovs_lasterror_to_string ( ) ) ; } CloseHandle ( write_pipe ) ; error = ReadFile ( read_pipe , & ch , 1 , NULL , NULL ) ; if ( ! error ) { VLOG_FATAL ( " " , ovs_lasterror_to_string ( ) ) ; } exit ( 0 ) ; }
If one of the command line option is "--detach", creates
 a new process in case of parent, waits for child to start and exits.
If one of the command line option is " -- detach " creates a new process in case of parent waits for child to start and exits .
/* We are only interested in the '--detach' and '--pipe-handle'. */ /* If running as a child, return. */ /* Nothing to do if the option --detach is not set. */ /* Set the security attribute such that a process created will
     * inherit the pipe handles. */ /* Create an anonymous pipe to communicate with the child. */ /* To the child, we pass an extra argument '--pipe-handle=write_pipe' */ /* Create a detached child */ /* Close one end of the pipe in the parent. */ /* Block and wait for child to say it is ready. */ /* The child has successfully started and is ready. */