aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)
350 component_free (list->head); 350 component_free (list->head);
351 cur = prev_index (); 351 cur = prev_index ();
352} 352}
353
354/* Return true if PROG is a leftover from previous configuration */
355static int
356prog_is_leftover (struct prog *prog)
357{
358 return IS_COMPONENT (prog) && !component_is_active (prog->v.p.comp);
359}
353 360
361/* If PROG is a leftover, gracefully stop it and mark as disabled */
354static int 362static int
355cb_terminate_prog (struct prog *prog, void *data) 363cb_terminate_prog (struct prog *prog, void *data)
356{ 364{
357 if (IS_COMPONENT (prog) && !component_is_active (prog->v.p.comp)) 365 if (prog_is_leftover (prog))
358 { 366 progman_stop_component (&prog);
359 progman_stop_component (prog);
360 prog->v.p.comp->flags |= CF_DISABLED;
361 }
362 return 0; 367 return 0;
363} 368}
364 369
370/* If PROG is a leftover, slay it with SIGKILL */
365static int 371static int
366cb_kill_prog (struct prog *prog, void *data) 372cb_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}
@@ -509,7 +515,7 @@ component_config_commit (void)
509 progman_wait_until (list_is_empty, list); 515 progman_wait_until (list_is_empty, list);
510 } 516 }
511 } 517 }
512 518
513 /* Build dependency map */ 519 /* Build dependency map */
514 component_build_depmap (); 520 component_build_depmap ();
515 521
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)
1866 } 1866 }
1867 else 1867 else
1868 { 1868 {
1869 progman_stop_component (prog); 1869 progman_stop_component (&prog);
1870 prog->v.p.comp->flags |= CF_DISABLED; 1870 if (prog)
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 }
1873 return 0; 1874 return 0;
@@ -1903,7 +1904,7 @@ fun_start (struct json_value *result, struct prog *prog)
1903static int 1904static int
1904fun_restart (struct json_value *result, struct prog *prog) 1905fun_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}
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);
318 318
319void register_prog (struct component *comp); 319void register_prog (struct component *comp);
320int progman_waiting_p (void); 320int progman_waiting_p (void);
321size_t progman_running_count (void);
322void progman_start (void); 321void progman_start (void);
323void progman_wake_sleeping (int); 322void progman_wake_sleeping (int);
324void progman_stop (void); 323void 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
84#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT) 84#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT)
85 85
86struct prog *progman_locate (const char *name); 86struct prog *progman_locate (const char *name);
87void progman_foreach (int (*filter) (struct prog *, void *data), void *data); 87int progman_foreach (int (*filter) (struct prog *, void *data), void *data);
88void prog_stop (struct prog *prog, int sig); 88void prog_stop (struct prog *prog, int sig);
89void progman_stop_component (struct prog *prog); 89void progman_stop_component (struct prog **prog);
90 90
91char const *prog_tag (struct prog const *prog); 91char 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
35void 35int
36progman_foreach (int (*filter) (struct prog *, void *data), void *data) 36progman_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 break; 41 {
42 struct prog *next = prog->next;
43 if ((rc = filter (prog, data)) != 0)
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
315size_t
316progman_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
327RETSIGTYPE 321RETSIGTYPE
328redir_exit (int sig) 322redir_exit (int sig)
329{ 323{
@@ -1742,7 +1736,7 @@ progman_wait_until (int (*cond) (void *), void *data)
1742static int 1736static int
1743no_children_left (void *p) 1737no_children_left (void *p)
1744{ 1738{
1745 return progman_running_count () == 0; 1739 return proghead == NULL;
1746} 1740}
1747 1741
1748void 1742void
@@ -2357,8 +2351,9 @@ progman_cleanup (int expect_term)
2357} 2351}
2358 2352
2359void 2353void
2360progman_stop_component (struct prog *prog) 2354progman_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
2404progman_stop_tag (const char *name) 2399progman_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 */

Return to:

Send suggestions and report system problems to the System administrator.