[systemd-devel] [PATCH] detect-virt: do not return exit failure code when the state is none

Lennart Poettering lennart at poettering.net
Thu May 24 10:20:36 UTC 2018


On Do, 24.05.18 13:47, Lee, Chun-Yi (joeyli.kernel at gmail.com) wrote:

> Currently the systemd-detect-virt returns exit failure code when it
> detected none state. But actually the none state is still a valid
> state but not a process failed.
> 
> This patch changes the logic to return success code when the state
> is none. It can avoid that subsequent activity is blocked by the
> failure code of systemd-detect-virt process.

This is supposed to be used in shell script constructs like the
following:

<snip>
if systemd-detect-virt -q ; then
        echo "Detected virtualization"
else
        echo "Detected no virtualization"
fi
</snip>

That exit code hence is used as boolean indication whether
virtualization is available or not. And this behaviour is explicitly
documented in the man page. It's API and for a good reason so. Even if
we could break API just like that we really shouldn't because such if
constructs make a ton of sense and are generally how shell does this,
see the "test" command for example.

Sorry, but you need to find a different way to do what you are trying
to do...

Sorry,

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list