Revision 368d31d4
Added by Hamish Coleman about 14 years ago
- ID 368d31d4816d2b3a346918bb426efce8ba716283
win-scm.c | ||
---|---|---|
SetServiceStatus( svcHandle, &svcStatus );
|
||
|
||
sd->mode=SVC_OK;
|
||
/* TODO - use either saved cmdline args or scm args here */
|
||
if ((err=sd->init(argc,argv))!=0) {
|
||
svcStatus.dwCurrentState = SERVICE_STOPPED;
|
||
svcStatus.dwWin32ExitCode = err;
|
||
... | ... | |
return;
|
||
}
|
||
|
||
int SCM_Start_Console(int argc, char **argv) {
|
||
int SCM_Start_Console(struct SCM_def *sd) {
|
||
|
||
global_sd->mode=SVC_CONSOLE;
|
||
int err = global_sd->init(argc,argv);
|
||
sd->mode=SVC_CONSOLE;
|
||
int err = sd->init(sd->argc,sd->argv);
|
||
if (err!=0) {
|
||
return SVC_FAIL;
|
||
}
|
||
|
||
global_sd->main(0);
|
||
sd->main(0);
|
||
return SVC_OK;
|
||
}
|
||
|
||
... | ... | |
{ NULL, NULL }
|
||
};
|
||
|
||
/* save the cmdline for possible use later */
|
||
sd->argc=argc;
|
||
sd->argv=argv;
|
||
|
||
global_sd = sd;
|
||
|
||
#if 0
|
||
/* turns out to be untrue! */
|
||
/* If we have commandline args, then we cannot have been started
|
||
* by the Windows SCM
|
||
*/
|
||
if (argc>1) {
|
||
return SCM_Start_Console(argc,argv);
|
||
return SCM_Start_Console(sd);
|
||
}
|
||
#endif
|
||
|
||
/* try to run as a service */
|
||
if (StartServiceCtrlDispatcher(ServiceTable)==0) {
|
||
int err = GetLastError();
|
||
|
||
if (err == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
|
||
return SCM_Start_Console(argc,argv);
|
||
return SCM_Start_Console(sd);
|
||
}
|
||
|
||
/* any other error, assume fatal */
|
||
... | ... | |
return SVC_OK;
|
||
}
|
||
|
||
char *SCM_Install(struct SCM_def *sd) {
|
||
char *SCM_Install(struct SCM_def *sd, char *args) {
|
||
SC_HANDLE schSCManager, schService;
|
||
|
||
static char path[MAX_PATH];
|
||
... | ... | |
return NULL;
|
||
}
|
||
|
||
/*
|
||
* Note - the above path calculation does not work for paths containing
|
||
* spaces. This is because Windows is stupid, mosttly due to bad
|
||
* design - see the next below.
|
||
*/
|
||
|
||
static char cmdline[MAX_PATH+10];
|
||
if (args) {
|
||
/*
|
||
* The "BinaryPathName" can also have cmdline params
|
||
* embedded into it. Stupid windows
|
||
*/
|
||
|
||
snprintf(cmdline,sizeof(cmdline),"\"%s\" %s",path,args);
|
||
} else {
|
||
snprintf(cmdline,sizeof(cmdline),"\"%s\"",path);
|
||
}
|
||
|
||
schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||
|
||
schService = CreateService(
|
||
... | ... | |
SERVICE_WIN32_OWN_PROCESS,
|
||
SERVICE_AUTO_START,
|
||
SERVICE_ERROR_NORMAL,
|
||
path,
|
||
cmdline,
|
||
NULL, NULL, NULL, NULL, NULL);
|
||
|
||
if (schService == NULL) {
|
Also available in: Unified diff
Update win-scm with new learnings, also add a service test helper program