Subject: bug#39364: closed (Re: bug#39364: [PATCH] rmdir: fix clobbered errno)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 04 Feb 2020 19:22:02 +0000

Your bug report

#39364: [PATCH] rmdir: fix clobbered errno

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
39364: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=39364
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#39364: [PATCH] rmdir: fix clobbered errno
From: Pádraig Brady <[email-masked]>
To: Matthew Pfeiffer <[email-masked]>, [email-masked]
Date: Tue, 4 Feb 2020 19:21:42 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

On 03/02/2020 16:45, Pádraig Brady wrote:
> On 03/02/2020 13:26, Pádraig Brady wrote:
>> On 31/01/2020 17:51, Pádraig Brady wrote:
>> Actually I think the key issue is not errno handling,
>> but a logic error fixed with:
>>
>> @@ -102,7 +102,7 @@ ignorable_failure (int error_number, char const *dir)
>>       return (ignore_fail_on_non_empty
>>               && (errno_rmdir_non_empty (error_number)
>>                   || (errno_may_be_empty (error_number)
>> -                  && is_empty_dir (AT_FDCWD, dir))));
>> +                  && ! is_empty_dir (AT_FDCWD, dir))));
>>
>>
>> Attached is a full patch to address these issues.
> 
> I'll also squash this in to the previous commit,
> to ensure we diagnose the case where we can't
> determine if the directory is empty.

pushed. marking done

Subject: [PATCH] rmdir: fix clobbered errno
From: Matthew Pfeiffer <[email-masked]>
To: [email-masked]
Cc: Matthew Pfeiffer <[email-masked]>
Date: Thu, 30 Jan 2020 20:46:40 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

'rmdir --ignore-fail-on-non-empty' would not report errors on non-empty
directories that fail for a different reason.
---
 src/rmdir.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/rmdir.c b/src/rmdir.c
index c9f417957..7b253ab0d 100644
--- a/src/rmdir.c
+++ b/src/rmdir.c
@@ -133,18 +133,19 @@ remove_parents (char *dir)
         prog_fprintf (stdout, _("removing directory, %s"), quoteaf (dir));
 
       ok = (rmdir (dir) == 0);
+      int rmdir_errno = errno;
 
       if (!ok)
         {
           /* Stop quietly if --ignore-fail-on-non-empty. */
-          if (ignorable_failure (errno, dir))
+          if (ignorable_failure (rmdir_errno, dir))
             {
               ok = true;
             }
           else
             {
               /* Barring race conditions, DIR is expected to be a directory.  */
-              error (0, errno, _("failed to remove directory %s"),
+              error (0, rmdir_errno, _("failed to remove directory %s"),
                      quoteaf (dir));
             }
           break;
@@ -233,12 +234,13 @@ main (int argc, char **argv)
 
       if (rmdir (dir) != 0)
         {
-          if (ignorable_failure (errno, dir))
+          int rmdir_errno = errno;
+          if (ignorable_failure (rmdir_errno, dir))
             continue;
 
           /* Here, the diagnostic is less precise, since we have no idea
              whether DIR is a directory.  */
-          error (0, errno, _("failed to remove %s"), quoteaf (dir));
+          error (0, rmdir_errno, _("failed to remove %s"), quoteaf (dir));
           ok = false;
         }
       else if (remove_empty_parents)
-- 
2.25.0