Make unlink on directory as root set errno.
authorEvan Zacks <zackse@cpan.org>
Tue, 26 Nov 2013 14:56:11 +0000 (09:56 -0500)
committerCraig A. Berry <craigberry@mac.com>
Tue, 3 Dec 2013 04:45:36 +0000 (22:45 -0600)
commit1dcae8b8dd1e2aa373ab045fee3d4f95d34f0b3c
treebe70583afa6fd8bdb89c3e26763f7148652961ab
parent448f81ea464c80a9a14d972e68f7649d1ed12d8a
Make unlink on directory as root set errno.

If unlink is called on an existing directory while running as root without -U
(PL_unsafe), the unlink call fails but does not set $!, because unlink(2) is
not actually called in this case.

If unlink is called as a user (or as root with -U), unlink(2) is invoked, so
attempting to remove a directory would set errno to EISDIR as expected. If
running as root without -U (PL_unsafe is false), lstat and S_ISDIR are called
instead. If the lstat succeeds and S_ISDIR returns true, the argument is
skipped without warning and without setting $!, meaning Perl's unlink can
return failure while leaving the previous value of errno in place.

This commit sets errno to EISDIR for this case.
AUTHORS
doio.c
t/io/fs.t