Bug 1311796 - --new-chroot causes incorrect $PATH
--new-chroot causes incorrect $PATH
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: mock (Show other bugs)
rawhide
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Miroslav Suchý
Fedora Extras Quality Assurance
: Reopened
: 1299494 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-02-24 21:06 EST by Colin Walters
Modified: 2016-06-02 10:31 EDT (History)
8 users (show)

See Also:
Fixed In Version: mock-1.2.17-1.fc22 mock-1.2.17-1.fc24 mock-1.2.17-1.el6 mock-1.2.17-1.el7 mock-1.2.17-1.fc23
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-03-30 21:53:51 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
0001-backend-Ensure-our-environment-is-set-for-rpmbuild-a.patch (3.46 KB, patch)
2016-02-24 22:00 EST, Colin Walters
no flags Details | Diff

  None (edit)
Description Colin Walters 2016-02-24 21:06:41 EST
$ rpm -q mock
mock-1.2.15-1.el7.noarch

I was trying to build an updated glib for centos7, which needed an updated gtk-doc, and got a strange error in the chain (rpmdistro-gitoverlay) that /bin/python couldn't be resolved.

I tracked this down to --new-chroot causing /bin to be earlier in $PATH:

<walters> if i add an echo in %build I get: PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/builddir/.local/bin:/builddir/bin  yet mock --shell echo $PATH has /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin as i'd expect

$ mock --new-chroot -r epel-7-x86_64 /mnt/Nomad/gtk-doc-1.19-3.el7.src.rpm
...
Requires: /bin/perl /bin/python /bin/sh /usr/bin/pkg-config perl(Cwd) 
...

$ mock --old-chroot -r epel-7-x86_64 /mnt/Nomad/gtk-doc-1.19-3.el7.src.rpm
...
Requires: /bin/sh /usr/bin/perl /usr/bin/pkg-config /usr/bin/python perl(Cwd) perl(Getopt::Long) perl(bytes) perl(strict)
...
Comment 1 Colin Walters 2016-02-24 21:59:27 EST
I am really mystified at what is munging the path that way...tentatively thinking it's something involving systemd-nspawn running through PAM in the new root?

Really...we should just kill /bin and /sbin from $PATH.
Comment 2 Colin Walters 2016-02-24 22:00 EST
Created attachment 1130420 [details]
0001-backend-Ensure-our-environment-is-set-for-rpmbuild-a.patch

Anyways, this patch fixes it for me.
Comment 3 Miroslav Suchý 2016-02-26 06:08:23 EST
This comes from default config. See /etc/mock/site-defaults.cfg
  config_opts['environment']['PATH'] = '/usr/bin:/bin:/usr/sbin:/sbin'

> Really...we should just kill /bin and /sbin from $PATH.

Not possible because EL5 and EL6 still have it.

> /bin/python couldn't be resolved.

This is not because of $PATH because /bin/ is in $PATH after /usr/bin.
I suspect that this is because some package either
1) requires /bin/python or
2) have in some script #!/bin/python so rpmbuild take it as automatic requires which is equivalent of 1)
And epel7 (and fedoras) no longer provides /bin/* automatic provides generated from filelist (I recall some discussion about it on devel mailing list).

To sum it up. This is likely packaging issue. If you really need to alter env, then you can use config to change it.
Comment 4 Colin Walters 2016-02-26 08:29:54 EST
(In reply to Miroslav Suchý from comment #3)
> This comes from default config. See /etc/mock/site-defaults.cfg
>   config_opts['environment']['PATH'] = '/usr/bin:/bin:/usr/sbin:/sbin'

I did not change the mock config between the two runs.

> > Really...we should just kill /bin and /sbin from $PATH.
> 
> Not possible because EL5 and EL6 still have it.

Sure, though we could conditionalize on distribution major likely.

> > /bin/python couldn't be resolved.
> 
> This is not because of $PATH because /bin/ is in $PATH after /usr/bin.

Did you even read my patch?  It *is* because of $PATH, I added an "echo PATH=$PATH" in gtk-doc's %build and saw it was wrong.  

Again, I think what's happening here is that for non-nspawn, we inherit the environment from doChroot().  But nspawn cleans the environment, so we need to inject it into our command.

> 2) have in some script #!/bin/python so rpmbuild take it as automatic
> requires which is equivalent of 1)

Yes, and that happens because it's found first in $PATH when using nspawn.

> To sum it up. This is likely packaging issue.

No, this is using unmodified CentOS 7 packages.  Just try it!
Comment 5 Miroslav Suchý 2016-02-26 09:41:18 EST
Ah, you are right. I tried to alter it and it is indeed not passed to nspawn container.

However I do not think your approach is correct as it just fix rebuilds. If you use e.g. --shell then you do not have those variables defined.

I think correct way is to alter util._prepare_nspawn_command() to get environment and pass it to systemd-nspawn as --set-env=KEY=VALUE.
Comment 6 Colin Walters 2016-02-26 10:11:35 EST
It's definitely something in the PAM stack which is breaking $PATH:

```
$ sudo systemd-nspawn -D /var/lib/mock/epel-7-x86_64/root
Spawning container root on /var/lib/mock/epel-7-x86_64/root.
Press ^] three times within 1s to kill container.
-bash-4.2# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
-bash-4.2# su -l mockbuild
Last login: Fri Feb 26 10:10:27 EST 2016 on console
[mockbuild@root ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/builddir/.local/bin:/builddir/bin
[mockbuild@root ~]$ 
```
Comment 7 Colin Walters 2016-02-26 10:27:14 EST
Which means using --set-env for nspawn won't work, we need to do it after su.  I'm not sure I have the stomach this morning to read the PAM code and figure out what's doing it, but even if we fixed PAM, we'd still need to support older distros...so we need to call `env` after `su` inside _prepare_nspawn_command(), agreed?
Comment 8 Miroslav Suchý 2016-02-26 11:19:38 EST
Fixed in commit:
* 057c51d (HEAD -> devel, origin/devel) tell nspawn which variables it should set [RHBZ#1311796]

I modified:
  config_opts['environment']['PATH'] = '/usr/bin:/usr/sbin'
and put in my spec:
  %build
  echo PATH is: $PATH
and run:
  $ mock -r epel-7-x86_64 --new-chroot /home/msuchy/rpmbuild/SRPMS/copr-ping-1-1.fc23.src.rpm
....
Provádění(%build): /bin/sh -e /var/tmp/rpm-tmp.7kbQOk
PATH is: /usr/bin:/usr/sbin

Can you test if it pass your tests, please?
Comment 9 Colin Walters 2016-02-26 11:35:58 EST
Ah, I see you changed more code to avoid shell strings.  That is definitely better.  I had a patch in progress for similar changes like -u mockbuild instead of su.

Works for me.
Comment 10 Colin Walters 2016-02-26 11:53:18 EST
I take that back, there's some other regression:

With devel tip @ 057c51d6a0e47377a45f811ec7c0c013c4c31e00:

$ mock -r fedora-23-i386 packaging/ostree-2016.2.9.g5345573-3.el7.src.rpm
...
INFO: Installed packages:
Start: build phase for ostree-2016.2.9.g5345573-3.el7.src.rpm
Start: build setup for ostree-2016.2.9.g5345573-3.el7.src.rpm
ERROR: Exception(packaging/ostree-2016.2.9.g5345573-3.el7.src.rpm) Config(fedora-23-i386) 0 minutes 56 seconds
INFO: Results and/or logs in: /var/lib/mock/fedora-23-i386/result
ERROR: Expected to find single rebuilt srpm, found 0.
WARNING: unable to delete selinux filesystems (/tmp/mock-selinux-plugin.3xSybj): [Errno 1] Operation not permitted: '/tmp/mock-selinux-plugin.3xSybj'

With the previous devel @ a9a957dbe23aa0c9ac1245897bf94ed70b78c951 it works.
Comment 11 Miroslav Suchý 2016-03-07 07:51:26 EST
(In reply to Colin Walters from comment #10)
> WARNING: unable to delete selinux filesystems
> (/tmp/mock-selinux-plugin.3xSybj): [Errno 1] Operation not permitted:
> '/tmp/mock-selinux-plugin.3xSybj'
> 
> With the previous devel @ a9a957dbe23aa0c9ac1245897bf94ed70b78c951 it works.

That is bug 1312820
Comment 12 Fedora Update System 2016-03-08 15:53:22 EST
mock-1.2.16-1.fc22 has been submitted as an update to Fedora 22. https://bodhi.fedoraproject.org/updates/FEDORA-2016-66229b4649
Comment 13 Fedora Update System 2016-03-08 15:53:48 EST
mock-1.2.16-1.el7 has been submitted as an update to Fedora EPEL 7. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-3405d4e45b
Comment 14 Fedora Update System 2016-03-08 15:54:22 EST
mock-1.2.16-1.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2016-a9958aa8eb
Comment 15 Fedora Update System 2016-03-08 15:54:39 EST
mock-1.2.16-1.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2016-bbb4bfc16f
Comment 16 Fedora Update System 2016-03-08 15:54:58 EST
mock-1.2.16-1.el6 has been submitted as an update to Fedora EPEL 6. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-25ff2f1000
Comment 17 Fedora Update System 2016-03-09 16:23:32 EST
mock-1.2.16-1.fc22 has been pushed to the Fedora 22 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-66229b4649
Comment 18 Fedora Update System 2016-03-09 17:55:31 EST
mock-1.2.16-1.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-a9958aa8eb
Comment 19 Fedora Update System 2016-03-09 18:18:30 EST
mock-1.2.16-1.el6 has been pushed to the Fedora EPEL 6 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-25ff2f1000
Comment 20 Fedora Update System 2016-03-09 18:21:01 EST
mock-1.2.16-1.el7 has been pushed to the Fedora EPEL 7 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-3405d4e45b
Comment 21 Fedora Update System 2016-03-09 20:56:50 EST
mock-1.2.16-1.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-bbb4bfc16f
Comment 22 Fedora Update System 2016-03-11 04:08:18 EST
mock-1.2.17-1.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2016-bbb4bfc16f
Comment 23 Fedora Update System 2016-03-11 04:17:21 EST
mock-1.2.17-1.fc22 has been submitted as an update to Fedora 22. https://bodhi.fedoraproject.org/updates/FEDORA-2016-66229b4649
Comment 24 Fedora Update System 2016-03-11 14:27:53 EST
mock-1.2.17-1.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-bbb4bfc16f
Comment 25 Fedora Update System 2016-03-12 11:54:26 EST
mock-1.2.17-1.fc22 has been pushed to the Fedora 22 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-66229b4649
Comment 26 Fedora Update System 2016-03-15 15:06:20 EDT
mock-1.2.17-1.el7 has been submitted as an update to Fedora EPEL 7. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-23c93722c3
Comment 27 Fedora Update System 2016-03-15 15:06:47 EDT
mock-1.2.17-1.el6 has been submitted as an update to Fedora EPEL 6. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-d4770f601d
Comment 28 Fedora Update System 2016-03-15 22:20:42 EDT
mock-1.2.17-1.el6 has been pushed to the Fedora EPEL 6 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-d4770f601d
Comment 29 Fedora Update System 2016-03-15 22:50:58 EDT
mock-1.2.17-1.el7 has been pushed to the Fedora EPEL 7 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-23c93722c3
Comment 30 Fedora Update System 2016-03-20 16:21:16 EDT
mock-1.2.17-1.fc22 has been pushed to the Fedora 22 stable repository. If problems still persist, please make note of it in this bug report.
Comment 31 Fedora Update System 2016-03-26 14:18:00 EDT
mock-1.2.17-1.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.
Comment 32 Fedora Update System 2016-03-28 10:54:30 EDT
mock-1.2.16-1.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2016-a9958aa8eb
Comment 33 Fedora Update System 2016-03-28 16:49:49 EDT
mock-1.2.17-1.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-a9958aa8eb
Comment 34 Fedora Update System 2016-03-30 21:53:32 EDT
mock-1.2.17-1.el6 has been pushed to the Fedora EPEL 6 stable repository. If problems still persist, please make note of it in this bug report.
Comment 35 Fedora Update System 2016-03-31 01:28:54 EDT
mock-1.2.17-1.el7 has been pushed to the Fedora EPEL 7 stable repository. If problems still persist, please make note of it in this bug report.
Comment 36 Fedora Update System 2016-04-02 00:21:01 EDT
mock-1.2.17-1.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.
Comment 37 Miroslav Suchý 2016-06-02 10:31:31 EDT
*** Bug 1299494 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.