public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: spawn: drop special handling for cmd.exe and command.com
Date: Fri, 28 Oct 2022 10:49:25 +0000 (GMT)	[thread overview]
Message-ID: <20221028104925.35CBD385783C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=f33635ae607660c3248aafdf8a53e926d41ae45b

commit f33635ae607660c3248aafdf8a53e926d41ae45b
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Oct 28 12:24:13 2022 +0200

    Cygwin: spawn: drop special handling for cmd.exe and command.com
    
    Apparently at one point handling cmd.exe and command.com special
    made sense, but what that should be has never been documented.
    There's also no clear reason why cmd.exe is different from any
    other native executable.  Additionaly, checking for command.com
    is entirely useless on 64 bit Windows anyway.
    
    Just drop this code.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/spawn.cc | 112 +++++++++++++++++++------------------------------
 1 file changed, 43 insertions(+), 69 deletions(-)

diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 4fc842a2b..a450ea443 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -345,7 +345,6 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
   PWCHAR runpath = tp.w_get ();
   int c_flags;
 
-  bool null_app_name = false;
   STARTUPINFOW si = {};
   int looped = 0;
 
@@ -397,47 +396,27 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
 	  __leave;
 	}
 
-      if (ac == 3 && argv[1][0] == '/' && tolower (argv[1][1]) == 'c' &&
-	  (iscmd (argv[0], "command.com") || iscmd (argv[0], "cmd.exe")))
+      if (real_path.iscygexec ())
 	{
-	  real_path.check (prog_arg);
-	  cmd.add ("\"");
-	  if (!real_path.error)
-	    cmd.add (real_path.get_win32 ());
-	  else
-	    cmd.add (argv[0]);
-	  cmd.add ("\"");
-	  cmd.add (" ");
-	  cmd.add (argv[1]);
-	  cmd.add (" ");
-	  cmd.add (argv[2]);
-	  real_path.set_path (argv[0]);
-	  null_app_name = true;
+	  moreinfo->argc = newargv.argc;
+	  moreinfo->argv = newargv;
 	}
-      else
+      if ((wincmdln || !real_path.iscygexec ())
+	   && !cmd.fromargv (newargv, real_path.get_win32 (),
+			     real_path.iscygexec ()))
 	{
-	  if (real_path.iscygexec ())
-	    {
-	      moreinfo->argc = newargv.argc;
-	      moreinfo->argv = newargv;
-	    }
-	  if ((wincmdln || !real_path.iscygexec ())
-	       && !cmd.fromargv (newargv, real_path.get_win32 (),
-				 real_path.iscygexec ()))
-	    {
-	      res = -1;
-	      __leave;
-	    }
+	  res = -1;
+	  __leave;
+	}
 
 
-	  if (mode != _P_OVERLAY || !real_path.iscygexec ()
-	      || !DuplicateHandle (GetCurrentProcess (), myself.shared_handle (),
-				   GetCurrentProcess (), &moreinfo->myself_pinfo,
-				   0, TRUE, DUPLICATE_SAME_ACCESS))
-	    moreinfo->myself_pinfo = NULL;
-	  else
-	    VerifyHandle (moreinfo->myself_pinfo);
-	}
+      if (mode != _P_OVERLAY || !real_path.iscygexec ()
+	  || !DuplicateHandle (GetCurrentProcess (), myself.shared_handle (),
+			       GetCurrentProcess (), &moreinfo->myself_pinfo,
+			       0, TRUE, DUPLICATE_SAME_ACCESS))
+	moreinfo->myself_pinfo = NULL;
+      else
+	VerifyHandle (moreinfo->myself_pinfo);
 
       PROCESS_INFORMATION pi;
       pi.hProcess = pi.hThread = NULL;
@@ -507,42 +486,37 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
 	    }
 	}
 
-      if (null_app_name)
-	runpath = NULL;
-      else
+      USHORT len = real_path.get_nt_native_path ()->Length / sizeof (WCHAR);
+      if (RtlEqualUnicodePathPrefix (real_path.get_nt_native_path (),
+				     &ro_u_natp, FALSE))
 	{
-	  USHORT len = real_path.get_nt_native_path ()->Length / sizeof (WCHAR);
-	  if (RtlEqualUnicodePathPrefix (real_path.get_nt_native_path (),
-					 &ro_u_natp, FALSE))
+	  runpath = real_path.get_wide_win32_path (runpath);
+	  /* If the executable path length is < MAX_PATH, make sure the long
+	     path win32 prefix is removed from the path to make subsequent
+	     not long path aware native Win32 child processes happy. */
+	  if (len < MAX_PATH + 4)
 	    {
-	      runpath = real_path.get_wide_win32_path (runpath);
-	      /* If the executable path length is < MAX_PATH, make sure the long
-		 path win32 prefix is removed from the path to make subsequent
-		 not long path aware native Win32 child processes happy. */
-	      if (len < MAX_PATH + 4)
-		{
-		  if (runpath[5] == ':')
-		    runpath += 4;
-		  else if (len < MAX_PATH + 6)
-		    *(runpath += 6) = L'\\';
-		}
+	      if (runpath[5] == ':')
+		runpath += 4;
+	      else if (len < MAX_PATH + 6)
+		*(runpath += 6) = L'\\';
 	    }
-	  else if (len < NT_MAX_PATH - ro_u_globalroot.Length / sizeof (WCHAR))
-	    {
-	      UNICODE_STRING rpath;
+	}
+      else if (len < NT_MAX_PATH - ro_u_globalroot.Length / sizeof (WCHAR))
+	{
+	  UNICODE_STRING rpath;
 
-	      RtlInitEmptyUnicodeString (&rpath, runpath,
-					 (NT_MAX_PATH - 1) * sizeof (WCHAR));
-	      RtlCopyUnicodeString (&rpath, &ro_u_globalroot);
-	      RtlAppendUnicodeStringToString (&rpath,
-					      real_path.get_nt_native_path ());
-	    }
-	  else
-	    {
-	      set_errno (ENAMETOOLONG);
-	      res = -1;
-	      __leave;
-	    }
+	  RtlInitEmptyUnicodeString (&rpath, runpath,
+				     (NT_MAX_PATH - 1) * sizeof (WCHAR));
+	  RtlCopyUnicodeString (&rpath, &ro_u_globalroot);
+	  RtlAppendUnicodeStringToString (&rpath,
+					  real_path.get_nt_native_path ());
+	}
+      else
+	{
+	  set_errno (ENAMETOOLONG);
+	  res = -1;
+	  __leave;
 	}
 
       cygbench ("spawn-worker");

                 reply	other threads:[~2022-10-28 10:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221028104925.35CBD385783C@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).