FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 03-20-2009, 06:36 PM
Lon Hohberger
 
Default 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
 

Thread Tools




All times are GMT. The time now is 10:27 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org