1 |
commit: 45a5982fe8076066323e91f6b5fe860f3a429f9f |
2 |
Author: Florian Schmaus <flo <AT> geekplace <DOT> eu> |
3 |
AuthorDate: Sat Sep 5 07:18:17 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Sep 8 00:01:47 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=45a5982f |
7 |
|
8 |
env-update: create systemd user-session environment definition |
9 |
|
10 |
Portage's env-update currently transforms the environment information |
11 |
from /etc/env.d into /etc/profile.env, which is typically sourced by |
12 |
every user session, setting up its environment. |
13 |
|
14 |
However, /etc/profile.env is not sourced by systemd user |
15 |
services. Instead, for the definition of a systemd user session |
16 |
environment, the 'environment.d' machinery exists. Unfortunately, up |
17 |
to now, env-update does not produce a profile.env equivalent for this |
18 |
machinery, causing issues for systemd user services. For example, an |
19 |
emacs daemon run as user systemd service does not have a complete |
20 |
PATH (bug #704412 [1]), because some PATH components are injected by |
21 |
packages via /etc/env.d. For example, an LLVM ebuild may set |
22 |
PATH="/usr/lib/llvm/9/bin". |
23 |
|
24 |
This commit changes env-update so that a systemd user session |
25 |
environment configuration file named |
26 |
|
27 |
/etc/environment.d/10-gentoo-env.conf |
28 |
|
29 |
is created. |
30 |
|
31 |
Thanks to Michael 'veremitz' Everitt, Arfrever Frehtes Taifersar |
32 |
Arahesis, Ulrich Müller, Joakim Tjernlund, and Zac Medico for the |
33 |
useful feedback. |
34 |
|
35 |
1: https://bugs.gentoo.org/704412 |
36 |
|
37 |
Bug: https://bugs.gentoo.org/704416 |
38 |
Signed-off-by: Florian Schmaus <flo <AT> geekplace.eu> |
39 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
40 |
|
41 |
lib/portage/util/env_update.py | 42 +++++++++++++++++++++++++++++++++++++++--- |
42 |
1 file changed, 39 insertions(+), 3 deletions(-) |
43 |
|
44 |
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py |
45 |
index f130b6f6b..dec086cf8 100644 |
46 |
--- a/lib/portage/util/env_update.py |
47 |
+++ b/lib/portage/util/env_update.py |
48 |
@@ -333,14 +333,16 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, |
49 |
|
50 |
del specials["LDPATH"] |
51 |
|
52 |
- penvnotice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" |
53 |
- penvnotice += "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n" |
54 |
+ notice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" |
55 |
+ notice += "# DO NOT EDIT THIS FILE." |
56 |
+ penvnotice = notice + " CHANGES TO STARTUP PROFILES\n" |
57 |
cenvnotice = penvnotice[:] |
58 |
penvnotice += "# GO INTO /etc/profile NOT /etc/profile.env\n\n" |
59 |
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n" |
60 |
|
61 |
#create /etc/profile.env for bash support |
62 |
- outfile = atomic_ofstream(os.path.join(eroot, "etc", "profile.env")) |
63 |
+ profile_env_path = os.path.join(eroot, "etc", "profile.env") |
64 |
+ outfile = atomic_ofstream(profile_env_path) |
65 |
outfile.write(penvnotice) |
66 |
|
67 |
env_keys = [x for x in env if x != "LDPATH"] |
68 |
@@ -353,6 +355,40 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, |
69 |
outfile.write("export %s='%s'\n" % (k, v)) |
70 |
outfile.close() |
71 |
|
72 |
+ # Create the systemd user environment configuration file |
73 |
+ # /etc/environment.d/10-gentoo-env.conf with the |
74 |
+ # environment configuration from /etc/env.d. |
75 |
+ systemd_environment_dir = os.path.join(eroot, "etc", "environment.d") |
76 |
+ os.makedirs(systemd_environment_dir, exist_ok=True) |
77 |
+ |
78 |
+ systemd_gentoo_env_path = os.path.join(systemd_environment_dir, |
79 |
+ "10-gentoo-env.conf") |
80 |
+ systemd_gentoo_env = atomic_ofstream(systemd_gentoo_env_path) |
81 |
+ try: |
82 |
+ senvnotice = notice + "\n\n" |
83 |
+ systemd_gentoo_env.write(senvnotice) |
84 |
+ |
85 |
+ for env_key in env_keys: |
86 |
+ env_key_value = env[env_key] |
87 |
+ |
88 |
+ # Skip variables with the empty string |
89 |
+ # as value. Those sometimes appear in |
90 |
+ # profile.env (e.g. "export GCC_SPECS=''"), |
91 |
+ # but are invalid in systemd's syntax. |
92 |
+ if not env_key_value: |
93 |
+ continue |
94 |
+ |
95 |
+ # Transform into systemd environment.d |
96 |
+ # conf syntax, basically shell variable |
97 |
+ # assignment (without "export "). |
98 |
+ line = f"{env_key}={env_key_value}\n" |
99 |
+ |
100 |
+ systemd_gentoo_env.write(line) |
101 |
+ except: |
102 |
+ systemd_gentoo_env.abort() |
103 |
+ raise |
104 |
+ systemd_gentoo_env.close() |
105 |
+ |
106 |
#create /etc/csh.env for (t)csh support |
107 |
outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env")) |
108 |
outfile.write(cenvnotice) |