lib/daemon-windows.c
/* Registers the call-back and configures the actions in case of a failure
 * with the Windows services manager. */
Registers the call-back and configures the actions in case of a failure
with the Windows services manager.
Registers the call - back and configures the actions in case of a failure with the Windows services manager .
void
service_start(int *argcp, char **argvp[])
{
    int argc = *argcp;
    char **argv = *argvp;
    int i;
    SERVICE_TABLE_ENTRY service_table[] = {
        {(LPTSTR)program_name, (LPSERVICE_MAIN_FUNCTION)main},
        {NULL, NULL}
    };
    if (detach_process(argc, argv)) {
        return;
    }
    if (service_started) {
        init_service_status();
        wevent = CreateEvent(NULL, TRUE, FALSE, NULL);
        if (!wevent) {
            char *msg_buf = ovs_lasterror_to_string();
            VLOG_FATAL("Failed to create a event (%s).", msg_buf);
        }
        poll_wevent_wait(wevent);
        hstatus = RegisterServiceCtrlHandler(program_name,
                                         (LPHANDLER_FUNCTION)control_handler);
        if (!hstatus) {
            char *msg_buf = ovs_lasterror_to_string();
            VLOG_FATAL("Failed to register the service control handler (%s).",
                        msg_buf);
        }
        if (monitor) {
            set_config_failure_actions();
        }
        *argcp = sargc;
        *argvp = *sargvp;
        SetErrorMode(0);
        return;
    }
    assert_single_threaded();
    sargc = argc;
    sargvp = argvp;
    for (i = 0; i < argc; i ++) {
        if (!strcmp(argv[i], "--service")) {
            service_create = true;
        } else if (!strcmp(argv[i], "--service-monitor")) {
            monitor = true;
        }
    }
    if (!service_create) {
        return;
    }
    check_service();
    service_started = true;
    if (!StartServiceCtrlDispatcher(service_table)) {
        char *msg_buf = ovs_lasterror_to_string();
        VLOG_FATAL("Failed at StartServiceCtrlDispatcher (%s)", msg_buf);
    }
    exit(0);
}
void service_start ( int * argcp , char * * argvp [ ] ) { int argc = * argcp ; char * * argv = * argvp ; int i ; SERVICE_TABLE_ENTRY service_table [ ] = { { ( LPTSTR ) program_name , ( LPSERVICE_MAIN_FUNCTION ) main } , { NULL , NULL } } ; if ( detach_process ( argc , argv ) ) { return ; } if ( service_started ) { init_service_status ( ) ; wevent = CreateEvent ( NULL , TRUE , FALSE , NULL ) ; if ( ! wevent ) { char * msg_buf = ovs_lasterror_to_string ( ) ; VLOG_FATAL ( " " , msg_buf ) ; } poll_wevent_wait ( wevent ) ; hstatus = RegisterServiceCtrlHandler ( program_name , ( LPHANDLER_FUNCTION ) control_handler ) ; if ( ! hstatus ) { char * msg_buf = ovs_lasterror_to_string ( ) ; VLOG_FATAL ( " " , msg_buf ) ; } if ( monitor ) { set_config_failure_actions ( ) ; } * argcp = sargc ; * argvp = * sargvp ; SetErrorMode ( 0 ) ; return ; } assert_single_threaded ( ) ; sargc = argc ; sargvp = argvp ; for ( i = 0 ; i < argc ; i ++ ) { if ( ! strcmp ( argv [ i ] , " " ) ) { service_create = true ; } else if ( ! strcmp ( argv [ i ] , " " ) ) { monitor = true ; } } if ( ! service_create ) { return ; } check_service ( ) ; service_started = true ; if ( ! StartServiceCtrlDispatcher ( service_table ) ) { char * msg_buf = ovs_lasterror_to_string ( ) ; VLOG_FATAL ( " " , msg_buf ) ; } exit ( 0 ) ; }
Registers the call-back and configures the actions in case of a failure
 with the Windows services manager.
Registers the call - back and configures the actions in case of a failure with the Windows services manager .
/* If one of the command line option is "--detach", we create
     * a new process in case of parent, wait for child to start and exit.
     * In case of the child, we just return. We should not be creating a
     * service in either case. */ /* 'service_started' is 'false' when service_start() is called the first
     * time.  It is 'true', when it is called the second time by the Windows
     * services manager. */ /* Register the control handler. This function is called by the service
         * manager to stop the service. */ /* When the service control manager does the call back, it does not
         * send the same arguments as sent to the main function during the
         * service start. So, use the arguments passed over during the first
         * time. */ /* Enable default error mode so we can take advantage of WER
         * (Windows Error Reporting) crash dumps.
         * Being a service it does not allow for WER window pop-up.
         * XXX implement our on crash dump collection mechanism. */ /* A reference to arguments passed to the main function the first time.
     * We need it after the call-back from service control manager. */ /* We are only interested in the '--service' and '--service-monitor'
     * options before the call-back from the service control manager. */ /* If '--service' is not a command line option, run in foreground. */ /* If we have been configured to run as a service, then that service
     * should already have been created either manually or through a start up
     * script. */ /* StartServiceCtrlDispatcher blocks and returns after the service is
     * stopped. */