Bug 1312384 - systemd-nspawn --setenv is too strict
Summary: systemd-nspawn --setenv is too strict
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: systemd
Version: 25
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: systemd-maint
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-02-26 15:22 UTC by Miroslav Suchý
Modified: 2016-08-08 17:44 UTC (History)
8 users (show)

Fixed In Version: systemd-229-1.fc24
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-08-04 05:00:28 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Miroslav Suchý 2016-02-26 15:22:13 UTC
Description of problem:
Mock using environment variable:
  config_opts['environment']['PROMPT_COMMAND'] = 'printf "\033]0;<mock-chroot>\007<mock-chroot>"'
See bug 1126235 for history if you want to know why.

And when I use systemd-nspawn in mock. (--new-chroot option) It will execute:
DEBUG: doshell: command: ['/usr/bin/systemd-nspawn', '-q', '-M', '1b48214dd52d4132aa711e3408619c74', '-D', '/var/lib/mock/epel-7-x86_64/root', '--setenv=FOO=BAR', '--setenv=HOSTNAME=mock', '--setenv=PROMPT_COMMAND=printf "\x1b]0;<mock-chroot>\x07<mock-chroot>"', '--setenv=SHELL=/bin/bash', '--setenv=PATH=/usr/bin:/usr/sbin', '--setenv=TERM=vt100', '--setenv=LANG=cs_CZ.UTF-8', '--setenv=HOME=/builddir', '/bin/sh', '-i', '-l']
Note that this is not even master. I discovered that during work on mock bug 1311796.

Which will fails with:
  Environment variable assignment 'PROMPT_COMMAND=printf "<mock-chroot>"' is not valid.

I suppose that it is because you check if the character is UTF.

Version-Release number of selected component (if applicable):
systemd-222-14.fc23.x86_64

How reproducible:
always

Steps to Reproduce:
1. systemd-nspawn -q -M 1b48214dd52d4132aa711e3408619c74 -D /var/lib/mock/epel-7-x86_64/root '--setenv=PROMPT_COMMAND=printf "\x1b]0;<mock-chroot>\x07<mock-chroot>"'

Actual results:
variable is not valid

Expected results:
no errors because that variable is perfectly valid

Additional info:
Until this get resolved Mock will use simpler PROMPT for nspawn.

Comment 1 Jan Synacek 2016-02-29 14:09:50 UTC
Works for me...

$ rpm -q systemd
systemd-222-14.fc23.x86_64

$ sudo systemd-nspawn -bM rawhide --setenv='PROMPT_COMMAND=printf "\x1b]0;<mock-chroot>\x07<mock-chroot>"'

<Boots fine...>

In the container:
# cat /proc/1/environ 
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bincontainer=systemd-nspawnTERM=xterm-256colorHOME=/rootUSER=rootLOGNAME=rootPROMPT_COMMAND=printf "\x1b]0;<mock-chroot>\x07<mock-chroot>"

# sudo env | grep PROMPT
# sudo systemctl show-environment | grep PROMPT

The --setenv only passes the environment to the init of the container. I'm not sure if it's currently possible to pass an environment variable to the entire container.

Maybe Zbyszek knows?

Comment 2 Zbigniew Jędrzejewski-Szmek 2016-03-21 20:53:09 UTC
I can't reproduce the problem using nspawn directly either.
https://github.com/systemd/systemd/pull/2880 adds some more tests.

Comment 3 Zbigniew Jędrzejewski-Szmek 2016-03-21 21:05:48 UTC
I tried setting  config_opts['environment']['PROMPT_COMMAND']  in mock config in various ways and it doesn't seem to have any effect when --new-chroot is specified.

Comment 4 Zbigniew Jędrzejewski-Szmek 2016-03-22 03:54:25 UTC
Maybe you need one more level of escaping?

Comment 5 Jan Kurik 2016-07-26 05:06:30 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 25 development cycle.
Changing version to '25'.

Comment 6 Zbigniew Jędrzejewski-Szmek 2016-08-04 05:00:28 UTC
Passing of the environment variable seems to work fine.

The variable is set for the init process in the container. To pass it to child processes, PassEnvironment should be used: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#PassEnvironment= (added in systemd-228).

Comment 7 Miroslav Suchý 2016-08-08 17:44:36 UTC
OK, I can confirm that with
  systemd-229-8.fc24.x86_64
it works. Even the reproducer from #0.


Note You need to log in before you can comment on or make changes to this bug.