1 Star 0 Fork 48

苏峰/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0438-basic-virt-try-the-proc-1-sched-hack-also-for-PID1.patch 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
geliwei 提交于 2021-06-16 16:46 . update to systemd-239-45.el8.src.rpm
From 2f584bd93d64a75ab11b5a5aa31d0b7145da5a86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Fri, 26 Apr 2019 13:37:31 +0200
Subject: [PATCH] basic/virt: try the /proc/1/sched hack also for PID1
If a container manager does not set $container, we could end up
in a strange situation when detect-virt returns container-other when
run as non-pid-1 and none when run as pid-1.
(cherry picked from commit 342bed02084c4396dd2f1054bd559bfb2699cfcb)
Resolves: #1868877
---
src/basic/virt.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/basic/virt.c b/src/basic/virt.c
index e05b3e6d99..dfa1525219 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -427,7 +427,6 @@ finish:
}
int detect_container(void) {
-
static const struct {
const char *value;
int id;
@@ -456,9 +455,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;
@@ -486,8 +491,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;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/su-feng-nmg/systemd.git
git@gitee.com:su-feng-nmg/systemd.git
su-feng-nmg
systemd
systemd
a8

搜索帮助