We should check for NULL here.
This commit is contained in:
parent
4c14666423
commit
b2f7606b23
@ -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,40 +561,31 @@ 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) {
|
||||
fclose (fp);
|
||||
retval = true;
|
||||
break;
|
||||
}
|
||||
if ((fp = fopen(pidfile, "r"))) {
|
||||
if (fscanf(fp, "%d", &pid) == 1)
|
||||
retval = false;
|
||||
|
||||
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)) {
|
||||
if (exec) {
|
||||
if (! list)
|
||||
list = rc_stringlist_new();
|
||||
if (! TAILQ_FIRST(list))
|
||||
rc_stringlist_add(list, exec);
|
||||
}
|
||||
|
||||
free(exec);
|
||||
exec = NULL;
|
||||
}
|
||||
|
||||
if (list) {
|
||||
/* We need to flatten our linked list into an array */
|
||||
i = 0;
|
||||
TAILQ_FOREACH(s, list, entries)
|
||||
@ -605,9 +596,11 @@ bool rc_service_daemons_crashed(const char *service)
|
||||
argv[i++] = s->value;
|
||||
argv[i] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (! retval) {
|
||||
if ((pids = rc_find_pids((const char *const *)argv,
|
||||
name, 0, pid)) == NULL)
|
||||
name, 0, pid)))
|
||||
{
|
||||
p1 = LIST_FIRST(pids);
|
||||
while (p1) {
|
||||
@ -616,18 +609,20 @@ bool rc_service_daemons_crashed(const char *service)
|
||||
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;
|
||||
|
@ -185,6 +185,8 @@ int rc_status (int argc, char **argv)
|
||||
TAILQ_FOREACH(l, levels, entries) {
|
||||
print_level(l->value);
|
||||
services = rc_services_in_runlevel(l->value);
|
||||
if (! services)
|
||||
continue;
|
||||
if (deptree) {
|
||||
if (! types) {
|
||||
types = rc_stringlist_new();
|
||||
|
@ -778,7 +778,7 @@ static void do_stop_services(const char *newlevel, bool going_down, bool paralle
|
||||
continue;
|
||||
|
||||
/* We always stop the service when in these runlevels */
|
||||
if (going_down) {
|
||||
if (going_down || ! start_services) {
|
||||
pid = rc_service_stop(service->value);
|
||||
if (pid > 0 && ! parallel)
|
||||
rc_waitpid(pid);
|
||||
@ -1097,18 +1097,20 @@ int main(int argc, char **argv)
|
||||
} else
|
||||
stop_services = tmplist;
|
||||
}
|
||||
if (stop_services)
|
||||
rc_stringlist_sort(&stop_services);
|
||||
|
||||
|
||||
types_nua = rc_stringlist_new();
|
||||
rc_stringlist_add(types_nua, "ineed");
|
||||
rc_stringlist_add(types_nua, "iuse");
|
||||
rc_stringlist_add(types_nua, "iafter");
|
||||
|
||||
if (stop_services) {
|
||||
tmplist = rc_deptree_depends(deptree, types_nua, stop_services,
|
||||
runlevel, depoptions | RC_DEP_STOP);
|
||||
rc_stringlist_free(stop_services);
|
||||
stop_services = tmplist;
|
||||
}
|
||||
|
||||
/* Load our list of coldplugged services */
|
||||
coldplugged_services = rc_services_in_state(RC_SERVICE_COLDPLUGGED);
|
||||
|
@ -734,6 +734,7 @@ static void svc_start(bool deps)
|
||||
services = rc_deptree_depends(deptree, types_nua, applet_list,
|
||||
runlevel, depoptions);
|
||||
|
||||
if (services) {
|
||||
/* We use tmplist to hold our scheduled by list */
|
||||
tmplist = NULL;
|
||||
TAILQ_FOREACH(svc, services, entries) {
|
||||
@ -815,6 +816,7 @@ static void svc_start(bool deps)
|
||||
rc_stringlist_free(services);
|
||||
services = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ibsave)
|
||||
setenv("IN_BACKGROUND", ibsave, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user