Boost logo

Boost :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2006-07-21 04:33:21


Vladimir Prus wrote:
> I like this patch. It's now committed.

I'm sorry to say this, but it was still buggy. Attached you will find relevant
patch

B.

--- C:\Documents and Settings\Bronek Kozicki\Desktop\execnt.c Fri Jul 21 08:26:21 2006 UTC
+++ E:\DEVEL\BOOST_RTEST\boost\tools\jam\src\execnt.c Fri Jul 21 08:22:47 2006 UTC
@@ -1002,22 +1002,22 @@
                     CloseHandle(ph);
                 }
             }
         }
         CloseHandle(process_snapshot_h);
     }
     /* now that the children are all dead, kill the root */
     TerminateProcess(process,-2);
 }
 
-/* recursive check if first process is parent (directly or indirectly) of
-the latter one. Both processes are passed as process ids, not handles */
+/* Recursive check if first process is parent (directly or indirectly) of
+the second one. Both processes are passed as process ids, not handles */
 static int
 is_parent_child(DWORD parent, DWORD child)
 {
     HANDLE process_snapshot_h = INVALID_HANDLE_VALUE;
 
     if (!child)
         return 0;
     if (parent == child)
         return 1;
 
@@ -1035,59 +1035,68 @@
             if (pinfo.th32ProcessID == child)
             {
                 /*
                 Unfortunately, process ids are not really unique. There might
                 be spurious "parent and child" relationship match between
                 two non-related processes if real parent process of a given
                 process has exited (while child process kept running as an
                 "orphan") and the process id of such parent process has been
                 reused by internals of the operating system when creating
                 another process. Thus additional check is needed - process
- creation time. */
+ creation time. This check may fail (ie. return 0) for system
+ processes due to insufficient privileges, and that's OK. */
                 double tchild = 0.0;
                 double tparent = 0.0;
                 HANDLE hchild = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pinfo.th32ProcessID);
+
+ CloseHandle(process_snapshot_h);
+
+ /* csrss.exe may display message box like following:
+ xyz.exe - Unable To Locate Component
+ This application has failed to start because
+ boost_foo-bar.dll was not found. Re-installing the
+ application may fix the problem
+ This actually happens when starting test process that depends
+ on a dynamic library which failed to build. We want to
+ automatically close these message boxes even though csrss.exe
+ is not our child process. We may depend on the fact that (in
+ all current versions of Windows) csrss.exe is directly
+ child of smss.exe process, which in turn is directly child of
+ System process, which always has process id == 4 .
+ This check must be performed before comparison of process
+ creation time */
+ if (stricmp(pinfo.szExeFile, "csrss.exe") == 0
+ || stricmp(pinfo.szExeFile, "smss.exe") == 0)
+ {
+ if (is_parent_child(4, pinfo.th32ParentProcessID))
+ return 1;
+ }
+
                 if (hchild != 0)
                 {
                     HANDLE hparent = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pinfo.th32ParentProcessID);
                     if (hparent != 0)
                     {
                         tchild = creation_time(hchild);
                         tparent = creation_time(hparent);
                         
                         CloseHandle(hparent);
                     }
                     CloseHandle(hchild);
                 }
- CloseHandle(process_snapshot_h);
 
- /* was child created before alleged parent? */
+ /* return 0 if one of the following is true:
+ 1. we failed to read process creation time
+ 2. child was created before alleged parent */
                 if (tchild == 0.0 || tparent == 0.0 || tchild < tparent)
                     return 0;
 
- /* csrss.exe may display message box like following:
- xyz.exe - Unable To Locate Component
- This application has failed to start because
- boost_foo-bar.dll was not found. Re-installing the
- application may fix the problem
- This actually happens when starting test process that depends
- on a dynamic library which failed to build. We want to
- automatically close these message boxes even though csrss.exe
- is not our child process. We may depend on the fact that (in
- all current versions of Windows) csrss.exe is indirectly
- child of System process, which always has process id == 4 */
- if (stricmp(pinfo.szExeFile, "csrss.exe") == 0)
- {
- if (is_parent_child(4, pinfo.th32ParentProcessID))
- return 1;
- }
-
                 return is_parent_child(parent, pinfo.th32ParentProcessID);
             }
         }
 
         CloseHandle(process_snapshot_h);
     }
 
     return 0;
 }
 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk