We should check for NULL here.

This commit is contained in:
Roy Marples 2008-03-17 14:31:44 +00:00
parent 4c14666423
commit b2f7606b23
4 changed files with 133 additions and 132 deletions

View File

@ -506,7 +506,7 @@ bool rc_service_daemons_crashed(const char *service)
char *p; char *p;
char *token; char *token;
bool retval = false; bool retval = false;
RC_STRINGLIST *list; RC_STRINGLIST *list = NULL;
RC_STRING *s; RC_STRING *s;
size_t i; size_t i;
@ -526,8 +526,6 @@ bool rc_service_daemons_crashed(const char *service)
if (! fp) if (! fp)
break; break;
list = rc_stringlist_new();
while ((line = rc_getline(fp))) { while ((line = rc_getline(fp))) {
p = line; p = line;
if ((token = strsep(&p, "=")) == NULL || ! p) { 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 (strncmp(token, "argv_", 5) == 0) {
if (! list)
list = rc_stringlist_new();
rc_stringlist_add(list, p); rc_stringlist_add(list, p);
} else if (strcmp(token, "exec") == 0) { } else if (strcmp(token, "exec") == 0) {
if (exec) if (exec)
@ -551,9 +551,9 @@ bool rc_service_daemons_crashed(const char *service)
free(name); free(name);
name = xstrdup(p); name = xstrdup(p);
} else if (strcmp(token, "pidfile") == 0) { } else if (strcmp(token, "pidfile") == 0) {
if (pidfile)
free(pidfile);
pidfile = xstrdup(p); pidfile = xstrdup(p);
free(line);
break;
} }
free(line); free(line);
} }
@ -561,40 +561,31 @@ bool rc_service_daemons_crashed(const char *service)
pid = 0; pid = 0;
if (pidfile) { if (pidfile) {
if (! exists(pidfile)) {
retval = true; retval = true;
break; if ((fp = fopen(pidfile, "r"))) {
} if (fscanf(fp, "%d", &pid) == 1)
retval = false;
if ((fp = fopen(pidfile, "r")) == NULL) {
retval = true;
break;
}
if (fscanf(fp, "%d", &pid) != 1) {
fclose (fp); fclose (fp);
retval = true;
break;
} }
fclose(fp);
free(pidfile); free(pidfile);
pidfile = NULL; pidfile = NULL;
/* We have the pid, so no need to match on name */ /* We have the pid, so no need to match on name */
rc_stringlist_free(list);
list = NULL;
free (exec);
exec = NULL;
free (name); free (name);
name = NULL; name = NULL;
} else { } else {
if (exec && ! TAILQ_FIRST(list)) { if (exec) {
if (! list)
list = rc_stringlist_new();
if (! TAILQ_FIRST(list))
rc_stringlist_add(list, exec); rc_stringlist_add(list, exec);
}
free(exec); free(exec);
exec = NULL; exec = NULL;
}
if (list) {
/* We need to flatten our linked list into an array */ /* We need to flatten our linked list into an array */
i = 0; i = 0;
TAILQ_FOREACH(s, list, entries) TAILQ_FOREACH(s, list, entries)
@ -605,9 +596,11 @@ bool rc_service_daemons_crashed(const char *service)
argv[i++] = s->value; argv[i++] = s->value;
argv[i] = '\0'; argv[i] = '\0';
} }
}
if (! retval) {
if ((pids = rc_find_pids((const char *const *)argv, if ((pids = rc_find_pids((const char *const *)argv,
name, 0, pid)) == NULL) name, 0, pid)))
{ {
p1 = LIST_FIRST(pids); p1 = LIST_FIRST(pids);
while (p1) { while (p1) {
@ -616,18 +609,20 @@ bool rc_service_daemons_crashed(const char *service)
p1 = p2; p1 = p2;
} }
free(pids); free(pids);
} else
retval = true; retval = true;
} }
rc_stringlist_free(list);
list = NULL;
free(argv); free(argv);
argv = NULL; argv = NULL;
rc_stringlist_free(list); free(exec);
exec = NULL;
free(name); free(name);
name = NULL; name = NULL;
if (retval) if (retval)
break; break;
} }
free(dirpath);
closedir(dp); closedir(dp);
return retval; return retval;

View File

@ -185,6 +185,8 @@ int rc_status (int argc, char **argv)
TAILQ_FOREACH(l, levels, entries) { TAILQ_FOREACH(l, levels, entries) {
print_level(l->value); print_level(l->value);
services = rc_services_in_runlevel(l->value); services = rc_services_in_runlevel(l->value);
if (! services)
continue;
if (deptree) { if (deptree) {
if (! types) { if (! types) {
types = rc_stringlist_new(); types = rc_stringlist_new();

View File

@ -778,7 +778,7 @@ static void do_stop_services(const char *newlevel, bool going_down, bool paralle
continue; continue;
/* We always stop the service when in these runlevels */ /* We always stop the service when in these runlevels */
if (going_down) { if (going_down || ! start_services) {
pid = rc_service_stop(service->value); pid = rc_service_stop(service->value);
if (pid > 0 && ! parallel) if (pid > 0 && ! parallel)
rc_waitpid(pid); rc_waitpid(pid);
@ -1097,18 +1097,20 @@ int main(int argc, char **argv)
} else } else
stop_services = tmplist; stop_services = tmplist;
} }
if (stop_services)
rc_stringlist_sort(&stop_services); rc_stringlist_sort(&stop_services);
types_nua = rc_stringlist_new(); types_nua = rc_stringlist_new();
rc_stringlist_add(types_nua, "ineed"); rc_stringlist_add(types_nua, "ineed");
rc_stringlist_add(types_nua, "iuse"); rc_stringlist_add(types_nua, "iuse");
rc_stringlist_add(types_nua, "iafter"); rc_stringlist_add(types_nua, "iafter");
if (stop_services) {
tmplist = rc_deptree_depends(deptree, types_nua, stop_services, tmplist = rc_deptree_depends(deptree, types_nua, stop_services,
runlevel, depoptions | RC_DEP_STOP); runlevel, depoptions | RC_DEP_STOP);
rc_stringlist_free(stop_services); rc_stringlist_free(stop_services);
stop_services = tmplist; stop_services = tmplist;
}
/* Load our list of coldplugged services */ /* Load our list of coldplugged services */
coldplugged_services = rc_services_in_state(RC_SERVICE_COLDPLUGGED); coldplugged_services = rc_services_in_state(RC_SERVICE_COLDPLUGGED);

View File

@ -694,7 +694,7 @@ static void svc_start(bool deps)
depoptions |= RC_DEP_STRICT; depoptions |= RC_DEP_STRICT;
if (deps) { if (deps) {
if (! deptree && ((deptree = _rc_deptree_load (NULL)) == NULL)) if (! deptree && ((deptree = _rc_deptree_load(NULL)) == NULL))
eerrorx("failed to load deptree"); eerrorx("failed to load deptree");
if (! types_b) if (! types_b)
@ -734,6 +734,7 @@ static void svc_start(bool deps)
services = rc_deptree_depends(deptree, types_nua, applet_list, services = rc_deptree_depends(deptree, types_nua, applet_list,
runlevel, depoptions); runlevel, depoptions);
if (services) {
/* We use tmplist to hold our scheduled by list */ /* We use tmplist to hold our scheduled by list */
tmplist = NULL; tmplist = NULL;
TAILQ_FOREACH(svc, services, entries) { TAILQ_FOREACH(svc, services, entries) {
@ -815,6 +816,7 @@ static void svc_start(bool deps)
rc_stringlist_free(services); rc_stringlist_free(services);
services = NULL; services = NULL;
} }
}
if (ibsave) if (ibsave)
setenv("IN_BACKGROUND", ibsave, 1); setenv("IN_BACKGROUND", ibsave, 1);