Skip to content

Update to Cygwin v3.4.3 - #125

Merged
lazka merged 39 commits into
msys2-3.4.3from
tentative/msys2-3.4.3
Dec 16, 2022
Merged

lazka merged 39 commits into
msys2-3.4.3from
tentative/msys2-3.4.3

Conversation

@dscho

@dscho dscho commented Dec 16, 2022

Copy link
Copy Markdown
Collaborator

This closes #124.

Range-diff relative to 3.4.2
  • 1: e354a56 = 1: 617e245 Add MSYS2 triplet

  • 2: 328c920 = 2: 6fbeca5 Fix msys library name in import libraries

  • 3: 7d2e081 ! 3: 90e20cd Rename dll from cygwin to msys

    @@ winsup/cygwin/Makefile.am: newlib_build=$(target_builddir)/newlib
     +# Parameters used in building the msys-2.0.dll.
      
     -DLL_NAME=cygwin1.dll
    --PRE_DLL_NAME=cygwin0.dll
    --DBG_DLL_NAME=cygwin1.dbg
     -NEW_DLL_NAME=new-cygwin1.dll
     -DEF_FILE=cygwin.def
     -LIB_NAME=libcygwin.a
     -TEST_LIB_NAME=libcygwin0.a
     +DLL_NAME=msys-2.0.dll
    -+PRE_DLL_NAME=msys0.dll
    -+DBG_DLL_NAME=msys-2.0.dbg
     +NEW_DLL_NAME=new-msys-2.0.dll
     +DEF_FILE=msys.def
     +LIB_NAME=libmsys-2.0.a
    @@ winsup/cygwin/Makefile.am: LIBSERVER = $(cygserver_blddir)/libcygserver.a
      
     -# cygwin dll
     +# msys-2.0 dll
    - $(PRE_DLL_NAME): $(LDSCRIPT) libdll.a $(VERSION_OFILES) $(LIBSERVER)\
    + $(NEW_DLL_NAME): $(LDSCRIPT) libdll.a $(VERSION_OFILES) $(LIBSERVER)\
      		  $(newlib_build)/libm.a $(newlib_build)/libc.a
      	$(AM_V_CXXLD)$(CXX) $(CXXFLAGS) \
      	-mno-use-libstdc-wrappers \
    @@ winsup/cygwin/Makefile.am: LIBSERVER = $(cygserver_blddir)/libcygserver.a
     -	-lgcc -lkernel32 -lntdll -Wl,-Map,cygwin.map
     +	-lgcc -lkernel32 -lntdll -Wl,-Map,msys.map
      
    --# create cygwin1.dbg file
    -+# create msys-2.0.dbg file
    - $(DBG_DLL_NAME): $(PRE_DLL_NAME)
    - 	$(AM_V_GEN)$(OBJCOPY) --add-gnu-debuglink=/dev/null \
    - 			      --only-keep-debug \
    -@@ winsup/cygwin/Makefile.am: $(NEW_DLL_NAME): $(PRE_DLL_NAME) $(DBG_DLL_NAME)
    - 			      --add-gnu-debuglink=$(DBG_DLL_NAME) \
    - 			      $(PRE_DLL_NAME) $(NEW_DLL_NAME)
    - 
     -# cygwin import library
     +# msys-2.0 import library
      toolopts=--cpu=@target_cpu@ --ar=@AR@ --as=@AS@ --nm=@NM@ --objcopy=@OBJCOPY@
    @@ winsup/cygwin/Makefile.am: all-local: $(LIB_NAME) $(TEST_LIB_NAME) $(SUBLIBS)
      	-rm -f $(DEF_FILE) sigfe.s
     -	-rm -f cygwin.sc cygdll.a cygwin.map
     +	-rm -f cygwin.sc msysdll.a msys.map
    - 	-rm -f $(PRE_DLL_NAME) $(DBG_DLL_NAME) $(NEW_DLL_NAME)
    + 	-rm -f $(NEW_DLL_NAME)
      	-rm -f $(LIB_NAME) $(TEST_LIB_NAME) $(SUBLIBS)
      	-rm -f version.cc
    -@@ winsup/cygwin/Makefile.am: install-libs:
    - 	@$(MKDIR_P) $(DESTDIR)$(bindir)
    - 	$(INSTALL_PROGRAM) $(NEW_DLL_NAME) $(DESTDIR)$(bindir)/$(DLL_NAME)
    - 	@$(MKDIR_P) $(DESTDIR)$(toollibdir)
    -+	$(INSTALL_DATA) msys-2.0.dbg $(DESTDIR)$(bindir)/msys-2.0.dbg
    - 	(cd $(DESTDIR)$(toollibdir) && ln -sf $(LIB_NAME) libg.a)
    - 
    - install-headers:
     @@ winsup/cygwin/Makefile.am: install-ldif:
      uninstall-hook: uninstall-headers uninstall-ldif uninstall-libs
      
  • 4: bbd256d = 4: 25aadb2 Add functionality for converting UNIX paths in arguments and environment variables to Windows form for native Win32 applications.

  • 5: 9a4906e = 5: 6f821ca Add functionality for changing OS name via MSYSTEM environment variables.

  • 6: a41f04c = 6: e75a8c9 - Move root to /usr. - Change sorting mount points. - By default mount without ACLs. - Can read /etc/fstab with short mount point format.

  • 7: 022a1b1 = 7: 05f0466 Instead of creating Cygwin symlinks, use deep copy by default

  • 8: 59fad92 = 8: 8fe4def Automatically rewrite TERM=msys to TERM=cygwin

  • 9: b12070a = 9: ac009a8 Do not convert environment for strace

  • 10: ff4b2b5 = 10: 33032fb path_conv: special-case root directory to have trailing slash

  • 11: efee836 = 11: 571b24a dcrt0.cc: Untangle allow_glob from winshell

  • 12: 769a69e = 12: ffb6a93 dcrt0.cc (globify): Don't quote literal strings differently when dos_spec

  • 13: 85b95c3 = 13: 0b5c7b2 strace.cc: Don't set MSYS=noglob

  • 14: af85de3 = 14: efa11ea Add debugging for build_argv

  • 15: 53202c3 = 15: 31a1e0d Add debugging for strace make_command_line

  • 16: 7d264a4 = 16: 762e50d environ.cc: New facility/environment variable MSYS2_ENV_CONV_EXCL

  • 17: 533ee9c = 17: e38a250 Fix native symbolic link spawn passing wrong arg0

  • 18: 2d811c5 = 18: 4ea54db strace --quiet: be really quiet

  • 19: 07e31bf = 19: 8412d07 Introduce the enable_pcon value for MSYS

  • 20: 9aef010 = 20: 8b924f8 popen: call /usr/bin/sh instead of /bin/sh

  • 21: 172103d = 21: 82e6120 Disable the 'cygwin' GitHub workflow

  • 22: c12497c = 22: 44a13ad CI: add a GHA for doing a basic build test

  • 23: 165668d = 23: 912d718 Set up a GitHub Action to keep in sync with Cygwin

  • 24: 93c604c = 24: 90424ef Expose full command-lines to other Win32 processes by default

  • 25: c6aee9a = 25: 03c7800 Do not show Error dialogs by default

  • 26: 1808dbe = 26: a512c03 Add a helper to obtain a function's address in kernel32.dll

  • 27: e193d90 = 27: 6d933a6 Emulate GenerateConsoleCtrlEvent() upon Ctrl+C

  • 28: e0a26e4 = 28: e208579 kill: kill Win32 processes more gently

  • 29: 7ad1589 = 29: 1adcf54 Cygwin: make option for native inner link handling.

  • 30: 8f0445d = 30: 8e4592a docs: skip building texinfo and PDF files

  • 31: b2c5463 = 31: 0d4ef02 install-libs: depend on the "toollibs"

  • 32: 3d286ce = 32: c38ef45 POSIX-ify the SHELL variable

  • 33: d783dd7 = 33: c2f5fa8 Handle ORIGINAL_PATH just like PATH

  • 34: 841a816 = 34: c694333 uname: allow setting the system name to CYGWIN

  • 35: 59b6d44 = 35: 9b1c9e9 Pass environment variables with empty values

  • 36: 805ffa6 = 36: 9cca911 Optionally disallow empty environment values again

  • 37: 69c01b1 = 37: 49d8e63 build_env(): respect the MSYS environment variable

  • 38: 428217d = 38: 449a2c5 When converting to a Unix path, avoid double trailing slashes

  • 39: aba92ee = 39: 0db1690 msys2_path_conv: pass PC_NOFULL to path_conv

  • 40: 6942fce < -: ---------- Revert "Cygwin: x86_64: add wmemset assembler entry point"

Diff relative to 3.4.2
diff --git a/winsup/cygwin/Makefile.am b/winsup/cygwin/Makefile.am
index 1de819e58e..673bb7b5e4 100644
--- a/winsup/cygwin/Makefile.am
+++ b/winsup/cygwin/Makefile.am
@@ -40,8 +40,6 @@ toolincludedir=$(tooldir)/include
 # Parameters used in building the msys-2.0.dll.
 
 DLL_NAME=msys-2.0.dll
-PRE_DLL_NAME=msys0.dll
-DBG_DLL_NAME=msys-2.0.dbg
 NEW_DLL_NAME=new-msys-2.0.dll
 DEF_FILE=msys.def
 LIB_NAME=libmsys-2.0.a
@@ -420,12 +418,20 @@ dirs = $(srcdir) $(srcdir)/fhandler $(srcdir)/lib $(srcdir)/libc $(srcdir)/math
 find_src_files = $(wildcard $(dir)/*.[chS]) $(wildcard $(dir)/*.cc)
 src_files := $(foreach dir,$(dirs),$(find_src_files))
 
+# Regenerate uname_version.c only if it doesn't exist or if it differs
+# from the former uname_version.c
 uname_version.c: .FORCE
 	$(AM_V_GEN)cd $(srcdir) && \
 	echo "const char *uname_dev_version = \
 	\"$$(git rev-parse --git-dir >/dev/null 2>&1 && \
 	     git describe --dirty | sed -e 's/cygwin-//')\";" \
-	     > $(abs_builddir)/uname_version.c
+	     > $(abs_builddir)/uname_version-pre.c && \
+	if [ -f $(abs_builddir)/uname_version.c ] && \
+	   cmp $(abs_builddir)/uname_version.c \
+	       $(abs_builddir)/uname_version-pre.c >/dev/null 2>&1 ; \
+	then :; else \
+	       mv $(abs_builddir)/uname_version-pre.c \
+		  $(abs_builddir)/uname_version.c; fi
 .FORCE:
 
 # mkvers.sh creates version.cc in the first place, winver.o always
@@ -575,7 +581,7 @@ $(LDSCRIPT): $(LDSCRIPT).in
 	$(AM_V_GEN)$(CC) -E - -P < $^ -o $@
 
 # msys-2.0 dll
-$(PRE_DLL_NAME): $(LDSCRIPT) libdll.a $(VERSION_OFILES) $(LIBSERVER)\
+$(NEW_DLL_NAME): $(LDSCRIPT) libdll.a $(VERSION_OFILES) $(LIBSERVER)\
 		  $(newlib_build)/libm.a $(newlib_build)/libc.a
 	$(AM_V_CXXLD)$(CXX) $(CXXFLAGS) \
 	-mno-use-libstdc-wrappers \
@@ -590,19 +596,6 @@ $(PRE_DLL_NAME): $(LDSCRIPT) libdll.a $(VERSION_OFILES) $(LIBSERVER)\
 	$(newlib_build)/libc.a \
 	-lgcc -lkernel32 -lntdll -Wl,-Map,msys.map
 
-# create msys-2.0.dbg file
-$(DBG_DLL_NAME): $(PRE_DLL_NAME)
-	$(AM_V_GEN)$(OBJCOPY) --add-gnu-debuglink=/dev/null \
-			      --only-keep-debug \
-			      $(PRE_DLL_NAME) \
-			      $(DBG_DLL_NAME)
-
-# create stripped release DLL, append .gnu_debuglink section
-$(NEW_DLL_NAME): $(PRE_DLL_NAME) $(DBG_DLL_NAME)
-	$(AM_V_GEN)$(OBJCOPY) -g \
-			      --add-gnu-debuglink=$(DBG_DLL_NAME) \
-			      $(PRE_DLL_NAME) $(NEW_DLL_NAME)
-
 # msys-2.0 import library
 toolopts=--cpu=@target_cpu@ --ar=@AR@ --as=@AS@ --nm=@NM@ --objcopy=@OBJCOPY@
 
@@ -675,7 +668,7 @@ clean-local:
 	-rm -f $(BUILT_SOURCES)
 	-rm -f $(DEF_FILE) sigfe.s
 	-rm -f cygwin.sc msysdll.a msys.map
-	-rm -f $(PRE_DLL_NAME) $(DBG_DLL_NAME) $(NEW_DLL_NAME)
+	-rm -f $(NEW_DLL_NAME)
 	-rm -f $(LIB_NAME) $(TEST_LIB_NAME) $(SUBLIBS)
 	-rm -f version.cc
 	-rm -f tlsoffsets
@@ -696,7 +689,6 @@ install-libs: install-toollibDATA
 	@$(MKDIR_P) $(DESTDIR)$(bindir)
 	$(INSTALL_PROGRAM) $(NEW_DLL_NAME) $(DESTDIR)$(bindir)/$(DLL_NAME)
 	@$(MKDIR_P) $(DESTDIR)$(toollibdir)
-	$(INSTALL_DATA) msys-2.0.dbg $(DESTDIR)$(bindir)/msys-2.0.dbg
 	(cd $(DESTDIR)$(toollibdir) && ln -sf $(LIB_NAME) libg.a)
 
 install-headers:
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index 2feb4bc3bb..5a8afb701d 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -11,7 +11,7 @@ details. */
    changes to the DLL and is mainly informative in nature. */
 
 #define CYGWIN_VERSION_DLL_MAJOR 3004
-#define CYGWIN_VERSION_DLL_MINOR 2
+#define CYGWIN_VERSION_DLL_MINOR 3
 
 /* CYGWIN_VERSION_DLL_COMBINED gives us a single number representing the
    combined DLL major and minor numbers. */
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 92b1fca320..e9dfd64486 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3186,6 +3186,65 @@ symlink_info::parse_device (const char *contents)
   return isdevice = true;
 }
 
+/* Probably we have a virtual drive input path and the resulting full path
+   starts with the substitution.  Retrieve the target path of the virtual
+   drive and try to revert what GetFinalPathNameByHandleW did to the
+   drive letter. */
+static bool
+revert_virtual_drive (PUNICODE_STRING upath, PUNICODE_STRING fpath,
+		      bool is_remote, ULONG ci_flag)
+{
+  /* Get the drive's target path. */
+  WCHAR drive[3] = {(WCHAR) towupper (upath->Buffer[4]), L':', L'\0'};
+  WCHAR target[MAX_PATH];
+  UNICODE_STRING tpath;
+  WCHAR *p;
+
+  DWORD remlen = QueryDosDeviceW (drive, target, MAX_PATH);
+  if (remlen < 3)
+    return false;
+  remlen -= 2; /* Two L'\0' */
+
+  if (target[remlen - 1] == L'\\')
+    remlen--;
+  RtlInitCountedUnicodeString (&tpath, target, remlen * sizeof (WCHAR));
+
+  const USHORT uncp_len = is_remote ? ro_u_uncp.Length / sizeof (WCHAR) - 1 : 0;
+
+  if (is_remote)
+    {
+      /* target path starts with \??\UNC\. */
+      if (RtlEqualUnicodePathPrefix (&tpath, &ro_u_uncp, TRUE))
+	{
+	  remlen -= uncp_len;
+	  p = target + uncp_len;
+	}
+      /* target path starts with \Device\<redirector>. */
+      else if ((p = wcschr (target, L';'))
+	       && p + 3 < target + remlen
+	       && wcsncmp (p + 1, drive, 2) == 0
+	       && (p = wcschr (p + 3, L'\\')))
+	remlen -= p - target;
+      else
+	return false;
+      if (wcsncasecmp (fpath->Buffer + uncp_len, p, remlen))
+	return false;
+    }
+  else if (!RtlEqualUnicodePathPrefix (fpath, &tpath, TRUE))
+    return false;
+  /* Replace fpath with source drive letter and append reminder of
+     final path after skipping target path */
+  fpath->Buffer[4] = drive[0]; /* Drive letter */
+  fpath->Buffer[5] = L':';
+  WCHAR *to = fpath->Buffer + 6; /* Next to L':' */
+  WCHAR *from = fpath->Buffer + uncp_len + remlen;
+  memmove (to, from, (wcslen (from) + 1) * sizeof (WCHAR));
+  fpath->Length -= (from - to) * sizeof (WCHAR);
+  if (RtlEqualUnicodeString (upath, fpath, !!ci_flag))
+    return false;
+  return true;
+}
+
 /* Check if PATH is a symlink.  PATH must be a valid Win32 path name.
 
    If PATH is a symlink, put the value of the symlink--the file to
@@ -3505,6 +3564,14 @@ restart:
 	  continue;
 	}
 
+      /* Consider the situation where a virtual drive points to a native
+         symlink.  Opening the virtual drive with FILE_OPEN_REPARSE_POINT
+	 actually opens the symlink.  If this symlink points to another
+	 directory using a relative path, symlink evaluation goes totally
+	 awry.  We never want a virtual drive evaluated as symlink. */
+      if (upath.Length <= 14)
+	  goto file_not_symlink;
+
       /* Reparse points are potentially symlinks.  This check must be
 	 performed before checking the SYSTEM attribute for sysfile
 	 symlinks, since reparse points can have this flag set, too. */
@@ -3653,80 +3720,38 @@ restart:
 	      RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR));
 	      if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
 	        {
-		  /* Check if the final path is an UNC path and the incoming
-		     path isn't.  If so... */
-		  if (RtlEqualUnicodePathPrefix (&fpath, &ro_u_uncp, TRUE)
-		      && !RtlEqualUnicodePathPrefix (&upath, &ro_u_uncp, TRUE))
+		  /* If the incoming path is a local drive letter path... */
+		  if (!RtlEqualUnicodePathPrefix (&upath, &ro_u_uncp, TRUE))
 		    {
-		      /* ...get the remote path, replace remote path
-			 with drive letter, check again. */
-		      WCHAR drive[3] =
-			{(WCHAR) towupper (upath.Buffer[4]), L':', L'\0'};
-		      WCHAR remote[MAX_PATH];
-
-		      DWORD remlen = QueryDosDeviceW (drive, remote, MAX_PATH);
-		      if (remlen < 3)
-			goto file_not_symlink; /* fallback */
-		      remlen -= 2; /* Two L'\0' */
-
-		      if (remote[remlen - 1] == L'\\')
-			remlen--;
-		      WCHAR *p;
-		      UNICODE_STRING rpath;
-		      RtlInitCountedUnicodeString (&rpath, remote,
-						   remlen * sizeof (WCHAR));
-		      const USHORT uncp_len =
-			ro_u_uncp.Length / sizeof (WCHAR) - 1;
-		      if (RtlEqualUnicodePathPrefix (&rpath, &ro_u_uncp, TRUE))
+		      /* ...and the final path is an UNC path, revert to the
+			 drive letter path syntax. */
+		      if (RtlEqualUnicodePathPrefix (&fpath, &ro_u_uncp, TRUE))
 			{
-			  remlen -= uncp_len;
-			  p = remote + uncp_len;
+			  if (!revert_virtual_drive (&upath, &fpath, true,
+						     ci_flag))
+			    goto file_not_symlink;
+			}
+		      /* ...otherwise, if the final path changes the drive
+			 letter, let revert_virtual_drive check for a
+			 virtual drive and revert that. */
+		      else if (upath.Buffer[5] == L':'
+			       && (WCHAR) towupper (upath.Buffer[4])
+				  != (WCHAR) towupper (fpath.Buffer[4]))
+			{
+			  if (!revert_virtual_drive (&upath, &fpath, false,
+						     ci_flag))
+			    goto file_not_symlink;
 			}
-		      else if ((p = wcschr (remote, L';'))
-			       && p + 3 < remote + remlen
-			       && wcsncmp (p + 1, drive, 2) == 0
-			       && (p = wcschr (p + 3, L'\\')))
-			remlen -= p - remote;
-		      else
-			goto file_not_symlink; /* fallback */
-		      if (wcsncasecmp (fpath.Buffer + uncp_len, p, remlen))
-			goto file_not_symlink; /* fallback (not expected) */
-		      /* Hackfest */
-		      fpath.Buffer[4] = drive[0]; /* Drive letter */
-		      fpath.Buffer[5] = L':';
-		      WCHAR *to = fpath.Buffer + 6; /* Next to L':' */
-		      WCHAR *from = fpath.Buffer + uncp_len + remlen;
-		      memmove (to, from,
-			       (wcslen (from) + 1) * sizeof (WCHAR));
-		      fpath.Length -= (from - to) * sizeof (WCHAR);
-		      if (RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
-			goto file_not_symlink;
 		    }
 		  issymlink = true;
 		  /* upath.Buffer is big enough and unused from this point on.
 		     Reuse it here, avoiding yet another buffer allocation. */
 		  char *nfpath = (char *) upath.Buffer;
 		  sys_wcstombs (nfpath, NT_MAX_PATH, fpbuf);
-		  res = posixify (nfpath);
-
-		  /* If the incoming path consisted of a drive prefix only,
-		     we just handle a virtual drive, created with, e.g.
-
-		       subst X: C:\foo\bar
-
-		     Treat it like a symlink.  This is required to tell an
-		     lstat caller that the "drive" is actually pointing
-		     somewhere else, thus, it's a symlink in POSIX speak. */
-		  if (upath.Length == 14)	/* \??\X:\ */
-		    {
-		      fileattr &= ~FILE_ATTRIBUTE_DIRECTORY;
-		      path_flags |= PATH_SYMLINK;
-		    }
 		  /* For final paths differing in inner path components return
 		     length as negative value.  This informs path_conv::check
 		     to skip realpath handling on the last path component. */
-		  else
-		    res = -res;
+		  res = -posixify (nfpath);
 		  break;
 	        }
 	    }
diff --git a/winsup/cygwin/release/3.4.3 b/winsup/cygwin/release/3.4.3
new file mode 100644
index 0000000000..eb1d6c6388
--- /dev/null
+++ b/winsup/cygwin/release/3.4.3
@@ -0,0 +1,9 @@
+Bug Fixes
+---------
+
+- Fix path handling to make sure virtual drives are never treated
+  as symlinks.
+  Addresses: https://cygwin.com/pipermail/cygwin/2022-December/252665.html
+
+- Revert incorrect optimization of wmemset()
+  Addresses: https://cygwin.com/pipermail/cygwin/2022-December/252699.html

The reason for the range-diff divergence: 99bb3e9

Alexpux and others added 30 commits December 16, 2022 16:37
Cygwin's speclib doesn't handle dashes or dots. However, we are about to
rename the output file name from `cygwin1.dll` to `msys-2.0.dll`.

Let's preemptively fix up all the import libraries that would link
against `msys_2_0.dll` to correctly link against `msys-2.0.dll` instead.
…ent variables to Windows form for native Win32 applications.
…t without ACLs. - Can read /etc/fstab with short mount point format.
The new `winsymlinks` mode `deepcopy` (which is made the default) lets
calls to `symlink()` create (deep) copies of the source file/directory.

This is necessary because unlike Cygwin, MSYS2 does not try to be its
own little ecosystem that lives its life separate from regular Win32
programs: the latter have _no idea_ about Cygwin-emulated symbolic links
(i.e. system files whose contents start with `!<symlink>\xff\xfe` and
the remainder consists of the NUL-terminated, UTF-16LE-encoded symlink
target).

To support Cygwin-style symlinks, the new mode `sysfile` is introduced.

Co-authored-by: Johannes Schindelin <[email protected]>
With MSys1, it was necessary to set the TERM variable to "msys". To
allow for a smooth transition from MSys1 to MSys2, let's simply handle
TERM=msys as if the user had not specified TERM at all and wanted us to
use our preferred TERM value.
Strace is a Windows program so MSYS2 will convert all arguments and environment vars and that makes debugging msys2 software with strace very tricky.
When converting `/c/` to `C:\`, the trailing slash is actually really
necessary, as `C:` is not an absolute path.

We must be very careful to do this only for root directories, though. If
we kept the trailing slash also for, say, `/y/directory/`, we would run
into the following issue: On FAT file systems, the normalized path is
used to fake inode numbers. As a result, `Y:\directory\` and
`Y:\directory` have different inode numbers!!!

This would result in very non-obvious symptoms. Back when we were too
careless about keeping the trailing slash, it was reported to the Git
for Windows project that the `find` and `rm` commands can error out on
FAT file systems with very confusing "No such file or directory" errors,
for no good reason.

During the original investigation, Vasil Minkov pointed out in
git-for-windows/git#1497 (comment),
that this bug had been fixed in Cygwin as early as 1997... and the bug
was unfortunately reintroduced into early MSYS2 versions.

Signed-off-by: Johannes Schindelin <[email protected]>
Otherwise if globbing is allowed and we get called from a
Windows program, build_argv thinks we've been called from
a Cygwin program.
…spec

Reverts 25ba8f3. I can't figure out what
the intention was. I'm sure I'll find out soon enough when everything breaks.

This change means that input of:
  '"C:/test.exe SOME_VAR=\"literal quotes\""'

becomes:
  'C:/test.exe SOME_VAR="literal quotes"'

instead of:
  'C:/test.exe SOME_VAR=\literal quotes\'

.. which is at least consistent with the result for:
  '"no_drive_or_colon SOME_VAR=\"literal quotes\""'

The old result of course resulted in the quoted string being split into
two arguments at the space which is clearly not intended.

I *guess* backslashes in dos paths may have been the issue here?
If so I don't care since we should not use them, ever, esp. not at
the expense of sensible forward-slash-containing input.
Commit message for this code was:

* strace.cc (create_child): Set CYGWIN=noglob when starting new process so that

  Cygwin will leave already-parsed the command line alonw."

I can see no reason for it and it badly breaks the ability to use
strace.exe to investigate calling a Cygwin program from a Windows
program, for example:
strace mingw32-make.exe
.. where mingw32-make.exe finds sh.exe and uses it as the shell.
The reason it badly breaks this use-case is because dcrt0.cc depends
on globbing to happen to parse commandlines from Windows programs;
irrespective of whether they contain any glob patterns or not.

See quoted () comment:
"This must have been run from a Windows shell, so preserve
 quotes for globify to play with later."
Works very much like MSYS2_ARG_CONV_EXCL. In fact it uses the same
function, arg_heuristic_with_exclusions (). Also refactors parsing
the env. variables to use new function, string_split_delimited ().

The env. that is searched through is the merged (POSIX + Windows)
one. It remains to be seen if this should be made an option or not.

This feature was prompted because the R language (Windows exe) calls
bash to run configure.win, which then calls back into R to read its
config variables (LOCAL_SOFT) and when this happens, msys2-runtime
converts R_ARCH from "/x64" to an absolute Windows path and appends
it to another absolute path, R_HOME, forming an invalid path.
The biggest problem with strace spitting out `create_child: ...` despite
being asked to be real quiet is that its output can very well interfere
with scripts' operations.

For example, when running any of Git for Windows' shell scripts with
`GIT_STRACE_COMMANDS=/path/to/logfile` (which is sadly an often needed
debugging technique while trying to address the many MSYS2 issues Git for
Windows faces), any time the output of any command is redirected into a
variable, it will include that `create_child: ...` line, wreaking havoc
with Git's expectations.

So let's just really be quiet when we're asked to be quiet.

Signed-off-by: Johannes Schindelin <[email protected]>
It is simply the negation of `disable_pcon`, i.e. `MSYS=enable_pcon` is
equivalent to `MSYS=nodisable_pcon` (the former is slightly more
intuitive than the latter) and likewise `MSYS=noenable_pcon` is
equivalent to `MSYS=disable_pcon` (here, the latter is definitely more
intuitive than the former).

This is needed because we just demoted the pseudo console feature to be
opt-in instead of opt-out, and it would be awkward to recommend to users
to use "nodisable_pcon"... "nodisable" is not even a verb.

Signed-off-by: Johannes Schindelin <[email protected]>
We mount /usr/bin to /bin, but in a chroot this is broken and we
have no /bin, so try to use the real path.

chroot is used by pacman to run install scripts when called with --root
and this broke programs in install scripts calling popen()
(install-info from texinfo for example)

There are more paths hardcoded to /bin in cygwin which might also be broken
in this scenario, so this maybe should be extended to all of them.
It does not work at all. For example, `rpm -E %fedora` says that there
should be version 33 of rpmsphere at
https://github.com/rpmsphere/noarch/tree/master/r, but there is only
version 32.

Another thing that is broken: Cygwin now assumes that a recent
mingw-w64-headers version is available, but Fedora apparently only
offers v7.0.0, which is definitely too old to accommodate for the
expectation of cygwin/cygwin@c1f7c4d1b6d7.

Signed-off-by: Johannes Schindelin <[email protected]>
This will help us by automating an otherwise tedious task.

Signed-off-by: Johannes Schindelin <[email protected]>
In the Cygwin project, it was decided that the command-line of Cygwin
processes, as shown in the output of `wmic process list`, would suffer
from being truncated to 32k (and is transmitted to the child process via
a different mechanism, anyway), and therefore only the absolute path of
the executable is shown by default.

Users who would like to see the full command-line (even if it is
truncated) are expected to set `CYGWIN=wincmdln` (or, in MSYS2's case,
`MSYS=wincmdln`).

Seeing as MSYS2 tries to integrate much better with the surrounding
Win32 ecosystem than Cygwin, it makes sense to turn this on by default.

Users who wish to suppress it can still set `MSYS=nowincmdln`.

Signed-off-by: Johannes Schindelin <[email protected]>
In #18, we discussed a change
that would allow default Windows error handling of spawned processes to
kick in (such as registered JIT debuggers). We even agreed that it would
make sense to hide this functionality behind a flag, `winjitdebug`.

However, when this got upstreamed as 21ec498 (cygwin: use
CREATE_DEFAULT_ERROR_MODE in spawn, 2020-12-09), that flag was deemed
unnecessary.

But it would appear that it _is_ necessary: As reported in
msys2/MSYS2-packages#2414 (comment)
this new behavior is pretty disruptive e.g. in CI scenarios.

So let's introduce that `winjitdebug` flag (settable via the environment
variable `MSYS`) at long last.

Signed-off-by: Johannes Schindelin <[email protected]>
In particular, we are interested in the address of the CtrlRoutine
and the ExitProcess functions. Since kernel32.dll is loaded first thing,
the addresses will be the same for all processes (matching the
CPU architecture, of course).

This will help us with emulating SIGINT properly (by not sending signals
to *all* processes attached to the same Console, as
GenerateConsoleCtrlEvent() would do).

Co-authored-by: Naveen M K <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
This patch is heavily inspired by the Git for Windows' strategy in
handling Ctrl+C.

When a process is terminated via TerminateProcess(), it has no chance to
do anything in the way of cleaning up. This is particularly noticeable
when a lengthy Git for Windows process tries to update Git's index file
and leaves behind an index.lock file. Git's idea is to remove the stale
index.lock file in that case, using the signal and atexit handlers
available in Linux. But those signal handlers never run.

Note: this is not an issue for MSYS2 processes because MSYS2 emulates
Unix' signal system accurately, both for the process sending the kill
signal and the process receiving it. Win32 processes do not have such a
signal handler, though, instead MSYS2 shuts them down via
`TerminateProcess()`.

For a while, Git for Windows tried to use a gentler method, described in
the Dr Dobb's article "A Safer Alternative to TerminateProcess()" by
Andrew Tucker (July 1, 1999),
http://www.drdobbs.com/a-safer-alternative-to-terminateprocess/184416547

Essentially, we injected a new thread into the running process that does
nothing else than running the ExitProcess() function.

However, this was still not in line with the way CMD handles Ctrl+C: it
gives processes a chance to do something upon Ctrl+C by calling
SetConsoleCtrlHandler(), and ExitProcess() simply never calls that
handler.

So for a while we tried to handle SIGINT/SIGTERM by attaching to the
console of the command to interrupt, and generating the very same event
as CMD does via GenerateConsoleCtrlEvent().

This method *still* was not correct, though, as it would interrupt
*every* process attached to that Console, not just the process (and its
children) that we wanted to signal. A symptom was that hitting Ctrl+C
while `git log` was shown in the pager would interrupt *the pager*.

The method we settled on is to emulate what GenerateConsoleCtrlEvent()
does, but on a process by process basis: inject a remote thread and call
the (private) function kernel32!CtrlRoutine.

To obtain said function's address, we use the dbghelp API to generate a
stack trace from a handler configured via SetConsoleCtrlHandler() and
triggered via GenerateConsoleCtrlEvent(). To avoid killing each and all
processes attached to the same Console as the MSYS2 runtime, we modify
the cygwin-console-helper to optionally print the address of
kernel32!CtrlRoutine to stdout, and then spawn it with a new Console.

Note that this also opens the door to handling 32-bit process from a
64-bit MSYS2 runtime and vice versa, by letting the MSYS2 runtime look
for the cygwin-console-helper.exe of the "other architecture" in a
specific place (we choose /usr/libexec/, as it seems to be the
convention for helper .exe files that are not intended for public
consumption).

The 32-bit helper implicitly links to libgcc_s_dw2.dll and
libwinpthread-1.dll, so to avoid cluttering /usr/libexec/, we look for
the helped of the "other" architecture in the corresponding mingw32/ or
mingw64/ subdirectory.

Among other bugs, this strategy to handle Ctrl+C fixes the MSYS2 side of
the bug where interrupting `git clone https://...` would send the
spawned-off `git remote-https` process into the background instead of
interrupting it, i.e. the clone would continue and its progress would be
reported mercilessly to the console window without the user being able
to do anything about it (short of firing up the task manager and killing
the appropriate task manually).

Note that this special-handling is only necessary when *MSYS2* handles
the Ctrl+C event, e.g. when interrupting a process started from within
MinTTY or any other non-cmd-based terminal emulator. If the process was
started from within `cmd.exe`'s terminal window, child processes are
already killed appropriately upon Ctrl+C, by `cmd.exe` itself.

Also, we can't trust the processes to end it's subprocesses upon receiving
Ctrl+C. For example, `pip.exe` from `python-pip` doesn't kill the python
it lauches (it tries to but fails), and I noticed that in cmd it kills python
also correctly, which mean we should kill all the process using
`exit_process_tree`.

Co-authored-by: Naveen M K <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
This change is the equivalent to the change to the Ctrl+C handling we
just made.

Co-authored-by: Naveen M K <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
This code has been causing issues with SUBST and mapped network drives,
so add an option (defaulted to on) which can be used to disable it where
needed.  MSYS=nonativeinnerlinks
The MSYS2 packages lack the infrastructure to build those.

Signed-off-by: Johannes Schindelin <[email protected]>
dscho and others added 9 commits December 16, 2022 16:40
Before symlinking libg.a, we need the symlink source `libmsys-2.0.a`: in
MSYS2, we copy by default (if we were creating Unix-style symlinks, the
target would not have to exist before symlinking, but when copying we do
need the source _right away_).

Signed-off-by: Johannes Schindelin <[email protected]>
When calling a non-MSys2 binary, all of the environment is converted from
POSIX to Win32, including the SHELL environment variable. In Git for
Windows, for example, `SHELL=/usr/bin/bash` is converted to
`SHELL=C:\Program Files\Git\usr\bin\bash.exe` when calling the `git.exe`
binary. This is appropriate because non-MSys2 binaries would not handle
POSIX paths correctly.

Under certain circumstances, however, `git.exe` calls an *MSys2* binary in
turn, such as `git config --edit` calling `vim.exe` unless Git is
configured to use another editor specifically.

Now, when this "improved vi" calls shell commands, it uses that $SHELL
variable *without quoting*, resulting in a nasty error:

	C:\Program: No such file or directory

Many other programs behave in the same manner, assuming that $SHELL does
not contain spaces and hence needs no quoting, unfortunately including
some of Git's own scripts.

Therefore let's make sure that $SHELL gets "posified" again when entering
MSys2 programs.

Earlier attempts by Git for Windows contributors claimed that adding
`SHELL` to the `conv_envvars` array does not have the intended effect.
These reports just missed that the `conv_start_chars` array (which makes
the code more performant) needs to be adjusted, too.

Note that we set the `immediate` flag to `true` so that the environment
variable is set immediately by the MSys2 runtime, i.e. not only spawned
processes will see the POSIX-ified `SHELL` variable, but the MSys2 runtime
*itself*, too.

This fixes git-for-windows/git#542,
git-for-windows/git#498, and
git-for-windows/git#468.

Signed-off-by: Johannes Schindelin <[email protected]>
MSYS2 recently introduced that hack where the ORIGINAL_PATH variable is
set to the original PATH value in /etc/profile, unless previously set.
In Git for Windows' default mode, that ORIGINAL_PATH value is the used
to define the PATH variable explicitly.

So far so good.

The problem: when calling from inside an MSYS2 process (such as Bash) a
MINGW executable (such as git.exe) that then calls another MSYS2
executable (such as bash.exe), that latter call will try to re-convert
ORIGINAL_PATH after the previous call converted ORIGINAL_PATH from POSIX
to Windows paths. And this conversion may very well fail, e.g. when the
path list contains mixed semicolons and colons.

So let's just *force* the MSYS2 runtime to handle ORIGINAL_PATH in the
same way as the PATH variable (which conversion works, as we know).

Signed-off-by: Johannes Schindelin <[email protected]>
We are currently trying to move our cygwin build environment closer
to cygwin and some autotools/bash based build systems call "uname -s"
to figure out the OS and in many cases only handle the cygwin case, so
we have to patch them.

With this instead of patching we can set MSYSTEM=CYGWIN and change
uname output that way.

The next step would be to always output CYGWIN in an msys env by default,
but for now this allows us to get rid of all the patches without
affecting users.
There is a difference between an empty value and an unset environment
variable. We should not confuse both; If the user wants to unset an
environment variable, they can certainly do so (unsetenv(3), or in the
shell: 'unset ABC').

This fixes Git's t3301-notes.sh, which overrides environment variables
with empty values.

Signed-off-by: Johannes Schindelin <[email protected]>
We just disabled the code that skips environment variables whose values
are empty.

However, this code was introduced a long time ago into Cygwin in
d6b1ac7 (* environ.cc (build_env): Don't put an empty environment
variable into the environment.  Optimize use of "len". * errno.cc
(ERROR_MORE_DATA): Translate to EMSGSIZE rather than EAGAIN.,
2006-09-07), seemingly without any complaints.

Meaning: There might very well be use cases out there where it makes
sense to skip empty-valued environment variables.

Therefore, it seems like a good idea to have a "knob" to turn it back
on. With this commit, we introduce such a knob: by setting
`noemptyenvvalues` the `MSYS` variable (or appending it if that variable
is already set), users can tell the MSYS2 runtime to behave just like in
the olden times.

Signed-off-by: Johannes Schindelin <[email protected]>
With this commit, you can call

	MSYS=noemptyenvvalues my-command

and it does what is expected: to pass no empty-valued environment
variables to `my-command`.

Signed-off-by: Johannes Schindelin <[email protected]>
When calling `cygpath -u C:/msys64/` in an MSYS2 setup that was
installed into `C:/msys64/`, the result should be `/`, not `//`.

Let's ensure that we do not append another trailing slash if the
converted path already ends in a slash.

This fixes #112

Signed-off-by: Johannes Schindelin <[email protected]>
In theory this doesn't make a difference because posix_to_win32_path()
is only called with rooted/absolute paths, but as pointed out in
#103 PC_NOFULL will preserve
the trailing slash of unix paths (for some reason).

See "cygpath -m /bin/" (preserved) vs "cygpath -am /bin/" (dropped)

One use case where we need to trailing slashes to be preserved is the GCC build
system:
https://github.com/gcc-mirror/gcc/blob/6d82e0fea5f988e829912a/gcc/Makefile.in#L2314

The Makefile appends a slash to the prefixes and the C code doing relocation will
treat the path as a directory if there is a trailing slash. See
msys2/MINGW-packages#14173 for details.

With this change all our MSYS2 path_conv tests pass again.
@dscho
dscho requested a review from lazka December 16, 2022 15:47
@dscho dscho self-assigned this Dec 16, 2022
@dscho dscho mentioned this pull request Dec 16, 2022
@dscho

dscho commented Dec 16, 2022

Copy link
Copy Markdown
Collaborator Author

Oh, and the diff between Cygwin 3.4.2 and 3.4.3 is here: cygwin-3.4.2...cygwin-3.4.3

@lazka lazka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@lazka
lazka merged commit 25b1cd1 into msys2-3.4.3 Dec 16, 2022
lazka added a commit to lazka/MSYS2-packages that referenced this pull request Dec 16, 2022
@lazka

lazka commented Dec 16, 2022

Copy link
Copy Markdown
Member

-> msys2/MSYS2-packages#3413

lazka added a commit to lazka/MSYS2-packages that referenced this pull request Dec 16, 2022
@dscho
dscho deleted the tentative/msys2-3.4.3 branch December 17, 2022 08:52
vszakats added a commit to curl/curl that referenced this pull request Oct 10, 2026
The root cause for unexplained test428 failures was older MSYS2/Cygwin
runtimes filtering out set but empty environment variables when a Cygwin
process launches a non-Cygwin one. In curl this happens when runtests
launches the native Windows curl tool. MSYS2 3.4.2+ (2022-12-16) no
longer does this filtering by default. In CI the affected environments
are AppVeyor CI's Visual Studio 2015/2017/2019 images, which use MSYS2
3.0.7 (newer images have 3.6.5 and 3.6.9).

Detect this condition in runtests and skip the test when unsupported.

Fixing:
```
=== Start of file stderr428
 curl: Variable 'BLANK' import fail, not set
 curl: log/17/cmd:3 config file option '--variable' variable expansion failure
 curl: option -K: variable expansion failure
 curl: try 'curl --help' or 'curl --manual' for more information
=== End of file stderr428
```

Refs:
 ```
2022-09-24 - Changed behavior for empty env vars
Empty environment variables are no longer removed when starting a new non-cygwin process.
```
https://www.msys2.org/news/#2022-09-24-changed-behavior-for-empty-env-vars
msys2/msys2-runtime@59b6d44
msys2/msys2-runtime#125

Notes:
- I did my best to figure out the cutoff version, but could only actually
  test that 3.6.5+ and 3.0.7. Please adjust if inaccurate.
- MSYS2 allows setting `MSYS=noemptyenvvalues` to disable the new
  behavior and breaking test428. This patch does not address this
  exception.
- Cygwin and MSYS2 are considered interchangable in the codebase,
  this patch included. However, AFAICT Cygwin did not receive this
  particular fix as of today's Cygwin master. Let us know if this causes
  an issue.

Follow-up to 0774051 #17991
Follow-up to 7cf8414
Cherry-picked from #23306

Closes #23345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants