[core] run all trigger and sighup handlers

(do not bail if a handler returns something other than HANDLER_GO_ON)

(preserve fn signature for simplicity and compat with plugin_fn_data)
This commit is contained in:
Glenn Strauss 2019-11-19 20:12:31 -05:00
parent b73949e03f
commit ba88ff0e93
4 changed files with 27 additions and 30 deletions

View File

@ -1276,6 +1276,7 @@ mod_webdav_sqlite3_prep (sql_config * const restrict sql,
#endif /* USE_PROPPATCH */
__attribute_cold__
SERVER_FUNC(mod_webdav_worker_init)
{
#ifdef USE_PROPPATCH

View File

@ -304,6 +304,15 @@ static handler_t plugins_call_fn_srv_data(server * const srv, const int e) {
return rc;
}
static void plugins_call_fn_srv_data_all(server * const srv, const int e) {
const uint32_t offset = ((const uint16_t *)srv->plugin_slots)[e];
if (0 == offset) return;
const plugin_fn_data *plfd = (const plugin_fn_data *)
(((uintptr_t)srv->plugin_slots) + offset);
for (; plfd->fn; ++plfd)
plfd->fn(srv, plfd->data);
}
/**
* plugins that use
*
@ -340,17 +349,21 @@ PLUGIN_CALL_FN_SRV_CON_DATA(PLUGIN_FUNC_CONNECTION_RESET, connection_reset)
* - void *p_d (plugin_data *)
*/
#define PLUGIN_CALL_FN_SRV_DATA(x, y) \
handler_t plugins_call_##y(server *srv) {\
return plugins_call_fn_srv_data(srv, x); \
}
handler_t plugins_call_set_defaults(server *srv) {
return plugins_call_fn_srv_data(srv, PLUGIN_FUNC_SET_DEFAULTS);
}
PLUGIN_CALL_FN_SRV_DATA(PLUGIN_FUNC_HANDLE_TRIGGER, handle_trigger)
PLUGIN_CALL_FN_SRV_DATA(PLUGIN_FUNC_HANDLE_SIGHUP, handle_sighup)
PLUGIN_CALL_FN_SRV_DATA(PLUGIN_FUNC_SET_DEFAULTS, set_defaults)
PLUGIN_CALL_FN_SRV_DATA(PLUGIN_FUNC_WORKER_INIT, worker_init)
handler_t plugins_call_worker_init(server *srv) {
return plugins_call_fn_srv_data(srv, PLUGIN_FUNC_WORKER_INIT);
}
#undef PLUGIN_CALL_FN_SRV_DATA
void plugins_call_handle_trigger(server *srv) {
plugins_call_fn_srv_data_all(srv, PLUGIN_FUNC_HANDLE_TRIGGER);
}
void plugins_call_handle_sighup(server *srv) {
plugins_call_fn_srv_data_all(srv, PLUGIN_FUNC_HANDLE_SIGHUP);
}
handler_t plugins_call_handle_waitpid(server *srv, pid_t pid, int status) {
const uint32_t offset =

View File

@ -90,11 +90,11 @@ handler_t plugins_call_handle_connection_shut_wr(server *srv, connection *con);
handler_t plugins_call_handle_connection_close(server *srv, connection *con);
handler_t plugins_call_connection_reset(server *srv, connection *con);
handler_t plugins_call_handle_trigger(server *srv);
void plugins_call_handle_trigger(server *srv);
handler_t plugins_call_handle_waitpid(server *srv, pid_t pid, int status);
__attribute_cold__
handler_t plugins_call_handle_sighup(server *srv);
void plugins_call_handle_sighup(server *srv);
__attribute_cold__
handler_t plugins_call_init(server *srv);

View File

@ -1622,17 +1622,10 @@ static int server_main (server * const srv, int argc, char **argv) {
__attribute_cold__
__attribute_noinline__
static int server_handle_sighup (server * const srv) {
handler_t r;
/* cycle logfiles */
switch(r = plugins_call_handle_sighup(srv)) {
case HANDLER_GO_ON:
break;
default:
log_error_write(srv, __FILE__, __LINE__, "sd", "sighup-handler return with an error", r);
break;
}
plugins_call_handle_sighup(srv);
if (-1 == log_error_cycle(srv)) {
log_error_write(srv, __FILE__, __LINE__, "s", "cycling errorlog failed, dying");
@ -1656,18 +1649,8 @@ static int server_handle_sighup (server * const srv) {
__attribute_noinline__
static void server_handle_sigalrm (server * const srv, time_t min_ts, time_t last_active_ts) {
handler_t r;
switch(r = plugins_call_handle_trigger(srv)) {
case HANDLER_GO_ON:
break;
case HANDLER_ERROR:
log_error_write(srv, __FILE__, __LINE__, "s", "one of the triggers failed");
break;
default:
log_error_write(srv, __FILE__, __LINE__, "d", r);
break;
}
plugins_call_handle_trigger(srv);
srv->cur_ts = min_ts;