public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Zac Medico <zmedico@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org, Florian Schmaus <flo@geekplace.eu>
Subject: Re: [gentoo-portage-dev] [PATCH v5] env-update: create systemd user-session environment definition
Date: Mon, 7 Sep 2020 17:06:21 -0700	[thread overview]
Message-ID: <42d5a830-3cb1-7332-fdf2-eec177a01daa@gentoo.org> (raw)
In-Reply-To: <20200905071817.13236-1-flo@geekplace.eu>


[-- 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 --]

      reply	other threads:[~2020-09-08  0:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42d5a830-3cb1-7332-fdf2-eec177a01daa@gentoo.org \
    --to=zmedico@gentoo.org \
    --cc=flo@geekplace.eu \
    --cc=gentoo-portage-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox