summaryrefslogtreecommitdiffabout
path: root/src
Side-by-side diff
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/comp.c20
-rw-r--r--src/ctl.c7
-rw-r--r--src/pies.h1
-rw-r--r--src/prog.h4
-rw-r--r--src/progman.c39
5 files changed, 36 insertions, 35 deletions
diff --git a/src/comp.c b/src/comp.c
index 5613e28..6a0e4ba 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -350,22 +350,28 @@ component_config_rollback (void)
component_free (list->head);
cur = prev_index ();
}
+
+/* Return true if PROG is a leftover from previous configuration */
+static int
+prog_is_leftover (struct prog *prog)
+{
+ 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 (IS_COMPONENT (prog) && !component_is_active (prog->v.p.comp))
- {
- progman_stop_component (prog);
- prog->v.p.comp->flags |= CF_DISABLED;
- }
+ if (prog_is_leftover (prog))
+ progman_stop_component (&prog);
return 0;
}
+/* If PROG is a leftover, slay it with SIGKILL */
static int
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);
return 0;
}
@@ -509,7 +515,7 @@ component_config_commit (void)
progman_wait_until (list_is_empty, list);
}
}
-
+
/* Build dependency map */
component_build_depmap ();
diff --git a/src/ctl.c b/src/ctl.c
index 489fc7f..bc2f78d 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1866,8 +1866,9 @@ fun_stop (struct json_value *result, struct prog *prog)
}
else
{
- progman_stop_component (prog);
- prog->v.p.comp->flags |= CF_DISABLED;
+ progman_stop_component (&prog);
+ if (prog)
+ prog->v.p.comp->flags |= CF_DISABLED;
json_object_set_string (result, "status", "OK");
}
return 0;
@@ -1903,7 +1904,7 @@ fun_start (struct json_value *result, struct prog *prog)
static int
fun_restart (struct json_value *result, struct prog *prog)
{
- progman_stop_component (prog);
+ progman_stop_component (&prog);
json_object_set_string (result, "status", "OK");
return 0;
}
diff --git a/src/pies.h b/src/pies.h
index 39977c7..1b77398 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -318,7 +318,6 @@ void free_action (struct action *act);
void register_prog (struct component *comp);
int progman_waiting_p (void);
-size_t progman_running_count (void);
void progman_start (void);
void progman_wake_sleeping (int);
void progman_stop (void);
diff --git a/src/prog.h b/src/prog.h
index fe42d3a..2dc8591 100644
--- a/src/prog.h
+++ b/src/prog.h
@@ -84,8 +84,8 @@ struct prog
#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT)
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);
char const *prog_tag (struct prog const *prog);
diff --git a/src/progman.c b/src/progman.c
index 020dccd..2c73b2b 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -32,13 +32,19 @@ progman_locate (const char *name)
return prog;
}
-void
+int
progman_foreach (int (*filter) (struct prog *, void *data), void *data)
{
struct prog *prog;
- for (prog = proghead; prog; prog = prog->next)
- if (filter (prog, data))
- break;
+ int rc = 0;
+ for (prog = proghead; prog; )
+ {
+ struct prog *next = prog->next;
+ if ((rc = filter (prog, data)) != 0)
+ break;
+ prog = next;
+ }
+ return rc;
}
/* FIXME: Rewrite this using progman_foreach? */
@@ -312,18 +318,6 @@ progman_waiting_p ()
return 0;
}
-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
redir_exit (int sig)
{
@@ -1742,7 +1736,7 @@ progman_wait_until (int (*cond) (void *), void *data)
static int
no_children_left (void *p)
{
- return progman_running_count () == 0;
+ return proghead == NULL;
}
void
@@ -2357,8 +2351,9 @@ 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))
{
switch (prog->v.p.status)
@@ -2371,7 +2366,7 @@ progman_stop_component (struct prog *prog)
case status_disabled:
if (!component_is_active (prog->v.p.comp))
- destroy_prog (&prog);
+ destroy_prog (progptr);
else if (!(prog->v.p.comp->flags & CF_DISABLED))
{
logmsg (LOG_INFO, _("enabling component `%s'"), prog_tag (prog));
@@ -2381,7 +2376,7 @@ progman_stop_component (struct prog *prog)
case status_sleeping:
if (!component_is_active (prog->v.p.comp))
- destroy_prog (&prog);
+ destroy_prog (progptr);
else
{
logmsg (LOG_INFO, _("waking up component `%s'"), prog_tag (prog));
@@ -2391,7 +2386,7 @@ progman_stop_component (struct prog *prog)
default:
if (!component_is_active (prog->v.p.comp))
- destroy_prog (&prog);
+ destroy_prog (progptr);
else
logmsg (LOG_INFO,
_("stopping component `%s': component not started"),
@@ -2404,6 +2399,6 @@ void
progman_stop_tag (const char *name)
{
struct prog *prog = progman_locate (name);
- progman_stop_component (prog);
+ progman_stop_component (&prog);
}
/* EOF */

Return to:

Send suggestions and report system problems to the System administrator.