delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2024/02/02/12:23:38

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 266A93857B97
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1706894617;
bh=goJz6Nl2fZsAT5cloW8dsVRWXnIgSepCKT4WR++CpCg=;
h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=UHwEILZ9IKaiPEZ0sQvQwRl3SP7ucmuSRT6RocKReDAMqIQI3s5P6vC7m0YtE25pB
L9u9euCIeyqJ1wxhNUMrgn5oUb/LkBPjB/zYD8ZOUmdHEVtHhYoxwrIQfSL8QEEwEw
fedBraRyuTnMpTSR2Z0ULl6WgiQrlnAeOqR/ek3I=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AB1A3858403
Date: Fri, 2 Feb 2024 18:22:38 +0100
To: cygwin AT cygwin DOT com
Subject: Re: Restore SEM_FAILCRITICALERRORS [was: Aren't Windows System Error
popups meant to be disabled in Cygwin?]
Message-ID: <Zb0k3mRt5_tW5EEB@calimero.vinschen.de>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <CAJQQdJiOEduFeAthZ+q+LNXV33aJOhAXqq3sCaxdCqRpAjVmvA AT mail DOT gmail DOT com>
<CAB8Xom-PnumWSLoDFgERXA4GX0zotQiKFvi_wL7Bvsv133WAmw AT mail DOT gmail DOT com>
<CAJQQdJhzSNZ5dG254g5dv_AuWRxt+R-HLdiCPTkCNv=o+4PVeQ AT mail DOT gmail DOT com>
<ZbtsBD2IKYtH-duQ AT calimero DOT vinschen DOT de>
<CAJQQdJhS3QgJe_KsfGof_6XM6cwtNRkbPQPR32-JaKCu8_8KEA AT mail DOT gmail DOT com>
<ZbzmLRByzmDJxUcb AT calimero DOT vinschen DOT de>
<16b354c2-bba4-40b8-8359-7eb9a79b3ee3 AT dronecode DOT org DOT uk>
<CAJQQdJhYSkjGOFxF=-CnvBGgZa_Qv3HaH8nr8b3fjwqnizq3_Q AT mail DOT gmail DOT com>
<Zbz5TGo_9rqkKMSp AT calimero DOT vinschen DOT de>
<CAJQQdJjurPUo_WfunkkXnraJrP57KUa0gTwSTUwT_mVpKTsLdg AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <CAJQQdJjurPUo_WfunkkXnraJrP57KUa0gTwSTUwT_mVpKTsLdg@mail.gmail.com>
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

On Feb  2 14:56, David Allsopp via Cygwin wrote:
> On Fri, 2 Feb 2024 at 14:18, Corinna Vinschen via Cygwin wrote:
> > On Feb  2 13:35, David Allsopp via Cygwin wrote:
> > > Not really suggesting it be done this way (it feels more complicated
> > > than just reverting the change), but in some ways perhaps Cygwin
> > > should be using GetErrorMode on startup and instead of not inheriting
> > > it, ensuring that it sets whatever it received? i.e. just before the
> > > call to CreateProcess for a non-Cygwin binary, Cygwin restores the
> > > error mode (for that thread only) to the value read at startup, calls
> > > CreateProcess and then sets the error mode back.
> >
> > This sounds like a good ide, but...
> >
> > Is it actually a safe bet that the error mode set by SetThreadErrorMode
> > is then propagated as process error mode to the child process?
> >
> > I have to ask that because Microsoft conveniently forgot to document
> > this scenario in the MSDN docs.
> 
> :o) Never knowingly clear, are they! It would seem to be the intent of
> SetThreadErrorMode that it would behave that way but who knows.
> 
> Happy to set up a quick experiment to check that it does work (i.e.
> the invoked process has GetErrorMode set as expected) and that there's
> no possible race between two threads in the calling process with
> differing values (i.e. that having SEM_FAILCRITICALERRORS in one
> thread and not in another behaves as expected. If it does appear to
> work consistently, would you be willing to go down this route? Happy
> to do the patch, although it'd be very helpful to have a couple of
> pointers: I'm guessing the value would want to be captured just before
> the one place where SetErrorMode is already called, but in which
> structure should it then be stashed away to be reused in spawn?

Wanna try this?  It ignores the case of starting a process
under another user account for now, but that can be added easily
if this proves to work as expected.

diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index a40129c22232..f1017e69b6b2 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -718,7 +718,8 @@ dll_crt0_0 ()
   init_windows_system_directory ();
   initial_env ();
 
-  SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
+  orig_proc_error_mode = SetErrorMode (SEM_FAILCRITICALERRORS
+				       | SEM_NOGPFAULTERRORBOX);
 
   lock_process::init ();
   user_data->impure_ptr = _impure_ptr;
diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc
index 885ada85e7b8..d2861ba98b42 100644
--- a/winsup/cygwin/globals.cc
+++ b/winsup/cygwin/globals.cc
@@ -28,6 +28,7 @@ PWCHAR windows_directory = windows_directory_buf + 4;
 UINT windows_directory_length;
 UNICODE_STRING windows_directory_path;
 WCHAR global_progname[NT_MAX_PATH];
+UINT orig_proc_error_mode;
 
 /* program exit the program */
 
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 8a2db5cf72e2..df83f25d13c6 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -648,6 +648,10 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
 	      && !::cygheap->user.groups.issetgroups ()
 	      && !::cygheap->user.setuid_to_restricted))
 	{
+	  UINT orig_thread_error_mode = SEM_FAILCRITICALERRORS
+					| SEM_NOGPFAULTERRORBOX;
+	  if (!iscygwin ())
+	    SetThreadErrorMode (orig_proc_error_mode, &orig_thread_error_mode);
 	  rc = CreateProcessW (runpath,		/* image name w/ full path */
 			       cmd.wcs (wcmd),	/* what was passed to exec */
 			       sa,		/* process security attrs */
@@ -658,6 +662,8 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
 			       NULL,
 			       &si,
 			       &pi);
+	  if (!iscygwin ())
+	    SetThreadErrorMode (orig_thread_error_mode, NULL);
 	}
       else
 	{

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019