From 42fe0409f61ac4fd862a4756fa9b630d5e67553b Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 19 Feb 2018 11:00:10 -0700 Subject: [PATCH] Add sudo_ev_dispatch(), a wrapper for ev_loop() with no flags. Similar the dispatch function in libevent. --- include/sudo_event.h | 4 ++++ lib/util/event.c | 6 ++++++ lib/util/util.exp.in | 9 +++++---- plugins/sudoers/sudoreplay.c | 4 ++-- src/exec_monitor.c | 2 +- src/exec_nopty.c | 2 +- src/exec_pty.c | 4 ++-- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/sudo_event.h b/include/sudo_event.h index 826f3d502..c60c7d104 100644 --- a/include/sudo_event.h +++ b/include/sudo_event.h @@ -131,6 +131,10 @@ __dso_public int sudo_ev_add_v1(struct sudo_event_base *head, struct sudo_event __dso_public int sudo_ev_del_v1(struct sudo_event_base *head, struct sudo_event *ev); #define sudo_ev_del(_a, _b) sudo_ev_del_v1((_a), (_b)) +/* Dispatch events, returns SUDO_CB_SUCCESS, SUDO_CB_BREAK or SUDO_CB_ERROR */ +__dso_public int sudo_ev_dispatch_v1(struct sudo_event_base *head); +#define sudo_ev_dispatch(_a) sudo_ev_dispatch_v1((_a)) + /* Main event loop, returns SUDO_CB_SUCCESS, SUDO_CB_BREAK or SUDO_CB_ERROR */ __dso_public int sudo_ev_loop_v1(struct sudo_event_base *head, int flags); #define sudo_ev_loop(_a, _b) sudo_ev_loop_v1((_a), (_b)) diff --git a/lib/util/event.c b/lib/util/event.c index 26cbff480..30e6e319e 100644 --- a/lib/util/event.c +++ b/lib/util/event.c @@ -583,6 +583,12 @@ sudo_ev_del_v1(struct sudo_event_base *base, struct sudo_event *ev) debug_return_int(0); } +int +sudo_ev_dispatch_v1(struct sudo_event_base *base) +{ + return sudo_ev_loop_v1(base, 0); +} + /* * Run main event loop. * Returns 0 on success, 1 if no events registered and -1 on error diff --git a/lib/util/util.exp.in b/lib/util/util.exp.in index 869b56c9d..acc4bd2ad 100644 --- a/lib/util/util.exp.in +++ b/lib/util/util.exp.in @@ -3,11 +3,11 @@ sudo_conf_askpass_path_v1 sudo_conf_clear_paths_v1 sudo_conf_debug_files_v1 sudo_conf_debugging_v1 +sudo_conf_devsearch_path_v1 sudo_conf_disable_coredump_v1 sudo_conf_group_source_v1 sudo_conf_max_groups_v1 sudo_conf_noexec_path_v1 -sudo_conf_devsearch_path_v1 sudo_conf_plugin_dir_path_v1 sudo_conf_plugins_v1 sudo_conf_probe_interfaces_v1 @@ -16,7 +16,6 @@ sudo_conf_sesh_path_v1 sudo_debug_deregister_v1 sudo_debug_enter_v1 sudo_debug_execve2_v1 -sudo_debug_exit_v1 sudo_debug_exit_bool_v1 sudo_debug_exit_id_t_v1 sudo_debug_exit_int_v1 @@ -24,9 +23,10 @@ sudo_debug_exit_long_v1 sudo_debug_exit_ptr_v1 sudo_debug_exit_size_t_v1 sudo_debug_exit_ssize_t_v1 -sudo_debug_exit_str_v1 sudo_debug_exit_str_masked_v1 +sudo_debug_exit_str_v1 sudo_debug_exit_time_t_v1 +sudo_debug_exit_v1 sudo_debug_fork_v1 sudo_debug_get_active_instance_v1 sudo_debug_get_fds_v1 @@ -48,6 +48,7 @@ sudo_ev_base_alloc_v1 sudo_ev_base_free_v1 sudo_ev_base_setdef_v1 sudo_ev_del_v1 +sudo_ev_dispatch_v1 sudo_ev_free_v1 sudo_ev_get_timeleft_v1 sudo_ev_got_break_v1 @@ -60,7 +61,6 @@ sudo_fatal_callback_deregister_v1 sudo_fatal_callback_register_v1 sudo_fatal_nodebug_v1 sudo_fatalx_nodebug_v1 -sudo_ttyname_dev_v1 sudo_get_ttysize_v1 sudo_gethostname_v1 sudo_gettime_mono_v1 @@ -92,6 +92,7 @@ sudo_term_kill sudo_term_noecho_v1 sudo_term_raw_v1 sudo_term_restore_v1 +sudo_ttyname_dev_v1 sudo_vfatal_nodebug_v1 sudo_vfatalx_nodebug_v1 sudo_vwarn_nodebug_v1 diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index 3034b8ac9..0875b4acd 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -598,7 +598,7 @@ xterm_get_size(int *new_rows, int *new_cols) /* Read back terminal size response */ if (sudo_ev_add(evbase, gc.ev, &gc.timeout, false) == -1) sudo_fatal(U_("unable to add event to queue")); - sudo_ev_loop(evbase, 0); + sudo_ev_dispatch(evbase); if (gc.state == GOTSIZE) { sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, @@ -1035,7 +1035,7 @@ replay_session(double max_delay, const char *decimal, bool interactive) } /* Run event loop. */ - sudo_ev_loop(closure->evbase, 0); + sudo_ev_dispatch(closure->evbase); if (sudo_ev_got_break(closure->evbase)) ret = 1; diff --git a/src/exec_monitor.c b/src/exec_monitor.c index 5546be635..1dc1d370d 100644 --- a/src/exec_monitor.c +++ b/src/exec_monitor.c @@ -617,7 +617,7 @@ exec_monitor(struct command_details *details, sigset_t *oset, */ cstat.type = CMD_INVALID; cstat.val = 0; - (void) sudo_ev_loop(mc.evbase, 0); + (void) sudo_ev_dispatch(mc.evbase); if (mc.cmnd_pid != -1) { pid_t pid; diff --git a/src/exec_nopty.c b/src/exec_nopty.c index 1d49f012d..3ba34fdb6 100644 --- a/src/exec_nopty.c +++ b/src/exec_nopty.c @@ -415,7 +415,7 @@ exec_nopty(struct command_details *details, struct command_status *cstat) * Non-pty event loop. * Wait for command to exit, handles signals and the error pipe. */ - if (sudo_ev_loop(ec.evbase, 0) == -1) + if (sudo_ev_dispatch(ec.evbase) == -1) sudo_warn(U_("error in event loop")); if (sudo_ev_got_break(ec.evbase)) { /* error from callback */ diff --git a/src/exec_pty.c b/src/exec_pty.c index c813924a5..ce7ca3b09 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -1472,7 +1472,7 @@ exec_pty(struct command_details *details, struct command_status *cstat) * and pass output from master to stdout and IO plugin. */ add_io_events(ec.evbase); - if (sudo_ev_loop(ec.evbase, 0) == -1) + if (sudo_ev_dispatch(ec.evbase) == -1) sudo_warn(U_("error in event loop")); if (sudo_ev_got_break(ec.evbase)) { /* error from callback or monitor died */ @@ -1606,7 +1606,7 @@ del_io_events(bool nonblocking) } } } - (void) sudo_ev_loop(evbase, 0); + (void) sudo_ev_dispatch(evbase); /* We should now have flushed all write buffers. */ SLIST_FOREACH(iob, &iobufs, entries) { -- 2.40.0