lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <b7810ac5-6b6e-7075-b3a8-92bda853fc8b@huawei.com>
Date:   Thu, 1 Dec 2022 11:58:24 +0800
From:   "lihaoxiang (F)" <lihaoxiang9@...wei.com>
To:     <jack@...e.cz>
CC:     <linux-ext4@...r.kernel.org>,
        Zhiqiang Liu <liuzhiqiang26@...wei.com>,
        <linfeilong@...wei.com>, <louhongxiang@...wei.com>,
        "lijinlin (A)" <lijinlin3@...wei.com>
Subject: [PATCH] quota-nld: fix open PID file failed when systemd read it

Running quota_nld by systemd might cause the problem that systemd
couldn't open the PID file generated by quota_nld. In fact, the PID
file hasn't existed yet because it originates from the child process
of quota_nld which is a daemon process. As the main process exit,
systemd try to access the PID file but the daemon hadn't create it
that time.

In this situation, we move the procedure of creating PID file into the
parent process to ensure the PID file must existed when quota_nld exit.
After that, the above problem would never occur again.

Signed-off-by: lihaoxiang <lihaoxiang9@...wei.com>
---
 quota_nld.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/quota_nld.c b/quota_nld.c
index 09c4775..7353e2f 100644
--- a/quota_nld.c
+++ b/quota_nld.c
@@ -413,7 +413,7 @@ static char *build_pid_file_name(void)
 }

 /* Store daemon's PID to file */
-static int store_pid(void)
+static int store_pid(pid_t pid)
 {
 	FILE *pid_file;
 	char *pid_name;
@@ -429,7 +429,7 @@ static int store_pid(void)
 		free(pid_name);
 		return -1;
 	}
-	if (fprintf(pid_file, "%jd\n", (intmax_t)getpid()) < 0) {
+	if (fprintf(pid_file, "%jd\n", pid) < 0) {
 		errstr(_("Could not write daemon's PID into '%s'.\n"),
 			pid_name);
 		fclose(pid_file);
@@ -460,7 +460,7 @@ static void remove_pid(int signal)
 }

 /* Store daemon's PID into file and register its removal on SIGTERM */
-static void use_pid_file(void)
+static void use_pid_file(pid_t pid)
 {
 	struct sigaction term_action;

@@ -468,8 +468,8 @@ static void use_pid_file(void)
 	term_action.sa_flags = 0;
 	if (sigemptyset(&term_action.sa_mask) || sigaction(SIGTERM, &term_action, NULL))
 		errstr(_("Could not register PID file removal on SIGTERM.\n"));
-	if (store_pid())
-		errstr(_("Could not store my PID %jd.\n"), (intmax_t )getpid());
+	if (store_pid(pid))
+		errstr(_("Could not store my PID %jd.\n"), pid);
 }

 int main(int argc, char **argv)
@@ -485,11 +485,7 @@ int main(int argc, char **argv)
 		dhandle = init_dbus();
 	if (!(flags & FL_NODAEMON)) {
 		use_syslog();
-		if (daemon(0, 0)) {
-			errstr(_("Failed to daemonize: %s\n"), strerror(errno));
-			exit(1);
-		};
-		use_pid_file();
+		fork_daemon();
 	}
 	run(nsock);
 	return 0;
-- 
2.37.0.windows.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ