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 11-23-2011, 09:15 AM
"Fabio M. Di Nitto"
 
Default qdiskd: add failure paths to check_process_running and drop duplicate check

Spotted by Coverity Scan

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
:100644 100644 c260cb8... 2ba6fa0... M cman/qdisk/daemon_init.c
:100644 100644 079af01... 175bdb6... M cman/qdisk/main.c
cman/qdisk/daemon_init.c | 27 ++++++++++++---------------
cman/qdisk/main.c | 9 ++++++++-
2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/cman/qdisk/daemon_init.c b/cman/qdisk/daemon_init.c
index c260cb8..2ba6fa0 100644
--- a/cman/qdisk/daemon_init.c
+++ b/cman/qdisk/daemon_init.c
@@ -113,6 +113,11 @@ check_process_running(char *prog, pid_t * pid)

*pid = -1;

+ if (!prog) {
+ errno = EINVAL;
+ return -1;
+ }
+
/*
* Now see if there is a pidfile associated with this cmd in /var/run
*/
@@ -120,7 +125,10 @@ check_process_running(char *prog, pid_t * pid)
memset(filename, 0, PATH_MAX);

cmd = basename(prog);
- snprintf(filename, sizeof (filename), "/var/run/%s.pid", cmd);
+ if (!cmd)
+ return -1;
+
+ snprintf(filename, sizeof (filename) - 1, "/var/run/%s.pid", cmd);

ret = stat(filename, &st);
if ((ret < 0) || (!st.st_size))
@@ -130,9 +138,8 @@ check_process_running(char *prog, pid_t * pid)
* Read the pid from the file.
*/
fp = fopen(filename, "r");
- if (fp == NULL) { /* error */
+ if (fp == NULL) /* error */
return 0;
- }

ret = fscanf(fp, "%d
", &oldpid);
fclose(fp);
@@ -144,6 +151,7 @@ check_process_running(char *prog, pid_t * pid)
*pid = oldpid;
return 1;
}
+
return 0;
}

@@ -200,22 +208,12 @@ setup_sigmask(void)
void
daemon_init(char *prog)
{
- uid_t uid;
- pid_t pid;
-
- uid = getuid();
- if (uid) {
+ if (getuid()) {
logt_print(LOG_ERR,
"daemon_init: Sorry, only root wants to run this.
");
exit(1);
}

- if (check_process_running(prog, &pid) && (pid != getpid())) {
- logt_print(LOG_ERR,
- "daemon_init: Process "%s" already running.
",
- prog);
- exit(1);
- }
if (setup_sigmask() < 0) {
logt_print(LOG_ERR, "daemon_init: Unable to set signal mask.
");
exit(1);
@@ -226,7 +224,6 @@ daemon_init(char *prog)
exit(1);
}

-
update_pidfile(prog);
}

diff --git a/cman/qdisk/main.c b/cman/qdisk/main.c
index 079af01..175bdb6 100644
--- a/cman/qdisk/main.c
+++ b/cman/qdisk/main.c
@@ -1980,7 +1980,14 @@ main(int argc, char **argv)
quorum_header_t qh;
qd_priv_t qp;

- if (check_process_running(argv[0], &pid) && pid !=getpid()) {
+
+ rv = check_process_running(argv[0], &pid);
+ if (rv < 0) {
+ fprintf(stderr, "Unable to determin if %s is already running: %s
",
+ argv[0], strerror(errno));
+ return -1;
+ }
+ if (rv && pid !=getpid()) {
printf("QDisk services already running
");
return 0;
}
--
1.7.4.4
 
Old 11-29-2011, 05:03 PM
Lon Hohberger
 
Default qdiskd: add failure paths to check_process_running and drop duplicate check

On 11/23/2011 05:15 AM, Fabio M. Di Nitto wrote:

+ fprintf(stderr, "Unable to determin if %s is already running: %s
",
+ argv[0], strerror(errno));


Typo (determine)

-- Lon
 

Thread Tools




All times are GMT. The time now is 02:25 AM.

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