which don't have access to the event base.
__dso_public void sudo_ev_base_free_v1(struct sudo_event_base *base);
#define sudo_ev_base_free(_a) sudo_ev_base_free_v1((_a))
+/* Set the default event base. */
+__dso_public void sudo_ev_base_setdef_v1(struct sudo_event_base *base);
+#define sudo_ev_base_setdef(_a) sudo_ev_base_setdef_v1((_a))
+
/* Allocate a new event. */
__dso_public struct sudo_event *sudo_ev_alloc_v1(int fd, short events, sudo_ev_callback_t callback, void *closure);
#define sudo_ev_alloc(_a, _b, _c, _d) sudo_ev_alloc_v1((_a), (_b), (_c), (_d))
static void sudo_ev_init(struct sudo_event *ev, int fd, short events,
sudo_ev_callback_t callback, void *closure);
+/* Default event base when none is specified. */
+static struct sudo_event_base *default_base;
+
/* We need the event base to be available from the signal handler. */
static struct sudo_event_base *signal_base;
debug_return;
}
+void
+sudo_ev_base_setdef_v1(struct sudo_event_base *base)
+{
+ debug_decl(sudo_ev_base_setdef, SUDO_DEBUG_EVENT)
+
+ default_base = base;
+
+ debug_return;
+}
+
/*
* Clear and fill in a struct sudo_event.
*/
}
}
-int
+static int
sudo_ev_add_signal(struct sudo_event_base *base, struct sudo_event *ev,
bool tohead)
{
{
debug_decl(sudo_ev_add, SUDO_DEBUG_EVENT)
- /* If no base specified, use existing one. */
+ /* If no base specified, use existing or default base. */
if (base == NULL) {
- if (ev->base == NULL) {
+ if (ev->base != NULL) {
+ base = ev->base;
+ } else if (default_base != NULL) {
+ base = default_base;
+ } else {
sudo_debug_printf(SUDO_DEBUG_ERROR, "%s: no base specified",
__func__);
debug_return_int(-1);
}
- base = ev->base;
}
/* Only add new events to the events list. */
sudo_ev_alloc_v1
sudo_ev_base_alloc_v1
sudo_ev_base_free_v1
+sudo_ev_base_setdef_v1
sudo_ev_del_v1
sudo_ev_free_v1
sudo_ev_get_timeleft_v1
sudo_fatal(NULL);
if (sudo_ev_add(mc->evbase, mc->sigchld_event, NULL, false) == -1)
sudo_fatal(U_("unable to add event to queue"));
+
+ /* Clear the default event base. */
+ sudo_ev_base_setdef(NULL);
+
+ debug_return;
}
/*
sudo_fatal(U_("unable to add event to queue"));
#endif
+ /* Set the default event base. */
+ sudo_ev_base_setdef(ec->evbase);
+
debug_return;
}
{
debug_decl(free_exec_closure_nopty, SUDO_DEBUG_EXEC)
+ sudo_ev_base_setdef(NULL);
sudo_ev_base_free(ec->evbase);
sudo_ev_free(ec->errpipe_event);
sudo_ev_free(ec->sigint_event);
SUDO_EV_WRITE, sigfwd_cb, ec);
if (ec->sigfwd_event == NULL)
sudo_fatal(NULL);
+
+ /* Set the default event base. */
+ sudo_ev_base_setdef(ec->evbase);
+
+ debug_return;
}
/*
{
debug_decl(free_exec_closure_pty, SUDO_DEBUG_EXEC)
+ sudo_ev_base_setdef(NULL);
sudo_ev_base_free(ec->evbase);
sudo_ev_free(ec->backchannel_event);
sudo_ev_free(ec->sigint_event);