diff options
-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
@@ -351,21 +351,27 @@ component_config_rollback (void) | |||
351 | cur = prev_index (); | 351 | cur = prev_index (); |
352 | } | 352 | } |
353 | 353 | ||
354 | /* Return true if PROG is a leftover from previous configuration */ | ||
354 | static int | 355 | static int |
355 | cb_terminate_prog (struct prog *prog, void *data) | 356 | prog_is_leftover (struct prog *prog) |
356 | { | ||
357 | if (IS_COMPONENT (prog) && !component_is_active (prog->v.p.comp)) | ||
358 | { | 357 | { |
359 | progman_stop_component (prog); | 358 | return IS_COMPONENT (prog) && !component_is_active (prog->v.p.comp); |
360 | prog->v.p.comp->flags |= CF_DISABLED; | ||
361 | } | 359 | } |
360 | |||
361 | /* If PROG is a leftover, gracefully stop it and mark as disabled */ | ||
362 | static int | ||
363 | cb_terminate_prog (struct prog *prog, void *data) | ||
364 | { | ||
365 | if (prog_is_leftover (prog)) | ||
366 | progman_stop_component (&prog); | ||
362 | return 0; | 367 | return 0; |
363 | } | 368 | } |
364 | 369 | ||
370 | /* If PROG is a leftover, slay it with SIGKILL */ | ||
365 | static int | 371 | static int |
366 | cb_kill_prog (struct prog *prog, void *data) | 372 | cb_kill_prog (struct prog *prog, void *data) |
367 | { | 373 | { |
368 | if (!(IS_COMPONENT (prog) && component_is_active (prog->v.p.comp))) | 374 | if (prog_is_leftover (prog)) |
369 | prog_stop (prog, SIGKILL); | 375 | prog_stop (prog, SIGKILL); |
370 | return 0; | 376 | return 0; |
371 | } | 377 | } |
@@ -1866,7 +1866,8 @@ fun_stop (struct json_value *result, struct prog *prog) | |||
1866 | } | 1866 | } |
1867 | else | 1867 | else |
1868 | { | 1868 | { |
1869 | progman_stop_component (prog); | 1869 | progman_stop_component (&prog); |
1870 | if (prog) | ||
1870 | prog->v.p.comp->flags |= CF_DISABLED; | 1871 | prog->v.p.comp->flags |= CF_DISABLED; |
1871 | json_object_set_string (result, "status", "OK"); | 1872 | json_object_set_string (result, "status", "OK"); |
1872 | } | 1873 | } |
@@ -1903,7 +1904,7 @@ fun_start (struct json_value *result, struct prog *prog) | |||
1903 | static int | 1904 | static int |
1904 | fun_restart (struct json_value *result, struct prog *prog) | 1905 | fun_restart (struct json_value *result, struct prog *prog) |
1905 | { | 1906 | { |
1906 | progman_stop_component (prog); | 1907 | progman_stop_component (&prog); |
1907 | json_object_set_string (result, "status", "OK"); | 1908 | json_object_set_string (result, "status", "OK"); |
1908 | return 0; | 1909 | return 0; |
1909 | } | 1910 | } |
@@ -318,7 +318,6 @@ void free_action (struct action *act); | |||
318 | 318 | ||
319 | void register_prog (struct component *comp); | 319 | void register_prog (struct component *comp); |
320 | int progman_waiting_p (void); | 320 | int progman_waiting_p (void); |
321 | size_t progman_running_count (void); | ||
322 | void progman_start (void); | 321 | void progman_start (void); |
323 | void progman_wake_sleeping (int); | 322 | void progman_wake_sleeping (int); |
324 | void progman_stop (void); | 323 | void progman_stop (void); |
@@ -84,8 +84,8 @@ struct prog | |||
84 | #define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT) | 84 | #define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT) |
85 | 85 | ||
86 | struct prog *progman_locate (const char *name); | 86 | struct prog *progman_locate (const char *name); |
87 | void progman_foreach (int (*filter) (struct prog *, void *data), void *data); | 87 | int progman_foreach (int (*filter) (struct prog *, void *data), void *data); |
88 | void prog_stop (struct prog *prog, int sig); | 88 | void prog_stop (struct prog *prog, int sig); |
89 | void progman_stop_component (struct prog *prog); | 89 | void progman_stop_component (struct prog **prog); |
90 | 90 | ||
91 | char const *prog_tag (struct prog const *prog); | 91 | 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) | |||
32 | return prog; | 32 | return prog; |
33 | } | 33 | } |
34 | 34 | ||
35 | void | 35 | int |
36 | progman_foreach (int (*filter) (struct prog *, void *data), void *data) | 36 | progman_foreach (int (*filter) (struct prog *, void *data), void *data) |
37 | { | 37 | { |
38 | struct prog *prog; | 38 | struct prog *prog; |
39 | for (prog = proghead; prog; prog = prog->next) | 39 | int rc = 0; |
40 | if (filter (prog, data)) | 40 | for (prog = proghead; prog; ) |
41 | { | ||
42 | struct prog *next = prog->next; | ||
43 | if ((rc = filter (prog, data)) != 0) | ||
41 | break; | 44 | break; |
45 | prog = next; | ||
46 | } | ||
47 | return rc; | ||
42 | } | 48 | } |
43 | 49 | ||
44 | /* FIXME: Rewrite this using progman_foreach? */ | 50 | /* FIXME: Rewrite this using progman_foreach? */ |
@@ -312,18 +318,6 @@ progman_waiting_p () | |||
312 | return 0; | 318 | return 0; |
313 | } | 319 | } |
314 | 320 | ||
315 | size_t | ||
316 | progman_running_count () | ||
317 | { | ||
318 | size_t size = 0; | ||
319 | struct prog *prog; | ||
320 | |||
321 | for (prog = proghead; prog; prog = prog->next) | ||
322 | if (prog->pid > 0) | ||
323 | size++; | ||
324 | return size; | ||
325 | } | ||
326 | |||
327 | RETSIGTYPE | 321 | RETSIGTYPE |
328 | redir_exit (int sig) | 322 | redir_exit (int sig) |
329 | { | 323 | { |
@@ -1742,7 +1736,7 @@ progman_wait_until (int (*cond) (void *), void *data) | |||
1742 | static int | 1736 | static int |
1743 | no_children_left (void *p) | 1737 | no_children_left (void *p) |
1744 | { | 1738 | { |
1745 | return progman_running_count () == 0; | 1739 | return proghead == NULL; |
1746 | } | 1740 | } |
1747 | 1741 | ||
1748 | void | 1742 | void |
@@ -2357,8 +2351,9 @@ progman_cleanup (int expect_term) | |||
2357 | } | 2351 | } |
2358 | 2352 | ||
2359 | void | 2353 | void |
2360 | progman_stop_component (struct prog *prog) | 2354 | progman_stop_component (struct prog **progptr) |
2361 | { | 2355 | { |
2356 | struct prog *prog = *progptr; | ||
2362 | if (prog && IS_COMPONENT (prog)) | 2357 | if (prog && IS_COMPONENT (prog)) |
2363 | { | 2358 | { |
2364 | switch (prog->v.p.status) | 2359 | switch (prog->v.p.status) |
@@ -2371,7 +2366,7 @@ progman_stop_component (struct prog *prog) | |||
2371 | 2366 | ||
2372 | case status_disabled: | 2367 | case status_disabled: |
2373 | if (!component_is_active (prog->v.p.comp)) | 2368 | if (!component_is_active (prog->v.p.comp)) |
2374 | destroy_prog (&prog); | 2369 | destroy_prog (progptr); |
2375 | else if (!(prog->v.p.comp->flags & CF_DISABLED)) | 2370 | else if (!(prog->v.p.comp->flags & CF_DISABLED)) |
2376 | { | 2371 | { |
2377 | logmsg (LOG_INFO, _("enabling component `%s'"), prog_tag (prog)); | 2372 | logmsg (LOG_INFO, _("enabling component `%s'"), prog_tag (prog)); |
@@ -2381,7 +2376,7 @@ progman_stop_component (struct prog *prog) | |||
2381 | 2376 | ||
2382 | case status_sleeping: | 2377 | case status_sleeping: |
2383 | if (!component_is_active (prog->v.p.comp)) | 2378 | if (!component_is_active (prog->v.p.comp)) |
2384 | destroy_prog (&prog); | 2379 | destroy_prog (progptr); |
2385 | else | 2380 | else |
2386 | { | 2381 | { |
2387 | logmsg (LOG_INFO, _("waking up component `%s'"), prog_tag (prog)); | 2382 | logmsg (LOG_INFO, _("waking up component `%s'"), prog_tag (prog)); |
@@ -2391,7 +2386,7 @@ progman_stop_component (struct prog *prog) | |||
2391 | 2386 | ||
2392 | default: | 2387 | default: |
2393 | if (!component_is_active (prog->v.p.comp)) | 2388 | if (!component_is_active (prog->v.p.comp)) |
2394 | destroy_prog (&prog); | 2389 | destroy_prog (progptr); |
2395 | else | 2390 | else |
2396 | logmsg (LOG_INFO, | 2391 | logmsg (LOG_INFO, |
2397 | _("stopping component `%s': component not started"), | 2392 | _("stopping component `%s': component not started"), |
@@ -2404,6 +2399,6 @@ void | |||
2404 | progman_stop_tag (const char *name) | 2399 | progman_stop_tag (const char *name) |
2405 | { | 2400 | { |
2406 | struct prog *prog = progman_locate (name); | 2401 | struct prog *prog = progman_locate (name); |
2407 | progman_stop_component (prog); | 2402 | progman_stop_component (&prog); |
2408 | } | 2403 | } |
2409 | /* EOF */ | 2404 | /* EOF */ |