]> Savannah Git Hosting - gnulib.git/commitdiff
savewd: set errnum for FINAL_STATE too
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 18 Nov 2024 06:58:13 +0000 (22:58 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 18 Nov 2024 06:58:40 +0000 (22:58 -0800)
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
lib/savewd.c
lib/savewd.h

index 117c4eb34517008da6dcf2e8e9f3dd610de60c3b..1c62948b6ba9f6664afe65342e3a976e601173ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-11-17  Paul Eggert  <eggert@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.funk1@gmail.com>
 
        doc: Prefer https urls where possible.
index dee8524abeabeafdd3a7c7d0c74994e85845a96b..debf9e9041310c688cd4a0f25af7997a72d2aafc 100644 (file)
@@ -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:
index e74ba82d9412e905b4c340ff97f21020ffc73d47..2cadbb62285e27ac17cc7ff127fedef34f0caba9 100644 (file)
@@ -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