aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/comp.c18
-rw-r--r--src/ctl.c5
-rw-r--r--src/pies.h1
-rw-r--r--src/prog.h4
-rw-r--r--src/progman.c37
5 files changed, 33 insertions, 32 deletions
diff --git a/src/comp.c b/src/comp.c
index 5613e28..6a0e4ba 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -353,10 +353,15 @@ component_config_rollback (void)
+/* Return true if PROG is a leftover from previous configuration */
static int
-cb_terminate_prog (struct prog *prog, void *data)
-{
- if (IS_COMPONENT (prog) && !component_is_active (prog->v.p.comp))
+prog_is_leftover (struct prog *prog)
{
- progman_stop_component (prog);
- prog->v.p.comp->flags |= CF_DISABLED;
+ return IS_COMPONENT (prog) && !component_is_active (prog->v.p.comp);
}
+
+/* If PROG is a leftover, gracefully stop it and mark as disabled */
+static int
+cb_terminate_prog (struct prog *prog, void *data)
+{
+ if (prog_is_leftover (prog))
+ progman_stop_component (&prog);
return 0;
@@ -364,2 +369,3 @@ cb_terminate_prog (struct prog *prog, void *data)
+/* If PROG is a leftover, slay it with SIGKILL */
static int
@@ -367,3 +373,3 @@ cb_kill_prog (struct prog *prog, void *data)
{
- if (!(IS_COMPONENT (prog) && component_is_active (prog->v.p.comp)))
+ if (prog_is_leftover (prog))
prog_stop (prog, SIGKILL);
diff --git a/src/ctl.c b/src/ctl.c
index 489fc7f..bc2f78d 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1868,3 +1868,4 @@ fun_stop (struct json_value *result, struct prog *prog)
{
- progman_stop_component (prog);
+ progman_stop_component (&prog);
+ if (prog)
prog->v.p.comp->flags |= CF_DISABLED;
@@ -1905,3 +1906,3 @@ fun_restart (struct json_value *result, struct prog *prog)
{
- progman_stop_component (prog);
+ progman_stop_component (&prog);
json_object_set_string (result, "status", "OK");
diff --git a/src/pies.h b/src/pies.h
index 39977c7..1b77398 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -320,3 +320,2 @@ void register_prog (struct component *comp);
int progman_waiting_p (void);
-size_t progman_running_count (void);
void progman_start (void);
diff --git a/src/prog.h b/src/prog.h
index fe42d3a..2dc8591 100644
--- a/src/prog.h
+++ b/src/prog.h
@@ -86,5 +86,5 @@ struct prog
struct prog *progman_locate (const char *name);
-void progman_foreach (int (*filter) (struct prog *, void *data), void *data);
+int progman_foreach (int (*filter) (struct prog *, void *data), void *data);
void prog_stop (struct prog *prog, int sig);
-void progman_stop_component (struct prog *prog);
+void progman_stop_component (struct prog **prog);
diff --git a/src/progman.c b/src/progman.c
index 020dccd..2c73b2b 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -34,3 +34,3 @@ progman_locate (const char *name)
-void
+int
progman_foreach (int (*filter) (struct prog *, void *data), void *data)
@@ -38,5 +38,11 @@ progman_foreach (int (*filter) (struct prog *, void *data), void *data)
struct prog *prog;
- for (prog = proghead; prog; prog = prog->next)
- if (filter (prog, data))
+ int rc = 0;
+ for (prog = proghead; prog; )
+ {
+ struct prog *next = prog->next;
+ if ((rc = filter (prog, data)) != 0)
break;
+ prog = next;
+ }
+ return rc;
}
@@ -314,14 +320,2 @@ progman_waiting_p ()
-size_t
-progman_running_count ()
-{
- size_t size = 0;
- struct prog *prog;
-
- for (prog = proghead; prog; prog = prog->next)
- if (prog->pid > 0)
- size++;
- return size;
-}
-
RETSIGTYPE
@@ -1744,3 +1738,3 @@ no_children_left (void *p)
{
- return progman_running_count () == 0;
+ return proghead == NULL;
}
@@ -2359,4 +2353,5 @@ progman_cleanup (int expect_term)
void
-progman_stop_component (struct prog *prog)
+progman_stop_component (struct prog **progptr)
{
+ struct prog *prog = *progptr;
if (prog && IS_COMPONENT (prog))
@@ -2373,3 +2368,3 @@ progman_stop_component (struct prog *prog)
if (!component_is_active (prog->v.p.comp))
- destroy_prog (&prog);
+ destroy_prog (progptr);
else if (!(prog->v.p.comp->flags & CF_DISABLED))
@@ -2383,3 +2378,3 @@ progman_stop_component (struct prog *prog)
if (!component_is_active (prog->v.p.comp))
- destroy_prog (&prog);
+ destroy_prog (progptr);
else
@@ -2393,3 +2388,3 @@ progman_stop_component (struct prog *prog)
if (!component_is_active (prog->v.p.comp))
- destroy_prog (&prog);
+ destroy_prog (progptr);
else
@@ -2406,3 +2401,3 @@ progman_stop_tag (const char *name)
struct prog *prog = progman_locate (name);
- progman_stop_component (prog);
+ progman_stop_component (&prog);
}

Return to:

Send suggestions and report system problems to the System administrator.