1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

Merge pull request #12414 from keszybz/detect-podman

Detect podman as separate container type
This commit is contained in:
Lennart Poettering 2019-04-29 19:07:24 +02:00 committed by GitHub
commit 987719d37d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 7 deletions

View File

@ -62,7 +62,7 @@
</thead>
<tbody>
<row>
<entry valign="top" morerows="11">VM</entry>
<entry valign="top" morerows="12">VM</entry>
<entry><varname>qemu</varname></entry>
<entry>QEMU software virtualization, without KVM</entry>
</row>
@ -128,7 +128,7 @@
</row>
<row>
<entry valign="top" morerows="6">Container</entry>
<entry valign="top" morerows="7">Container</entry>
<entry><varname>openvz</varname></entry>
<entry>OpenVZ/Virtuozzo</entry>
</row>
@ -153,6 +153,11 @@
<entry>Docker container manager</entry>
</row>
<row>
<entry><varname>podman</varname></entry>
<entry><ulink url="https://podman.io">Podman</ulink> container manager</entry>
</row>
<row>
<entry><varname>rkt</varname></entry>
<entry>rkt app container runtime</entry>

View File

@ -1089,6 +1089,7 @@
<literal>lxc-libvirt</literal>,
<literal>systemd-nspawn</literal>,
<literal>docker</literal>,
<literal>podman</literal>,
<literal>rkt</literal>,
<literal>wsl</literal>,
<literal>acrn</literal> to test

View File

@ -428,7 +428,6 @@ finish:
}
int detect_container(void) {
static const struct {
const char *value;
int id;
@ -437,6 +436,7 @@ int detect_container(void) {
{ "lxc-libvirt", VIRTUALIZATION_LXC_LIBVIRT },
{ "systemd-nspawn", VIRTUALIZATION_SYSTEMD_NSPAWN },
{ "docker", VIRTUALIZATION_DOCKER },
{ "podman", VIRTUALIZATION_PODMAN },
{ "rkt", VIRTUALIZATION_RKT },
{ "wsl", VIRTUALIZATION_WSL },
};
@ -468,9 +468,15 @@ int detect_container(void) {
}
if (getpid_cached() == 1) {
/* If we are PID 1 we can just check our own environment variable, and that's authoritative. */
/* If we are PID 1 we can just check our own environment variable, and that's authoritative.
* We distinguish three cases:
* - the variable is not defined we jump to other checks
* - the variable is defined to an empty value we are not in a container
* - anything else some container, either one of the known ones or "container-other"
*/
e = getenv("container");
if (!e)
goto check_sched;
if (isempty(e)) {
r = VIRTUALIZATION_NONE;
goto finish;
@ -498,8 +504,9 @@ int detect_container(void) {
if (r < 0) /* This only works if we have CAP_SYS_PTRACE, hence let's better ignore failures here */
log_debug_errno(r, "Failed to read $container of PID 1, ignoring: %m");
/* Interestingly /proc/1/sched actually shows the host's PID for what we see as PID 1. Hence, if the PID shown
* there is not 1, we know we are in a PID namespace. and hence a container. */
/* Interestingly /proc/1/sched actually shows the host's PID for what we see as PID 1. If the PID
* shown there is not 1, we know we are in a PID namespace and hence a container. */
check_sched:
r = read_one_line_file("/proc/1/sched", &m);
if (r >= 0) {
const char *t;
@ -649,6 +656,7 @@ static const char *const virtualization_table[_VIRTUALIZATION_MAX] = {
[VIRTUALIZATION_LXC] = "lxc",
[VIRTUALIZATION_OPENVZ] = "openvz",
[VIRTUALIZATION_DOCKER] = "docker",
[VIRTUALIZATION_PODMAN] = "podman",
[VIRTUALIZATION_RKT] = "rkt",
[VIRTUALIZATION_WSL] = "wsl",
[VIRTUALIZATION_CONTAINER_OTHER] = "container-other",

View File

@ -31,6 +31,7 @@ enum {
VIRTUALIZATION_LXC,
VIRTUALIZATION_OPENVZ,
VIRTUALIZATION_DOCKER,
VIRTUALIZATION_PODMAN,
VIRTUALIZATION_RKT,
VIRTUALIZATION_WSL,
VIRTUALIZATION_CONTAINER_OTHER,