4

Sample:

[ctor@dom0 ~]$ cat nonsense 
#!/bin/bash

set -vex
systemctl show "sys-devices-virtual-block-dm\x2d0.device"
echo 
systemctl show sys-devices-virtual-block-dm\x2d0.device
echo 
systemctl show 'random text here'.device
echo 

The following output is good when \x2d is not interpreted by the shell (because it's quoted):

[ctor@dom0 ~]$ ./nonsense 
systemctl show "sys-devices-virtual-block-dm\x2d0.device"
+ systemctl show 'sys-devices-virtual-block-dm\x2d0.device'
SysFSPath=/sys/devices/virtual/block/dm-0
Id=sys-devices-virtual-block-dm\x5cx2d0.device
Names=sys-devices-virtual-block-dm\x5cx2d0.device
Wants=lvm2-pvscan@253:0.service
Description=/sys/devices/virtual/block/dm-0
LoadState=loaded
ActiveState=active
SubState=plugged
StateChangeTimestamp=Sun 2018-09-09 15:49:14 CEST
StateChangeTimestampMonotonic=10072227
InactiveExitTimestamp=Sun 2018-09-09 15:49:14 CEST
InactiveExitTimestampMonotonic=10072227
ActiveEnterTimestamp=Sun 2018-09-09 15:49:14 CEST
ActiveEnterTimestampMonotonic=10072227
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=no
CanStop=no
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
NeedDaemonReload=no
JobTimeoutUSec=30s
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
Transient=no
StartLimitIntervalSec=10000000
StartLimitBurst=5
StartLimitAction=none
echo 
+ echo

The following output is bad because the sys-devices-virtual-block-dmx2d0.device doesn't exist (note how the shell removed the \):

systemctl show sys-devices-virtual-block-dm\x2d0.device
+ systemctl show sys-devices-virtual-block-dmx2d0.device
Id=sys-devices-virtual-block-dmx2d0.device
Names=sys-devices-virtual-block-dmx2d0.device
Description=sys-devices-virtual-block-dmx2d0.device
LoadState=loaded
ActiveState=inactive
SubState=dead
StateChangeTimestampMonotonic=0
InactiveExitTimestampMonotonic=0
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=no
CanStop=no
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
NeedDaemonReload=no
JobTimeoutUSec=30s
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
Transient=no
StartLimitIntervalSec=10000000
StartLimitBurst=5
StartLimitAction=none
echo 
+ echo

The following output is bad because random text here.device doesn't exist:

systemctl show 'random text here'.device
+ systemctl show 'random text here.device'
Id=random\x5cx20text\x5cx20here.device
Names=random\x5cx20text\x5cx20here.device
Description=random\x5cx20text\x5cx20here.device
LoadState=loaded
ActiveState=inactive
SubState=dead
StateChangeTimestampMonotonic=0
InactiveExitTimestampMonotonic=0
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=no
CanStop=no
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
NeedDaemonReload=no
JobTimeoutUSec=30s
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
Transient=no
StartLimitIntervalSec=10000000
StartLimitBurst=5
StartLimitAction=none
echo 
+ echo

So the above two nonexistent .device are showing similar generic output, not really indicating that they don't exist(Substate=dead ?). It's easy to forget to quote the device name and you get no error, thus thinking that's the real info for the specific .device that you wanted to see.

Systemd version 231 from Fedora 25 used, in dom0 of Qubes OS 4.0:

[ctor@dom0 ~]$ systemctl --version
systemd 231
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

Why doesn't systemctl give an error (and exit code != 0) instead?

1 Answers1

1

The show command is meant to be parsed by a computer (not an user), use the equivalent (but defined for humans) command status:

$ systemctl status 'random-text-here'.device; echo "Exit Status :$?"
● random-text-here.device
   Loaded: loaded
   Active: inactive (dead)
Exit Status :3