virt: drop /proc/1/sched hack
On really old kernels (< 4.14+) a bug in /proc/1/sched handling in the kernel could be used to determine whether we are running in a PID namespace. This hasn't worked for a long time, and there's little point in making things work on old kernels we can't make work on current kernels, hence let's drop that old cruft. See: #8153
This commit is contained in:
parent
1c36b8bf53
commit
5e3effb1f3
|
@ -517,7 +517,7 @@ int detect_container(void) {
|
||||||
*/
|
*/
|
||||||
e = getenv("container");
|
e = getenv("container");
|
||||||
if (!e)
|
if (!e)
|
||||||
goto check_sched;
|
goto none;
|
||||||
if (isempty(e)) {
|
if (isempty(e)) {
|
||||||
r = VIRTUALIZATION_NONE;
|
r = VIRTUALIZATION_NONE;
|
||||||
goto finish;
|
goto finish;
|
||||||
|
@ -545,24 +545,7 @@ int detect_container(void) {
|
||||||
if (r < 0) /* This only works if we have CAP_SYS_PTRACE, hence let's better ignore failures here */
|
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");
|
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. If the PID
|
none:
|
||||||
* 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;
|
|
||||||
|
|
||||||
t = strrchr(m, '(');
|
|
||||||
if (!t)
|
|
||||||
return -EIO;
|
|
||||||
|
|
||||||
if (!startswith(t, "(1,")) {
|
|
||||||
r = VIRTUALIZATION_CONTAINER_OTHER;
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
} else if (r != -ENOENT)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
/* If that didn't work, give up, assume no container manager. */
|
/* If that didn't work, give up, assume no container manager. */
|
||||||
r = VIRTUALIZATION_NONE;
|
r = VIRTUALIZATION_NONE;
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
Loading…
Reference in New Issue