diff options
author | Roy Marples <roy@marples.name> | 2008-03-17 14:31:44 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2008-03-17 14:31:44 +0000 |
commit | b2f7606b2366bd4c7196f3ce786375353e942e80 (patch) | |
tree | f7c377485f3a3a755b1d6a74ecb27bc8811da6f8 /src/librc | |
parent | 4c1466642351ddb01cc7353601153a79326f18f7 (diff) |
We should check for NULL here.
Diffstat (limited to 'src/librc')
-rw-r--r-- | src/librc/librc-daemon.c | 99 |
1 files changed, 47 insertions, 52 deletions
diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c index b174a82b..ac72c904 100644 --- a/src/librc/librc-daemon.c +++ b/src/librc/librc-daemon.c @@ -506,7 +506,7 @@ bool rc_service_daemons_crashed(const char *service) char *p; char *token; bool retval = false; - RC_STRINGLIST *list; + RC_STRINGLIST *list = NULL; RC_STRING *s; size_t i; @@ -526,8 +526,6 @@ bool rc_service_daemons_crashed(const char *service) if (! fp) break; - list = rc_stringlist_new(); - while ((line = rc_getline(fp))) { p = line; if ((token = strsep(&p, "=")) == NULL || ! p) { @@ -541,6 +539,8 @@ bool rc_service_daemons_crashed(const char *service) } if (strncmp(token, "argv_", 5) == 0) { + if (! list) + list = rc_stringlist_new(); rc_stringlist_add(list, p); } else if (strcmp(token, "exec") == 0) { if (exec) @@ -551,9 +551,9 @@ bool rc_service_daemons_crashed(const char *service) free(name); name = xstrdup(p); } else if (strcmp(token, "pidfile") == 0) { - if (pidfile) - free(pidfile); pidfile = xstrdup(p); + free(line); + break; } free(line); } @@ -561,73 +561,68 @@ bool rc_service_daemons_crashed(const char *service) pid = 0; if (pidfile) { - if (! exists(pidfile)) { - retval = true; - break; - } - - if ((fp = fopen(pidfile, "r")) == NULL) { - retval = true; - break; - } - - if (fscanf(fp, "%d", &pid) != 1) { + retval = true; + if ((fp = fopen(pidfile, "r"))) { + if (fscanf(fp, "%d", &pid) == 1) + retval = false; + fclose (fp); - retval = true; - break; } - - fclose(fp); free(pidfile); pidfile = NULL; /* We have the pid, so no need to match on name */ - rc_stringlist_free(list); - list = NULL; - free (exec); - exec = NULL; free (name); name = NULL; } else { - if (exec && ! TAILQ_FIRST(list)) { - rc_stringlist_add(list, exec); + if (exec) { + if (! list) + list = rc_stringlist_new(); + if (! TAILQ_FIRST(list)) + rc_stringlist_add(list, exec); + + free(exec); + exec = NULL; } - free(exec); - exec = NULL; - - /* We need to flatten our linked list into an array */ - i = 0; - TAILQ_FOREACH(s, list, entries) - i++; - argv = xmalloc(sizeof(char *) * (i + 1)); - i = 0; - TAILQ_FOREACH(s, list, entries) - argv[i++] = s->value; - argv[i] = '\0'; - } - if ((pids = rc_find_pids((const char *const *)argv, - name, 0, pid)) == NULL) - { - p1 = LIST_FIRST(pids); - while (p1) { - p2 = LIST_NEXT(p1, entries); - free(p1); - p1 = p2; + if (list) { + /* We need to flatten our linked list into an array */ + i = 0; + TAILQ_FOREACH(s, list, entries) + i++; + argv = xmalloc(sizeof(char *) * (i + 1)); + i = 0; + TAILQ_FOREACH(s, list, entries) + argv[i++] = s->value; + argv[i] = '\0'; } - free(pids); - retval = true; } + + if (! retval) { + if ((pids = rc_find_pids((const char *const *)argv, + name, 0, pid))) + { + p1 = LIST_FIRST(pids); + while (p1) { + p2 = LIST_NEXT(p1, entries); + free(p1); + p1 = p2; + } + free(pids); + } else + retval = true; + } + rc_stringlist_free(list); + list = NULL; free(argv); argv = NULL; - rc_stringlist_free(list); + free(exec); + exec = NULL; free(name); name = NULL; if (retval) break; } - - free(dirpath); closedir(dp); return retval; |