代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/nfs-utils 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 9565ab64e60f8282967e138f43c6057562dc5c27 Mon Sep 17 00:00:00 2001
From: zhanchengbin <zhanchengbin1@huawei.com>
Date: Sat, 19 Nov 2022 11:50:07 -0500
Subject: [PATCH] nfs-blkmapd: PID file read by systemd failed
When started nfs-blkmap.service, the PID file can't be opened, The
cause is that the child process does not create the PID file before
the systemd reads the PID file.
Adding "ExecStartPost=/bin/sleep 0.1" to
/usr/lib/systemd/system/nfs-blkmap.service will probably solve this
problem, However, there is no guarantee that the above solutions are
effective under high cpu pressure.So replace the daemon function with
the fork function, and put the behavior of creating the PID file in
the parent process to solve the above problems.
Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
---
utils/blkmapd/device-discovery.c | 48 ++++++++++++++++++++++++++--------------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/utils/blkmapd/device-discovery.c b/utils/blkmapd/device-discovery.c
index bd89059..a565fdb 100644
--- a/utils/blkmapd/device-discovery.c
+++ b/utils/blkmapd/device-discovery.c
@@ -504,28 +504,44 @@ int main(int argc, char **argv)
if (fg) {
openlog("blkmapd", LOG_PERROR, 0);
} else {
- if (daemon(0, 0) != 0) {
- fprintf(stderr, "Daemonize failed\n");
- exit(1);
+ pid_t pid = fork();
+ if (pid < 0) {
+ BL_LOG_ERR("fork error\n");
+ exit(1);
+ } else if (pid != 0) {
+ pidfd = open(PID_FILE, O_WRONLY | O_CREAT, 0644);
+ if (pidfd < 0) {
+ BL_LOG_ERR("Create pid file %s failed\n", PID_FILE);
+ exit(1);
+ }
+
+ if (lockf(pidfd, F_TLOCK, 0) < 0) {
+ BL_LOG_ERR("Already running; Exiting!");
+ close(pidfd);
+ exit(1);
+ }
+ if (ftruncate(pidfd, 0) < 0)
+ BL_LOG_ERR("ftruncate on %s failed: m\n", PID_FILE);
+ sprintf(pidbuf, "%d\n", pid);
+ if (write(pidfd, pidbuf, strlen(pidbuf)) != (ssize_t)strlen(pidbuf))
+ BL_LOG_ERR("write on %s failed: m\n", PID_FILE);
+ exit(0);
+ }
+
+ (void)setsid();
+ if (chdir("/")) {
+ BL_LOG_ERR("chdir error\n");
+ }
+ int fd = open("/dev/null", O_RDWR, 0);
+ if (fd >= 0) {
+ (void)dup2(fd, STDIN_FILENO);
+ (void)dup2(fd, STDOUT_FILENO);
+ (void)dup2(fd, STDERR_FILENO);
+
+ (void)close(fd);
}
openlog("blkmapd", LOG_PID, 0);
- pidfd = open(PID_FILE, O_WRONLY | O_CREAT, 0644);
- if (pidfd < 0) {
- BL_LOG_ERR("Create pid file %s failed\n", PID_FILE);
- exit(1);
- }
-
- if (lockf(pidfd, F_TLOCK, 0) < 0) {
- BL_LOG_ERR("Already running; Exiting!");
- close(pidfd);
- exit(1);
- }
- if (ftruncate(pidfd, 0) < 0)
- BL_LOG_WARNING("ftruncate on %s failed: m\n", PID_FILE);
- sprintf(pidbuf, "%d\n", getpid());
- if (write(pidfd, pidbuf, strlen(pidbuf)) != (ssize_t)strlen(pidbuf))
- BL_LOG_WARNING("write on %s failed: m\n", PID_FILE);
}
signal(SIGINT, sig_die);
--
2.27.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。