From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 35CBD385783C; Fri, 28 Oct 2022 10:49:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35CBD385783C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666954165; bh=wmEAMFRqHuyUBSCvgAwBwYIw2M5HGsnD57L2WQzOwS8=; h=From:To:Subject:Date:From; b=y51gfBDjcz1AexNFHuU91TlsVONoo562663Q6YFTr/Vrd3Par99BYRS5XXrb7AZNb U/Oa3HXe2LPpr1dDfaOeRbZ8uQDr9iNDqN9VgrmQCLZk5mw399dovPUVRrDwVV/nDa OeJxJs9nvjy/pyDN9diKZVtH1XjZzKuhpQNkhfls= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: spawn: drop special handling for cmd.exe and command.com X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 85148c43c4e502364ee34c14ec265f1a275ce20e X-Git-Newrev: f33635ae607660c3248aafdf8a53e926d41ae45b Message-Id: <20221028104925.35CBD385783C@sourceware.org> Date: Fri, 28 Oct 2022 10:49:25 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Df33635ae607= 660c3248aafdf8a53e926d41ae45b commit f33635ae607660c3248aafdf8a53e926d41ae45b Author: Corinna Vinschen Date: Fri Oct 28 12:24:13 2022 +0200 Cygwin: spawn: drop special handling for cmd.exe and command.com =20 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. =20 Just drop this code. =20 Signed-off-by: Corinna Vinschen 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 c= har *const *argv, PWCHAR runpath =3D tp.w_get (); int c_flags; =20 - bool null_app_name =3D false; STARTUPINFOW si =3D {}; int looped =3D 0; =20 @@ -397,47 +396,27 @@ child_info_spawn::worker (const char *prog_arg, const= char *const *argv, __leave; } =20 - if (ac =3D=3D 3 && argv[1][0] =3D=3D '/' && tolower (argv[1][1]) =3D= =3D '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 =3D true; + moreinfo->argc =3D newargv.argc; + moreinfo->argv =3D newargv; } - else + if ((wincmdln || !real_path.iscygexec ()) + && !cmd.fromargv (newargv, real_path.get_win32 (), + real_path.iscygexec ())) { - if (real_path.iscygexec ()) - { - moreinfo->argc =3D newargv.argc; - moreinfo->argv =3D newargv; - } - if ((wincmdln || !real_path.iscygexec ()) - && !cmd.fromargv (newargv, real_path.get_win32 (), - real_path.iscygexec ())) - { - res =3D -1; - __leave; - } + res =3D -1; + __leave; + } =20 =20 - if (mode !=3D _P_OVERLAY || !real_path.iscygexec () - || !DuplicateHandle (GetCurrentProcess (), myself.shared_handle (), - GetCurrentProcess (), &moreinfo->myself_pinfo, - 0, TRUE, DUPLICATE_SAME_ACCESS)) - moreinfo->myself_pinfo =3D NULL; - else - VerifyHandle (moreinfo->myself_pinfo); - } + if (mode !=3D _P_OVERLAY || !real_path.iscygexec () + || !DuplicateHandle (GetCurrentProcess (), myself.shared_handle (), + GetCurrentProcess (), &moreinfo->myself_pinfo, + 0, TRUE, DUPLICATE_SAME_ACCESS)) + moreinfo->myself_pinfo =3D NULL; + else + VerifyHandle (moreinfo->myself_pinfo); =20 PROCESS_INFORMATION pi; pi.hProcess =3D pi.hThread =3D NULL; @@ -507,42 +486,37 @@ child_info_spawn::worker (const char *prog_arg, const= char *const *argv, } } =20 - if (null_app_name) - runpath =3D NULL; - else + USHORT len =3D real_path.get_nt_native_path ()->Length / sizeof (WCH= AR); + if (RtlEqualUnicodePathPrefix (real_path.get_nt_native_path (), + &ro_u_natp, FALSE)) { - USHORT len =3D real_path.get_nt_native_path ()->Length / sizeof (WCHAR); - if (RtlEqualUnicodePathPrefix (real_path.get_nt_native_path (), - &ro_u_natp, FALSE)) + runpath =3D 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 =3D 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] =3D=3D ':') - runpath +=3D 4; - else if (len < MAX_PATH + 6) - *(runpath +=3D 6) =3D L'\\'; - } + if (runpath[5] =3D=3D ':') + runpath +=3D 4; + else if (len < MAX_PATH + 6) + *(runpath +=3D 6) =3D 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; =20 - 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 =3D -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 =3D -1; + __leave; } =20 cygbench ("spawn-worker");