summaryrefslogtreecommitdiff
path: root/system/coreutils/revert-gnulib-getcwd-speedup-linux.patch
diff options
context:
space:
mode:
authorZach van Rijn <me@zv.io>2023-04-10 09:14:53 +0000
committerZach van Rijn <me@zv.io>2023-04-10 09:30:49 +0000
commitf9f1195d1490e17a72b1f2fda12aeedf1aec8d8f (patch)
tree06a82726a932ff14d4961edb077f7f14f7385b96 /system/coreutils/revert-gnulib-getcwd-speedup-linux.patch
parentdb3f3501151c012751012659e149a7f80e4efd54 (diff)
downloadpackages-f9f1195d1490e17a72b1f2fda12aeedf1aec8d8f.tar.gz
packages-f9f1195d1490e17a72b1f2fda12aeedf1aec8d8f.tar.bz2
packages-f9f1195d1490e17a72b1f2fda12aeedf1aec8d8f.tar.xz
packages-f9f1195d1490e17a72b1f2fda12aeedf1aec8d8f.zip
system/coreutils: revert gnulib getcwd optimization. fixes #985, #987.
This commit reverts a commit in gnulib in coreutils that caused a functional change between coreutils { 9.1 --> 9.2 }. tl;dr: * on some systems, `(cd //tmp && /bin/pwd)` may return '/tmp' or '//tmp' depending on several factors; this is generally OK * in a musl-based Adélie environment, we identified a change in this behavior between coreutils updates during testing * the functional change was bisected to coreutils commit d42e4e9191abb818fc0e28507085a3945eed1477, which itself bumps the gnulib submodule, and is unrelated to coreutils itself * gnulib commit 356a414e8c15ef3f8cc7b7157427c8ce9a9f7c1b has been identified as the culprit for this functional change See #987 for more information.
Diffstat (limited to 'system/coreutils/revert-gnulib-getcwd-speedup-linux.patch')
-rw-r--r--system/coreutils/revert-gnulib-getcwd-speedup-linux.patch92
1 files changed, 92 insertions, 0 deletions
diff --git a/system/coreutils/revert-gnulib-getcwd-speedup-linux.patch b/system/coreutils/revert-gnulib-getcwd-speedup-linux.patch
new file mode 100644
index 000000000..fa8f66395
--- /dev/null
+++ b/system/coreutils/revert-gnulib-getcwd-speedup-linux.patch
@@ -0,0 +1,92 @@
+From d598f8169bbc9178c59d35f0df95637a70d3377f Mon Sep 17 00:00:00 2001
+From: Zach van Rijn <me@zv.io>
+Date: Mon, 10 Apr 2023 04:09:56 -0500
+Subject: [PATCH] Revert "getcwd: Speed up on Linux. Add support for Android."
+
+This reverts commit 356a414e8c15ef3f8cc7b7157427c8ce9a9f7c1b.
+
+diff --git a/lib/getcwd.c b/lib/getcwd.c
+index 0530630c43..04b8d2df39 100644
+--- a/lib/getcwd.c
++++ b/lib/getcwd.c
+@@ -173,9 +173,6 @@ __getcwd_generic (char *buf, size_t size)
+ #if HAVE_OPENAT_SUPPORT
+ int fd = AT_FDCWD;
+ bool fd_needs_closing = false;
+-# if defined __linux__
+- bool proc_fs_not_mounted = false;
+-# endif
+ #else
+ char dots[DEEP_NESTING * sizeof ".." + BIG_FILE_NAME_COMPONENT_LENGTH + 1];
+ char *dotlist = dots;
+@@ -441,67 +438,6 @@ __getcwd_generic (char *buf, size_t size)
+
+ thisdev = dotdev;
+ thisino = dotino;
+-
+-#if HAVE_OPENAT_SUPPORT
+- /* On some platforms, a system call returns the directory that FD points
+- to. This is useful if some of the ancestor directories of the
+- directory are unreadable, because in this situation the loop that
+- climbs up the ancestor hierarchy runs into an EACCES error.
+- For example, in some Android app, /data/data/com.termux is readable,
+- but /data/data and /data are not. */
+-# if defined __linux__
+- /* On Linux, in particular, if /proc is mounted,
+- readlink ("/proc/self/fd/<fd>")
+- returns the directory, if its length is < 4096. (If the length is
+- >= 4096, it fails with error ENAMETOOLONG, even if the buffer that we
+- pass to the readlink function would be large enough.) */
+- if (!proc_fs_not_mounted)
+- {
+- char namebuf[14 + 10 + 1];
+- sprintf (namebuf, "/proc/self/fd/%u", (unsigned int) fd);
+- char linkbuf[4096];
+- ssize_t linklen = readlink (namebuf, linkbuf, sizeof linkbuf);
+- if (linklen < 0)
+- {
+- if (errno != ENAMETOOLONG)
+- /* If this call was not successful, the next one will likely be
+- not successful either. */
+- proc_fs_not_mounted = true;
+- }
+- else
+- {
+- dirroom = dirp - dir;
+- if (dirroom < linklen)
+- {
+- if (size != 0)
+- {
+- __set_errno (ERANGE);
+- goto lose;
+- }
+- else
+- {
+- char *tmp;
+- size_t oldsize = allocated;
+-
+- allocated += linklen - dirroom;
+- if (allocated < oldsize
+- || ! (tmp = realloc (dir, allocated)))
+- goto memory_exhausted;
+-
+- /* Move current contents up to the end of the buffer. */
+- dirp = memmove (tmp + dirroom + (allocated - oldsize),
+- tmp + dirroom,
+- oldsize - dirroom);
+- dir = tmp;
+- }
+- }
+- dirp -= linklen;
+- memcpy (dirp, linkbuf, linklen);
+- break;
+- }
+- }
+-# endif
+-#endif
+ }
+
+ if (dirstream && __closedir (dirstream) != 0)
+--
+2.25.1
+