diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-02-12 14:25:26 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-02-12 14:25:26 +0200 |
commit | 05f16374d677f7c606d5100df3ca3499b9891aca (patch) | |
tree | efa6177f87df2ba1e9f63edec6cc55cb621c9745 | |
parent | d9d267052215f223897af18310e4adee310308e7 (diff) | |
download | pies-05f16374d677f7c606d5100df3ca3499b9891aca.tar.gz pies-05f16374d677f7c606d5100df3ca3499b9891aca.tar.bz2 |
Improve progman API (progman_foreach and progman_stop_component).
* src/progman.c (progman_foreach): Allow filter to remove its prog
argument from the list. Return integer (result of the call
to filter, that returned non-zero). All uses changed.
(progman_running_count): Remove.
(progman_stop_component): Take a pointer to
pointer. Pass it to destroy_prog when needed. All uses changed.
* src/comp.c (prog_is_leftover): New function.
(cb_terminate_prog): Use prog_is_leftover. Don't raise CF_DISABLED
flag, as prog will have been destroyed by progman_stop_component.
(cb_kill_prog): Use prog_is_leftover.
* src/ctl.c (fun_stop): Check if prog still exists after the
call to progman_stop_component.
* src/pies.h (progman_running_count): Removed.
* src/prog.h (progman_foreach): Return int.
(progman_stop_component): Change signature.
-rw-r--r-- | src/comp.c | 18 | ||||
-rw-r--r-- | src/ctl.c | 5 | ||||
-rw-r--r-- | src/pies.h | 1 | ||||
-rw-r--r-- | src/prog.h | 4 | ||||
-rw-r--r-- | src/progman.c | 37 |
5 files changed, 33 insertions, 32 deletions
@@ -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); @@ -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"); @@ -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); @@ -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); } |