1 |
Portage's env-update currently transforms the environment information |
2 |
from /etc/env.d into /etc/profile.env, which is typically sourced by |
3 |
every user session, setting up its environment. |
4 |
|
5 |
However, /etc/profile.env is not sourced by systemd user |
6 |
services. Instead, for the definition of a systemd user session |
7 |
environment, the 'environment.d' machinery exists. Unfortunately, up |
8 |
to now, env-update does not produce a profile.env equivalent for this |
9 |
machinery, causing issues for systemd user services. For example, |
10 |
an emacs daemon run a user systemd service does not have a complete |
11 |
PATH (bug #704412 [1]), because some PATH components are injected by |
12 |
packages via /etc/env.d. For example, an LLVM ebuild may set |
13 |
PATH="/usr/lib/llvm/9/bin". |
14 |
|
15 |
This commit changes env-update so that, after profile.env has was |
16 |
generated, a systemd user session environment configuration file named |
17 |
|
18 |
/usr/lib/environment.d/gentoo-profile-env.conf |
19 |
|
20 |
is created, if the directory /usr/lib/environment.d exists. |
21 |
|
22 |
1: https://bugs.gentoo.org/704412 |
23 |
|
24 |
Closes: https://bugs.gentoo.org/704416 |
25 |
Signed-off-by: Florian Schmaus <flo@×××××××××.eu> |
26 |
--- |
27 |
lib/portage/util/env_update.py | 40 +++++++++++++++++++++++++++++++++- |
28 |
1 file changed, 39 insertions(+), 1 deletion(-) |
29 |
|
30 |
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py |
31 |
index f130b6f6b..9bddf281b 100644 |
32 |
--- a/lib/portage/util/env_update.py |
33 |
+++ b/lib/portage/util/env_update.py |
34 |
@@ -6,6 +6,7 @@ __all__ = ['env_update'] |
35 |
import errno |
36 |
import glob |
37 |
import io |
38 |
+import re |
39 |
import stat |
40 |
import time |
41 |
|
42 |
@@ -340,7 +341,8 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, |
43 |
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n" |
44 |
|
45 |
#create /etc/profile.env for bash support |
46 |
- outfile = atomic_ofstream(os.path.join(eroot, "etc", "profile.env")) |
47 |
+ profile_env_path = os.path.join(eroot, "etc", "profile.env") |
48 |
+ outfile = atomic_ofstream(profile_env_path) |
49 |
outfile.write(penvnotice) |
50 |
|
51 |
env_keys = [x for x in env if x != "LDPATH"] |
52 |
@@ -353,6 +355,42 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, |
53 |
outfile.write("export %s='%s'\n" % (k, v)) |
54 |
outfile.close() |
55 |
|
56 |
+ # Create the systemd user environment configuration file |
57 |
+ # /usr/lib/environment.d/gentoo-profile-env.conf with the |
58 |
+ # environment variables of /etc/profile.enf if |
59 |
+ # /usr/lib/environment.d exists. |
60 |
+ systemd_environment_dir = os.path.join(eroot, "usr", "lib", "environment.d") |
61 |
+ if os.path.isdir(systemd_environment_dir): |
62 |
+ with open(profile_env_path, "r") as profile_env: |
63 |
+ lines = profile_env.readlines() |
64 |
+ |
65 |
+ systemd_profile_env_path = os.path.join(systemd_environment_dir, |
66 |
+ "gentoo-profile-env.conf") |
67 |
+ |
68 |
+ with open(systemd_profile_env_path, "w") as systemd_profile_env: |
69 |
+ for line in lines: |
70 |
+ # Skip comments. |
71 |
+ if re.match(r"^[ \t]*#", line): |
72 |
+ continue |
73 |
+ |
74 |
+ # Skip empty lines. |
75 |
+ if re.match(r"^[ \t]*$", line): |
76 |
+ continue |
77 |
+ |
78 |
+ # Skip variables with the empty string |
79 |
+ # as value. Those sometimes appear in |
80 |
+ # profile.env (e.g. "export GCC_SPECS=''"), |
81 |
+ # but are invalid in systemd's syntax. |
82 |
+ if line.endswith("=''\n"): |
83 |
+ continue |
84 |
+ |
85 |
+ # Transform into systemd environment.d |
86 |
+ # conf syntax, basically shell variable |
87 |
+ # assignment (without "export "). |
88 |
+ line = re.sub(r"^export ", "", line) |
89 |
+ |
90 |
+ systemd_profile_env.write(line) |
91 |
+ |
92 |
#create /etc/csh.env for (t)csh support |
93 |
outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env")) |
94 |
outfile.write(cenvnotice) |
95 |
-- |
96 |
2.26.2 |