// The following is defined if you want to receive Power notifications,
// including Hibernation, and also subsequent flushing of AFS volumes
//
-// #define REGISTER_POWER_NOTIFICATIONS
+#define REGISTER_POWER_NOTIFICATIONS
//
// Check
*/
extern void afsi_log(char *pattern, ...);
+HANDLE hAFSDMainThread = NULL;
+
HANDLE WaitToTerminate;
int GlobalStatus;
+#ifdef JUMP
unsigned int MainThreadId;
jmp_buf notifier_jmp;
+#endif /* JUMP */
extern int traceOnPanic;
extern HANDLE afsi_file;
SetEvent(WaitToTerminate);
+#ifdef JUMP
if (GetCurrentThreadId() == MainThreadId)
longjmp(notifier_jmp, 1);
else
+#endif /* JUMP */
ExitThread(1);
}
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;
- WaitToTerminate = CreateEvent(NULL, TRUE, FALSE, NULL);
+ 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"));
#ifndef NOTSERVICE
StatusHandle = RegisterServiceCtrlHandlerEx(AFS_DAEMON_SERVICE_NAME,
PowerNotificationThreadCreate();
#endif
- afsi_start();
-
/* allow an exit to be called prior to any initialization */
hInitHookDll = LoadLibrary(AFSD_HOOK_DLL);
if (hInitHookDll)
ServiceStatus.dwWin32ExitCode = NO_ERROR;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
- ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+ ServiceStatus.dwControlsAccepted = 0;
SetServiceStatus(StatusHandle, &ServiceStatus);
/* exit if initialization failed */
ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
ServiceStatus.dwWin32ExitCode = NO_ERROR;
ServiceStatus.dwCheckPoint = 2;
- ServiceStatus.dwWaitHint = 15000;
- ServiceStatus.dwControlsAccepted = 0;
+ ServiceStatus.dwWaitHint = 20000;
+ /* accept Power Events */
+ ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_POWEREVENT;
SetServiceStatus(StatusHandle, &ServiceStatus);
}
}
+#ifdef JUMP
MainThreadId = GetCurrentThreadId();
jmpret = setjmp(notifier_jmp);
- if (jmpret == 0) {
+ if (jmpret == 0)
+#endif /* JUMP */
+ {
code = afsd_InitCM(&reason);
if (code != 0)
osi_panic(reason, __FILE__, __LINE__);
CheckMountDrive();
WaitForSingleObject(WaitToTerminate, INFINITE);
-
+
{
HANDLE h; char *ptbuf[1];
h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
DeregisterEventSource(h);
}
- ServiceStatus.dwCurrentState = SERVICE_STOPPED;
- ServiceStatus.dwWin32ExitCode = GlobalStatus ? ERROR_EXCEPTION_IN_SERVICE : NO_ERROR;
- ServiceStatus.dwCheckPoint = 0;
- ServiceStatus.dwWaitHint = 0;
- ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
-
- /* also now accept Power events - shutdown maybe? */
- ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
-
#ifdef REGISTER_POWER_NOTIFICATIONS
/* terminate thread used to flush cache */
PowerNotificationThreadExit();
#endif
+ /* Remove the ExceptionFilter */
+ SetUnhandledExceptionFilter(NULL);
+
+ if ( hInitHookDll )
+ FreeLibrary(hInitHookDll);
+
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ ServiceStatus.dwWin32ExitCode = GlobalStatus ? ERROR_EXCEPTION_IN_SERVICE : NO_ERROR;
+ ServiceStatus.dwCheckPoint = 0;
+ ServiceStatus.dwWaitHint = 0;
+ ServiceStatus.dwControlsAccepted = 0;
SetServiceStatus(StatusHandle, &ServiceStatus);
}
DWORD __stdcall afsdMain_thread(void* notUsed)
{
afsd_Main(0, (LPTSTR*)NULL);
- return(0);
+ exit(0);
}
-void main()
+int
+main(void)
{
- SERVICE_TABLE_ENTRY dispatchTable[] = {
+ static SERVICE_TABLE_ENTRY dispatchTable[] = {
{AFS_DAEMON_SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION) afsd_Main},
{NULL, NULL}
};
- afsd_SetUnhandledExceptionFilter();
-
if (!StartServiceCtrlDispatcher(dispatchTable))
{
LONG status = GetLastError();
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);
}