> 2020-02-16 Bruno Haible <br...@clisp.org> > > lchmod: Make more future-proof. > * m4/lchmod.m4 (gl_FUNC_LCHMOD): Define NEED_LCHMOD_NONSYMLINK_FIX. > (gl_PREREQ_LCHMOD): New macro. > * lib/lchmod.c (orig_lchmod): New function. > (lchmod): Test NEED_LCHMOD_NONSYMLINK_FIX. Access /proc only on Linux. > Return EOPNOTSUPP only on Linux and on platforms without lchmod > function. > * modules/lchmod (configure.ac): Invoke gl_PREREQ_LCHMOD.
Oops, this change is broken: It causes a link error on Solaris 10: cc -xarch=generic64 -O -D_STDC_C99= -g -L/home/haible/prefix-x86_64/lib -o test-areadlinkat test-areadlinkat.o libtests.a ../gllib/libgnu.a libtests.a Undefined first referenced symbol in file orig_lchmod ../gllib/libgnu.a(lchmod.o) ld: fatal: symbol referencing errors. No output written to test-areadlinkat *** Error code 1 This patch fixes it. 2020-02-22 Bruno Haible <br...@clisp.org> lchmod: Fix link error on Solaris 10 (regression from 2020-02-16). * lib/lchmod.c (lchmod): Use the code with lstat and chmod also when NEED_LCHMOD_NONSYMLINK_FIX is not defined. diff --git a/lib/lchmod.c b/lib/lchmod.c index 57f75da..e62111c 100644 --- a/lib/lchmod.c +++ b/lib/lchmod.c @@ -64,9 +64,9 @@ lchmod (char const *file, mode_t mode) /* Gnulib's fchmodat contains the workaround. No need to duplicate it here. */ return fchmodat (AT_FDCWD, file, mode, AT_SYMLINK_NOFOLLOW); -#elif NEED_LCHMOD_NONSYMLINK_FIX -# if defined AT_FDCWD && defined O_PATH && defined AT_EMPTY_PATH \ - && (defined __linux__ || defined __ANDROID__) +#elif NEED_LCHMOD_NONSYMLINK_FIX \ + && defined AT_FDCWD && defined O_PATH && defined AT_EMPTY_PATH \ + && (defined __linux__ || defined __ANDROID__) /* newer Linux */ /* Open a file descriptor with O_NOFOLLOW, to make sure we don't follow symbolic links, if /proc is mounted. O_PATH is used to avoid a failure if the file is not readable. @@ -113,8 +113,9 @@ lchmod (char const *file, mode_t mode) /* /proc is not mounted. */ /* Fall back on chmod, despite the race. */ return chmod (file, mode); -# elif HAVE_LSTAT -# if (defined __linux__ || defined __ANDROID__) || !HAVE_LCHMOD +#elif HAVE_LSTAT +# if (NEED_LCHMOD_NONSYMLINK_FIX && (defined __linux__ || defined __ANDROID__)) \ + || !HAVE_LCHMOD /* older Linux, Solaris 10 */ struct stat st; int lstat_result = lstat (file, &st); if (lstat_result != 0) @@ -126,13 +127,10 @@ lchmod (char const *file, mode_t mode) } /* Fall back on chmod, despite the race. */ return chmod (file, mode); -# else /* GNU/kFreeBSD, GNU/Hurd, macOS, FreeBSD, NetBSD, HP-UX */ +# else /* GNU/kFreeBSD, GNU/Hurd, macOS, FreeBSD, NetBSD, HP-UX */ return orig_lchmod (file, mode); -# endif -# else /* native Windows */ - return chmod (file, mode); # endif -#else - return orig_lchmod (file, mode); +#else /* native Windows */ + return chmod (file, mode); #endif }