On 2024-11-14 14:52, Grisha Levit wrote:
if cwd lacks search permission, relative paths in the list
passed to savewd_process_files end up resolved relative to the dir used
to process any previous absolute path in the list

Thanks for reporting that. I installed the attached patch to Gnulib and propagated this to coreutils master. Please give it a try.

Is that the only test failure you're seeing?
From 1f36fee699926dbd04d4b97ca19fad29a847c3ae Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sun, 17 Nov 2024 22:58:13 -0800
Subject: [PATCH] savewd: set errnum for FINAL_STATE too

Problem reported by Grisha Levit in:
https://lists.gnu.org/r/bug-gnulib/2024-11/msg00137.html
* lib/savewd.c (savewd_finish):
Set errnum to 0 unless we were in an error state.
* lib/savewd.h (savewd_errno): Report final state errnum too.
---
 ChangeLog    | 9 +++++++++
 lib/savewd.c | 5 ++++-
 lib/savewd.h | 5 +++--
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 117c4eb345..1c62948b6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-11-17  Paul Eggert  <egg...@cs.ucla.edu>
+
+	savewd: set errnum for FINAL_STATE too
+	Problem reported by Grisha Levit in:
+	https://lists.gnu.org/r/bug-gnulib/2024-11/msg00137.html
+	* lib/savewd.c (savewd_finish):
+	Set errnum to 0 unless we were in an error state.
+	* lib/savewd.h (savewd_errno): Report final state errnum too.
+
 2024-11-17  Collin Funk  <collin.fu...@gmail.com>
 
 	doc: Prefer https urls where possible.
diff --git a/lib/savewd.c b/lib/savewd.c
index dee8524abe..debf9e9041 100644
--- a/lib/savewd.c
+++ b/lib/savewd.c
@@ -240,17 +240,20 @@ savewd_finish (struct savewd *wd)
 {
   switch (wd->state)
     {
-    case INITIAL_STATE:
     case ERROR_STATE:
       break;
 
     case FD_STATE:
     case FD_POST_CHDIR_STATE:
       close (wd->val.fd);
+      FALLTHROUGH;
+    case INITIAL_STATE:
+      wd->val.errnum = 0;
       break;
 
     case FORKING_STATE:
       assure (wd->val.child < 0);
+      wd->val.errnum = 0;
       break;
 
     default:
diff --git a/lib/savewd.h b/lib/savewd.h
index e74ba82d94..2cadbb6228 100644
--- a/lib/savewd.h
+++ b/lib/savewd.h
@@ -67,7 +67,8 @@ struct savewd
 
       /* savewd_finish has been called, so the application no longer
          cares whether the working directory is saved, and there is no
-         more work to do.  */
+         more work to do.  val.errnum contains the error number if
+         there was a serious problem, 0 otherwise.  */
       FINAL_STATE
     } state;
 
@@ -129,7 +130,7 @@ int savewd_restore (struct savewd *wd, int status);
 SAVEWD_INLINE int _GL_ATTRIBUTE_PURE
 savewd_errno (struct savewd const *wd)
 {
-  return (wd->state == ERROR_STATE ? wd->val.errnum : 0);
+  return wd->state < ERROR_STATE ? 0 : wd->val.errnum;
 }
 
 /* Deallocate any resources associated with WD.  A program that chdirs
-- 
2.43.0

Reply via email to