From 5f74adad06e97f6accbffab762b4118149578091 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 7 Nov 2022 06:44:21 +0100 Subject: [PATCH] Take down condition subsystem at shutdown/reboot Leave the system as it was when we found it. Also, we'll build things on top of cond_is_available() to handle pre bootstrap and pre shutdown tasks. Signed-off-by: Joachim Wiberg --- src/cond-w.c | 14 ++++++++++++++ src/cond.h | 3 +++ src/sig.c | 3 +++ 3 files changed, 20 insertions(+) diff --git a/src/cond-w.c b/src/cond-w.c index 4af9b32a..b1a891d7 100644 --- a/src/cond-w.c +++ b/src/cond-w.c @@ -410,6 +410,15 @@ void cond_deassert(const char *pat) nftw(cond_path(pat), deassert, 20, FTW_DEPTH); } +/* + * Check if we have bootstrapped enough of the system to use conditions. + * Will answer 'No' before bootstrap done *and* at shutdown/reboot. + */ +int cond_is_available(void) +{ + return fisdir(_PATH_COND); +} + void cond_init(void) { char path[MAX_ARG_LEN]; @@ -423,6 +432,11 @@ void cond_init(void) cond_boot_strap(); } +void cond_exit(void) +{ + cond_delpath(_PATH_COND); +} + /** * Local Variables: * indent-tabs-mode: t diff --git a/src/cond.h b/src/cond.h index 8dd7c168..f727efec 100644 --- a/src/cond.h +++ b/src/cond.h @@ -46,7 +46,10 @@ int cond_clear_noupdate(const char *name); void cond_reassert (const char *pat); void cond_deassert (const char *pat); +int cond_is_available(void); + void cond_init (void); +void cond_exit (void); #endif /* FINIT_COND_H_ */ diff --git a/src/sig.c b/src/sig.c index 7c36e3b3..3de33e5f 100644 --- a/src/sig.c +++ b/src/sig.c @@ -322,6 +322,9 @@ void do_shutdown(shutop_t op) plugin_exit(); api_exit(); + /* We can no longer act on conditions, activate script runner */ + cond_exit(); + /* Reap 'em */ while (waitpid(-1, NULL, WNOHANG) > 0) ;