Hi, Today I noticed the following behaviour on a 6-stable machine: $ cd /tmp $ mkdir -p foo/var $ cd foo/bar $ rm -rf ../ rm: ../: Invalid argument $ rm -rf ../ $ Note that the command "rm -rf ../" was entered twice. The first time I got an error message (and exit code 1), the second time it apparently succeeded. The very same command. Further investigation: $ cd /tmp $ mkdir -p foo/var $ cd foo/bar $ rm -rf ../ rm: ../: Invalid argument $ ls -al .. ls: ..: No such file or directory $ ls /tmp/foo/bar ls: /tmp/foo/bar: No such file or directory That means: Even though "rm -rf ../" prints an error message, indicating that the argument is invalid, it *DOES* remove the contents of the parent directory! To add further confusion, another "rm -rf ../" does not print an error message and seemingly succeeds, even though ".." does not exist anymore in the current directory (which has been removed). Shall I file a PR? Or is rm working correctly, and my assumptions are wrong? Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Gesch?ftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht M?n- chen, HRB 125758, Gesch?ftsf?hrer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd "The scanf() function is a large and complex beast that often does something almost but not quite entirely unlike what you desired." -- Chris Torek
On 9/25/07, Oliver Fromme <olli@lurza.secnetix.de> wrote:> Hi, > > Today I noticed the following behaviour on a 6-stable > machine: > > $ cd /tmp > $ mkdir -p foo/var > $ cd foo/bar > $ rm -rf ../ > rm: ../: Invalid argument > $ rm -rf ../ > $ > > Note that the command "rm -rf ../" was entered twice. > The first time I got an error message (and exit code 1), > the second time it apparently succeeded. The very same > command. > > Further investigation: > > $ cd /tmp > $ mkdir -p foo/var > $ cd foo/bar > $ rm -rf ../ > rm: ../: Invalid argument > $ ls -al .. > ls: ..: No such file or directory > $ ls /tmp/foo/bar > ls: /tmp/foo/bar: No such file or directory > > That means: Even though "rm -rf ../" prints an error > message, indicating that the argument is invalid, it > *DOES* remove the contents of the parent directory! > > To add further confusion, another "rm -rf ../" does > not print an error message and seemingly succeeds, > even though ".." does not exist anymore in the current > directory (which has been removed). > > Shall I file a PR? Or is rm working correctly, and > my assumptions are wrong? > > Best regards > OliverConfirmed on CURRENT as well. Note that if you run rf -rf .. as the first command, the command does fail with 'rm: "." and ".." may not be removed'. Adding a / at the end does seem to get around this check. - Max
On Tue, Sep 25, 2007 at 05:12:50PM +0200, Oliver Fromme wrote:> Hi, > > Today I noticed the following behaviour on a 6-stable > machine: > > $ cd /tmp > $ mkdir -p foo/var > $ cd foo/barLooks like you have mistyped 'mkdir' argument :)> $ rm -rf ../ > rm: ../: Invalid argumentPlease type 'pwd' here> $ rm -rf ../ > $ > > Note that the command "rm -rf ../" was entered twice. > The first time I got an error message (and exit code 1), > the second time it apparently succeeded. The very same > command. > > Further investigation: > > $ cd /tmp > $ mkdir -p foo/var > $ cd foo/bar > $ rm -rf ../ > rm: ../: Invalid argument > $ ls -al .. > ls: ..: No such file or directory > $ ls /tmp/foo/bar > ls: /tmp/foo/bar: No such file or directory > > That means: Even though "rm -rf ../" prints an error > message, indicating that the argument is invalid, it > *DOES* remove the contents of the parent directory! > > To add further confusion, another "rm -rf ../" does > not print an error message and seemingly succeeds, > even though ".." does not exist anymore in the current > directory (which has been removed). > > Shall I file a PR? Or is rm working correctly, and > my assumptions are wrong? > > Best regards > Oliver > > -- > Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. > Handelsregister: Registergericht Muenchen, HRA 74606, Gesch?ftsfuehrung: > secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht M?n- > chen, HRB 125758, Gesch?ftsf?hrer: Maik Bachmann, Olaf Erb, Ralf Gebhart > > FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd > > "The scanf() function is a large and complex beast that often does > something almost but not quite entirely unlike what you desired." > -- Chris Torek-- The ultimate artifact may be found in the driven snow...
On Tue, 25 Sep 2007 17:12:50 +0200 (CEST) Oliver Fromme <olli@lurza.secnetix.de> wrote:> $ cd /tmp > $ mkdir -p foo/var > $ cd foo/bar > $ rm -rf ../ > rm: ../: Invalid argument > $ rm -rf ../ > $ > > Note that the command "rm -rf ../" was entered twice. > The first time I got an error message (and exit code 1), > the second time it apparently succeeded. The very same > command.What happens if you issue a 'pwd' command after each 'rm -rf ../'? We want to see the output. IMHO, the only way the second rm command *should* succeed, is if it invalidates the current working directory, thus releasing the last lock on the directory. Quick testing here: tingo@kg-work$ mkdir -p foo/bar tingo@kg-work$ cd foo/bar tingo@kg-work$ ll total 4 drwxr-xr-x 2 tingo wheel - 512 Sep 25 17:31 ./ drwxr-xr-x 3 tingo wheel - 512 Sep 25 17:31 ../ tingo@kg-work$ pwd /tmp/foo/bar tingo@kg-work$ rm -rf ../ rm: ../: Invalid argument tingo@kg-work$ pwd /tmp/foo/bar tingo@kg-work$ rm -rf ../ tingo@kg-work$ pwd /tmp/foo/bar tingo@kg-work$ ls -al total 0 tingo@kg-work$ ll total 0 tingo@kg-work$ pwd /tmp/foo/bar tingo@kg-work$ ls -al .. ls: ..: No such file or directory tingo@kg-work$ ls -al /tmp/foo/bar ls: /tmp/foo/bar: No such file or directory tingo@kg-work$ ls -al /tmp/foo total 8 drwxr-xr-x 2 tingo wheel 512 Sep 25 17:32 . drwxrwxrwt 35 root wheel 5632 Sep 25 17:31 .. Ok, I think it is a bug. -- Regards, Torfinn Ingolfsen
On Tue, 25 Sep 2007, Oliver Fromme wrote:> Note that the command "rm -rf ../" was entered twice. > The first time I got an error message (and exit code 1), > the second time it apparently succeeded.Check the man page for rm: -f Attempt to remove the files without prompting for confirma- tion, regardless of the file's permissions. If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. That's what's happening the second time through. The first time, your current directory is getting removed (so ../ won't refer to a real directory the second time around). The bug is really in rm(1)'s initial diagnostic message. -- jan grant, ISYS, University of Bristol. http://www.bris.ac.uk/ Tel +44 (0)117 3317661 http://ioctl.org/jan/ We thought time travel was impossible. But that was now and this is then.