<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>15770</bug_id>
          
          <creation_ts>2025-02-22 01:05:58 +0000</creation_ts>
          <short_desc>Environment variables added via systemd environment generators don&apos;t work</short_desc>
          <delta_ts>2026-04-09 15:22:04 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>core</component>
          <version>5.0.7</version>
          <rep_platform>x86</rep_platform>
          <op_sys>x86_64</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>6.99</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Trent Piepho">trent.piepho</reporter>
          <assigned_to name="Unassigned">unassigned</assigned_to>
          <cc>changqing.li</cc>
    
    <cc>hongxu.jia</cc>
    
    <cc>kai.kang</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>narpat.falna</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>ross.burton</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>101205</commentid>
    <comment_count>0</comment_count>
    <who name="Trent Piepho">trent.piepho</who>
    <bug_when>2025-02-22 01:05:58 +0000</bug_when>
    <thetext>It should be possible to set session default environment variables via a systemd environment generator: https://www.freedesktop.org/software/systemd/man/latest/systemd.environment-generator.html

And example would be setting XDG_CACHE_HOME to a value that is not inside a read-only root filesystem, which is not done by the existing read-only rootfs support.

An executable script is placed in the appropriate directory to generate a variable:

&gt; yocto:~$ ls -l /usr/lib/systemd/user-environment-generators/99-test
&gt; -rwxr-xr-x    1 root     root            41 Feb 21 19:39 /usr/lib/systemd/user-environment-generators/99-test
&gt; 
&gt; yocto:~$ cat /usr/lib/systemd/user-environment-generators/99-test
&gt; #!/bin/sh
&gt; 
&gt; echo &quot;TESTENV=from-generator&quot;

It appears that doing this should add the variable the systemd default environment:
&gt; yocto:~$ systemctl --user show-environment | grep TESTENV
&gt; TESTENV=from-generator

And yet the variable is not set in the environment:
&gt; yocto:~$ env | grep TESTENV
&gt; yocto:~$

I&apos;ve tested logins via ssh, the virtual console, and the default weston session.  For both the weston user as well as root.  None of them gain environment variables set by systemd environement generators.

Adding the same generator to a Fedora system works as expected.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101242</commentid>
    <comment_count>1</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2025-02-27 15:39:56 +0000</bug_when>
    <thetext>Do you need to enable &apos;pam&apos; as a DISTRO_FEATURE ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101254</commentid>
    <comment_count>2</comment_count>
    <who name="Trent Piepho">trent.piepho</who>
    <bug_when>2025-02-27 19:12:56 +0000</bug_when>
    <thetext>It is enabled:

DISTRO_FEATURES=&quot;debuginfod ext4 ipv4 ipv6 usbhost wifi pci 3g vfat wifi pam efi opengl  multiarch wayland vulkan systemd-resolved rauc systemd usrmerge gobject-introspection-data ldconfig&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101255</commentid>
    <comment_count>3</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2025-02-27 20:31:10 +0000</bug_when>
    <thetext>Hi Trent,

Thanks for showing that your DISTRO_FEATURES include pam.

Are you able to dig through the systemd configuration and
add what&apos;s needed to enable this feature and send a patch to master?

I only have a kirkstone build at hand but in:
    tmp/work/core2-64-poky-linux/systemd/1_250.5-r0/temp/log.do_configure
I see:
 Message: Skipping systemd-xdg-autostart-generator.8 because ENABLE_XDG_AUTOSTART is false

You seem to be using 5.0.7 aka scarthgap, is that right?

../Randy</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101256</commentid>
    <comment_count>4</comment_count>
    <who name="Trent Piepho">trent.piepho</who>
    <bug_when>2025-02-27 21:29:45 +0000</bug_when>
    <thetext>Yes, using scarthgap.

systemd-xdg-autostart-generator is a service generator.  Similar to the one that automatically adds the getty@ttyS0.service serial console unit if the kernel command line references a serial console.  But its for desktop app auto start files.  Totally unrelated to environment generators.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101257</commentid>
    <comment_count>5</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2025-02-27 22:04:55 +0000</bug_when>
    <thetext>Thanks for explaining what systemd-xdg-autostart-generator is.

Are you able to dig through the systemd configuration and
add what&apos;s needed to enable this feature and send a patch to master?

If so, please put the bug in ACCEPTED and assign it to yourself.
Otherwise, I&apos;ll set the owner to unassigned and someone might get to this eventually.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101260</commentid>
    <comment_count>6</comment_count>
    <who name="Trent Piepho">trent.piepho</who>
    <bug_when>2025-03-01 22:56:49 +0000</bug_when>
    <thetext>I don&apos;t know what needs to be done to fix it.  I don&apos;t think there is a systemd feature that needs to be enabled.  I didn&apos;t see anything optional in the systemd code related to this.  And systemd is running the environment generator and it is adding the output to the environment shown with systemctl show-environment.  I think it&apos;s something with how user sessions are started, maybe related to systemd-logind, but I&apos;ve not dug into how all that works now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101279</commentid>
    <comment_count>7</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2025-03-04 19:57:44 +0000</bug_when>
    <thetext>&quot;I don&apos;t know what needs to be done to fix it.&quot; -&gt; unassigned.

I thought about suggesting that you strace the various systemd processes on Yocto and Fedora but the logs would be huge! ;-)

If you come up with a plan, please let us know here.

Thanks Trent.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101792</commentid>
    <comment_count>8</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2025-05-01 14:07:04 +0000</bug_when>
    <thetext>Bulk move of all unassigned 5.2 medium importance bugs to 5.3.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105028</commentid>
    <comment_count>9</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2026-04-09 15:22:04 +0000</bug_when>
    <thetext>We don&apos;t have anyone to work on this issue, parking in 6.99.
If you can check master or wrynose when it&apos;s released, that would be good.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>