[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH] qdiskd: Remove pid file on clean/normal exit



Signed-off-by: Lon Hohberger <lhh redhat com>
---
 cman/qdisk/daemon_init.c |   19 +++++++++++++++----
 cman/qdisk/main.c        |    2 ++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/cman/qdisk/daemon_init.c b/cman/qdisk/daemon_init.c
index 7a24733..f29c71a 100644
--- a/cman/qdisk/daemon_init.c
+++ b/cman/qdisk/daemon_init.c
@@ -36,6 +36,7 @@ int check_process_running(char *prog, pid_t * pid);
  */
 static void update_pidfile(char *prog);
 static int setup_sigmask(void);
+static char pid_filename[PATH_MAX];
 
 static int
 check_pid_valid(pid_t pid, char *prog)
@@ -148,14 +149,13 @@ update_pidfile(char *prog)
 {
 	FILE *fp = NULL;
 	char *cmd;
-	char filename[PATH_MAX];
 
-	memset(filename, 0, PATH_MAX);
+	memset(pid_filename, 0, PATH_MAX);
 
 	cmd = basename(prog);
-	snprintf(filename, sizeof (filename), "/var/run/%s.pid", cmd);
+	snprintf(pid_filename, sizeof (pid_filename), "/var/run/%s.pid", cmd);
 
-	fp = fopen(filename, "w");
+	fp = fopen(pid_filename, "w");
 	if (fp == NULL) {
 		exit(1);
 	}
@@ -225,3 +225,14 @@ daemon_init(char *prog)
 
 	update_pidfile(prog);
 }
+
+
+void
+daemon_cleanup(void)
+{
+	if (!strlen(pid_filename))
+		return;
+
+	unlink(pid_filename);
+	memset(pid_filename, 0, sizeof(pid_filename));
+}
diff --git a/cman/qdisk/main.c b/cman/qdisk/main.c
index 86187ee..a30dfea 100644
--- a/cman/qdisk/main.c
+++ b/cman/qdisk/main.c
@@ -31,6 +31,7 @@
 
 /* from daemon_init.c */
 int daemon_init(char *);
+int daemon_cleanup(void);
 int check_process_running(char *, pid_t *);
 
 /* from proc.c */
@@ -1773,6 +1774,7 @@ out:
 	}
 	qd_destroy(&ctx);
 	logt_exit();
+	daemon_cleanup();
 	return ret;
 }
 
-- 
1.5.6.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]