Skip to content
Permalink
Browse files

* fix the pid file generates too late problem

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.
  • Loading branch information...
hejingxian123 committed Sep 6, 2019
1 parent 97c4a15 commit a23a3b9881eff000f79ca4cf9bd0e526399e6a68
Showing with 15 additions and 14 deletions.
  1. +15 −14 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);

0 comments on commit a23a3b9

Please sign in to comment.
You can’t perform that action at this time.