From d0b80b404ca9f6a8ba5f37991e9ff7449ffcd08b Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sat, 7 Dec 2019 08:42:10 -0700 Subject: [PATCH] Replace timeleft with pending in sudo plugin event API. --- doc/sudo_plugin.man.in | 28 +++++++++++++++++----------- doc/sudo_plugin.mdoc.in | 28 +++++++++++++++++----------- include/sudo_plugin.h | 2 +- src/sudo.c | 11 +++++------ 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/doc/sudo_plugin.man.in b/doc/sudo_plugin.man.in index 281a456ca..4120029f3 100644 --- a/doc/sudo_plugin.man.in +++ b/doc/sudo_plugin.man.in @@ -2459,7 +2459,8 @@ struct sudo_plugin_event { sudo_plugin_ev_callback_t callback, void *closure); int (*add)(struct sudo_plugin_event *pev, struct timespec *timeout); int (*del)(struct sudo_plugin_event *pev); - int (*timeleft)(struct sudo_plugin_event *pev, struct timespec *ts); + int (*pending)(struct sudo_plugin_event *pev, int events, + struct timespec *ts); int (*fd)(struct sudo_plugin_event *pev); void (*setbase)(struct sudo_plugin_event *pev, void *base); void (*loopbreak)(struct sudo_plugin_event *pev); @@ -2634,25 +2635,30 @@ The function returns 1 on success, and \-1 if a error occurred. .RE .TP 6n -\fBtimeleft\fR() +\fBpending\fR() .nf .RS 6n -int (*timeleft)(struct sudo_plugin_event *pev, struct timespec *ts); +int (*pending)(struct sudo_plugin_event *pev, int events, struct timespec *ts); .RE .fi .RS 6n .sp The -\fBtimeleft\fR() -function can be used to determine how much time remains in an event's -timeout, if one was specified when the event was added. +\fBpending\fR() +function can be used to determine whether one or more events is pending. The +\fIevents\fR +argument specifies which events to check for. +See the +\fBset\fR() +function for a list of valid event types. +If +\fRSUDO_PLUGIN_EV_TIMEOUT\fR +is specified in +\fRevents\fR, +the event has an associated timeout and the \fIts\fR -pointer is filled in with the remaining time. -.sp -The -\fBtimeleft\fR() -function returns 1 on success, and \-1 if the event has no associated timeout. +pointer is non-NULL, it will be filled in with the remaining time. .RE .TP 6n \fBfd\fR() diff --git a/doc/sudo_plugin.mdoc.in b/doc/sudo_plugin.mdoc.in index 8faec387a..94e4b8c8f 100644 --- a/doc/sudo_plugin.mdoc.in +++ b/doc/sudo_plugin.mdoc.in @@ -2139,7 +2139,8 @@ struct sudo_plugin_event { sudo_plugin_ev_callback_t callback, void *closure); int (*add)(struct sudo_plugin_event *pev, struct timespec *timeout); int (*del)(struct sudo_plugin_event *pev); - int (*timeleft)(struct sudo_plugin_event *pev, struct timespec *ts); + int (*pending)(struct sudo_plugin_event *pev, int events, + struct timespec *ts); int (*fd)(struct sudo_plugin_event *pev); void (*setbase)(struct sudo_plugin_event *pev, void *base); void (*loopbreak)(struct sudo_plugin_event *pev); @@ -2276,22 +2277,27 @@ function. The .Fn del function returns 1 on success, and \-1 if a error occurred. -.It Fn timeleft +.It Fn pending .Bd -literal -compact -int (*timeleft)(struct sudo_plugin_event *pev, struct timespec *ts); +int (*pending)(struct sudo_plugin_event *pev, int events, struct timespec *ts); .Ed .Pp The -.Fn timeleft -function can be used to determine how much time remains in an event's -timeout, if one was specified when the event was added. +.Fn pending +function can be used to determine whether one or more events is pending. The +.Fa events +argument specifies which events to check for. +See the +.Fn set +function for a list of valid event types. +If +.Dv SUDO_PLUGIN_EV_TIMEOUT +is specified in +.Dv events , +the event has an associated timeout and the .Fa ts -pointer is filled in with the remaining time. -.Pp -The -.Fn timeleft -function returns 1 on success, and \-1 if the event has no associated timeout. +pointer is non-NULL, it will be filled in with the remaining time. .It Fn fd .Bd -literal -compact int (*fd)(struct sudo_plugin_event *pev); diff --git a/include/sudo_plugin.h b/include/sudo_plugin.h index 85a7ddec6..0f026e2f7 100644 --- a/include/sudo_plugin.h +++ b/include/sudo_plugin.h @@ -138,7 +138,7 @@ struct sudo_plugin_event { int (*set)(struct sudo_plugin_event *pev, int fd, int events, sudo_plugin_ev_callback_t callback, void *closure); int (*add)(struct sudo_plugin_event *pev, struct timespec *timeout); int (*del)(struct sudo_plugin_event *pev); - int (*timeleft)(struct sudo_plugin_event *pev, struct timespec *ts); + int (*pending)(struct sudo_plugin_event *pev, int events, struct timespec *ts); int (*fd)(struct sudo_plugin_event *pev); void (*setbase)(struct sudo_plugin_event *pev, void *base); void (*loopbreak)(struct sudo_plugin_event *pev); diff --git a/src/sudo.c b/src/sudo.c index 6e2778278..cd666b46f 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -1411,15 +1411,14 @@ plugin_event_del(struct sudo_plugin_event *pev) * Get the amount of time remaining in a timeout event. */ static int -plugin_event_timeleft(struct sudo_plugin_event *pev, struct timespec *ts) +plugin_event_pending(struct sudo_plugin_event *pev, int events, + struct timespec *ts) { struct sudo_plugin_event_int *ev_int; - debug_decl(plugin_event_timeleft, SUDO_DEBUG_PCOMM) + debug_decl(plugin_event_pending, SUDO_DEBUG_PCOMM) ev_int = __containerof(pev, struct sudo_plugin_event_int, public); - if (sudo_ev_get_timeleft(&ev_int->private, ts) == -1) - debug_return_int(-1); - debug_return_int(1); + debug_return_int(sudo_ev_pending(&ev_int->private, events, ts)); } /* @@ -1499,7 +1498,7 @@ sudo_plugin_event_alloc(void) ev_int->public.add = plugin_event_add; ev_int->public.del = plugin_event_del; ev_int->public.fd = plugin_event_fd; - ev_int->public.timeleft = plugin_event_timeleft; + ev_int->public.pending = plugin_event_pending; ev_int->public.setbase = plugin_event_setbase; ev_int->public.loopbreak = plugin_event_loopbreak; ev_int->public.free = plugin_event_free;