Add sudo_ev_dispatch(), a wrapper for ev_loop() with no flags.

Similar the dispatch function in libevent.
This commit is contained in:
Todd C. Miller
2018-02-19 11:00:10 -07:00
parent 525c6a3d94
commit 42fe0409f6
7 changed files with 21 additions and 10 deletions

View File

@@ -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))

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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) {