extern void afsi_log(char *pattern, ...);
+HANDLE hAFSDMainThread = NULL;
+
HANDLE WaitToTerminate;
int GlobalStatus;
ServiceStatus.dwWin32ExitCode = NO_ERROR;
ServiceStatus.dwCheckPoint = 1;
ServiceStatus.dwWaitHint = 10000;
- ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT;
+ ServiceStatus.dwControlsAccepted = 0;
SetServiceStatus(StatusHandle, &ServiceStatus);
SetEvent(WaitToTerminate);
dwRet = NO_ERROR;
{
long code;
char *reason;
+#ifdef JUMP
int jmpret;
+#endif /* JUMP */
HANDLE hInitHookDll;
AfsdInitHook initHook;
GlobalStatus = 0;
+ afsi_start();
+
WaitToTerminate = CreateEvent(NULL, TRUE, FALSE, TEXT("afsd_service_WaitToTerminate"));
if ( GetLastError() == ERROR_ALREADY_EXISTS )
afsi_log("Event Object Already Exists: %s", TEXT("afsd_service_WaitToTerminate"));
PowerNotificationThreadCreate();
#endif
- afsi_start();
-
/* allow an exit to be called prior to any initialization */
hInitHookDll = LoadLibrary(AFSD_HOOK_DLL);
if (hInitHookDll)
#endif /* JUMP */
{
code = afsd_InitCM(&reason);
- if (code != 0)
+ if (code != 0) {
+ afsi_log("afsd_InitCM failed: %s (code = %d)", reason, code);
osi_panic(reason, __FILE__, __LINE__);
+ }
#ifndef NOTSERVICE
ServiceStatus.dwCheckPoint++;
SetServiceStatus(StatusHandle, &ServiceStatus);
#endif
code = afsd_InitDaemons(&reason);
- if (code != 0)
+ if (code != 0) {
+ afsi_log("afsd_InitDaemons failed: %s (code = %d)", reason, code);
osi_panic(reason, __FILE__, __LINE__);
+ }
#ifndef NOTSERVICE
ServiceStatus.dwCheckPoint++;
SetServiceStatus(StatusHandle, &ServiceStatus);
#endif
code = afsd_InitSMB(&reason, DummyMessageBox);
- if (code != 0)
+ if (code != 0) {
+ afsi_log("afsd_InitSMB failed: %s (code = %d)", reason, code);
osi_panic(reason, __FILE__, __LINE__);
+ }
#ifndef NOTSERVICE
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
WaitForSingleObject(WaitToTerminate, INFINITE);
- ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
- ServiceStatus.dwWin32ExitCode = NO_ERROR;
- ServiceStatus.dwCheckPoint = 0;
- ServiceStatus.dwWaitHint = 5000;
- ServiceStatus.dwControlsAccepted = 0;
- SetServiceStatus(StatusHandle, &ServiceStatus);
-
{
HANDLE h; char *ptbuf[1];
h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
/* Remove the ExceptionFilter */
SetUnhandledExceptionFilter(NULL);
- ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ if ( hInitHookDll )
+ FreeLibrary(hInitHookDll);
+
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = GlobalStatus ? ERROR_EXCEPTION_IN_SERVICE : NO_ERROR;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
if (status == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
{
DWORD tid;
- CreateThread(NULL, 0, afsdMain_thread, 0, 0, &tid);
+ hAFSDMainThread = CreateThread(NULL, 0, afsdMain_thread, 0, 0, &tid);
printf("Hit <Enter> to terminate OpenAFS Client Service\n");
getchar();
SetEvent(WaitToTerminate);
}
}
+
+ if ( hAFSDMainThread ) {
+ WaitForSingleObject( hAFSDMainThread, INFINITE );
+ CloseHandle( hAFSDMainThread );
+ }
return(0);
}