irqbalance/fix-the-pid-file-generates-too-late-problem.patch

66 lines
2.1 KiB
Diff
Raw Normal View History

2020-03-24 11:44:22 +08:00
From a23a3b9881eff000f79ca4cf9bd0e526399e6a68 Mon Sep 17 00:00:00 2001
From: hejingxian 00273181 <hejingxian@huawei.com>
Date: Fri, 6 Sep 2019 21:00:52 +0800
2020-07-03 17:09:39 +08:00
Subject: [PATCH 11/53] * fix the pid file generates too late problem
2020-03-24 11:44:22 +08:00
When the system processes many irqs with using user policy script,
the build_object_tree function will fork many child processes which costs several minutes.
In the irqbalance main process, the pid file generates after build_object_tree.
Therefore, the generation time of the pid file is several minutes later than the process start time.
When the irqbalance service is started by systemd based forking mode, systemd will check the pid file.
If the pid file generates too late, systemd will think the irqbalance service as starting failed.
---
irqbalance.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/irqbalance.c b/irqbalance.c
index d424326..8199c06 100644
--- a/irqbalance.c
+++ b/irqbalance.c
@@ -573,6 +573,21 @@ int main(int argc, char** argv)
log(TO_ALL, LOG_WARNING, "Unable to determin HZ defaulting to 100\n");
HZ = 100;
}
+
+ if (!foreground_mode) {
+ int pidfd = -1;
+ if (daemon(0,0))
+ exit(EXIT_FAILURE);
+ /* Write pidfile which can be used to avoid starting mutiple instances */
+ if (pidfile && (pidfd = open(pidfile,
+ O_WRONLY | O_CREAT | O_EXCL | O_TRUNC,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) >= 0) {
+ char str[16];
+ snprintf(str, sizeof(str), "%u\n", getpid());
+ write(pidfd, str, strlen(str));
+ close(pidfd);
+ }
+ }
build_object_tree();
if (debug_mode)
@@ -588,20 +603,6 @@ int main(int argc, char** argv)
exit(EXIT_SUCCESS);
}
- if (!foreground_mode) {
- int pidfd = -1;
- if (daemon(0,0))
- exit(EXIT_FAILURE);
- /* Write pidfile */
- if (pidfile && (pidfd = open(pidfile,
- O_WRONLY | O_CREAT | O_EXCL | O_TRUNC,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) >= 0) {
- char str[16];
- snprintf(str, sizeof(str), "%u\n", getpid());
- write(pidfd, str, strlen(str));
- close(pidfd);
- }
- }
g_unix_signal_add(SIGINT, handler, NULL);
g_unix_signal_add(SIGTERM, handler, NULL);
--
2020-07-03 17:09:39 +08:00
2.23.0
2020-03-24 11:44:22 +08:00