[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
make lchmodat friendlier
From: |
Eric Blake |
Subject: |
make lchmodat friendlier |
Date: |
Sun, 06 Sep 2009 21:30:28 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 |
-----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 address@hidden
-----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 <address@hidden>
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 <address@hidden>
---
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 <address@hidden>
+ 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
- make lchmodat friendlier,
Eric Blake <=