[Bug 221331] [PATCH] update for unlink(2) manpage

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Fri Nov 8 09:17:23 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221331

Oleksandr Tymoshenko <gonzo at FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doc at FreeBSD.org
          Component|Documentation               |Manual Pages
           Assignee|doc at FreeBSD.org             |bugs at FreeBSD.org

WHR <msl0000023508 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msl0000023508 at gmail.com

--- Comment #1 from WHR <msl0000023508 at gmail.com> ---
There was a case that unlink(2) may return EISDIR.

Function kern_unlinkat calls namei(9) to find the parent directory of the file;
it will return EISDIR if the requested path was '/'.

Since '/' isn't a real link (but '/.' and '/..'), it can't be unlinked anyways.

Test:

# cat unlink.c 
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv) {
        if(argc != 2) {
                fprintf(stderr, "Usage: %s <path>\n", argv[0]);
                return -1;
        }
        if(unlink(argv[1]) < 0) {
                perror(argv[1]);
                return 1;
        }
        return 0;
}
# gcc -Wall -O1 unlink.c -o unlink
# ./unlink /etc/
/etc/: Operation not permitted
# ./unlink /.
/.: Operation not permitted
# ./unlink /
/: Is a directory

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.


More information about the freebsd-doc mailing list