Windows: move debug break in afsd_notifier
[openafs.git] / src / WINNT / afsd / afsd_service.c
index 5a59be4..b7bb6a4 100644 (file)
@@ -53,11 +53,15 @@ extern HANDLE afsi_file;
 static int powerEventsRegistered = 0;
 extern int powerStateSuspended = 0;
 
+static VOID (WINAPI* pRtlCaptureContext)(PCONTEXT ContextRecord) = NULL;
+
 /*
  * Notifier function for use by osi_panic
  */
 static void afsd_notifier(char *msgp, char *filep, long line)
 {
+    CONTEXT context;
+
     if (!msgp)
         msgp = "unspecified assert";
 
@@ -74,23 +78,30 @@ static void afsd_notifier(char *msgp, char *filep, long line)
     afsd_ForceTrace(TRUE);
     buf_ForceTrace(TRUE);
 
+    if (pRtlCaptureContext) {
+        pRtlCaptureContext(&context);
+        afsd_printStack(GetCurrentThread(), &context);
+    }
+
+#ifdef DEBUG
+    if (IsDebuggerPresent())
+        DebugBreak();
+#endif
+
     afsi_log("--- begin dump ---");
     cm_MemDumpDirStats(afsi_file, "a", 0);
     cm_MemDumpBPlusStats(afsi_file, "a", 0);
     cm_DumpCells(afsi_file, "a", 0);
     cm_DumpVolumes(afsi_file, "a", 0);
     cm_DumpSCache(afsi_file, "a", 0);
-#ifdef keisa
-    cm_dnlcDump(afsi_file, "a");
-#endif
     cm_DumpBufHashTable(afsi_file, "a", 0);
+    cm_DumpServers(afsi_file, "a", 0);
     smb_DumpVCP(afsi_file, "a", 0);                    
+    rx_DumpPackets(afsi_file, "a");
+    rx_DumpCalls(afsi_file, "a");
     afsi_log("--- end   dump ---");
     
-#ifdef DEBUG
-    if (IsDebuggerPresent())
-        DebugBreak();  
-#endif
+    GenerateMiniDump(NULL);
 
     SetEvent(WaitToTerminate);
 
@@ -456,7 +467,7 @@ static DWORD __stdcall MountGlobalDrivesThread(void * notUsed)
 
             nr.dwScope = RESOURCE_GLOBALNET;              /* ignored parameter */
             nr.dwType=RESOURCETYPE_DISK;
-            nr.lpLocalName=szDriveToMapTo;
+            nr.lpLocalName=strlen(szDriveToMapTo) > 0 ? szDriveToMapTo : NULL;
             nr.lpRemoteName=szAfsPath;
             nr.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE; /* ignored parameter */
             nr.dwUsage = RESOURCEUSAGE_CONNECTABLE;       /* ignored parameter */
@@ -1097,6 +1108,7 @@ afsd_Main(DWORD argc, LPTSTR *argv)
 #endif /* JUMP */
     HMODULE hHookDll;
     HMODULE hAdvApi32;
+    HMODULE hKernel32;
 
 #ifdef _DEBUG
     void afsd_DbgBreakAllocInit();
@@ -1111,6 +1123,14 @@ afsd_Main(DWORD argc, LPTSTR *argv)
     osi_InitPanic(afsd_notifier);
     osi_InitTraceOption();
 
+    hKernel32 = LoadLibrary("kernel32.dll");
+    if (hKernel32 == NULL)
+    {
+        afsi_log("Fatal: cannot load kernel32.dll");
+        return;
+    }
+    pRtlCaptureContext = GetProcAddress(hKernel32, "RtlCaptureContext");
+
     GlobalStatus = 0;
 
     afsi_start();
@@ -1198,7 +1218,7 @@ afsd_Main(DWORD argc, LPTSTR *argv)
     }
 
     /* allow an exit to be called prior to any initialization */
-    hHookDll = LoadLibrary(AFSD_HOOK_DLL);
+    hHookDll = cm_LoadAfsdHookLib();
     if (hHookDll)
     {
         BOOL hookRc = TRUE;
@@ -1263,14 +1283,8 @@ afsd_Main(DWORD argc, LPTSTR *argv)
             SetServiceStatus(StatusHandle, &ServiceStatus);
         }
 #endif
-        code = afsd_InitDaemons(&reason);
-        if (code != 0) {
-            afsi_log("afsd_InitDaemons failed: %s (code = %d)", reason, code);
-                       osi_panic(reason, __FILE__, __LINE__);
-        }
-
         /* allow an exit to be called post rx initialization */
-        hHookDll = LoadLibrary(AFSD_HOOK_DLL);
+        hHookDll = cm_LoadAfsdHookLib();
         if (hHookDll)
         {
             BOOL hookRc = TRUE;
@@ -1308,9 +1322,6 @@ afsd_Main(DWORD argc, LPTSTR *argv)
         /* Notify any volume status handlers that the cache manager has started */
         cm_VolStatus_Service_Started();
 
-/* the following ifdef chooses the mode of operation for the service.  to enable
- * a runtime flag (instead of compile-time), pioctl() would need to dynamically
- * determine the mode, in order to use the correct ioctl special-file path. */
         code = afsd_InitSMB(&reason, MessageBox);
         if (code != 0) {
             afsi_log("afsd_InitSMB failed: %s (code = %d)", reason, code);
@@ -1318,7 +1329,7 @@ afsd_Main(DWORD argc, LPTSTR *argv)
         }
 
         /* allow an exit to be called post smb initialization */
-        hHookDll = LoadLibrary(AFSD_HOOK_DLL);
+        hHookDll = cm_LoadAfsdHookLib();
         if (hHookDll)
         {
             BOOL hookRc = TRUE;
@@ -1347,6 +1358,12 @@ afsd_Main(DWORD argc, LPTSTR *argv)
 
         MountGlobalDrives();
 
+        code = afsd_InitDaemons(&reason);
+        if (code != 0) {
+            afsi_log("afsd_InitDaemons failed: %s (code = %d)", reason, code);
+                       osi_panic(reason, __FILE__, __LINE__);
+        }
+
 #ifndef NOTSERVICE
         if (bRunningAsService) {
             ServiceStatus.dwCurrentState = SERVICE_RUNNING;
@@ -1364,7 +1381,7 @@ afsd_Main(DWORD argc, LPTSTR *argv)
     }
 
     /* allow an exit to be called when started */
-    hHookDll = LoadLibrary(AFSD_HOOK_DLL);
+    hHookDll = cm_LoadAfsdHookLib();
     if (hHookDll)
     {
         BOOL hookRc = TRUE;
@@ -1409,7 +1426,7 @@ afsd_Main(DWORD argc, LPTSTR *argv)
        LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_SERVICE_STOPPING);
 
     /* allow an exit to be called prior to stopping the service */
-    hHookDll = LoadLibrary(AFSD_HOOK_DLL);
+    hHookDll = cm_LoadAfsdHookLib();
     if (hHookDll)
     {
         BOOL hookRc = TRUE;
@@ -1431,29 +1448,26 @@ afsd_Main(DWORD argc, LPTSTR *argv)
     DismountGlobalDrives();
     afsi_log("Global Drives dismounted");
                                          
+    smb_Shutdown();                      
+    afsi_log("smb shutdown complete");   
+                                         
+    RpcShutdown();                       
+
+    cm_ReleaseAllLocks();
+
     cm_DaemonShutdown();                 
     afsi_log("Daemon shutdown complete");
     
-    afsd_ShutdownCM();
-
     buf_Shutdown();                      
     afsi_log("Buffer shutdown complete");
                                          
-    rx_Finalize();                       
-    afsi_log("rx finalization complete");
-                                         
-    smb_Shutdown();                      
-    afsi_log("smb shutdown complete");   
-                                         
-    RpcShutdown();                       
+    afsd_ShutdownCM();
 
-    cm_ReleaseAllLocks();
+    cm_ShutdownMappedMemory();           
 
     rx_Finalize();
     afsi_log("rx finalization complete");
 
-    cm_ShutdownMappedMemory();           
-
 #ifdef REGISTER_POWER_NOTIFICATIONS
     /* terminate thread used to flush cache */
     if (powerEventsRegistered)
@@ -1472,7 +1486,7 @@ afsd_Main(DWORD argc, LPTSTR *argv)
     cm_VolStatus_Finalize();
 
     /* allow an exit to be called after stopping the service */
-    hHookDll = LoadLibrary(AFSD_HOOK_DLL);
+    hHookDll = cm_LoadAfsdHookLib();
     if (hHookDll)
     {
         BOOL hookRc = TRUE;