Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 709422 - app-eselect/eselect-php-0.9.4-r5: does not respect ROOT env variable
Summary: app-eselect/eselect-php-0.9.4-r5: does not respect ROOT env variable
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: PHP Bugs
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2020-02-12 19:57 UTC by Stefan Langenmaier
Modified: 2020-03-01 13:59 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
root-env-patch (root_env.patch,1.92 KB, patch)
2020-02-12 19:59 UTC, Stefan Langenmaier
Details | Diff
patch to respect the ROOT env variable (0001-respect-ROOT-env-variable.patch,2.47 KB, patch)
2020-02-28 23:13 UTC, Stefan Langenmaier
Details | Diff
relative-links.patch (relative-links.patch,1.78 KB, patch)
2020-02-29 17:02 UTC, Michael Orlitzky
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Langenmaier 2020-02-12 19:57:34 UTC
I'm trying to build a custom system with the ROOT env variable.
eselect php does not seem to respect this variable. It does not list installed php versions and cannot set them.
According to the wiki this should be supported:
https://wiki.gentoo.org/wiki/Project:Eselect/User_guide#Advantages_for_end_users_and_system_administrators

I didn't find any support in the code. I have attached my current fix/patch.
It can list and set php modules but does not display the active version. I'm willing to work on it in case I get feedback or if this is a desired functionality.

Reproducible: Always

Steps to Reproduce:
1. ROOT=/var/mybuilroot/ USE="fpm" emerge php
2. ROOT=/var/mybuilroot/ eselect php list fpm
3. 
Actual Results:  
Cannot find a php installation.

Actually already the post installation step of php fails.

Expected Results:  
Should find the php installation
Comment 1 Stefan Langenmaier 2020-02-12 19:59:30 UTC
Created attachment 613582 [details, diff]
root-env-patch

My current patch to update the symlinks in to ROOT environment.

This does not display the active php module.
Comment 2 Michael Orlitzky gentoo-dev 2020-02-12 22:25:20 UTC
This should work, but I've never tried it, so.... it probably doesn't. The PHP eselect module is actually configured with all of the right paths at build-time, using autotools:

  https://gitweb.gentoo.org/proj/eselect-php.git/

So if you have ROOT=/var/mybuilroot and if you install eselect-php (this should happen when you install PHP itself), then the copy of eselect-php that you get under /var/mybuilroot *should* look in the correct location. In other words, you should have two copies of "eselect php",

  1. the system one in /usr/share/eselect/modules/php.eselect

  2. the ROOTed one in /var/mybuilroot/usr/share/eselect/modules/php.eselect

The first one should control the system copy of PHP, and the second one should control the copy of PHP in /var/mybuilroot.

Does anything resembling the correct behavior happen if you run

  $ /var/mybuilroot/usr/bin/eselect php

instead of just "eselect php"?
Comment 3 Stefan Langenmaier 2020-02-13 06:51:41 UTC
Hi Michal,

thanks for the fast response. Yes I have seen that it's set a build-time.


> In other words, you should have two copies of "eselect php",

Yes, there are two installations in my setup. Both modules contain "/usr/lib64/" and I think this is correct. As the system under "/var/build-root" is supposed to later run on it's own this will be the correct path in that environment.

During the build of this environment the executables from the "host" are used. So I have no influence what is executed in the post installation step of the php package. It will be /usr/bin/eselect.

I have tried to execute /var/build-root/usr/bin/eselect manually, but without luck as it contains the same @LIBDIR@ path as the the one in the host.

I think that has to be solved dynamically in the eselect module of the host environment. ideally the path has to created relatively so it could be checked if it links to the correct files.
Comment 4 Michael Orlitzky gentoo-dev 2020-02-13 12:59:51 UTC
(In reply to Stefan Langenmaier from comment #3)
> 
> > In other words, you should have two copies of "eselect php",
> 
> Yes, there are two installations in my setup. Both modules contain
> "/usr/lib64/" and I think this is correct. As the system under
> "/var/build-root" is supposed to later run on it's own this will be the
> correct path in that environment.

Upon closer inspection, you are right.

Does everything work with the patch you provided? I think we should strip the trailing slash with ${ROOT%/} everywhere, but other than that it looks OK to me.
Comment 5 Stefan Langenmaier 2020-02-18 08:01:18 UTC
The installation has worked so far for me, but I'll report back on the functionality and with an updated patch next week.
Comment 6 Stefan Langenmaier 2020-02-28 23:13:46 UTC
Created attachment 616552 [details, diff]
patch to respect the ROOT env variable

This patch includes the trimming of the trailing slash and a warning if the module is used to display the configuration.

The patch is working for me.
Comment 7 Michael Orlitzky gentoo-dev 2020-02-29 01:19:08 UTC
Thanks. I played with it for a bit to see if it was possible to get the list/show actions working. I think you just forgot to add ROOT in one place,

  -       local link_target_dir="@LIBDIR@/${target}/bin"
  +       local link_target_dir="${ROOT%/}@LIBDIR@/${target}/bin"

unless there's a reason why that instance was left alone?
Comment 8 Stefan Langenmaier 2020-02-29 11:26:25 UTC
Hi Michael,

this was intentional if I understand the `set_sapi` function correctly.

https://gitweb.gentoo.org/proj/eselect-php.git/tree/src/php.eselect.in.in#n461

There, the symlinks are created while we are in the "host" environment. The symlinks have to be created to work later in the environment of the "ROOT" variable.

So inside the "ROOT" environment if the link is still prefixed with the "ROOT" variable it will not work.

While we are in the "host" environment the link actually points to the wrong binaries, but it should not be executed there.

I hope this explains my understanding.
Comment 9 Michael Orlitzky gentoo-dev 2020-02-29 16:12:48 UTC
(In reply to Stefan Langenmaier from comment #8)
> Hi Michael,
> 
> this was intentional if I understand the `set_sapi` function correctly.
> 
> https://gitweb.gentoo.org/proj/eselect-php.git/tree/src/php.eselect.in.
> in#n461
> 
> There, the symlinks are created while we are in the "host" environment. The
> symlinks have to be created to work later in the environment of the "ROOT"
> variable.
> 
> So inside the "ROOT" environment if the link is still prefixed with the
> "ROOT" variable it will not work.
> 
> While we are in the "host" environment the link actually points to the wrong
> binaries, but it should not be executed there.
> 
> I hope this explains my understanding.

Ahhh I see. You need to be able to chroot() into the ROOT and have the symlinks still work.

But for the list/show actions... if the symlinks are absolute and *not* prefixed with ROOT, then the symlinks inside the ROOT point outside of it and won't work before you chroot().

Maybe this can all be fixed by using relative symlinks. I'll think about it.
Comment 10 Michael Orlitzky gentoo-dev 2020-02-29 17:02:21 UTC
Created attachment 616630 [details, diff]
relative-links.patch

Can you try this? It seems to do the right thing in my made-up test scenario.
Comment 11 Michael Orlitzky gentoo-dev 2020-02-29 17:02:52 UTC
That applies on top of your patch, BTW.
Comment 12 Stefan Langenmaier 2020-02-29 19:16:28 UTC
(In reply to Michael Orlitzky from comment #10)
> Created attachment 616630 [details, diff] [details, diff]
> relative-links.patch
> 
> Can you try this? It seems to do the right thing in my made-up test scenario.

Cool, I just tried it and it's working for me. I can set the options and display them.

> Ahhh I see. You need to be able to chroot() into the ROOT and have the symlinks still work.

Yes, actually I'm trying to create the filesystem that I later want to use as Docker image.
Comment 13 Larry the Git Cow gentoo-dev 2020-02-29 22:16:15 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=eccdef0c3d501060838c803ffa81ed79ca614dc0

commit eccdef0c3d501060838c803ffa81ed79ca614dc0
Author:     Michael Orlitzky <mjo@gentoo.org>
AuthorDate: 2020-02-29 21:53:38 +0000
Commit:     Michael Orlitzky <mjo@gentoo.org>
CommitDate: 2020-02-29 22:00:28 +0000

    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@gentoo.org>

 src/php.eselect.in.in | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
Comment 14 Michael Orlitzky gentoo-dev 2020-02-29 22:17:52 UTC
Thanks, I committed your patch and made the symlinks relative. There's one other thing to do and then I'll make a new release.
Comment 15 Stefan Langenmaier 2020-03-01 08:44:39 UTC
(In reply to Michael Orlitzky from comment #14)
> Thanks, I committed your patch and made the symlinks relative. There's one
> other thing to do and then I'll make a new release.

Thanks for your feedback and all the work!
Comment 16 Larry the Git Cow gentoo-dev 2020-03-01 13:59:42 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=80e9cccfa6bf0f6fc15dda9f1423d5cdca8b2354

commit 80e9cccfa6bf0f6fc15dda9f1423d5cdca8b2354
Author:     Michael Orlitzky <mjo@gentoo.org>
AuthorDate: 2020-03-01 13:10:27 +0000
Commit:     Michael Orlitzky <mjo@gentoo.org>
CommitDate: 2020-03-01 13:58:34 +0000

    app-eselect/eselect-php: new version 0.9.6.
    
    New EAPI=7 version with some nice stuff:
    
      * The php-fpm-launcher script and php-fpm.conf tmpfiles.d entry
        are now upstream, simplifying the ebuild.
    
      * We install a logrotate script for php-fpm.
    
      * The eselect module itself now supports $ROOT.
    
      * We support symlinks for the "phar" executable.
    
    Closes: https://bugs.gentoo.org/692194
    Closes: https://bugs.gentoo.org/709422
    Closes: https://bugs.gentoo.org/707876
    Package-Manager: Portage-2.3.84, Repoman-2.3.20
    Signed-off-by: Michael Orlitzky <mjo@gentoo.org>

 app-eselect/eselect-php/Manifest                 |  1 +
 app-eselect/eselect-php/eselect-php-0.9.6.ebuild | 33 ++++++++++++++++++++++++
 2 files changed, 34 insertions(+)