1 Star 0 Fork 131

JianChunfu/src-qemu

forked from src-openEuler/qemu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
qsd-Unlink-absolute-PID-file-path.patch 2.54 KB
一键复制 编辑 原始数据 按行查看 历史
Jiabo Feng 提交于 2023-11-28 15:57 +08:00 . QEMU update to version 6.2.0-84(master)
From 43668bdb7ebaa64536277d4b5b47875e58a3452a Mon Sep 17 00:00:00 2001
From: tangbinzy <tangbin_yewu@cmss.chinamobile.com>
Date: Tue, 21 Nov 2023 07:00:39 +0000
Subject: [PATCH] qsd: Unlink absolute PID file path mainline inclusion commit
9d8f8233b9fa525a7e37350fbc18877051128c5d category: bugfix
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---------------------------------------------------------------
After writing the PID file, we register an atexit() handler to unlink it
when the process terminates. However, if the process has changed its
working directory in the meantime (e.g. in os_setup_post() when
daemonizing), this will not work when the PID file path was relative.
Therefore, pass the absolute path (created with realpath()) to the
unlink() call in the atexit() handler.
(realpath() needs a path pointing to an existing file, so we cannot use
it before qemu_write_pidfile().)
Reproducer:
$ cd /tmp
$ qemu-storage-daemon --daemonize --pidfile qsd.pid
$ file qsd.pid
qsd.pid: ASCII text
$ kill $(cat qsd.pid)
$ file qsd.pid
qsd.pid: ASCII text
(qsd.pid should be gone after the process has terminated.)
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2092322
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20220609122701.17172-2-hreitz@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: tangbinzy <tangbin_yewu@cmss.chinamobile.com>
---
storage-daemon/qemu-storage-daemon.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c
index 52cf17e8ac..f3d8c4ca11 100644
--- a/storage-daemon/qemu-storage-daemon.c
+++ b/storage-daemon/qemu-storage-daemon.c
@@ -60,6 +60,7 @@
#include "trace/control.h"
static const char *pid_file;
+static char *pid_file_realpath;
static volatile bool exit_requested = false;
void qemu_system_killed(int signal, pid_t pid)
@@ -292,7 +293,7 @@ static void process_options(int argc, char *argv[])
static void pid_file_cleanup(void)
{
- unlink(pid_file);
+ unlink(pid_file_realpath);
}
static void pid_file_init(void)
@@ -308,6 +309,14 @@ static void pid_file_init(void)
exit(EXIT_FAILURE);
}
+ pid_file_realpath = g_malloc(PATH_MAX);
+ if (!realpath(pid_file, pid_file_realpath)) {
+ error_report("cannot resolve PID file path: %s: %s",
+ pid_file, strerror(errno));
+ unlink(pid_file);
+ exit(EXIT_FAILURE);
+ }
+
atexit(pid_file_cleanup);
}
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jianchunfu/src-qemu.git
git@gitee.com:jianchunfu/src-qemu.git
jianchunfu
src-qemu
src-qemu
master

搜索帮助