Gentoo Archives: gentoo-portage-dev

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

Attachments

File name MIME type
signature.asc application/pgp-signature