* [gentoo-portage-dev] [PATCH] env-update: create systemd env configuration if required
@ 2020-09-02 16:43 Florian Schmaus
2020-09-03 11:11 ` [gentoo-portage-dev] [PATCH v2] " Florian Schmaus
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Florian Schmaus @ 2020-09-02 16:43 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Florian Schmaus
Portage's env-update currently transforms the environment information
from /etc/env.d into /etc/profile.env, which is typically sourced by
every user session, setting up its environment.
However, /etc/profile.env is not sourced by systemd user
services. Instead, for the definition of a systemd user session
environment, the 'environment.d' machinery exists. Unfortunately, up
to now, env-update does not produce a profile.env equivalent for this
machinery, causing issues for systemd user services. For example,
an emacs daemon run a user systemd service does not have a complete
PATH (bug #704412 [1]), because some PATH components are injected by
packages via /etc/env.d. For example, an LLVM ebuild may set
PATH="/usr/lib/llvm/9/bin".
This commit changes env-update so that, after profile.env has was
generated, a systemd user session environment configuration file named
/usr/lib/environment.d/gentoo-profile-env.conf
is created, if the directory /usr/lib/environment.d exists.
1: https://bugs.gentoo.org/704412
Closes: https://bugs.gentoo.org/704416
Signed-off-by: Florian Schmaus <flo@geekplace.eu>
---
lib/portage/util/env_update.py | 40 +++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
index f130b6f6b..9bddf281b 100644
--- a/lib/portage/util/env_update.py
+++ b/lib/portage/util/env_update.py
@@ -6,6 +6,7 @@ __all__ = ['env_update']
import errno
import glob
import io
+import re
import stat
import time
@@ -340,7 +341,8 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
#create /etc/profile.env for bash support
- outfile = atomic_ofstream(os.path.join(eroot, "etc", "profile.env"))
+ profile_env_path = os.path.join(eroot, "etc", "profile.env")
+ outfile = atomic_ofstream(profile_env_path)
outfile.write(penvnotice)
env_keys = [x for x in env if x != "LDPATH"]
@@ -353,6 +355,42 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
outfile.write("export %s='%s'\n" % (k, v))
outfile.close()
+ # Create the systemd user environment configuration file
+ # /usr/lib/environment.d/gentoo-profile-env.conf with the
+ # environment variables of /etc/profile.enf if
+ # /usr/lib/environment.d exists.
+ systemd_environment_dir = os.path.join(eroot, "usr", "lib", "environment.d")
+ if os.path.isdir(systemd_environment_dir):
+ with open(profile_env_path, "r") as profile_env:
+ lines = profile_env.readlines()
+
+ systemd_profile_env_path = os.path.join(systemd_environment_dir,
+ "gentoo-profile-env.conf")
+
+ with open(systemd_profile_env_path, "w") as systemd_profile_env:
+ for line in lines:
+ # Skip comments.
+ if re.match(r"^[ \t]*#", line):
+ continue
+
+ # Skip empty lines.
+ if re.match(r"^[ \t]*$", line):
+ continue
+
+ # Skip variables with the empty string
+ # as value. Those sometimes appear in
+ # profile.env (e.g. "export GCC_SPECS=''"),
+ # but are invalid in systemd's syntax.
+ if line.endswith("=''\n"):
+ continue
+
+ # Transform into systemd environment.d
+ # conf syntax, basically shell variable
+ # assignment (without "export ").
+ line = re.sub(r"^export ", "", line)
+
+ systemd_profile_env.write(line)
+
#create /etc/csh.env for (t)csh support
outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env"))
outfile.write(cenvnotice)
--
2.26.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [gentoo-portage-dev] [PATCH v2] env-update: create systemd env configuration if required
2020-09-02 16:43 [gentoo-portage-dev] [PATCH] env-update: create systemd env configuration if required Florian Schmaus
@ 2020-09-03 11:11 ` Florian Schmaus
2020-09-03 11:30 ` Ulrich Mueller
2020-09-03 13:06 ` [gentoo-portage-dev] [PATCH v3] " Florian Schmaus
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Florian Schmaus @ 2020-09-03 11:11 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Florian Schmaus
Portage's env-update currently transforms the environment information
from /etc/env.d into /etc/profile.env, which is typically sourced by
every user session, setting up its environment.
However, /etc/profile.env is not sourced by systemd user
services. Instead, for the definition of a systemd user session
environment, the 'environment.d' machinery exists. Unfortunately, up
to now, env-update does not produce a profile.env equivalent for this
machinery, causing issues for systemd user services. For example,
an emacs daemon run a user systemd service does not have a complete
PATH (bug #704412 [1]), because some PATH components are injected by
packages via /etc/env.d. For example, an LLVM ebuild may set
PATH="/usr/lib/llvm/9/bin".
This commit changes env-update so that, after profile.env has was
generated, a systemd user session environment configuration file named
/usr/lib/environment.d/gentoo-profile-env.conf
is created, if the directory /usr/lib/environment.d exists.
Thanks to Michael 'veremitz' Everitt and Arfrever Frehtes Taifersar
Arahesis for the useful feedback.
1: https://bugs.gentoo.org/704412
Closes: https://bugs.gentoo.org/704416
Signed-off-by: Florian Schmaus <flo@geekplace.eu>
---
Notes:
- Fix typo s/profile.enf/profile.env/ (thanks Michael)
- Use env_keys to generate gentoo-profile-env.conf (thanks Arfrever)
- Add "file is auto generated" notice header to generated conf
lib/portage/util/env_update.py | 37 +++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
index f130b6f6bacb..0aace8f4c5f4 100644
--- a/lib/portage/util/env_update.py
+++ b/lib/portage/util/env_update.py
@@ -333,14 +333,16 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
del specials["LDPATH"]
- penvnotice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
- penvnotice += "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n"
+ notice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
+ notice += "# DO NOT EDIT THIS FILE."
+ penvnotice = notice + " CHANGES TO STARTUP PROFILES\n"
cenvnotice = penvnotice[:]
penvnotice += "# GO INTO /etc/profile NOT /etc/profile.env\n\n"
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
#create /etc/profile.env for bash support
- outfile = atomic_ofstream(os.path.join(eroot, "etc", "profile.env"))
+ profile_env_path = os.path.join(eroot, "etc", "profile.env")
+ outfile = atomic_ofstream(profile_env_path)
outfile.write(penvnotice)
env_keys = [x for x in env if x != "LDPATH"]
@@ -353,6 +355,35 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
outfile.write("export %s='%s'\n" % (k, v))
outfile.close()
+ # Create the systemd user environment configuration file
+ # /usr/lib/environment.d/gentoo-profile-env.conf with the
+ # environment variables of /etc/profile.env if
+ # /usr/lib/environment.d exists.
+ systemd_environment_dir = os.path.join(eroot, "usr", "lib", "environment.d")
+ if os.path.isdir(systemd_environment_dir):
+ systemd_profile_env_path = os.path.join(systemd_environment_dir,
+ "gentoo-profile-env.conf")
+ with open(systemd_profile_env_path, "w") as systemd_profile_env:
+ senvnotice = notice + "\n\n"
+ systemd_profile_env.write(senvnotice)
+
+ for env_key in env_keys:
+ env_key_value = env[env_key]
+
+ # Skip variables with the empty string
+ # as value. Those sometimes appear in
+ # profile.env (e.g. "export GCC_SPECS=''"),
+ # but are invalid in systemd's syntax.
+ if not env_key_value:
+ continue
+
+ # Transform into systemd environment.d
+ # conf syntax, basically shell variable
+ # assignment (without "export ").
+ line = f"{env_key}={env_key_value}\n"
+
+ systemd_profile_env.write(line)
+
#create /etc/csh.env for (t)csh support
outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env"))
outfile.write(cenvnotice)
--
2.26.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v2] env-update: create systemd env configuration if required
2020-09-03 11:11 ` [gentoo-portage-dev] [PATCH v2] " Florian Schmaus
@ 2020-09-03 11:30 ` Ulrich Mueller
2020-09-03 12:07 ` Florian Schmaus
0 siblings, 1 reply; 13+ messages in thread
From: Ulrich Mueller @ 2020-09-03 11:30 UTC (permalink / raw
To: Florian Schmaus; +Cc: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 465 bytes --]
>>>>> On Thu, 03 Sep 2020, Florian Schmaus wrote:
> This commit changes env-update so that, after profile.env has was
> generated, a systemd user session environment configuration file named
> /usr/lib/environment.d/gentoo-profile-env.conf
> is created, if the directory /usr/lib/environment.d exists.
Maybe a stupid question, but can't this file just source /etc/profile?
Maintaining the same information twice doesn't look like the right thing
to do.
Ulrich
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v2] env-update: create systemd env configuration if required
2020-09-03 11:30 ` Ulrich Mueller
@ 2020-09-03 12:07 ` Florian Schmaus
2020-09-03 12:43 ` Ulrich Mueller
0 siblings, 1 reply; 13+ messages in thread
From: Florian Schmaus @ 2020-09-03 12:07 UTC (permalink / raw
To: Ulrich Mueller; +Cc: gentoo-portage-dev
[-- Attachment #1.1: Type: text/plain, Size: 1137 bytes --]
On 03.09.20 13:30, Ulrich Mueller wrote:
>>>>>> On Thu, 03 Sep 2020, Florian Schmaus wrote:
>
>> This commit changes env-update so that, after profile.env has was
>> generated, a systemd user session environment configuration file named
>
>> /usr/lib/environment.d/gentoo-profile-env.conf
>
>> is created, if the directory /usr/lib/environment.d exists.
>
> Maybe a stupid question, but can't this file just source /etc/profile?
Akin to what 96e0294f0892 ("Add env gen to inject full Gentoo PATH to
services") in gentoo-systemd-integration does?
Unfortunately the answer is 'no', because gentoo-profile-env.conf is not
an interactive script, it is just a systemd configuration file.
> Maintaining the same information twice doesn't look like the right thing
> to do.
It's not really maintaining the information twice. The information is
maintained at a single point: /etc/env.d
And from there is is transformed by env-update already into two
different formats:
- /etc/profile.env
- /etc/csh.env
And with that change additionally into
- /usr/lib/environment.d/gentoo-profile-env.conf
- Florian
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 618 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v2] env-update: create systemd env configuration if required
2020-09-03 12:07 ` Florian Schmaus
@ 2020-09-03 12:43 ` Ulrich Mueller
2020-09-03 12:58 ` Florian Schmaus
0 siblings, 1 reply; 13+ messages in thread
From: Ulrich Mueller @ 2020-09-03 12:43 UTC (permalink / raw
To: Florian Schmaus; +Cc: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 734 bytes --]
>>>>> On Thu, 03 Sep 2020, Florian Schmaus wrote:
> It's not really maintaining the information twice. The information is
> maintained at a single point: /etc/env.d
> And from there is is transformed by env-update already into two
> different formats:
> - /etc/profile.env
> - /etc/csh.env
> And with that change additionally into
> - /usr/lib/environment.d/gentoo-profile-env.conf
Sorry for another nitpick, but it's changing a file in /usr at runtime?
Also, does the file belong to any package, or is it an orphan?
Maybe it would be cleaner to generate the file in /etc like the others,
if necessary with a symlink in /usr/lib/environment.d? The symlink could
belong to some package, maybe even sys-apps/systemd itself.
Ulrich
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v2] env-update: create systemd env configuration if required
2020-09-03 12:43 ` Ulrich Mueller
@ 2020-09-03 12:58 ` Florian Schmaus
0 siblings, 0 replies; 13+ messages in thread
From: Florian Schmaus @ 2020-09-03 12:58 UTC (permalink / raw
To: Ulrich Mueller; +Cc: gentoo-portage-dev
[-- Attachment #1.1: Type: text/plain, Size: 983 bytes --]
On 03.09.20 14:43, Ulrich Mueller wrote:
>>>>>> On Thu, 03 Sep 2020, Florian Schmaus wrote:
>
>> It's not really maintaining the information twice. The information is
>> maintained at a single point: /etc/env.d
>> And from there is is transformed by env-update already into two
>> different formats:
>> - /etc/profile.env
>> - /etc/csh.env
>
>> And with that change additionally into
>> - /usr/lib/environment.d/gentoo-profile-env.conf
>
> Sorry for another nitpick, but it's changing a file in /usr at runtime> Also, does the file belong to any package, or is it an orphan?
It's an orphan.
> Maybe it would be cleaner to generate the file in /etc like the others,
> if necessary with a symlink in /usr/lib/environment.d?
Good point. A symlink wont be necessary. We could also generate the file
in /etc/environment.d
I guess /etc/environment.d is preferred over /usr/lib/environment.d?
I'll make the according changes to the patch.
- Florian
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 618 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* [gentoo-portage-dev] [PATCH v3] env-update: create systemd env configuration if required
2020-09-02 16:43 [gentoo-portage-dev] [PATCH] env-update: create systemd env configuration if required Florian Schmaus
2020-09-03 11:11 ` [gentoo-portage-dev] [PATCH v2] " Florian Schmaus
@ 2020-09-03 13:06 ` Florian Schmaus
2020-09-03 15:21 ` Joakim Tjernlund
2020-09-03 17:57 ` [gentoo-portage-dev] [PATCH v4] " Florian Schmaus
2020-09-05 7:18 ` [gentoo-portage-dev] [PATCH v5] env-update: create systemd user-session environment definition Florian Schmaus
3 siblings, 1 reply; 13+ messages in thread
From: Florian Schmaus @ 2020-09-03 13:06 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Florian Schmaus
Portage's env-update currently transforms the environment information
from /etc/env.d into /etc/profile.env, which is typically sourced by
every user session, setting up its environment.
However, /etc/profile.env is not sourced by systemd user
services. Instead, for the definition of a systemd user session
environment, the 'environment.d' machinery exists. Unfortunately, up
to now, env-update does not produce a profile.env equivalent for this
machinery, causing issues for systemd user services. For example,
an emacs daemon run a user systemd service does not have a complete
PATH (bug #704412 [1]), because some PATH components are injected by
packages via /etc/env.d. For example, an LLVM ebuild may set
PATH="/usr/lib/llvm/9/bin".
This commit changes env-update so that, after profile.env has was
generated, a systemd user session environment configuration file named
/etc/environment.d/gentoo-profile-env.conf
is created.
Thanks to Michael 'veremitz' Everitt, Arfrever Frehtes Taifersar
Arahesis and Ulrich Müller for the useful feedback.
1: https://bugs.gentoo.org/704412
Closes: https://bugs.gentoo.org/704416
Signed-off-by: Florian Schmaus <flo@geekplace.eu>
---
Notes:
- Place generated file in /etc/environment.d (Thanks ulm)
lib/portage/util/env_update.py | 38 +++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
index f130b6f6bacb..0baca8a98676 100644
--- a/lib/portage/util/env_update.py
+++ b/lib/portage/util/env_update.py
@@ -333,14 +333,16 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
del specials["LDPATH"]
- penvnotice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
- penvnotice += "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n"
+ notice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
+ notice += "# DO NOT EDIT THIS FILE."
+ penvnotice = notice + " CHANGES TO STARTUP PROFILES\n"
cenvnotice = penvnotice[:]
penvnotice += "# GO INTO /etc/profile NOT /etc/profile.env\n\n"
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
#create /etc/profile.env for bash support
- outfile = atomic_ofstream(os.path.join(eroot, "etc", "profile.env"))
+ profile_env_path = os.path.join(eroot, "etc", "profile.env")
+ outfile = atomic_ofstream(profile_env_path)
outfile.write(penvnotice)
env_keys = [x for x in env if x != "LDPATH"]
@@ -353,6 +355,36 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
outfile.write("export %s='%s'\n" % (k, v))
outfile.close()
+ # Create the systemd user environment configuration file
+ # /etc/environment.d/gentoo-profile-env.conf with the
+ # environment variables of /etc/profile.env.
+ systemd_environment_dir = os.path.join(eroot, "etc", "environment.d")
+ if not os.path.isdir(systemd_environment_dir):
+ os.mkdir(systemd_environment_dir)
+
+ systemd_profile_env_path = os.path.join(systemd_environment_dir,
+ "gentoo-profile-env.conf")
+ with open(systemd_profile_env_path, "w") as systemd_profile_env:
+ senvnotice = notice + "\n\n"
+ systemd_profile_env.write(senvnotice)
+
+ for env_key in env_keys:
+ env_key_value = env[env_key]
+
+ # Skip variables with the empty string
+ # as value. Those sometimes appear in
+ # profile.env (e.g. "export GCC_SPECS=''"),
+ # but are invalid in systemd's syntax.
+ if not env_key_value:
+ continue
+
+ # Transform into systemd environment.d
+ # conf syntax, basically shell variable
+ # assignment (without "export ").
+ line = f"{env_key}={env_key_value}\n"
+
+ systemd_profile_env.write(line)
+
#create /etc/csh.env for (t)csh support
outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env"))
outfile.write(cenvnotice)
--
2.26.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v3] env-update: create systemd env configuration if required
2020-09-03 13:06 ` [gentoo-portage-dev] [PATCH v3] " Florian Schmaus
@ 2020-09-03 15:21 ` Joakim Tjernlund
0 siblings, 0 replies; 13+ messages in thread
From: Joakim Tjernlund @ 2020-09-03 15:21 UTC (permalink / raw
To: gentoo-portage-dev@lists.gentoo.org; +Cc: flo@geekplace.eu
On Thu, 2020-09-03 at 15:06 +0200, Florian Schmaus wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
>
> Portage's env-update currently transforms the environment information
> from /etc/env.d into /etc/profile.env, which is typically sourced by
> every user session, setting up its environment.
>
> However, /etc/profile.env is not sourced by systemd user
> services. Instead, for the definition of a systemd user session
> environment, the 'environment.d' machinery exists. Unfortunately, up
> to now, env-update does not produce a profile.env equivalent for this
> machinery, causing issues for systemd user services. For example,
> an emacs daemon run a user systemd service does not have a complete
> PATH (bug #704412 [1]), because some PATH components are injected by
> packages via /etc/env.d. For example, an LLVM ebuild may set
> PATH="/usr/lib/llvm/9/bin".
>
> This commit changes env-update so that, after profile.env has was
> generated, a systemd user session environment configuration file named
>
> /etc/environment.d/gentoo-profile-env.conf
Are files /etc/environment.d/ ordered in anyway? If so it might be a good idea
to name the file 10-gentoo-profile-env.conf or similar.
Jocke
^ permalink raw reply [flat|nested] 13+ messages in thread
* [gentoo-portage-dev] [PATCH v4] env-update: create systemd env configuration if required
2020-09-02 16:43 [gentoo-portage-dev] [PATCH] env-update: create systemd env configuration if required Florian Schmaus
2020-09-03 11:11 ` [gentoo-portage-dev] [PATCH v2] " Florian Schmaus
2020-09-03 13:06 ` [gentoo-portage-dev] [PATCH v3] " Florian Schmaus
@ 2020-09-03 17:57 ` Florian Schmaus
2020-09-04 15:39 ` [gentoo-portage-dev] " Florian Schmaus
2020-09-05 7:18 ` [gentoo-portage-dev] [PATCH v5] env-update: create systemd user-session environment definition Florian Schmaus
3 siblings, 1 reply; 13+ messages in thread
From: Florian Schmaus @ 2020-09-03 17:57 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Florian Schmaus
Portage's env-update currently transforms the environment information
from /etc/env.d into /etc/profile.env, which is typically sourced by
every user session, setting up its environment.
However, /etc/profile.env is not sourced by systemd user
services. Instead, for the definition of a systemd user session
environment, the 'environment.d' machinery exists. Unfortunately, up
to now, env-update does not produce a profile.env equivalent for this
machinery, causing issues for systemd user services. For example,
an emacs daemon run a user systemd service does not have a complete
PATH (bug #704412 [1]), because some PATH components are injected by
packages via /etc/env.d. For example, an LLVM ebuild may set
PATH="/usr/lib/llvm/9/bin".
This commit changes env-update so that, after profile.env has was
generated, a systemd user session environment configuration file named
/etc/environment.d/10-gentoo-profile-env.conf
is created.
Thanks to Michael 'veremitz' Everitt, Arfrever Frehtes Taifersar
Arahesis, Ulrich Müller, and Joakim Tjernlund for the useful
feedback.
1: https://bugs.gentoo.org/704412
Closes: https://bugs.gentoo.org/704416
Signed-off-by: Florian Schmaus <flo@geekplace.eu>
---
Notes:
- Prefix generated conf with "10-", for easier overwriting (thanks Joakim)
lib/portage/util/env_update.py | 38 +++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
index f130b6f6bacb..8ba86c0bfd47 100644
--- a/lib/portage/util/env_update.py
+++ b/lib/portage/util/env_update.py
@@ -333,14 +333,16 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
del specials["LDPATH"]
- penvnotice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
- penvnotice += "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n"
+ notice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
+ notice += "# DO NOT EDIT THIS FILE."
+ penvnotice = notice + " CHANGES TO STARTUP PROFILES\n"
cenvnotice = penvnotice[:]
penvnotice += "# GO INTO /etc/profile NOT /etc/profile.env\n\n"
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
#create /etc/profile.env for bash support
- outfile = atomic_ofstream(os.path.join(eroot, "etc", "profile.env"))
+ profile_env_path = os.path.join(eroot, "etc", "profile.env")
+ outfile = atomic_ofstream(profile_env_path)
outfile.write(penvnotice)
env_keys = [x for x in env if x != "LDPATH"]
@@ -353,6 +355,36 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
outfile.write("export %s='%s'\n" % (k, v))
outfile.close()
+ # Create the systemd user environment configuration file
+ # /etc/environment.d/gentoo-profile-env.conf with the
+ # environment variables of /etc/profile.env.
+ systemd_environment_dir = os.path.join(eroot, "etc", "environment.d")
+ if not os.path.isdir(systemd_environment_dir):
+ os.mkdir(systemd_environment_dir)
+
+ systemd_profile_env_path = os.path.join(systemd_environment_dir,
+ "10-gentoo-profile-env.conf")
+ with open(systemd_profile_env_path, "w") as systemd_profile_env:
+ senvnotice = notice + "\n\n"
+ systemd_profile_env.write(senvnotice)
+
+ for env_key in env_keys:
+ env_key_value = env[env_key]
+
+ # Skip variables with the empty string
+ # as value. Those sometimes appear in
+ # profile.env (e.g. "export GCC_SPECS=''"),
+ # but are invalid in systemd's syntax.
+ if not env_key_value:
+ continue
+
+ # Transform into systemd environment.d
+ # conf syntax, basically shell variable
+ # assignment (without "export ").
+ line = f"{env_key}={env_key_value}\n"
+
+ systemd_profile_env.write(line)
+
#create /etc/csh.env for (t)csh support
outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env"))
outfile.write(cenvnotice)
--
2.26.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [gentoo-portage-dev] Re: [PATCH v4] env-update: create systemd env configuration if required
2020-09-03 17:57 ` [gentoo-portage-dev] [PATCH v4] " Florian Schmaus
@ 2020-09-04 15:39 ` Florian Schmaus
2020-09-05 1:12 ` Zac Medico
0 siblings, 1 reply; 13+ messages in thread
From: Florian Schmaus @ 2020-09-04 15:39 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1.1: Type: text/plain, Size: 383 bytes --]
On 9/3/20 7:57 PM, Florian Schmaus wrote:
> + systemd_profile_env_path = os.path.join(systemd_environment_dir,
> + "10-gentoo-profile-env.conf")
> + with open(systemd_profile_env_path, "w") as systemd_profile_env:
I just noticed that portage has atomic_ofstream(). Would you prefer this
change to use atomic_ofstream() instead of using "with open()"?
- Florian
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 618 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-portage-dev] Re: [PATCH v4] env-update: create systemd env configuration if required
2020-09-04 15:39 ` [gentoo-portage-dev] " Florian Schmaus
@ 2020-09-05 1:12 ` Zac Medico
0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2020-09-05 1:12 UTC (permalink / raw
To: gentoo-portage-dev, Florian Schmaus
[-- Attachment #1.1: Type: text/plain, Size: 574 bytes --]
On 9/4/20 8:39 AM, Florian Schmaus wrote:
> On 9/3/20 7:57 PM, Florian Schmaus wrote:
>> + systemd_profile_env_path = os.path.join(systemd_environment_dir,
>> + "10-gentoo-profile-env.conf")
>> + with open(systemd_profile_env_path, "w") as systemd_profile_env:
>
> I just noticed that portage has atomic_ofstream(). Would you prefer this
> change to use atomic_ofstream() instead of using "with open()"?
Yes, please do. Also, we can eliminate the earlier os.path.isdir by
using os.makedirs(systemd_environment_dir, exist_ok=True).
--
Thanks,
Zac
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 981 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* [gentoo-portage-dev] [PATCH v5] env-update: create systemd user-session environment definition
2020-09-02 16:43 [gentoo-portage-dev] [PATCH] env-update: create systemd env configuration if required Florian Schmaus
` (2 preceding siblings ...)
2020-09-03 17:57 ` [gentoo-portage-dev] [PATCH v4] " Florian Schmaus
@ 2020-09-05 7:18 ` Florian Schmaus
2020-09-08 0:06 ` Zac Medico
3 siblings, 1 reply; 13+ messages in thread
From: Florian Schmaus @ 2020-09-05 7:18 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Florian Schmaus
Portage's env-update currently transforms the environment information
from /etc/env.d into /etc/profile.env, which is typically sourced by
every user session, setting up its environment.
However, /etc/profile.env is not sourced by systemd user
services. Instead, for the definition of a systemd user session
environment, the 'environment.d' machinery exists. Unfortunately, up
to now, env-update does not produce a profile.env equivalent for this
machinery, causing issues for systemd user services. For example, an
emacs daemon run as user systemd service does not have a complete
PATH (bug #704412 [1]), because some PATH components are injected by
packages via /etc/env.d. For example, an LLVM ebuild may set
PATH="/usr/lib/llvm/9/bin".
This commit changes env-update so that a systemd user session
environment configuration file named
/etc/environment.d/10-gentoo-env.conf
is created.
Thanks to Michael 'veremitz' Everitt, Arfrever Frehtes Taifersar
Arahesis, Ulrich Müller, Joakim Tjernlund, and Zac Medico for the
useful feedback.
1: https://bugs.gentoo.org/704412
Closes: https://bugs.gentoo.org/704416
Signed-off-by: Florian Schmaus <flo@geekplace.eu>
---
Notes:
- Shorten created filename to 10-gentoo-env.conf
- Minor fixes in the commit message
- Use atomic_ofstream()
- Use os.makedirs() (Thanks Zac)
lib/portage/util/env_update.py | 42 +++++++++++++++++++++++++++++++---
1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
index f130b6f6b..ab3caee47 100644
--- a/lib/portage/util/env_update.py
+++ b/lib/portage/util/env_update.py
@@ -333,14 +333,16 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
del specials["LDPATH"]
- penvnotice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
- penvnotice += "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n"
+ notice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
+ notice += "# DO NOT EDIT THIS FILE."
+ penvnotice = notice + " CHANGES TO STARTUP PROFILES\n"
cenvnotice = penvnotice[:]
penvnotice += "# GO INTO /etc/profile NOT /etc/profile.env\n\n"
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
#create /etc/profile.env for bash support
- outfile = atomic_ofstream(os.path.join(eroot, "etc", "profile.env"))
+ profile_env_path = os.path.join(eroot, "etc", "profile.env")
+ outfile = atomic_ofstream(profile_env_path)
outfile.write(penvnotice)
env_keys = [x for x in env if x != "LDPATH"]
@@ -353,6 +355,40 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
outfile.write("export %s='%s'\n" % (k, v))
outfile.close()
+ # Create the systemd user environment configuration file
+ # /etc/environment.d/10-gentoo-env.conf with the
+ # environment configuration from /etc/env.d.
+ systemd_environment_dir = os.path.join(eroot, "etc", "environment.d")
+ os.makedirs(systemd_environment_dir, exist_ok=True)
+
+ systemd_gentoo_env_path = os.path.join(systemd_environment_dir,
+ "10-gentoo-env.conf")
+ systemd_gentoo_env = atomic_ofstream(systemd_gentoo_env_path)
+ try:
+ senvnotice = notice + "\n\n"
+ systemd_gentoo_env.write(senvnotice)
+
+ for env_key in env_keys:
+ env_key_value = env[env_key]
+
+ # Skip variables with the empty string
+ # as value. Those sometimes appear in
+ # profile.env (e.g. "export GCC_SPECS=''"),
+ # but are invalid in systemd's syntax.
+ if not env_key_value:
+ continue
+
+ # Transform into systemd environment.d
+ # conf syntax, basically shell variable
+ # assignment (without "export ").
+ line = f"{env_key}={env_key_value}\n"
+
+ systemd_gentoo_env.write(line)
+ except:
+ systemd_gentoo_env.abort()
+ raise
+ systemd_gentoo_env.close()
+
#create /etc/csh.env for (t)csh support
outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env"))
outfile.write(cenvnotice)
--
2.26.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v5] env-update: create systemd user-session environment definition
2020-09-05 7:18 ` [gentoo-portage-dev] [PATCH v5] env-update: create systemd user-session environment definition Florian Schmaus
@ 2020-09-08 0:06 ` Zac Medico
0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2020-09-08 0:06 UTC (permalink / raw
To: gentoo-portage-dev, Florian Schmaus
[-- Attachment #1.1: Type: text/plain, Size: 4439 bytes --]
On 9/5/20 12:18 AM, Florian Schmaus wrote:
> Portage's env-update currently transforms the environment information
> from /etc/env.d into /etc/profile.env, which is typically sourced by
> every user session, setting up its environment.
>
> However, /etc/profile.env is not sourced by systemd user
> services. Instead, for the definition of a systemd user session
> environment, the 'environment.d' machinery exists. Unfortunately, up
> to now, env-update does not produce a profile.env equivalent for this
> machinery, causing issues for systemd user services. For example, an
> emacs daemon run as user systemd service does not have a complete
> PATH (bug #704412 [1]), because some PATH components are injected by
> packages via /etc/env.d. For example, an LLVM ebuild may set
> PATH="/usr/lib/llvm/9/bin".
>
> This commit changes env-update so that a systemd user session
> environment configuration file named
>
> /etc/environment.d/10-gentoo-env.conf
>
> is created.
>
> Thanks to Michael 'veremitz' Everitt, Arfrever Frehtes Taifersar
> Arahesis, Ulrich Müller, Joakim Tjernlund, and Zac Medico for the
> useful feedback.
>
> 1: https://bugs.gentoo.org/704412
>
> Closes: https://bugs.gentoo.org/704416
> Signed-off-by: Florian Schmaus <flo@geekplace.eu>
> ---
>
> Notes:
> - Shorten created filename to 10-gentoo-env.conf
> - Minor fixes in the commit message
> - Use atomic_ofstream()
> - Use os.makedirs() (Thanks Zac)
>
> lib/portage/util/env_update.py | 42 +++++++++++++++++++++++++++++++---
> 1 file changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
> index f130b6f6b..ab3caee47 100644
> --- a/lib/portage/util/env_update.py
> +++ b/lib/portage/util/env_update.py
> @@ -333,14 +333,16 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
>
> del specials["LDPATH"]
>
> - penvnotice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
> - penvnotice += "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n"
> + notice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
> + notice += "# DO NOT EDIT THIS FILE."
> + penvnotice = notice + " CHANGES TO STARTUP PROFILES\n"
> cenvnotice = penvnotice[:]
> penvnotice += "# GO INTO /etc/profile NOT /etc/profile.env\n\n"
> cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
>
> #create /etc/profile.env for bash support
> - outfile = atomic_ofstream(os.path.join(eroot, "etc", "profile.env"))
> + profile_env_path = os.path.join(eroot, "etc", "profile.env")
> + outfile = atomic_ofstream(profile_env_path)
> outfile.write(penvnotice)
>
> env_keys = [x for x in env if x != "LDPATH"]
> @@ -353,6 +355,40 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env,
> outfile.write("export %s='%s'\n" % (k, v))
> outfile.close()
>
> + # Create the systemd user environment configuration file
> + # /etc/environment.d/10-gentoo-env.conf with the
> + # environment configuration from /etc/env.d.
> + systemd_environment_dir = os.path.join(eroot, "etc", "environment.d")
> + os.makedirs(systemd_environment_dir, exist_ok=True)
> +
> + systemd_gentoo_env_path = os.path.join(systemd_environment_dir,
> + "10-gentoo-env.conf")
> + systemd_gentoo_env = atomic_ofstream(systemd_gentoo_env_path)
> + try:
> + senvnotice = notice + "\n\n"
> + systemd_gentoo_env.write(senvnotice)
> +
> + for env_key in env_keys:
> + env_key_value = env[env_key]
> +
> + # Skip variables with the empty string
> + # as value. Those sometimes appear in
> + # profile.env (e.g. "export GCC_SPECS=''"),
> + # but are invalid in systemd's syntax.
> + if not env_key_value:
> + continue
> +
> + # Transform into systemd environment.d
> + # conf syntax, basically shell variable
> + # assignment (without "export ").
> + line = f"{env_key}={env_key_value}\n"
> +
> + systemd_gentoo_env.write(line)
> + except:
> + systemd_gentoo_env.abort()
> + raise
> + systemd_gentoo_env.close()
> +
> #create /etc/csh.env for (t)csh support
> outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env"))
> outfile.write(cenvnotice)
>
Thanks, merged:
https://gitweb.gentoo.org/proj/portage.git/commit/?id=45a5982fe8076066323e91f6b5fe860f3a429f9f
--
Thanks,
Zac
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 981 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2020-09-08 0:06 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-02 16:43 [gentoo-portage-dev] [PATCH] env-update: create systemd env configuration if required Florian Schmaus
2020-09-03 11:11 ` [gentoo-portage-dev] [PATCH v2] " Florian Schmaus
2020-09-03 11:30 ` Ulrich Mueller
2020-09-03 12:07 ` Florian Schmaus
2020-09-03 12:43 ` Ulrich Mueller
2020-09-03 12:58 ` Florian Schmaus
2020-09-03 13:06 ` [gentoo-portage-dev] [PATCH v3] " Florian Schmaus
2020-09-03 15:21 ` Joakim Tjernlund
2020-09-03 17:57 ` [gentoo-portage-dev] [PATCH v4] " Florian Schmaus
2020-09-04 15:39 ` [gentoo-portage-dev] " Florian Schmaus
2020-09-05 1:12 ` Zac Medico
2020-09-05 7:18 ` [gentoo-portage-dev] [PATCH v5] env-update: create systemd user-session environment definition Florian Schmaus
2020-09-08 0:06 ` Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox