bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make lchmodat friendlier


From: Jim Meyering
Subject: Re: make lchmodat friendlier
Date: Mon, 07 Sep 2009 07:49:11 +0200

Eric Blake wrote:
> 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.

Good idea.
I hesitated to appropriate the names initially, but the combination
of increased readability and orthogonality make it worthwhile.

> 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;
> +}

Is this useful to you on Cygwin?  Fewer diagnostics?
If so, go ahead.
The drawback is that it makes it harder
to perform a run-time test for lchmod support.
The test requires a symlink.

More importantly, the test writer would need to know
about this half-functional implementation.
Otherwise, an application that doesn't know about this
new feature/requirement risks determining that
lchmod support is available when it is not.
So maybe a word in NEWS or documentation.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]