Revision 39736270
Added by Hamish Coleman about 14 years ago
- ID 39736270c860147751b68999fd4645ae1717815d
win-scm.c | ||
---|---|---|
if (opcode == SERVICE_CONTROL_STOP) {
|
||
svcStatus.dwCurrentState = SERVICE_STOP_PENDING;
|
||
SetServiceStatus( svcHandle, &svcStatus );
|
||
global_sd->stop(0);
|
||
global_sd->stop(NULL);
|
||
return;
|
||
}
|
||
SetServiceStatus( svcHandle, &svcStatus );
|
||
... | ... | |
svcHandle = RegisterServiceCtrlHandler(sd->name,ServiceCtrlHandler);
|
||
if (!svcHandle) {
|
||
/* FIXME - use SvcReportEvent() */
|
||
printf("RegisterServiceCtrlHandler failed %d\n", GetLastError());
|
||
printf("RegisterServiceCtrlHandler failed %u\n",
|
||
(unsigned int)GetLastError());
|
||
return;
|
||
}
|
||
|
||
... | ... | |
}
|
||
|
||
sd->mode=SVC_OK;
|
||
if ((err=sd->init(argc,argv))!=0) {
|
||
svcStatus.dwCurrentState = SERVICE_STOPPED;
|
||
svcStatus.dwWin32ExitCode = err;
|
||
SetServiceStatus( svcHandle, &svcStatus );
|
||
return;
|
||
if (sd->init) {
|
||
if ((err=sd->init(argc,argv))!=0) {
|
||
svcStatus.dwCurrentState = SERVICE_STOPPED;
|
||
svcStatus.dwWin32ExitCode = err;
|
||
SetServiceStatus( svcHandle, &svcStatus );
|
||
return;
|
||
}
|
||
}
|
||
|
||
svcStatus.dwCurrentState = SERVICE_RUNNING;
|
||
svcStatus.dwWin32ExitCode = NO_ERROR;
|
||
SetServiceStatus( svcHandle, &svcStatus );
|
||
|
||
err=sd->main(0);
|
||
err=sd->main(argc,argv);
|
||
|
||
svcStatus.dwCurrentState = SERVICE_STOPPED;
|
||
svcStatus.dwWin32ExitCode = NO_ERROR;
|
||
... | ... | |
int SCM_Start_Console(struct SCM_def *sd) {
|
||
|
||
sd->mode=SVC_CONSOLE;
|
||
int err = sd->init(sd->argc,sd->argv);
|
||
if (err!=0) {
|
||
return SVC_FAIL;
|
||
int err;
|
||
if (sd->init) {
|
||
err = sd->init(sd->argc,sd->argv);
|
||
if (err!=0) {
|
||
return SVC_FAIL;
|
||
}
|
||
}
|
||
|
||
sd->main(0);
|
||
sd->main(sd->argc,sd->argv);
|
||
return SVC_OK;
|
||
}
|
||
|
||
... | ... | |
*/
|
||
char buf[100];
|
||
if (getenv("USERNAME") && getenv("SESSIONNAME")
|
||
&& GetConsoleTitle(&buf,sizeof(buf))) {
|
||
&& GetConsoleTitle((LPTSTR)&buf,sizeof(buf))) {
|
||
return SCM_Start_Console(sd);
|
||
}
|
||
|
||
... | ... | |
static char path[MAX_PATH];
|
||
|
||
if( !GetModuleFileName( NULL, path, MAX_PATH ) ) {
|
||
printf("GetModuleFileName failed %d\n", GetLastError());
|
||
printf("GetModuleFileName failed %u\n",
|
||
(unsigned int)GetLastError());
|
||
return NULL;
|
||
}
|
||
|
Also available in: Unified diff
Pass the args to the main function and thus allow the init function to be optional.