![为什么不出现此错误:systemctl show 'random text here'.device](https://linux22.com/image/139873/%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%8D%E5%87%BA%E7%8E%B0%E6%AD%A4%E9%94%99%E8%AF%AF%EF%BC%9Asystemctl%20show%20'random%20text%20here'.device.png)
样本:
[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
\x2d
当shell 不解释 时,以下输出很好(因为它被引用了):
[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
以下输出很糟糕,因为sys-devices-virtual-block-dmx2d0.device
不存在(请注意 shell 如何删除\
):
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
以下输出是错误的,因为random text here.device
不存在:
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
因此,上面两个不存在的内容.device
显示了类似的通用输出,并不真正表明它们不存在(Substate=dead
?)。您很容易忘记引用设备名称,并且不会出现错误,从而认为这是.device
您想要查看的特定设备的真实信息。
使用 Fedora 25 的 Systemd 版本 231,在 Qubes OS 4.0 的 dom0 中:
[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
为什么 systemctl 不给出错误(并且退出代码!= 0)?
答案1
该show
命令旨在由计算机(而不是用户)解析,使用等效的(但为人类定义的)命令status
:
$ systemctl status 'random-text-here'.device; echo "Exit Status :$?"
● random-text-here.device
Loaded: loaded
Active: inactive (dead)
Exit Status :3