]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
windows-process-detach-20051227
authorJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 27 Dec 2005 16:17:11 +0000 (16:17 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 27 Dec 2005 16:17:11 +0000 (16:17 +0000)
The procmgmt library replaces the C RunTime Library's signal handlers
but does not restore them on process detachment.  This leaves the
process with signal handlers pointing to invalid code that generates
an invalid access error during process termination if the library
was previously unloaded.

src/procmgmt/pmgtprivate.h
src/procmgmt/procmgmt_nt.c
src/procmgmt/redirect_nt.c

index bbbabe63ae21649748ae037d8542ec40bf8e8ead..04b0dd23663840d3cd6de8f5b9ba1e0da3bbc26a 100644 (file)
@@ -30,6 +30,7 @@
 
 extern int pmgt_SignalRaiseLocalByName(const char *signo, int *libSigno);
 extern int pmgt_RedirectNativeSignals(void);
+extern int pmgt_RestoreNativeSignals(void);
 
 #else
 /* Private process management definitions and declarations for Unix */
index 0f99ea97ad4405744e816071b5cf3b97daa8b2cd..8cfa2b53ca469993dc61663a90e9ac80275d0c79 100644 (file)
@@ -1363,7 +1363,8 @@ DllMain(HINSTANCE dllInstHandle,  /* instance handle for this DLL module */
        DWORD reason,           /* reason function is being called */
        LPVOID reserved)
 {                              /* reserved for future use */
-    if (reason == DLL_PROCESS_ATTACH) {
+    switch (reason) {
+    case DLL_PROCESS_ATTACH:
        /* library is being attached to a process */
        if (PmgtLibraryInitialize()) {
            /* failed to initialize library */
@@ -1372,7 +1373,11 @@ DllMain(HINSTANCE dllInstHandle, /* instance handle for this DLL module */
 
        /* disable thread attach/detach notifications */
        (void)DisableThreadLibraryCalls(dllInstHandle);
+       return TRUE;
+    case DLL_PROCESS_DETACH:
+       pmgt_RestoreNativeSignals();
+       return TRUE;
+    default:
+       return FALSE;
     }
-
-    return TRUE;
 }
index 2eabcc1621e2156d0191cb5ba38e87f93d193a1e..c27551e3e27713b1d3c058d1002ebde24890f148 100644 (file)
@@ -110,3 +110,23 @@ pmgt_RedirectNativeSignals(void)
        return 0;
     }
 }
+
+/*
+ * pmgt_RedirectNativeSignals() -- initialize native signal redirection.
+ */
+int
+pmgt_RestoreNativeSignals(void)
+{
+    if (signal(SIGINT, SIG_DFL) == SIG_ERR
+       || signal(SIGILL, SIG_DFL) == SIG_ERR
+       || signal(SIGFPE, SIG_DFL) == SIG_ERR
+       || signal(SIGSEGV, SIG_DFL) == SIG_ERR
+       || signal(SIGTERM, SIG_DFL) == SIG_ERR
+       || signal(SIGABRT, SIG_DFL) == SIG_ERR) {
+       errno = EINVAL;
+       return -1;
+    } else {
+       return 0;
+    }
+}
+