[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 33/35] qsd: Unlink absolute PID file path
From: |
Hanna Reitz |
Subject: |
[PULL 33/35] qsd: Unlink absolute PID file path |
Date: |
Tue, 12 Jul 2022 20:08:51 +0200 |
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>
---
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 448c318e23..7718f6dcda 100644
--- a/storage-daemon/qemu-storage-daemon.c
+++ b/storage-daemon/qemu-storage-daemon.c
@@ -61,6 +61,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)
@@ -363,7 +364,7 @@ static void process_options(int argc, char *argv[], bool
pre_init_pass)
static void pid_file_cleanup(void)
{
- unlink(pid_file);
+ unlink(pid_file_realpath);
}
static void pid_file_init(void)
@@ -379,6 +380,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.35.3
- [PULL 20/35] block: Add blk_[co_]preadv_part(), (continued)
- [PULL 20/35] block: Add blk_[co_]preadv_part(), Hanna Reitz, 2022/07/12
- [PULL 22/35] block: Change blk_pwrite_compressed() param order, Hanna Reitz, 2022/07/12
- [PULL 21/35] block: Export blk_pwritev_part() in block-backend-io.h, Hanna Reitz, 2022/07/12
- [PULL 18/35] block: Implement blk_{pread, pwrite}() using generated_co_wrapper, Hanna Reitz, 2022/07/12
- [PULL 26/35] block: Implement blk_flush() using generated_co_wrapper, Hanna Reitz, 2022/07/12
- [PULL 27/35] block: Add blk_co_ioctl(), Hanna Reitz, 2022/07/12
- [PULL 30/35] block: Remove remaining unused symbols in coroutines.h, Hanna Reitz, 2022/07/12
- [PULL 23/35] block: Add blk_co_pwrite_compressed(), Hanna Reitz, 2022/07/12
- [PULL 29/35] block: Reorganize some declarations in block-backend-io.h, Hanna Reitz, 2022/07/12
- [PULL 32/35] iotests/297: Have mypy ignore unused ignores, Hanna Reitz, 2022/07/12
- [PULL 33/35] qsd: Unlink absolute PID file path,
Hanna Reitz <=
- [PULL 34/35] vl: Conditionally register PID file unlink notifier, Hanna Reitz, 2022/07/12
- [PULL 35/35] vl: Unlink absolute PID file path, Hanna Reitz, 2022/07/12
- Re: [PULL 00/35] Block patches, Peter Maydell, 2022/07/13