1 Star 0 Fork 71

章北海/libvirt

forked from src-openEuler/libvirt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vircgroupmock-Be-wiser-about-detecting-fakerootdir-c.patch 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
Jiangjiacheng 提交于 2023-01-04 12:02 . Backport patches from upstream
From 6ce9382804a5598150d4d357adfef2fd2d09c48b Mon Sep 17 00:00:00 2001
From: xuyinghao <xuyinghao2@huawei.com>
Date: Tue, 16 Aug 2022 19:38:53 +0800
Subject: [PATCH 12/13] vircgroupmock: Be wiser about detecting fakerootdir
change
The way that vircgroupmock works is that the vircgrouptest creates a temporary directory and sets LIBVIRT_FAKE_ROOT_DIR env variable which is then checked by the mock at the beginning of basically every function it overrides (access(), stat in all its flavours, mkdir(), etc.). The mock then creates a CGroup dir structure. But the test is allowed to change the directory, to accommodate environment for the particular test case. This is done by changing the environment variable which is then detected by the mock and the whole process repeats.
However, the way the mock detect changes is buggy. After it got the environment variable it compares it to the last known value (global variable @fakerootdir) and if they don't match the last known value is set to point to the new value. Problem is that the result of getenv() is assigned to the @fakerootdir directly.Therefore, @fakerootdir points somewhere into the buffer of environment variables. In turn, when the test sets new value (via g_setenv()) it may be placed at the very same position in the env var buffer and thus the mock fails to detect the change.
The solution is to keep our private copy of the value (by g_strdup()) which makes the variable not rely on getenv()/setenv() placing values at random positions.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
tests/vircgroupmock.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index 66b8c01852..4acadb8686 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -352,7 +352,8 @@ static void init_sysfs(void)
if (fakerootdir && STREQ(fakerootdir, newfakerootdir))
return;
- fakerootdir = newfakerootdir;
+ VIR_FREE(fakerootdir);
+ fakerootdir = g_strdup(newfakerootdir);
mock = getenv("VIR_CGROUP_MOCK_MODE");
if (mock) {
--
2.33.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dependent/libvirt.git
git@gitee.com:dependent/libvirt.git
dependent
libvirt
libvirt
master

搜索帮助