From: Jeffrey Altman Date: Tue, 19 Apr 2005 07:26:27 +0000 (+0000) Subject: windows-hooks-20050418 X-Git-Tag: openafs-devel-1_5_0~621 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=c0753e9ee7ff61ecd162cebbb30da7f0a8ca0bb6;hp=f4f8176464bab9256786135df2f09fe8b129e7c1 windows-hooks-20050418 Add new hooks from "AfsdHook.dll" to the afsd_service.exe AfsdInitHook - where you currently have one AfsdRxStartedHook - after RxInit but before SmbInit AfsdSmbStartedHook - after SmbInit AfsdBkDaemonHook - called by the BkDaemon thread and is executed once per cycle AfsdStoppingHook - called just after a shutdown event has been received but before any shutdown has been performed AfsdStoppedHook - called just after all shutdown operations after completed but before the service terminates The type of the function is BOOL ( APIENTRY * AfsdHook )(void) in all cases. Returning FALSE will cause the service to shutdown. --- diff --git a/src/WINNT/afsd/afsd.c b/src/WINNT/afsd/afsd.c index d8661eb..2f10e2e 100644 --- a/src/WINNT/afsd/afsd.c +++ b/src/WINNT/afsd/afsd.c @@ -36,6 +36,8 @@ extern int traceOnPanic; extern void afsd_DbgBreakAllocInit(); extern void afsd_DbgBreakAdd(DWORD requestNumber); +HANDLE WaitToTerminate = NULL; + /* * Notifier function for use by osi_panic */ diff --git a/src/WINNT/afsd/afsd.h b/src/WINNT/afsd/afsd.h index 5c7c8ff..be9d25b 100644 --- a/src/WINNT/afsd/afsd.h +++ b/src/WINNT/afsd/afsd.h @@ -123,6 +123,8 @@ extern int cm_freelanceEnabled; extern long rx_mtu; +extern HANDLE WaitToTerminate; + #define CAPABILITY_ERRORTRANS (1<<0) #define CAPABILITY_BITS 1 @@ -130,4 +132,17 @@ extern long rx_mtu; #define LOG_PACKET 1 #undef NOTSERVICE +#define AFSD_HOOK_DLL "afsdhook.dll" +#define AFSD_INIT_HOOK "AfsdInitHook" +typedef BOOL ( APIENTRY * AfsdInitHook )(void); +#define AFSD_RX_STARTED_HOOK "AfsdRxStartedHook" +typedef BOOL ( APIENTRY * AfsdRxStartedHook )(void); +#define AFSD_SMB_STARTED_HOOK "AfsdSmbStartedHook" +typedef BOOL ( APIENTRY * AfsdSmbStartedHook )(void); +#define AFSD_DAEMON_HOOK "AfsdDaemonHook" +typedef BOOL ( APIENTRY * AfsdDaemonHook )(void); +#define AFSD_STOPPING_HOOK "AfsdStoppingHook" +typedef BOOL ( APIENTRY * AfsdStoppingHook )(void); +#define AFSD_STOPPED_HOOK "AfsdStoppedHook" +typedef BOOL ( APIENTRY * AfsdStoppedHook )(void); #endif /* AFSD_H_ENV */ diff --git a/src/WINNT/afsd/afsd_service.c b/src/WINNT/afsd/afsd_service.c index 53d750d..4e115d1 100644 --- a/src/WINNT/afsd/afsd_service.c +++ b/src/WINNT/afsd/afsd_service.c @@ -987,10 +987,6 @@ BOOL AFSModulesVerify(void) return success; } -typedef BOOL ( APIENTRY * AfsdInitHook )(void); -#define AFSD_INIT_HOOK "AfsdInitHook" -#define AFSD_HOOK_DLL "afsdhook.dll" - /* control serviceex exists only on 2000/xp. These functions will be loaded dynamically. */ @@ -1009,9 +1005,8 @@ afsd_Main(DWORD argc, LPTSTR *argv) #ifdef JUMP int jmpret; #endif /* JUMP */ - HANDLE hInitHookDll; - HANDLE hAdvApi32; - AfsdInitHook initHook; + HMODULE hHookDll; + HMODULE hAdvApi32; #ifdef _DEBUG _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF /*| _CRTDBG_CHECK_ALWAYS_DF*/ | @@ -1109,17 +1104,17 @@ afsd_Main(DWORD argc, LPTSTR *argv) } /* allow an exit to be called prior to any initialization */ - hInitHookDll = LoadLibrary(AFSD_HOOK_DLL); - if (hInitHookDll) + hHookDll = LoadLibrary(AFSD_HOOK_DLL); + if (hHookDll) { BOOL hookRc = FALSE; - initHook = ( AfsdInitHook ) GetProcAddress(hInitHookDll, AFSD_INIT_HOOK); + AfsdInitHook initHook = ( AfsdInitHook ) GetProcAddress(hHookDll, AFSD_INIT_HOOK); if (initHook) { hookRc = initHook(); } - FreeLibrary(hInitHookDll); - hInitHookDll = NULL; + FreeLibrary(hHookDll); + hHookDll = NULL; if (hookRc == FALSE) { @@ -1172,6 +1167,33 @@ afsd_Main(DWORD argc, LPTSTR *argv) osi_panic(reason, __FILE__, __LINE__); } + /* allow an exit to be called post rx initialization */ + hHookDll = LoadLibrary(AFSD_HOOK_DLL); + if (hHookDll) + { + BOOL hookRc = FALSE; + AfsdRxStartedHook rxStartedHook = ( AfsdRxStartedHook ) GetProcAddress(hHookDll, AFSD_RX_STARTED_HOOK); + if (rxStartedHook) + { + hookRc = rxStartedHook(); + } + FreeLibrary(hHookDll); + hHookDll = NULL; + + if (hookRc == FALSE) + { + ServiceStatus.dwCurrentState = SERVICE_STOPPED; + ServiceStatus.dwWin32ExitCode = NO_ERROR; + ServiceStatus.dwCheckPoint = 0; + ServiceStatus.dwWaitHint = 0; + ServiceStatus.dwControlsAccepted = 0; + SetServiceStatus(StatusHandle, &ServiceStatus); + + /* exit if initialization failed */ + return; + } + } + #ifndef NOTSERVICE ServiceStatus.dwCheckPoint++; ServiceStatus.dwWaitHint -= 5000; @@ -1183,6 +1205,33 @@ afsd_Main(DWORD argc, LPTSTR *argv) osi_panic(reason, __FILE__, __LINE__); } + /* allow an exit to be called post smb initialization */ + hHookDll = LoadLibrary(AFSD_HOOK_DLL); + if (hHookDll) + { + BOOL hookRc = FALSE; + AfsdSmbStartedHook smbStartedHook = ( AfsdSmbStartedHook ) GetProcAddress(hHookDll, AFSD_SMB_STARTED_HOOK); + if (smbStartedHook) + { + hookRc = smbStartedHook(); + } + FreeLibrary(hHookDll); + hHookDll = NULL; + + if (hookRc == FALSE) + { + ServiceStatus.dwCurrentState = SERVICE_STOPPED; + ServiceStatus.dwWin32ExitCode = NO_ERROR; + ServiceStatus.dwCheckPoint = 0; + ServiceStatus.dwWaitHint = 0; + ServiceStatus.dwControlsAccepted = 0; + SetServiceStatus(StatusHandle, &ServiceStatus); + + /* exit if initialization failed */ + return; + } + } + MountGlobalDrives(); #ifndef NOTSERVICE @@ -1217,6 +1266,34 @@ afsd_Main(DWORD argc, LPTSTR *argv) DeregisterEventSource(h); } + /* allow an exit to be called prior to stopping the service */ + hHookDll = LoadLibrary(AFSD_HOOK_DLL); + if (hHookDll) + { + BOOL hookRc = FALSE; + AfsdStoppingHook stoppingHook = ( AfsdStoppingHook ) GetProcAddress(hHookDll, AFSD_STOPPING_HOOK); + if (stoppingHook) + { + hookRc = stoppingHook(); + } + FreeLibrary(hHookDll); + hHookDll = NULL; + + if (hookRc == FALSE) + { + ServiceStatus.dwCurrentState = SERVICE_STOPPED; + ServiceStatus.dwWin32ExitCode = NO_ERROR; + ServiceStatus.dwCheckPoint = 0; + ServiceStatus.dwWaitHint = 0; + ServiceStatus.dwControlsAccepted = 0; + SetServiceStatus(StatusHandle, &ServiceStatus); + + /* exit if initialization failed */ + return; + } + } + + #ifdef AFS_FREELANCE_CLIENT cm_FreelanceShutdown(); afsi_log("Freelance Shutdown complete"); @@ -1247,6 +1324,20 @@ afsd_Main(DWORD argc, LPTSTR *argv) PowerNotificationThreadExit(); #endif + /* allow an exit to be called after stopping the service */ + hHookDll = LoadLibrary(AFSD_HOOK_DLL); + if (hHookDll) + { + BOOL hookRc = FALSE; + AfsdStoppedHook stoppedHook = ( AfsdStoppedHook ) GetProcAddress(hHookDll, AFSD_STOPPED_HOOK); + if (stoppedHook) + { + hookRc = stoppedHook(); + } + FreeLibrary(hHookDll); + hHookDll = NULL; + } + /* Remove the ExceptionFilter */ SetUnhandledExceptionFilter(NULL); diff --git a/src/WINNT/afsd/cm_daemon.c b/src/WINNT/afsd/cm_daemon.c index 81ba145..f3f39b5 100644 --- a/src/WINNT/afsd/cm_daemon.c +++ b/src/WINNT/afsd/cm_daemon.c @@ -21,6 +21,7 @@ #include #include +#include #include "afsd.h" @@ -111,6 +112,7 @@ void cm_Daemon(long parm) char thostName[200]; unsigned long code; struct hostent *thp; + HMODULE hHookDll; /* ping all file servers, up or down, with unauthenticated connection, * to find out whether we have all our callbacks from the server still. @@ -178,6 +180,25 @@ void cm_Daemon(long parm) lastTokenCacheCheck = now; cm_CheckTokenCache(now); } + + /* allow an exit to be called prior to stopping the service */ + hHookDll = LoadLibrary(AFSD_HOOK_DLL); + if (hHookDll) + { + BOOL hookRc = FALSE; + AfsdDaemonHook daemonHook = ( AfsdDaemonHook ) GetProcAddress(hHookDll, AFSD_DAEMON_HOOK); + if (daemonHook) + { + hookRc = daemonHook(); + } + FreeLibrary(hHookDll); + hHookDll = NULL; + + if (hookRc == FALSE) + { + SetEvent(WaitToTerminate); + } + } } } diff --git a/src/WINNT/afsd/smb.c b/src/WINNT/afsd/smb.c index f7f7c5e..3382b52 100644 --- a/src/WINNT/afsd/smb.c +++ b/src/WINNT/afsd/smb.c @@ -25,6 +25,8 @@ #include #include +#include +#include #include "afsd.h" #include @@ -152,7 +154,6 @@ int smb_useV3; /* try to negotiate V3 */ static showErrors = 1; /* MessageBox or something like it */ int (_stdcall *smb_MBfunc)(HWND, LPCTSTR, LPCTSTR, UINT) = NULL; -extern HANDLE WaitToTerminate; #endif /* DJGPP */ /* GMT time info: