Boost logo

Boost-Build :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2006-06-20 03:24:47


Bronek Kozicki wrote:
[...]

still removing bugs. Function "related" did not check for error, thus (if the
process was gone by this time and pid returned from get_process_id was 0) it
would match any process, thus close any dialog that happend to be open at time.

Also waiting on thread id (of dialog message loop) does not make any sense,
the thread has to be open first to get the handle if we want to wait for it.
Function OpenThread is available since Windows 2000 and Windows Me, I hope I
can use it?

B.


--- C:\Documents and Settings\Bronek Kozicki\Desktop\execnt.c Mon Jun 19 21:37:05 2006 UTC
+++ C:\DEVEL\BOOST_RTEST\boost\tools\jam\src\execnt.c Mon Jun 19 21:41:12 2006 UTC
@@ -1016,9 +1016,12 @@
             ok == TRUE;
             ok = Process32Next(process_snapshot_h, &pinfo) )
         {
             if (pinfo.th32ProcessID == child && pinfo.th32ParentProcessID)
+ {
+ CloseHandle(process_snapshot_h);
                 return is_parent_child(parent, pinfo.th32ParentProcessID);
+ }
         }
 
         CloseHandle(process_snapshot_h);
     }
@@ -1027,28 +1030,48 @@
 }
 
 int related(HANDLE h, DWORD p)
 {
- return is_parent_child(get_process_id(h), p);
+ DWORD pid = get_process_id(h);
+ if (pid)
+ {
+ return is_parent_child(pid, p);
+ }
+ return 0;
 }
 
 BOOL CALLBACK window_enum(HWND hwnd, LPARAM lParam)
 {
- char buf[10] = {0};
+ char buf[7] = {0};
     HANDLE h = *((HANDLE*) (lParam));
     DWORD pid = 0;
+ DWORD tid = 0;
 
- if (!GetClassNameA(hwnd, buf, 10))
- return TRUE; // failed to read class name
+ if (!GetClassNameA(hwnd, buf, 7))
+ return TRUE; /* failed to read class name; presume it's not a dialog */
 
     if (strcmp(buf, "#32770"))
- return TRUE; // not a dialog
+ return TRUE; /* not a dialog */
 
- GetWindowThreadProcessId(hwnd, &pid);
+ tid = GetWindowThreadProcessId(hwnd, &pid);
     if (related(h, pid))
     {
- PostMessage(hwnd, WM_QUIT, 0, 0);
- // just one window at a time
+ HANDLE hid = OpenThread(SYNCHRONIZE, FALSE, tid);
+ /* ask really nice */
+ PostMessageA(hwnd, WM_CLOSE, 0, 0);
+ /* now wait and see if it worked. If not, insist */
+ if (hid != NULL)
+ {
+ if (WaitForSingleObject(hid, 200) == WAIT_TIMEOUT)
+ {
+ PostThreadMessageA(tid, WM_QUIT, 0, 0);
+ if (WaitForSingleObject(hid, 500) == WAIT_TIMEOUT)
+ {
+ PostThreadMessageA(tid, WM_QUIT, 0, 0);
+ }
+ }
+ CloseHandle(hid);
+ }
         return FALSE;
     }
 
     return TRUE;
@@ -1104,13 +1127,13 @@
                 /* check if any jobs have surpassed the maximum run time. */
                 for ( i = 0; i < num_active; ++i )
                 {
                     double t = running_time(active_handles[i]);
+ /* the job may have left an alert dialog around,
+ try and get rid of it before killing */
+ close_alert(active_handles[i]);
                     if ( t > (double)globs.timeout )
                     {
- /* the job may have left an alert dialog around,
- try and get rid of it before killing */
- close_alert(active_handles[i]);
                         /* we have a "runaway" job, kill it */
                         kill_all(0,active_handles[i]);
                         /* indicate the job "finished" so we query its status below */
                         waitcode = WAIT_ABANDONED_0+i;


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk