Replace timeleft with pending in sudo plugin event API.

This commit is contained in:
Todd C. Miller
2019-12-07 08:42:10 -07:00
parent bf3b93f080
commit d0b80b404c
4 changed files with 40 additions and 29 deletions

View File

@@ -2459,7 +2459,8 @@ struct sudo_plugin_event {
sudo_plugin_ev_callback_t callback, void *closure); sudo_plugin_ev_callback_t callback, void *closure);
int (*add)(struct sudo_plugin_event *pev, struct timespec *timeout); int (*add)(struct sudo_plugin_event *pev, struct timespec *timeout);
int (*del)(struct sudo_plugin_event *pev); 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); int (*fd)(struct sudo_plugin_event *pev);
void (*setbase)(struct sudo_plugin_event *pev, void *base); void (*setbase)(struct sudo_plugin_event *pev, void *base);
void (*loopbreak)(struct sudo_plugin_event *pev); void (*loopbreak)(struct sudo_plugin_event *pev);
@@ -2634,25 +2635,30 @@ The
function returns 1 on success, and \-1 if a error occurred. function returns 1 on success, and \-1 if a error occurred.
.RE .RE
.TP 6n .TP 6n
\fBtimeleft\fR() \fBpending\fR()
.nf .nf
.RS 6n .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 .RE
.fi .fi
.RS 6n .RS 6n
.sp .sp
The The
\fBtimeleft\fR() \fBpending\fR()
function can be used to determine how much time remains in an event's function can be used to determine whether one or more events is pending.
timeout, if one was specified when the event was added.
The 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 \fIts\fR
pointer is filled in with the remaining time. pointer is non-NULL, it will be filled in with the remaining time.
.sp
The
\fBtimeleft\fR()
function returns 1 on success, and \-1 if the event has no associated timeout.
.RE .RE
.TP 6n .TP 6n
\fBfd\fR() \fBfd\fR()

View File

@@ -2139,7 +2139,8 @@ struct sudo_plugin_event {
sudo_plugin_ev_callback_t callback, void *closure); sudo_plugin_ev_callback_t callback, void *closure);
int (*add)(struct sudo_plugin_event *pev, struct timespec *timeout); int (*add)(struct sudo_plugin_event *pev, struct timespec *timeout);
int (*del)(struct sudo_plugin_event *pev); 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); int (*fd)(struct sudo_plugin_event *pev);
void (*setbase)(struct sudo_plugin_event *pev, void *base); void (*setbase)(struct sudo_plugin_event *pev, void *base);
void (*loopbreak)(struct sudo_plugin_event *pev); void (*loopbreak)(struct sudo_plugin_event *pev);
@@ -2276,22 +2277,27 @@ function.
The The
.Fn del .Fn del
function returns 1 on success, and \-1 if a error occurred. function returns 1 on success, and \-1 if a error occurred.
.It Fn timeleft .It Fn pending
.Bd -literal -compact .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 .Ed
.Pp .Pp
The The
.Fn timeleft .Fn pending
function can be used to determine how much time remains in an event's function can be used to determine whether one or more events is pending.
timeout, if one was specified when the event was added.
The 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 .Fa ts
pointer is filled in with the remaining time. pointer is non-NULL, it will be filled in with the remaining time.
.Pp
The
.Fn timeleft
function returns 1 on success, and \-1 if the event has no associated timeout.
.It Fn fd .It Fn fd
.Bd -literal -compact .Bd -literal -compact
int (*fd)(struct sudo_plugin_event *pev); int (*fd)(struct sudo_plugin_event *pev);

View File

@@ -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 (*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 (*add)(struct sudo_plugin_event *pev, struct timespec *timeout);
int (*del)(struct sudo_plugin_event *pev); 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); int (*fd)(struct sudo_plugin_event *pev);
void (*setbase)(struct sudo_plugin_event *pev, void *base); void (*setbase)(struct sudo_plugin_event *pev, void *base);
void (*loopbreak)(struct sudo_plugin_event *pev); void (*loopbreak)(struct sudo_plugin_event *pev);

View File

@@ -1411,15 +1411,14 @@ plugin_event_del(struct sudo_plugin_event *pev)
* Get the amount of time remaining in a timeout event. * Get the amount of time remaining in a timeout event.
*/ */
static int 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; 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); ev_int = __containerof(pev, struct sudo_plugin_event_int, public);
if (sudo_ev_get_timeleft(&ev_int->private, ts) == -1) debug_return_int(sudo_ev_pending(&ev_int->private, events, ts));
debug_return_int(-1);
debug_return_int(1);
} }
/* /*
@@ -1499,7 +1498,7 @@ sudo_plugin_event_alloc(void)
ev_int->public.add = plugin_event_add; ev_int->public.add = plugin_event_add;
ev_int->public.del = plugin_event_del; ev_int->public.del = plugin_event_del;
ev_int->public.fd = plugin_event_fd; 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.setbase = plugin_event_setbase;
ev_int->public.loopbreak = plugin_event_loopbreak; ev_int->public.loopbreak = plugin_event_loopbreak;
ev_int->public.free = plugin_event_free; ev_int->public.free = plugin_event_free;