Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 651904 - sys-devel/distcc: systemd service does not include slotted clang in PATH
Summary: sys-devel/distcc: systemd service does not include slotted clang in PATH
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Michał Górny
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-29 11:19 UTC by Michał Górny
Modified: 2020-01-02 16:32 UTC (History)
2 users (show)

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


Attachments
Set PATH to ROOTPATH: /etc/systemd/system-environment-generators/50_distcc_path (50_distcc_path,242 bytes, application/x-shellscript)
2019-09-30 08:25 UTC, Bernd Feige
Details
Set PATH to ROOTPATH: /etc/systemd/system-environment-generators/50_distcc_path (50_distcc_path,188 bytes, application/x-shellscript)
2019-09-30 08:29 UTC, Bernd Feige
Details
Set PATH to ROOTPATH: /etc/systemd/system-environment-generators/50_distcc_path (50_distcc_path,223 bytes, text/plain)
2019-10-06 10:53 UTC, Bernd Feige
Details
Set PATH to ROOTPATH: /etc/systemd/system-environment-generators/50_distcc_path (50_distcc_path,170 bytes, text/plain)
2019-10-06 10:55 UTC, Bernd Feige
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2018-03-29 11:19:33 UTC
It seems that systemd uses a fixed $PATH when spawning distcc. As a result, our clang location from /etc/env.d/*llvm isn't respected and distccd is unable to find clang.

distcc-3.3 might be unaffected due to its new-ish shadowdir handling.
Comment 1 Bernd Feige 2018-10-09 12:59:57 UTC
I'm affected by this. distccmon-gui showed each job submitted to other workers waiting on "receiving" until a timeout.

Is there an official workaround?

My own kludge, which works for me, is to add

EnvironmentFile=/etc/env.d/10llvm-9992

to /etc/systemd/system/distccd.service.d/00gentoo.conf
Comment 2 Bernd Feige 2018-10-10 12:05:32 UTC
(In reply to Bernd Feige from comment #1)
> I'm affected by this. distccmon-gui showed each job submitted to other
> workers waiting on "receiving" until a timeout.
> 
> Is there an official workaround?
> 
> My own kludge, which works for me, is to add
> 
> EnvironmentFile=/etc/env.d/10llvm-9992
> 
> to /etc/systemd/system/distccd.service.d/00gentoo.conf

Then gcc distributed compilation stops working. It works with

EnvironmentFile=/etc/profile.env
Comment 3 Bernd Feige 2019-09-30 08:25:00 UTC
Created attachment 591276 [details]
Set PATH to ROOTPATH: /etc/systemd/system-environment-generators/50_distcc_path

Found a better fix now: Place an environment generator file in /etc/systemd/system-environment-generators which sets the PATH to ROOTPATH taken from /etc/profile.env.
Without this, I confirmed the PATH in the environment of systemd units (including distccd) to be
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

With it, it becomes the current ROOTPATH:
/usr/lib/llvm/9/bin:/usr/lib/llvm/8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin

With this, clang works with distccd.
Comment 4 Bernd Feige 2019-09-30 08:29:41 UTC
Created attachment 591278 [details]
Set PATH to ROOTPATH: /etc/systemd/system-environment-generators/50_distcc_path

Sorry, removed misleading comment in the generator
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2019-09-30 09:36:31 UTC
Hmm but this shouldn't be necessary with modern versions of distccd, as they require separate shadow directory for distccd-available compilers and we symlink clang there.
Comment 6 Bernd Feige 2019-09-30 10:56:14 UTC
(In reply to Michał Górny from comment #5)
> Hmm but this shouldn't be necessary with modern versions of distccd, as they
> require separate shadow directory for distccd-available compilers and we
> symlink clang there.

Well, sys-devel/distcc-3.3.3 here with "eselect compiler-shadow update distccd" and all. I still got "COMPILE_ERROR exit:110" (i.e. Compiler not found) errors after updating clang because the static EnvironmentFile solution I had before did not reflect the change (setting EnvironmentFile=/etc/profile.env does not work because of the "export" key words and is also an overkill). Advantage of using an environment generator is that it auto-updates.
Of course it would be nice if the symlinks maintained by eselect compiler-shadow would be sufficient. I doubt that that would be feasible though because the primary whitelisted binary (clang) needs to call other binaries (llvm) which it expects to be in the PATH as well. Shame on me that I didn't look it up in the source right now, but I think that distcc just matches the name with the symlink but still relies on PATH to actually start it?
Comment 7 Bernd Feige 2019-10-06 10:09:05 UTC
I have now checked the distcc sources confirming that /usr/lib/distcc is only used to check whether the compiler=command name (which must not contain a slash) is an accessible file in that directory (dcc_check_compiler_whitelist() in serve.c). The symlinks are never actually read. If the check is successful, the command is just executed using execvp() (in exec.c). Thus, the directory in which the binary resides must be in the PATH.
Comment 8 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2019-10-06 10:14:02 UTC
Oh my, that's really silly indeed.  Thanks for checking it.

Any reason your patch is using ROOTPATH instead of plain PATH?  Both should have LLVM paths in them.

Also, please use "sed -n -e '/.../p'" instead of the other way around ;-).
Comment 9 Bernd Feige 2019-10-06 10:51:49 UTC
(In reply to Michał Górny from comment #8)
> Oh my, that's really silly indeed.  Thanks for checking it.
> 
> Any reason your patch is using ROOTPATH instead of plain PATH?  Both should
> have LLVM paths in them.

Sure they do. However, the altered PATH is used for all commands started by systemd, not just for distccd, and it would be a security risk to set PATH to the common user PATH. It also is the least invasive change having the desired effect, since the resulting PATH is practically what the overly restricted default for systemd uses, with just llvm and /opt/bin added. I'm not sure how systemd derives that default PATH, maybe we should file a bug requesting to use ROOTPATH...

> Also, please use "sed -n -e '/.../p'" instead of the other way around ;-).

Thanks, my sed skills are a bit rusty... Upgraded script comes in a second...
Comment 10 Bernd Feige 2019-10-06 10:53:29 UTC
Created attachment 591964 [details]
Set PATH to ROOTPATH: /etc/systemd/system-environment-generators/50_distcc_path
Comment 11 Bernd Feige 2019-10-06 10:55:41 UTC
Created attachment 591966 [details]
Set PATH to ROOTPATH: /etc/systemd/system-environment-generators/50_distcc_path

Sorry, one more misleading comment fixed...
Comment 12 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2019-10-06 11:12:24 UTC
I think you are associating the wrong idea with ROOTPATH.

Originally, it existed to add /sbin & /usr/sbin only for root.  However, that's been really painful to our power users, so eventually PATH and ROOTPATH became the same.

That said, the only reason LLVM is present in ROOTPATH is that Portage historically used ROOTPATH instead of PATH.
Comment 13 Bernd Feige 2019-10-06 14:56:31 UTC
(In reply to Michał Górny from comment #12)
> I think you are associating the wrong idea with ROOTPATH.
> 
> Originally, it existed to add /sbin & /usr/sbin only for root.  However,
> that's been really painful to our power users, so eventually PATH and
> ROOTPATH became the same.
> 
> That said, the only reason LLVM is present in ROOTPATH is that Portage
> historically used ROOTPATH instead of PATH.

Actually ROOTPATH was previously used to construct the default PATH for root in /etc/profile, so it's not my "wrong idea" but, if anything, an idea previously heeded in gentoo. And as far as I can see, it's still maintained separately from PATH, not mainly to avoid 'sbin' in the common user PATH but to avoid paths like /usr/games/bin in root's PATH. It still makes perfect sense to me to keep the PATH for root (and processes running with root privileges) as short as possible. 

In systemd, a compile-time "search-binaries-default" setting is used (cf. man systemd.service). Whether PATH or ROOTPATH, it seems wrong to me that the system maintains a PATH setting making the installed software work, and then systemd starts services with an arbitrary fixed (and sometimes wrong) value for it. Strangely I couldn't find any bug report on systemd and PATH settings for services...
Comment 14 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2019-10-22 10:12:31 UTC
@systemd, how would you feel about using system-environment-generators to put our regular PATH for all systemd units?
Comment 15 Mike Gilbert gentoo-dev 2019-10-24 03:49:20 UTC
That sounds like a reasonable thing to add to sys-apps/gentoo-systemd-integration.

I don't understand why we are using sed to transform profile.env; it's a shell script, so you could just source it and echo the PATH variable. As well, profile.env is POSIX sh compatible, so there's no need to hard-code /bin/bash.

Example:

#!/bin/sh
. /etc/profile.env
echo "PATH=$PATH"
Comment 16 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2019-10-24 14:03:56 UTC
(In reply to Mike Gilbert from comment #15)
> That sounds like a reasonable thing to add to
> sys-apps/gentoo-systemd-integration.
> 
> I don't understand why we are using sed to transform profile.env; it's a
> shell script, so you could just source it and echo the PATH variable. As
> well, profile.env is POSIX sh compatible, so there's no need to hard-code
> /bin/bash.
> 
> Example:
> 
> #!/bin/sh
> . /etc/profile.env
> echo "PATH=$PATH"

Precisely my idea.  Do you want to do it, or should I?
Comment 17 Larry the Git Cow gentoo-dev 2019-12-06 19:22:41 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/gentoo-systemd-integration.git/commit/?id=96e0294f0892d355cf6f632b9848c06a2cd2578d

commit 96e0294f0892d355cf6f632b9848c06a2cd2578d
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2019-12-06 19:21:53 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2019-12-06 19:21:53 +0000

    Add env gen to inject full Gentoo PATH to services
    
    Bug: https://bugs.gentoo.org/651904
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 Makefile.am                                  | 5 +++++
 system-environment-generators/10-gentoo-path | 3 +++
 2 files changed, 8 insertions(+)
Comment 18 Larry the Git Cow gentoo-dev 2019-12-06 19:36:45 UTC
The bug has been closed via the following commit(s):

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

commit f4cad940e98c5160cf0bb98825dfbd1205199260
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2019-12-06 19:31:43 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2019-12-06 19:36:40 +0000

    sys-apps/gentoo-systemd-integration: Bump to v8
    
    Closes: https://bugs.gentoo.org/651904
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 sys-apps/gentoo-systemd-integration/Manifest       |  1 +
 .../gentoo-systemd-integration-8.ebuild            | 32 ++++++++++++++++++++++
 2 files changed, 33 insertions(+)