/*-------------------------------------------------------------------- * ServiceStart * * each time starting the service, this is the entry point of the service. * Start the service, certainly it is on server-mode * *-------------------------------------------------------------------- */ VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) { // report the status to the service control manager. // if ( !ReportStatusToSCMgr( SERVICE_START_PENDING, // service state NO_ERROR, // exit code 3000) ) // wait hint goto clean; thread_Settings* ext_gSettings = new thread_Settings; // Initialize settings to defaults Settings_Initialize( ext_gSettings ); // read settings from environment variables Settings_ParseEnvironment( ext_gSettings ); // read settings from command-line parameters Settings_ParseCommandLine( dwArgc, lpszArgv, ext_gSettings ); // report the status to the service control manager. // if ( !ReportStatusToSCMgr( SERVICE_START_PENDING, // service state NO_ERROR, // exit code 3000) ) // wait hint goto clean; // if needed, redirect the output into a specified file if ( !isSTDOUT( ext_gSettings ) ) { redirect( ext_gSettings->mOutputFileName ); } // report the status to the service control manager. // if ( !ReportStatusToSCMgr( SERVICE_START_PENDING, // service state NO_ERROR, // exit code 3000) ) // wait hint goto clean; // initialize client(s) if ( ext_gSettings->mThreadMode == kMode_Client ) { client_init( ext_gSettings ); } // start up the reporter and client(s) or listener { thread_Settings *into = NULL; #ifdef HAVE_THREAD Settings_Copy( ext_gSettings, &into ); into->mThreadMode = kMode_Reporter; into->runNow = ext_gSettings; #else into = ext_gSettings; #endif thread_start( into ); } // report the status to the service control manager. // if ( !ReportStatusToSCMgr( SERVICE_RUNNING, // service state NO_ERROR, // exit code 0) ) // wait hint goto clean; clean: // wait for other (client, server) threads to complete thread_joinall(); }
VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) { // report the status to the service control manager. // if ( !ReportStatusToSCMgr( SERVICE_START_PENDING, // service state NO_ERROR, // exit code 3000) ) // wait hint goto clean; thread_Settings* ext_gSettings = (thread_Settings*) malloc(sizeof(thread_Settings)); FAIL_errno( ext_gSettings == NULL, ( "No memory for thread_Settings ext_gSettings.\n" ), NULL ); IPERF_DEBUGF( MEMALLOC_DEBUG | IPERF_DBG_TRACE, IPERF_MEMALLOC_MSG( ext_gSettings, sizeof(thread_Settings) ) ); // Initialize settings to defaults Settings_Initialize( ext_gSettings ); #ifndef NO_ENVIRONMENT // read settings from environment variables Settings_ParseEnvironment( ext_gSettings ); #endif /* NO_ENVIRONMENT */ // read settings from command-line parameters Settings_ParseCommandLine( dwArgc, lpszArgv, ext_gSettings ); // report the status to the service control manager. // if ( !ReportStatusToSCMgr( SERVICE_START_PENDING, // service state NO_ERROR, // exit code 3000) ) // wait hint goto clean; // if needed, redirect the output into a specified file if ( !isSTDOUT( ext_gSettings ) ) { redirect( ext_gSettings->mOutputFileName ); } // report the status to the service control manager. // if ( !ReportStatusToSCMgr( SERVICE_START_PENDING, // service state NO_ERROR, // exit code 3000) ) // wait hint goto clean; // initialize client(s) if ( ext_gSettings->mThreadMode == kMode_Client ) { client_init( ext_gSettings ); } // start up the reporter and client(s) or listener { thread_Settings *into = NULL; #ifdef HAVE_THREAD Settings_Copy( ext_gSettings, &into ); into->mThreadMode = kMode_Reporter; into->runNow = ext_gSettings; #else into = ext_gSettings; #endif /* HAVE_THREAD */ thread_start( into ); } // report the status to the service control manager. // if ( !ReportStatusToSCMgr( SERVICE_RUNNING, // service state NO_ERROR, // exit code 0) ) // wait hint goto clean; clean: // wait for other (client, server) threads to complete thread_joinall(); } // end ServiceStart