commit:     eccdef0c3d501060838c803ffa81ed79ca614dc0
Author:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 29 21:53:38 2020 +0000
Commit:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
CommitDate: Sat Feb 29 22:00:28 2020 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=eccdef0c

src/php.eselect.in.in: create symlinks relatively.

As part of our $ROOT support, we need symlinks within $ROOT to point
to stuff within $ROOT. The problem with that is that, if we create
those symlinks with absolute paths, then you can't later chroot() into
$ROOT and use them, because they'll point to the wrong place -- an
absolute path that was only correct before you chrooted.

Using relative symlinks seems to fix the problem, and shouldn't hurt
anything in the common case where ROOT is unset or contains only a
trailing slash.

Thanks are due to Stefan Langenmaier for reporting the problem and
helping us test the solution.

Bug: https://bugs.gentoo.org/709422
Signed-off-by: Michael Orlitzky <mjo <AT> gentoo.org>

 src/php.eselect.in.in | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/php.eselect.in.in b/src/php.eselect.in.in
index 12ef1e1..f78bf3d 100644
--- a/src/php.eselect.in.in
+++ b/src/php.eselect.in.in
@@ -85,7 +85,7 @@ sapi_active_link_target_dir() {
        local sapi="${1}"
        local target="${2}"
 
-       local link_target_dir="@LIBDIR@/${target}/bin"
+       local link_target_dir="${ROOT%/}@LIBDIR@/${target}/bin"
        if [[ "${sapi}" == "apache2" ]] ; then
                link_target_dir+="/../apache2"
        fi
@@ -459,9 +459,16 @@ set_sapi() {
        for link_name in $(sapi_active_link_names "${sapi}"); do
                local link_target=$(sapi_link_name_target "${sapi}" 
"${target_name}" "${link_name}")
 
+               # We need these links to be relative: when setting a target
+               # with ROOT nonempty, the symlink needs to point within
+               # ROOT. But if you later chroot() into ROOT, that link will
+               # point... nowhere, most likely. We need it to still point
+               # at the right target in that case!
+               local relative_target=$(relative_name \
+                                                                       
"${link_tgt_dir}/${link_target}" \
+                                                                       
"${link_dir}" )
                # Use the short "-f" option for POSIX compatibility.
-               @LN_S@ -f "${link_tgt_dir}/${link_target}" \
-                       "${link_dir}/${link_name}" || \
+               @LN_S@ -f "${relative_target}" "${link_dir}/${link_name}" || \
                        die -q "failed to create active ${link_name} symlink"
        done
 
@@ -518,11 +525,6 @@ describe_list_options() {
 }
 
 do_list() {
-       if [ "${ROOT%/}" != "" ] ; then
-               local msg
-               write_warning_msg "ROOT only supported in setting the 
configuration"
-               echo
-       fi
        local sapi="${1}"
        check_module "${sapi}"
        list_sapi "${sapi}"
@@ -543,11 +545,6 @@ describe_show_options() {
 }
 
 do_show() {
-       if [ "${ROOT%/}" != "" ] ; then
-               local msg
-               write_warning_msg "ROOT only supported in setting the 
configuration"
-               echo
-       fi
        local sapi="${1}"
        check_module "${sapi}"
        get_sapi_active_target "${sapi}"

Reply via email to