Skip to content

Commit

Permalink
shutdown: use cond_clear_noupdate() to prevent nested service_stop()
Browse files Browse the repository at this point in the history
When the system shuts down, or user changes runlevels, we don't have to
call cond_clear_update(), because this can lead to nested service_stop()
calls, which in turn lead to out of sync progress updates:

[ .. ] Stopping Foo
[ OK ] Stopping Bar
[ OK ]

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Feb 3, 2024
1 parent 248f7d3 commit c221823
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/cond-w.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "cond.h"
#include "pid.h"
#include "service.h"
#include "sm.h"

struct cond_boot {
TAILQ_ENTRY(cond_boot) link;
Expand Down Expand Up @@ -214,7 +215,10 @@ static int do_delete(const char *fpath, const struct stat *sb, int tflag, struct
err(1, "Failed removing condition %s", fpath);

cond = ptr + strlen(COND_BASE) + 1;
cond_update(cond);
if (sm_is_in_teardown(&sm))
cond_clear_noupdate(cond);
else
cond_update(cond);

return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,7 @@ static void svc_set_state(svc_t *svc, svc_state_t new_state)
/* if PID isn't collected within SVC_TERM_TIMEOUT msec, kill it! */
if (new_state == SVC_STOPPING_STATE) {
dbg("%s is stopping, wait %d sec before sending SIGKILL ...",
svc_ident(svc, NULL, 0), svc->killdelay / 1000);
svc_ident(svc, NULL, 0), svc->killdelay / 1000);
service_timeout_cancel(svc);
service_timeout_after(svc, svc->killdelay, service_kill);
}
Expand Down Expand Up @@ -2299,6 +2299,8 @@ static void svc_set_state(svc_t *svc, svc_state_t new_state)
if ((old_state == SVC_RUNNING_STATE && new_state == SVC_PAUSED_STATE) ||
(old_state == SVC_PAUSED_STATE && new_state == SVC_RUNNING_STATE))
; /* only paused during reload, don't clear conds. */
else if (sm_is_in_teardown(&sm))
cond_clear_noupdate(cond);
else
cond_clear(cond);

Expand Down

0 comments on commit c221823

Please sign in to comment.