X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fvirt.c;h=f10baab40bc0ccbc0620930e467f0ffc6d4908b4;hb=23fbe14f503c1e98292efc4ba1238adb7dc38d80;hp=b4368952ffac3d8f3dde431caff786e39f11a5b8;hpb=f41925b4e442a34c93ad120ef1426c974a047ed1;p=elogind.git diff --git a/src/shared/virt.c b/src/shared/virt.c index b4368952f..f10baab40 100644 --- a/src/shared/virt.c +++ b/src/shared/virt.c @@ -293,8 +293,26 @@ int detect_container(const char **id) { r = read_one_line_file("/run/systemd/container", &m); if (r == -ENOENT) { - r = 0; - goto finish; + + /* Fallback for cases where PID 1 was not + * systemd (for example, cases where + * init=/bin/sh is used. */ + + r = getenv_for_pid(1, "container", &m); + if (r <= 0) { + + /* If that didn't work, give up, + * assume no container manager. + * + * Note: This means we still cannot + * detect containers if init=/bin/sh + * is passed but privileges dropped, + * as /proc/1/environ is only readable + * with privileges. */ + + r = 0; + goto finish; + } } if (r < 0) return r; @@ -310,6 +328,8 @@ int detect_container(const char **id) { _id = "lxc-libvirt"; else if (streq(e, "systemd-nspawn")) _id = "systemd-nspawn"; + else if (streq(e, "docker")) + _id = "docker"; else _id = "other";