Bug 1525593 - show variables containing spaces in 'systemctl show -p Environment'
Summary: show variables containing spaces in 'systemctl show -p Environment'
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: systemd
Version: rawhide
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: 2017-12-13 16:05 UTC by Pavel Raiskup
Modified: 2020-07-09 08:50 UTC (History)
5 users (show)

Fixed In Version: systemd-246~rc1-1.fc33
Clone Of:
Environment:
Last Closed: 2020-07-09 08:50:08 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Pavel Raiskup 2017-12-13 16:05:52 UTC
$ systemctl show -p Environment postgresql.service
..  PG_OOM_ADJUST_VALUE=0 [unprintable] ...

The "unprintable" variable is set by:

   Environment=PGDATA=/var/lib/pgsql/'da ta'

Or by:

   Environment='PGDATA=/var/lib/pgsql/da ta'

and there's actually nothing "unprintable" on that. It would be nice
if systemctl could quote && print that variable, too.

Comment 1 Lukáš Nykrýn 2017-12-14 11:43:42 UTC
Looks like upstream systemd uses escaping in this case.
[root@notas ~]#  systemctl show -p Environment cups.service
Environment=PGDATA=/var/lib/pgsql/da\x20ta

Comment 2 Pavel Raiskup 2017-12-14 13:10:04 UTC
Good, thanks - just for reference - could we link the upstream implementation
(the escaping) from here?  I'd like to ensure that something like this works:

#! /bin/bash
systemd_output=$(systemctl show -p Environment "$1")
set -- ${systemd_output##Environment=}
for item; do
    name=${item%%=*}
    value=$(echo -e "${item##*=}")
    eval "$name=\$value"
done

Comment 3 Lukáš Nykrýn 2017-12-14 13:13:39 UTC
I guess you want to call systemd-escape --unescape on the string.

Comment 4 Pavel Raiskup 2017-12-14 13:22:53 UTC
Thanks, nice to know :-) but I guess I still need to split the environment
variables, somehow.

Comment 5 Zbigniew Jędrzejewski-Szmek 2017-12-16 14:49:55 UTC
Upstream used to do that, but it doesn't anymore :(
https://github.com/systemd/systemd/commit/5993d46a1a

Comment 6 Zbigniew Jędrzejewski-Szmek 2020-04-06 08:59:40 UTC
https://github.com/systemd/systemd/pull/15345

Comment 7 Zbigniew Jędrzejewski-Szmek 2020-07-09 08:50:08 UTC
Built in rawhide.


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