-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jim, what do you think of this patch, so that lchmodat only fails with ENOSYS when called on a symlink (when called on other file types, it would now succeed)?
Also, should "openat.h" provide shortcuts named: accessat() => faccessat(,0) euidaccessat() => faccessat(,AT_EACCESS) statat() => fstatat(,0) lstatat() => fstatat(,AT_SYMLINK_NOFOLLOW) to match the existing shortcuts of chownat, lchownat, etc. - -- Don't work too hard, make some time for fun as well! Eric Blake e...@byu.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkqkflQACgkQ84KuGfSFAYCXSACguRsFKUn+gdH52N8Rvdj/Rw6Z 3PUAoKCfDxsUaCVRxgwxZdEZYtfakuf8 =EPIy -----END PGP SIGNATURE-----
>From d4d4d1cae33f0dcc2829d3fbf12fa0b83bc3c53e Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Sun, 6 Sep 2009 21:08:00 -0600 Subject: [PATCH] openat: with no lchmod, only fail lchmodat on symlinks * lib/fchmodat.c (lchmod) [!HAVE_LCHMOD]: Perform lstat first, to minimize failure cases. Signed-off-by: Eric Blake <e...@byu.net> --- ChangeLog | 4 ++++ lib/fchmodat.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletions(-) diff --git a/ChangeLog b/ChangeLog index 06287d4..03e91c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-09-06 Eric Blake <e...@byu.net> + openat: with no lchmod, only fail lchmodat on symlinks + * lib/fchmodat.c (lchmod) [!HAVE_LCHMOD]: Perform lstat first, to + minimize failure cases. + renameat: new module * modules/renameat: New file. * lib/at-func2.c: Likewise. diff --git a/lib/fchmodat.c b/lib/fchmodat.c index 53cafe0..11ace83 100644 --- a/lib/fchmodat.c +++ b/lib/fchmodat.c @@ -30,7 +30,16 @@ system-supplied declaration. */ # undef lchmod # define lchmod lchmod_rpl -static int lchmod (char const *f, mode_t m) { errno = ENOSYS; return -1; } +static int +lchmod (char const *f, mode_t m) +{ + /* This is slightly racy, but better than nothing. */ + struct stat st; + if (lstat (f, &st) == -1 || !S_ISLNK (st.st_mode)) + return chmod (f, m); + errno = ENOSYS; + return -1; +} #endif /* Solaris 10 has no function like this. -- 1.6.3.3.334.g916e1