The message box, displayed by the system debugger (drwtsn32.exe on WinNT or dwwin.exe on WinXP) in case when the child process causes Access Violation, remains on the screen after the child process is terminated by the exec utility.

Attached is a patch for the exec utility to prevent displaying error message box when child causes access violation.

This patch do not prevent the displaying of the message box on assertion fail, but this message box is not a big problem, because of it's disappear when child process terminates.

  ChangeLog:
  * exec.cpp [_WIN32 || _WIN64] (exec_file): Set appropriate error mode
  before running the child process to disable displaying the
  critical-error-handler and general-protection-fault message boxes.
  * runall.cpp [_WIN32 || _WIN64] : Included windows.h and
  signal.h.
  (process_results): Handle returned status STATUS_ACCESS_VIOLATION
  and print status "SEGV".

Farid.
Index: exec.cpp
===================================================================
--- exec.cpp    (revision 433620)
+++ exec.cpp    (working copy)
@@ -930,6 +930,11 @@
 
     merged = merge_argv (argv);
 
+    /* set appropriate error mode (the child process inherits this
+       error mode) to disable displaying the critical-error-handler
+       and general-protection-fault message boxes */
+    UINT old_mode = SetErrorMode (SEM_FAILCRITICALERRORS
+                                | SEM_NOGPFAULTERRORBOX);
     /* Create the child process */
     if (0 == CreateProcess (argv [0], merged, 0, 0, 1, 
         CREATE_NEW_PROCESS_GROUP, 0, 0, &context, &child)) {
@@ -938,6 +943,9 @@
         status.error = warn_last_error ("Creating child process");;
     }
 
+    /* restore the previous error mode */
+    SetErrorMode (old_mode);
+
     /* Clean up handles */
     if (context.hStdInput)
         if (0 == CloseHandle (context.hStdInput))
Index: runall.cpp
===================================================================
--- runall.cpp  (revision 433620)
+++ runall.cpp  (working copy)
@@ -35,6 +35,9 @@
 #include <sys/stat.h>
 #if !defined (_WIN32) && !defined (_WIN64)
 #  include <sys/wait.h>   /* for WIFEXITED(), ... */
+#else
+#  include <windows.h>    /* for STATUS_ACCESS_VIOLATION */
+#  include <signal.h>     /* for SIGSEGV */
 #endif
 
 #include "cmdopt.h"
@@ -256,7 +259,7 @@
             size_t target_len = strlen (target_name);
             size_t tmp_len = path_len + target_len - 2;
                 /* - 2 comes from removing 4 characters (extra .exe) and 
-                   adding 2 characters (\ directory seperator and trailing 
+                   adding 2 characters (\ directory separator and trailing 
                    null) */
             tmp_name = (char*)RW_MALLOC (tmp_len);
             memcpy (tmp_name, target, path_len - 4);
@@ -305,7 +308,7 @@
      - n\n
        Child exited with the non-zero return code n
      - name\n
-       Child terminated upon recieving the signal SIGname
+       Child terminated upon receiving the signal SIGname
 
    @param target the path to the executable that was run
    @param exec_name the short name of the executable
@@ -350,6 +353,8 @@
         puts ("   I/O");
     else if (result->error)
         puts ("KILLED");
+    else if (STATUS_ACCESS_VIOLATION == result->status)
+        printf ("%6s\n", get_signame (SIGSEGV));
     else
         printf ("%6d\n", result->status);
 #endif   /* _WIN{32,64} */
@@ -363,7 +368,7 @@
 
    @warning this method is UTF-8 unsafe
    @warning this method assumes there are no trailing slashes in the path name
-   @warning this method retuns a pointer referencing a position inside the 
+   @warning this method returns a pointer referencing a position inside the 
    provided path.  As such, the returned string isn't a new string, but rather 
    an alias to the provided string.
    @param path path name to determine the basename for
@@ -430,11 +435,11 @@
    Entry point to the application.
 
    Passes arguments to the option processing subsystem, then processes all
-   remaing arguments as targets using run_target
+   remaining arguments as targets using run_target
 
-   @param argc number of arguments recieved
-   @param argv array of arguments recieved
-   @return 0 upon successfull completeion of execution
+   @param argc number of arguments received
+   @param argv array of arguments received
+   @return 0 upon successful completeion of execution
 */
 
 int

Reply via email to