Debian Bug report logs -
#270967
gconf2-common fails to purge when /etc isn't removable
Reported by: Klaus Ethgen <Klaus@Ethgen.de>
Date: Fri, 10 Sep 2004 09:48:07 UTC
Severity: normal
Tags: moreinfo, unreproducible
Found in version 2.6.3-2
Reply or subscribe to this bug.
Toggle useless messages
Report forwarded to debian-bugs-dist@lists.debian.org, Takuo KITAME <kitame@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to Klaus Ethgen <Klaus@Ethgen.de>:
New Bug report received and forwarded. Copy sent to Takuo KITAME <kitame@debian.org>.
(full text, mbox, link).
Message #5 received at submit@bugs.debian.org (full text, mbox, reply):
-----BEGIN PGP SIGNED MESSAGE-----
Package: gconf2
Version: 2.6.3-2
Severity: critical
When removing (purging) gconf2 it trys to remove /etc c ompletely!
This will destroy the whole system if /etc can be removed on it and is not
protected as on my system.
- -- System Information:
Debian Release: 3.1
APT prefers testing
APT policy: (800, 'testing'), (70, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.27
Locale: LANG=de_DE, LC_CTYPE=de_DE (ignored: LC_ALL set to de_DE)
Versions of packages gconf2 depends on:
ii libatk1.0-0 1.6.1-3 The ATK accessibility toolkit
ii libc6 2.3.2.ds1-13 GNU C Library: Shared libraries an
pn libgconf2-4 Not found.
ii libglib2.0-0 2.4.6-2 The GLib library of C routines
ii libgtk2.0-0 2.4.9-1 The GTK+ graphical user interface
ii liborbit2 1:2.10.2-1.1 libraries for ORBit2 - a CORBA ORB
ii libpango1.0-0 1.4.1-2 Layout and rendering of internatio
ii libpopt0 1.7-4 lib for parsing cmdline parameters
ii libxml2 2.6.11-3 GNOME XML library
ii zlib1g 1:1.2.1.1-5 compression library - runtime
- -- no debconf information
- --
Klaus Ethgen http://www.ethgen.de/
pub 2048R/D1A4EDE5 2000-02-26 Klaus Ethgen <Klaus@Ethgen.de>
Fingerprint: D7 67 71 C4 99 A6 D4 FE EA 40 30 57 3C 88 26 2B
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iQEVAwUBQUF3oJ+OKpjRpO3lAQHtYQgAgcBu3EjrpjAX76yd1bWn3YewyCMc7Enw
SqMkHHiKU4xz6htY6kgrdY0ROx+otThFQuPbQWHgobq1qioMahWzK9bcDlSBGomY
OVqqmobp5HX0Z40U0NTEZb8C3xtMcCvx++cwI8Vm0W74Rm1t1rG+RIDGQRZZ3eE2
YBmOfABMI+W4NyWvdDvrIcd2B4ehkA6McPDh/QjU/VeaSs8DGN3jXDTSWCT1Yokp
TQlJRl4/+OuPzQ9oTWGHA4Zyunu2fTuCsZ/Ww57yFG3N0G1i40LhDjytFbhUuCr7
+aDcexCxsBBE0/XYNElVEhuV03SZHiJJBooSSRgio2phARYT3LYr6Q==
=YrFu
-----END PGP SIGNATURE-----
Information forwarded to debian-bugs-dist@lists.debian.org, Takuo KITAME <kitame@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to Sebastien Bacher <seb128@debian.org>:
Extra info received and forwarded to list. Copy sent to Takuo KITAME <kitame@debian.org>.
(full text, mbox, link).
Message #10 received at 270967@bugs.debian.org (full text, mbox, reply):
severity 270967 important
tag 270967 + unreproducible moreinfo
thanks
Le vendredi 10 septembre 2004 à 11:45 +0200, Klaus Ethgen a écrit :
> When removing (purging) gconf2 it trys to remove /etc c ompletely!
>
> This will destroy the whole system if /etc can be removed on it and is not
> protected as on my system.
Hi,
Could you provide some details ? Are you sure that the /etc dir has been
deleted by gconf2 ?
The postrm command used on purge is:
"rmdir -p --ignore-fail-on-non-empty /etc/gconf/2" ... this only removes
empty dirs, /etc was empty on your box ?
I'm changing the severity to important for the moment, this problem is
not reproducible.
Thanks,
Sebastien Bacher
Severity set to `important'.
Request was from Sebastien Bacher <seb128@debian.org>
to control@bugs.debian.org.
(full text, mbox, link).
Tags added: unreproducible, moreinfo
Request was from Sebastien Bacher <seb128@debian.org>
to control@bugs.debian.org.
(full text, mbox, link).
Information forwarded to debian-bugs-dist@lists.debian.org, Takuo KITAME <kitame@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to Klaus Ethgen <Klaus@Ethgen.de>:
Extra info received and forwarded to list. Copy sent to Takuo KITAME <kitame@debian.org>.
(full text, mbox, link).
Message #19 received at 270967@bugs.debian.org (full text, mbox, reply):
-----BEGIN PGP SIGNED MESSAGE-----
Hi,
Am Fr den 10. Sep 2004 um 12:47 schriebst Du:
> Could you provide some details ? Are you sure that the /etc dir has been
> deleted by gconf2 ?
When I purged the package first it failed because /etc/gconf/2 was not found on
my system and then after I created it it prints:
rmdir: `/etc': Permission denied
when purging. /etc is not removable in my environment thank goodnes.
I did not check if it whould remove /etc if it whould be removable.
> "rmdir -p --ignore-fail-on-non-empty /etc/gconf/2" ... this only removes
> empty dirs, /etc was empty on your box ?
No, but see above.
Hmm.. I didn't look to the postrm afterwards. I only did a
echo "#!/bin/sh" > /var/lib/dpkg/info/gconf2.postrm
to remove it completely. But it is strange that the rmdir above give this
message.
Regards
Klaus
- --
Klaus Ethgen http://www.ethgen.de/
pub 2048R/D1A4EDE5 2000-02-26 Klaus Ethgen <Klaus@Ethgen.de>
Fingerprint: D7 67 71 C4 99 A6 D4 FE EA 40 30 57 3C 88 26 2B
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iQEVAwUBQUGPTZ+OKpjRpO3lAQHThwf/Vx8pLAadgvE68WILe1NxxIQKozzADYcU
0PZG4m/7z4IpQjuuefym0Z1ViBJY6rny8HXZwkp7NVmLK9//IDyrhPYIu5UX9hNZ
ivSL/z2hQW18pflVxf8KkS5kn9xXhcyLujSZ8avCJoRyQt+PvXbG/yZ7hqq2MVIo
zlooC15xNO+EIyOq/iQOqgqldQ0YhihHT9U+Dzuj64UtRZ8OdxPBPbwiZ43r+ihU
PV3zUKMfSg1Aq00Lqc8zrlHcbB0RQ/E/NV4NnpphOu/OAyeV+MKOVyYOhevp10um
tfGG/rCurWRV5TVcrWwdMZTbNX9Ycm/4nTCiuPZXL8O0omY08cafkg==
=VbXL
-----END PGP SIGNATURE-----
Information forwarded to debian-bugs-dist@lists.debian.org, Takuo KITAME <kitame@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to Sebastien Bacher <seb128@debian.org>:
Extra info received and forwarded to list. Copy sent to Takuo KITAME <kitame@debian.org>.
(full text, mbox, link).
Message #24 received at 270967@bugs.debian.org (full text, mbox, reply):
Le vendredi 10 septembre 2004 à 13:26 +0200, Klaus Ethgen a écrit :
> When I purged the package first it failed because /etc/gconf/2 was not found on
> my system and then after I created it it prints:
> rmdir: `/etc': Permission denied
> when purging. /etc is not removable in my environment thank goodnes.
You've purged only this one ? Do you remember which version of the
package it was ?
I've just tried in a fresh pbuilder, no problem ...
> I did not check if it whould remove /etc if it whould be removable.
Can you still reproduce the problem ?
> to remove it completely. But it is strange that the rmdir above give this
> message.
Yes, I don't understand where is the problem, but that's not a gconf
problem ... if "rmdir -p --ignore-fail-on-non-empty /etc/gconf/2" wants
to remove /etc you have a problem but that with coreutils, not gconf.
Cheers,
Sebastien Bacher
Information forwarded to debian-bugs-dist@lists.debian.org, Takuo KITAME <kitame@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to Klaus Ethgen <Klaus@Ethgen.de>:
Extra info received and forwarded to list. Copy sent to Takuo KITAME <kitame@debian.org>.
(full text, mbox, link).
Message #29 received at 270967@bugs.debian.org (full text, mbox, reply):
-----BEGIN PGP SIGNED MESSAGE-----
Hi,
Am Fr den 10. Sep 2004 um 13:41 schriebst Du:
> You've purged only this one ? Do you remember which version of the
> package it was ?
No. But see below...
> Can you still reproduce the problem ?
Yes, I did on a other host (sid, newest version, all my hosts have "chattr +i /").
- ---
xxxx:~# dpkg --force-all --purge gconf2
dpkg: gconf2: dependency problems, but removing anyway as you request:
libgnome2-common depends on gconf2 (>= 2.6.0-1).
libgnomevfs2-common depends on gconf2 (>= 2.6.0).
libgconf2-4 depends on gconf2 (>= 2.6.4-2).
(Reading database ... 94571 files and directories currently installed.)
Removing gconf2 ...
Purging configuration files for gconf2 ...
rmdir: `/etc': Permission denied
dpkg: error processing gconf2 (--purge):
subprocess post-removal script returned error exit status 1
Errors were encountered while processing:
gconf2
- ---
When there is somethink inside of /etc/gconf then no problem. But when there is
nothing more inside this bug happens.
When I then recreate /etc/gconfd/2 and make a "chattr -i /" the purge work well
without erasing something from /etc.
As the /etc gets not really deleted, i think the severity can be lowered to
'normal'.
Regards
Klaus
- --
Klaus Ethgen http://www.ethgen.de/
pub 2048R/D1A4EDE5 2000-02-26 Klaus Ethgen <Klaus@Ethgen.de>
Fingerprint: D7 67 71 C4 99 A6 D4 FE EA 40 30 57 3C 88 26 2B
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iQEVAwUBQUGWd5+OKpjRpO3lAQFOHgf+LB81o/fvb67fhujir8qxrwTBmnFiyEA1
1JkKHgLmTGlBCa0VgoDeW4NOHpFqxJnpGu+V7k9GklSfUhnVyqnTWG+6qCBCZCZ1
ZH9m6JV18VOe6uf43HTPAXQFLFjZshPs9d0Vh+Nm3qEqeAuGXUVwr9KDklghxn5U
bSFsJ7SH9GkW7l5HI+QL9puua9/MYxBotdmdmvLtYVmRDaSf1da0w3lH5PEKjfaN
JW4GCsqOJjk4Ju6FITJvafYfXXO/X17uTyrSYvgMn2oamWt0Ss3bMqjthLxOPCjy
d73zS7mFwuE44/SYVCJR91vSTYu2C5itospIv61exvaQzdMkjF4+FQ==
=fpP/
-----END PGP SIGNATURE-----
Information forwarded to debian-bugs-dist@lists.debian.org, Takuo KITAME <kitame@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to Sebastien Bacher <seb128@debian.org>:
Extra info received and forwarded to list. Copy sent to Takuo KITAME <kitame@debian.org>.
(full text, mbox, link).
Message #34 received at 270967@bugs.debian.org (full text, mbox, reply):
Le vendredi 10 septembre 2004 à 13:56 +0200, Klaus Ethgen a écrit :
> Yes, I did on a other host (sid, newest version, all my hosts have "chattr +i /").
Ok, I've the problem too.
$ chattr +i /
$ dpkg --purge libgconf2-4 gconf2
and I get the same error
The weird point is that running "sh /var/lib/dpkg/info/gconf2.postrm
purge" doesn't display any error, but the same line called by apt raises
an error ...
Anybody with an idea on this ?
BTW not a gconf problem ...
Thanks,
Sebastien Bacher
Information forwarded to debian-bugs-dist@lists.debian.org, Josselin Mouette <joss@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to Adrian Bunk <bunk@stusta.de>:
Extra info received and forwarded to list. Copy sent to Josselin Mouette <joss@debian.org>.
(full text, mbox, link).
Message #39 received at 270967@bugs.debian.org (full text, mbox, reply):
severity 270967 critical
thanks
Hi Sebastien,
I think I can answer the following question you raised:
<-- snip -->
The weird point is that running "sh /var/lib/dpkg/info/gconf2.postrm
purge" doesn't display any error, but the same line called by apt raises
an error ...
<-- snip -->
The problem is only triggered when /etc/gconf2/ is empty.
cu
Adrian
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
Severity set to `critical'.
Request was from Adrian Bunk <bunk@stusta.de>
to control@bugs.debian.org.
(full text, mbox, link).
Message sent on to Klaus Ethgen <Klaus@Ethgen.de>:
Bug#270967.
(full text, mbox, link).
Information forwarded to debian-bugs-dist@lists.debian.org, Josselin Mouette <joss@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to 270967@bugs.debian.org:
Extra info received and forwarded to list. Copy sent to Josselin Mouette <joss@debian.org>.
(full text, mbox, link).
Message #49 received at 270967@bugs.debian.org (full text, mbox, reply):
severity 270967 normal
clone 270967 -1
retitle 270967 gconf2-common fails to purge when /etc isn't removable
reassign -1 coreutils
retitle -1 rmdir should check emptiness before permissions
thanks
Le lundi 30 janvier 2006 à 03:23 +0100, Adrian Bunk a écrit :
> severity 270967 critical
> thanks
This is by no means a critical bug. There's no way this script can wipe
out your /etc.
> Hi Sebastien,
>
> I think I can answer the following question you raised:
>
> <-- snip -->
>
> The weird point is that running "sh /var/lib/dpkg/info/gconf2.postrm
> purge" doesn't display any error, but the same line called by apt raises
> an error ...
>
> <-- snip -->
>
> The problem is only triggered when /etc/gconf2/ is empty.
This error message is triggered by rmdir trying to remove /etc.
Normally, rmdir -p --ignore-fail-on-non-empty will try to
remove /etc/gconf/2, then /etc/gconf, then /etc, and will stop with /etc
because it isn't empty.
On your system, the chattr -i prevents the removal of /etc, and rmdir
fails on "permission denied" instead of "directory not empty".
I'd say that, so that rmdir -p --ignore-fail-on-non-empty can work on
such systems, it should be made to check first if the directory is
empty, and then if it has the permissions to remove it. I'm creating a
clone report on coreutils, but maybe it is caused directly by the kernel
or libc - in which case it should still be possible to work around the
issue in coreutils.
Currently, rmdir --ignore-fail-on-non-empty seems to do the following:
* call rmdir(2)
* check errno
* ignore ENOTEMPTY
Maybe it could be modified to do the following:
* check if the directory is empty
* call rmdir(2)
I don't know whether this would be acceptable. Depending on the
coreutils maintainers' advice and decision, I will modify - or not - the
gconf2 scripts.
Regards,
--
.''`. Josselin Mouette /\./\
: :' : josselin.mouette@ens-lyon.org
`. `' joss@debian.org
`- Debian GNU/Linux -- The power of freedom
Severity set to `normal'.
Request was from Josselin Mouette <joss@debian.org>
to control@bugs.debian.org.
(full text, mbox, link).
Changed Bug title.
Request was from Josselin Mouette <joss@debian.org>
to control@bugs.debian.org.
(full text, mbox, link).
Information forwarded to debian-bugs-dist@lists.debian.org, Josselin Mouette <joss@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to bob@proulx.com (Bob Proulx):
Extra info received and forwarded to list. Copy sent to Josselin Mouette <joss@debian.org>.
(full text, mbox, link).
Message #60 received at 270967@bugs.debian.org (full text, mbox, reply):
Josselin Mouette wrote:
> This error message is triggered by rmdir trying to remove /etc.
> Normally, rmdir -p --ignore-fail-on-non-empty will try to
> remove /etc/gconf/2, then /etc/gconf, then /etc, and will stop with /etc
> because it isn't empty.
I see in the gconf2-common.postrm that the following command is being
run:
rm -f /etc/gconf/2/path
rmdir -p --ignore-fail-on-non-empty /etc/gconf/2
Can that instead be changed to the following so as to avoid trying to
remove /etc at all?
rm -f /etc/gconf/2/path
rmdir --ignore-fail-on-non-empty /etc/gconf/2 /etc/gconf
It just seems simpler this way.
Meanwhile, I have removed the moreinfo and unreproducible tags and am
forwarding this upstream.
Bob
Information forwarded to debian-bugs-dist@lists.debian.org, Josselin Mouette <joss@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to bob@proulx.com (Bob Proulx):
Extra info received and forwarded to list. Copy sent to Josselin Mouette <joss@debian.org>.
(full text, mbox, link).
Message #65 received at 270967@bugs.debian.org (full text, mbox, reply):
> Meanwhile, I have removed the moreinfo and unreproducible tags and am
> forwarding this upstream.
Actually I am doing that to the cloned bug 350541.
Bob
Information forwarded to debian-bugs-dist@lists.debian.org, Josselin Mouette <joss@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to bob@proulx.com (Bob Proulx):
Extra info received and forwarded to list. Copy sent to Josselin Mouette <joss@debian.org>.
(full text, mbox, link).
Message #70 received at 270967@bugs.debian.org (full text, mbox, reply):
Please maintain the CC to both the bug number and the mailing list
when responding. Thanks.
Reported to the Debian BTS:
http://bugs.debian.org/350541
'rmdir --ignore-fail-on-non-empty' will ignore non-empty directories
unless it has insufficient permission to remove them, in which case it
fails. Can rmdir avoid failing in this case?
Here is a way to reproduce the issue. Root access is required in
order to have permission to set the immutable attribute. The
filesystem needs to be ext2-like in order to support it.
# mkdir testdir
# mkdir testdir/foo
# mkdir testdir/foo/bar
# mkdir testdir/foo/boo
# chattr +i testdir
# rmdir -p --ignore-fail-on-non-empty testdir/foo/bar ; echo $?
rmdir: testdir/foo: Permission denied
1
But without the immutable attribute:
# chattr -i testdir
# mkdir testdir/foo/bar
# rmdir -p --ignore-fail-on-non-empty testdir/foo/bar ; echo $?
0
This was found in a package postrm script which tried to clean up by
doing the following:
rm -f /etc/gconf/2/path
rmdir -p --ignore-fail-on-non-empty /etc/gconf/2
rmdir: `/etc': Permission denied
Bob
----- Forwarded *TRIMMED* message from Josselin Mouette <joss@debian.org> -----
From: Josselin Mouette <joss@debian.org>
Subject: Bug#270967: Why purging gconf2-common might erase your /etc
Date: Mon, 30 Jan 2006 10:10:57 +0100
[...TRIMMED CONTENT, ORIGINAL IN ARCHIVE...]
This error message is triggered by rmdir trying to remove /etc.
Normally, rmdir -p --ignore-fail-on-non-empty will try to
remove /etc/gconf/2, then /etc/gconf, then /etc, and will stop with /etc
because it isn't empty.
On your system, the chattr -i prevents the removal of /etc, and rmdir
fails on "permission denied" instead of "directory not empty".
I'd say that, so that rmdir -p --ignore-fail-on-non-empty can work on
such systems, it should be made to check first if the directory is
empty, and then if it has the permissions to remove it. I'm creating a
clone report on coreutils, but maybe it is caused directly by the kernel
or libc - in which case it should still be possible to work around the
issue in coreutils.
Currently, rmdir --ignore-fail-on-non-empty seems to do the following:
* call rmdir(2)
* check errno
* ignore ENOTEMPTY
Maybe it could be modified to do the following:
* check if the directory is empty
* call rmdir(2)
I don't know whether this would be acceptable. Depending on the
coreutils maintainers' advice and decision, I will modify - or not - the
gconf2 scripts.
Regards,
--
.''`. Josselin Mouette /\./\
: :' : josselin.mouette@ens-lyon.org
`. `' joss@debian.org
`- Debian GNU/Linux -- The power of freedom
----- End forwarded message -----
Information forwarded to debian-bugs-dist@lists.debian.org, Josselin Mouette <joss@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to bob@proulx.com (Bob Proulx):
Extra info received and forwarded to list. Copy sent to Josselin Mouette <joss@debian.org>.
(full text, mbox, link).
Message #75 received at 270967@bugs.debian.org (full text, mbox, reply):
Bob Proulx wrote:
> Please maintain the CC to both the bug number and the mailing list
> when responding. Thanks.
Which would have been great if I had not been confused by the cloning
of this bug into two different bugs. My bad. Please keep
350541@bugs.debian.org instead of 270967@bugs.debian.org in the CC
list. Sorry about that.
> Reported to the Debian BTS:
>
> http://bugs.debian.org/350541
Bob
Information forwarded to debian-bugs-dist@lists.debian.org, Josselin Mouette <joss@debian.org>:
Bug#270967; Package gconf2.
(full text, mbox, link).
Acknowledgement sent to Jim Meyering <jim@meyering.net>:
Extra info received and forwarded to list. Copy sent to Josselin Mouette <joss@debian.org>.
(full text, mbox, link).
Message #80 received at 270967@bugs.debian.org (full text, mbox, reply):
bob@proulx.com (Bob Proulx) wrote:
> Please maintain the CC to both the bug number and the mailing list
> when responding. Thanks.
>
> Reported to the Debian BTS:
>
> http://bugs.debian.org/350541
>
> 'rmdir --ignore-fail-on-non-empty' will ignore non-empty directories
> unless it has insufficient permission to remove them, in which case it
> fails. Can rmdir avoid failing in this case?
>
> Here is a way to reproduce the issue. Root access is required in
> order to have permission to set the immutable attribute. The
> filesystem needs to be ext2-like in order to support it.
>
> # mkdir testdir
> # mkdir testdir/foo
> # mkdir testdir/foo/bar
> # mkdir testdir/foo/boo
> # chattr +i testdir
> # rmdir -p --ignore-fail-on-non-empty testdir/foo/bar ; echo $?
> rmdir: testdir/foo: Permission denied
> 1
I've fixed it like this:
(but no test case yet -- volunteers welcome!)
Improve "rmdir --ignore-fail-on-non-empty"
* src/rmdir.c (remove_parents, main): With --ignore-fail-on-non-empty,
suppress a diagnostic also for e.g., EACCES, which can happen
with read-only media or when the parent directory has the immutable
attribute (set via chattr +i).
(errno_may_be_empty, ignorable_failure): New functions.
* src/remove.c (is_empty_dir): Move function to ...
* src/system.h (is_empty_dir): ...here, and make it inline.
Suggested by Josselin Mouette in <http://bugs.debian.org/363011>
via Bob Proulx.
* NEWS: Mention the improvement.
Signed-off-by: Jim Meyering <meyering@redhat.com>
---
ChangeLog | 14 ++++++++++++++
NEWS | 10 +++++++++-
THANKS | 1 +
src/remove.c | 32 +-------------------------------
src/rmdir.c | 36 +++++++++++++++++++++++++++++++-----
src/system.h | 30 ++++++++++++++++++++++++++++++
6 files changed, 86 insertions(+), 37 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5e15325..017c307 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-01-30 Jim Meyering <meyering@redhat.com>
+
+ Improve "rmdir --ignore-fail-on-non-empty"
+ * src/rmdir.c (remove_parents, main): With --ignore-fail-on-non-empty,
+ suppress a diagnostic also for e.g., EACCES, which can happen
+ with read-only media or when the parent directory has the immutable
+ attribute (set via chattr +i).
+ (errno_may_be_empty, ignorable_failure): New functions.
+ * src/remove.c (is_empty_dir): Move function to ...
+ * src/system.h (is_empty_dir): ...here, and make it inline.
+ Suggested by Josselin Mouette in <http://bugs.debian.org/363011>
+ via Bob Proulx.
+ * NEWS: Mention the improvement.
+
2008-01-29 Paul Eggert <eggert@cs.ucla.edu>
Don't modify argv in dd.
diff --git a/NEWS b/NEWS
index f474141..0d2d97d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,12 +1,20 @@
GNU coreutils NEWS -*- outline -*-
-* Noteworthy changes in release 6.10 (2008-01-22) [stable]
+* Noteworthy changes in release 6.?? (2008-??-??) [stable]
** Bug fixes
ls no longer segfaults on files in /proc when linked with an older version
of libselinux. E.g., ls -l /proc/sys would dereference a NULL pointer.
+ "rmdir --ignore-fail-on-non-empty" detects and ignores the failure
+ in more cases when a directory is empty.
+
+
+* Noteworthy changes in release 6.10 (2008-01-22) [stable]
+
+** Bug fixes
+
Fix a non-portable use of sed in configure.ac.
[bug introduced in coreutils-6.9.92]
diff --git a/THANKS b/THANKS
index 1e04f9b..bb536b3 100644
--- a/THANKS
+++ b/THANKS
@@ -264,6 +264,7 @@ Joost van Baal joostvb@xs4all.nl
Jorge Stolfi stolfi@ic.unicamp.br
Joseph S. Myers jsm28@cam.ac.uk
Joshua Hudson joshudson@gmail.com
+Josselin Mouette joss@debian.org
Juan F. Codagnone juam@arnet.com.ar
Juan M. Guerrero st001906@hrz1.hrz.tu-darmstadt.de
Jungshik Shin jshin@pantheon.yale.edu
diff --git a/src/remove.c b/src/remove.c
index de8f5ff..fe603bb 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -1,5 +1,5 @@
/* remove.c -- core functions for removing files and directories
- Copyright (C) 88, 90, 91, 1994-2007 Free Software Foundation, Inc.
+ Copyright (C) 88, 90, 91, 1994-2008 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -726,36 +726,6 @@ AD_is_removable (Dirstack_state const *ds, char const *file)
return ! (top->unremovable && hash_lookup (top->unremovable, file));
}
-/* Return true if DIR is determined to be an empty directory. */
-static bool
-is_empty_dir (int fd_cwd, char const *dir)
-{
- DIR *dirp;
- struct dirent const *dp;
- int saved_errno;
- int fd = openat (fd_cwd, dir,
- (O_RDONLY | O_DIRECTORY
- | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK));
-
- if (fd < 0)
- return false;
-
- dirp = fdopendir (fd);
- if (dirp == NULL)
- {
- close (fd);
- return false;
- }
-
- errno = 0;
- dp = readdir_ignoring_dot_and_dotdot (dirp);
- saved_errno = errno;
- closedir (dirp);
- if (dp != NULL)
- return false;
- return saved_errno == 0 ? true : false;
-}
-
/* Return -1 if FILE is an unwritable non-symlink,
0 if it is writable or some other type of file,
a positive error number if there is some problem in determining the answer.
diff --git a/src/rmdir.c b/src/rmdir.c
index 96aa9af..bb1a0c8 100644
--- a/src/rmdir.c
+++ b/src/rmdir.c
@@ -74,13 +74,41 @@ static struct option const longopts[] =
/* Return true if ERROR_NUMBER is one of the values associated
with a failed rmdir due to non-empty target directory. */
-
static bool
errno_rmdir_non_empty (int error_number)
{
return (error_number == RMDIR_ERRNO_NOT_EMPTY);
}
+/* Return true if when rmdir fails with errno == ERROR_NUMBER
+ the directory may be empty. */
+static bool
+errno_may_be_empty (int error_number)
+{
+ switch (error_number)
+ {
+ case EACCES:
+ case EPERM:
+ case EROFS:
+ case EEXIST:
+ case EBUSY:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/* Return true if an rmdir failure with errno == error_number
+ for DIR is ignorable. */
+static bool
+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))));
+}
+
/* Remove any empty parent directories of DIR.
If DIR contains slash characters, at least one of them
(beginning with the rightmost) is replaced with a NUL byte.
@@ -113,8 +141,7 @@ remove_parents (char *dir)
if (!ok)
{
/* Stop quietly if --ignore-fail-on-non-empty. */
- if (ignore_fail_on_non_empty
- && errno_rmdir_non_empty (errno))
+ if (ignorable_failure (errno, dir))
{
ok = true;
}
@@ -210,8 +237,7 @@ main (int argc, char **argv)
if (rmdir (dir) != 0)
{
- if (ignore_fail_on_non_empty
- && errno_rmdir_non_empty (errno))
+ if (ignorable_failure (errno, dir))
continue;
/* Here, the diagnostic is less precise, since we have no idea
diff --git a/src/system.h b/src/system.h
index 54c8a8b..b0b9545 100644
--- a/src/system.h
+++ b/src/system.h
@@ -384,6 +384,36 @@ readdir_ignoring_dot_and_dotdot (DIR *dirp)
}
}
+/* Return true if DIR is determined to be an empty directory. */
+static inline bool
+is_empty_dir (int fd_cwd, char const *dir)
+{
+ DIR *dirp;
+ struct dirent const *dp;
+ int saved_errno;
+ int fd = openat (fd_cwd, dir,
+ (O_RDONLY | O_DIRECTORY
+ | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK));
+
+ if (fd < 0)
+ return false;
+
+ dirp = fdopendir (fd);
+ if (dirp == NULL)
+ {
+ close (fd);
+ return false;
+ }
+
+ errno = 0;
+ dp = readdir_ignoring_dot_and_dotdot (dirp);
+ saved_errno = errno;
+ closedir (dirp);
+ if (dp != NULL)
+ return false;
+ return saved_errno == 0 ? true : false;
+}
+
/* Factor out some of the common --help and --version processing code. */
/* These enum values cannot possibly conflict with the option values
--
1.5.4.rc5.1.ge6bfe
Send a report that this bug log contains spam.
Debian bug tracking system administrator <owner@bugs.debian.org>.
Last modified:
Wed Jan 10 19:53:10 2018;
Machine Name:
beach
Debian Bug tracking system
Debbugs is free software and licensed under the terms of the GNU
Public License version 2. The current version can be obtained
from https://bugs.debian.org/debbugs-source/.
Copyright © 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson,
2005-2017 Don Armstrong, and many other contributors.