aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/librc/librc-daemon.c99
-rw-r--r--src/rc/rc-status.c2
-rw-r--r--src/rc/rc.c16
-rw-r--r--src/rc/runscript.c148
4 files changed, 133 insertions, 132 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;
diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c
index 9f7167f6..c7173e29 100644
--- a/src/rc/rc-status.c
+++ b/src/rc/rc-status.c
@@ -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();
diff --git a/src/rc/rc.c b/src/rc/rc.c
index 04b814e6..30bedcbf 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -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;
}
- rc_stringlist_sort(&stop_services);
-
+ 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");
- tmplist = rc_deptree_depends(deptree, types_nua, stop_services,
- runlevel, depoptions | RC_DEP_STOP);
- rc_stringlist_free(stop_services);
- stop_services = tmplist;
+ 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);
diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index 704d32fe..08d2c4e8 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -694,14 +694,14 @@ static void svc_start(bool deps)
depoptions |= RC_DEP_STRICT;
if (deps) {
- if (! deptree && ((deptree = _rc_deptree_load (NULL)) == NULL))
+ if (! deptree && ((deptree = _rc_deptree_load(NULL)) == NULL))
eerrorx("failed to load deptree");
if (! types_b)
setup_types();
services = rc_deptree_depends(deptree, types_b, applet_list,
- runlevel, 0);
+ runlevel, 0);
if (services && TAILQ_FIRST(services)) {
eerrorn("ERROR: `%s' needs ", applet);
first = true;
@@ -718,9 +718,9 @@ static void svc_start(bool deps)
services = NULL;
need_services = rc_deptree_depends(deptree, types_n, applet_list,
- runlevel, depoptions);
+ runlevel, depoptions);
use_services = rc_deptree_depends(deptree, types_nu, applet_list,
- runlevel, depoptions);
+ runlevel, depoptions);
if (! rc_runlevel_starting() && use_services)
TAILQ_FOREACH(svc, use_services, entries)
@@ -732,88 +732,90 @@ static void svc_start(bool deps)
/* Now wait for them to start */
services = rc_deptree_depends(deptree, types_nua, applet_list,
- runlevel, depoptions);
+ runlevel, depoptions);
- /* We use tmplist to hold our scheduled by list */
- tmplist = NULL;
- TAILQ_FOREACH(svc, services, entries) {
- RC_SERVICE svcs = rc_service_state(svc->value);
- if (svcs & RC_SERVICE_STARTED)
- continue;
-
- /* Don't wait for services which went inactive but are now in
- * starting state which we are after */
- if (svcs & RC_SERVICE_STARTING &&
- svcs & RC_SERVICE_WASINACTIVE) {
- TAILQ_FOREACH(svc2, use_services, entries) {
- if (strcmp (svc->value, svc2->value) == 0)
- break;
- }
- if (! svc2)
+ if (services) {
+ /* We use tmplist to hold our scheduled by list */
+ tmplist = NULL;
+ TAILQ_FOREACH(svc, services, entries) {
+ RC_SERVICE svcs = rc_service_state(svc->value);
+ if (svcs & RC_SERVICE_STARTED)
continue;
- }
- if (! svc_wait(svc->value))
- eerror ("%s: timed out waiting for %s",
- applet, svc->value);
- if (! need_services)
- continue;
- if ((svcs = rc_service_state(svc->value)) & RC_SERVICE_STARTED)
- continue;
- TAILQ_FOREACH(svc2, need_services, entries) {
- if (strcmp (svc->value, svc2->value) == 0) {
- if (svcs & RC_SERVICE_INACTIVE ||
- svcs & RC_SERVICE_WASINACTIVE)
- {
- if (! tmplist)
- tmplist = rc_stringlist_new();
- rc_stringlist_add(tmplist, svc->value);
- } else
- eerrorx("ERROR: cannot start %s as"
- " %s would not start",
+ /* Don't wait for services which went inactive but are now in
+ * starting state which we are after */
+ if (svcs & RC_SERVICE_STARTING &&
+ svcs & RC_SERVICE_WASINACTIVE) {
+ TAILQ_FOREACH(svc2, use_services, entries) {
+ if (strcmp (svc->value, svc2->value) == 0)
+ break;
+ }
+ if (! svc2)
+ continue;
+ }
+
+ if (! svc_wait(svc->value))
+ eerror ("%s: timed out waiting for %s",
applet, svc->value);
+ if (! need_services)
+ continue;
+ if ((svcs = rc_service_state(svc->value)) & RC_SERVICE_STARTED)
+ continue;
+ TAILQ_FOREACH(svc2, need_services, entries) {
+ if (strcmp (svc->value, svc2->value) == 0) {
+ if (svcs & RC_SERVICE_INACTIVE ||
+ svcs & RC_SERVICE_WASINACTIVE)
+ {
+ if (! tmplist)
+ tmplist = rc_stringlist_new();
+ rc_stringlist_add(tmplist, svc->value);
+ } else
+ eerrorx("ERROR: cannot start %s as"
+ " %s would not start",
+ applet, svc->value);
+ }
}
}
- }
- if (tmplist && TAILQ_FIRST(tmplist)) {
- /* Set the state now, then unlink our exclusive so that
- our scheduled list is preserved */
- rc_service_mark(service, RC_SERVICE_STOPPED);
- unlink_mtime_test();
+ if (tmplist && TAILQ_FIRST(tmplist)) {
+ /* Set the state now, then unlink our exclusive so that
+ our scheduled list is preserved */
+ rc_service_mark(service, RC_SERVICE_STOPPED);
+ unlink_mtime_test();
- rc_stringlist_free(use_services);
- use_services = NULL;
- len = 0;
- n = 0;
- TAILQ_FOREACH(svc, tmplist, entries) {
- rc_service_schedule_start(svc->value, service);
- use_services = rc_deptree_depend(deptree, "iprovide",
- svc->value);
- TAILQ_FOREACH (svc2, use_services, entries)
- rc_service_schedule_start(svc2->value, service);
rc_stringlist_free(use_services);
use_services = NULL;
- len += strlen(svc->value) + 2;
- n++;
- }
+ len = 0;
+ n = 0;
+ TAILQ_FOREACH(svc, tmplist, entries) {
+ rc_service_schedule_start(svc->value, service);
+ use_services = rc_deptree_depend(deptree, "iprovide",
+ svc->value);
+ TAILQ_FOREACH (svc2, use_services, entries)
+ rc_service_schedule_start(svc2->value, service);
+ rc_stringlist_free(use_services);
+ use_services = NULL;
+ len += strlen(svc->value) + 2;
+ n++;
+ }
- len += 5;
- tmp = p = xmalloc(sizeof(char) * len);
- TAILQ_FOREACH(svc, tmplist, entries) {
- if (p != tmp)
- p += snprintf(p, len, ", ");
- p += snprintf(p, len, "%s", svc->value);
+ len += 5;
+ tmp = p = xmalloc(sizeof(char) * len);
+ TAILQ_FOREACH(svc, tmplist, entries) {
+ if (p != tmp)
+ p += snprintf(p, len, ", ");
+ p += snprintf(p, len, "%s", svc->value);
+ }
+ free(tmp);
+ rc_stringlist_free(tmplist);
+ tmplist = NULL;
+ ewarnx("WARNING: %s is scheduled to start when %s has started",
+ applet, tmp);
}
- free(tmp);
- rc_stringlist_free(tmplist);
- tmplist = NULL;
- ewarnx("WARNING: %s is scheduled to start when %s has started",
- applet, tmp);
- }
- rc_stringlist_free(services);
- services = NULL;
+ rc_stringlist_free(services);
+ services = NULL;
+ }
}
if (ibsave)