This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] ldconfig: Do not remove stale symbolic links with -X [BZ #19610]
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: Florian Weimer <fweimer at redhat dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Fri, 12 Feb 2016 13:34:28 -0500
- Subject: Re: [PATCH] ldconfig: Do not remove stale symbolic links with -X [BZ #19610]
- Authentication-results: sourceware.org; auth=none
- References: <56BC8790 dot 1080400 at redhat dot com>
On 02/11/2016 08:07 AM, Florian Weimer wrote:
> I think this change makes ldconfig match user expectations.
I think this patch is the right way forward. Particularly if
you look at create_links, it never removes a symlink if opt_link
is zero. It violates the principle of least surprise to have
stale links removed and new ones not created.
At the high level:
- Excellent test case and use of ldconfig options to test this.
- Needs clarifying documentation patch sent to linux man pages
to remove ambiguity from description of '-X' functionalty.
Right now it says "Don't update links", but it should really
say "Do not create or remove any existing links." to be as
clear as possible.
At the design level:
- Comment for opt_link needs to change. Expand the comment on
line 103 in elf/ldconfig.c to describe in more detail that
symlinks are not created, and that neither are they removed
if they exist and are stale.
- Use mktemp to create a temporary directory that exists instead
of using /opt which might be problematic.
Looks good with those 2 design-level changes.
Looking forward to the man page patch to clarify documentation.
> 2016-02-11 Florian Weimer <fweimer@redhat.com>
>
> [BZ #19610]
> * elf/ldconfig.c (search_dir): Unlink stale symbolic link only if
> updating symbolic links.
> (options): Update help string for option -X.
> * elf/bug19610.sh: New file.
> * elf/Makefile (tests-special): Add bug19610.out.
> (bug19610.out): New rule to run bug19610.sh.
>
> diff --git a/elf/Makefile b/elf/Makefile
> index 63a5355..4655033 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -163,7 +163,8 @@ endif
> endif
> ifeq ($(run-built-tests),yes)
> tests-special += $(objpfx)tst-leaks1-mem.out \
> - $(objpfx)tst-leaks1-static-mem.out $(objpfx)noload-mem.out
> + $(objpfx)tst-leaks1-static-mem.out $(objpfx)noload-mem.out \
> + $(objpfx)bug19610.out
OK.
> endif
> tlsmod17a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> tlsmod18a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
> @@ -1252,3 +1253,7 @@ $(objpfx)tst-prelink-cmp.out: tst-prelink.exp \
> $(objpfx)tst-prelink-conflict.out
> cmp $^ > $@; \
> $(evaluate-test)
> +
> +$(objpfx)bug19610.out : bug19610.sh $(objpfx)ldconfig
> + $(SHELL) $< '$(common-objpfx)' '$(test-wrapper)' '$(test-wrapper-env)' > $@; \
> + $(evaluate-test)
OK.
> diff --git a/elf/bug19610.sh b/elf/bug19610.sh
> new file mode 100644
> index 0000000..f125bc1
> --- /dev/null
> +++ b/elf/bug19610.sh
> @@ -0,0 +1,60 @@
> +#!/bin/sh
> +# Test that ldconfig -X does not remove stale symbolic links.
> +# Copyright (C) 2000-2016 Free Software Foundation, Inc.
> +# This file is part of the GNU C Library.
> +
> +# The GNU C Library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU Lesser General Public
> +# License as published by the Free Software Foundation; either
> +# version 2.1 of the License, or (at your option) any later version.
> +
> +# The GNU C Library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +# Lesser General Public License for more details.
> +
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with the GNU C Library; if not, see
> +# <http://www.gnu.org/licenses/>.
> +
> +set -ex
> +
> +common_objpfx=$1
> +test_wrapper_env=$2
> +run_program_env=$3
> +
> +testroot="${common_objpfx}elf/bug19610-test-directory"
> +cleanup () {
> + rm -rf "$testroot"
> +}
> +trap cleanup 0
OK.
> +
> +rm -rf "$testroot"
> +mkdir -p $testroot/lib $testroot/etc
OK.
> +
> +ln -s libdoesnotexist.so.1.1 $testroot/lib/libdoesnotexist.so.1
> +ln -s /opt/sw/lib/libdoesnotexist2.so.1.1 $testroot/lib/
OK. I worry slightly about users having stale NFS handles for /opt
causing tests to hang. Might we use mktemp to generate that path?
I think /tmp should never be invalid in that case.
> +errors=0
> +check_files () {
> + for name in libdoesnotexist.so.1 libdoesnotexist2.so.1.1 ; do
> + path="$testroot/lib/$name"
> + if test ! -h $path ; then
> + echo "error: missing file: $path"
> + errors=1
> + fi
> + done
> +}
> +
> +check_files
> +
> +${test_wrapper_env} \
> +${run_program_env} \
> +${common_objpfx}elf/ldconfig -X -f /dev/null \
> + -C $testroot/etc/ld.so.cache \
> + $testroot/lib
> +
> +check_files
> +
> +exit $errors
OK. Awesome test.
> diff --git a/elf/ldconfig.c b/elf/ldconfig.c
> index 9c6f2ba..5890322 100644
> --- a/elf/ldconfig.c
> +++ b/elf/ldconfig.c
> @@ -141,7 +141,7 @@ static const struct argp_option options[] =
> { "print-cache", 'p', NULL, 0, N_("Print cache"), 0},
> { "verbose", 'v', NULL, 0, N_("Generate verbose messages"), 0},
> { NULL, 'N', NULL, 0, N_("Don't build cache"), 0},
> - { NULL, 'X', NULL, 0, N_("Don't generate links"), 0},
> + { NULL, 'X', NULL, 0, N_("Don't update symbolic links"), 0},
OK.
> { NULL, 'r', N_("ROOT"), 0, N_("Change to and use ROOT as root directory"), 0},
> { NULL, 'C', N_("CACHE"), 0, N_("Use CACHE as cache file"), 0},
> { NULL, 'f', N_("CONF"), 0, N_("Use CONF as configuration file"), 0},
> @@ -800,7 +800,7 @@ search_dir (const struct dir_entry *entry)
> error (0, errno, _("Cannot stat %s"), file_name);
>
> /* Remove stale symlinks. */
> - if (strstr (direntry->d_name, ".so."))
> + if (opt_link && strstr (direntry->d_name, ".so."))
OK.
> unlink (real_file_name);
> continue;
> }
Cheers,
Carlos.