mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 09:57:41 +00:00
Use int, not short for events in the event API.
This fixes some -Wconversion warnings and fixes an inconsistency between the libsudo_util event API and the plugin event API. The actual struct internals still use shorts to avoid changing the ABI.
This commit is contained in:
parent
0f2e5dae90
commit
811051d32a
@ -126,7 +126,8 @@ sudo_dso_public void sudo_ev_base_setdef_v1(struct sudo_event_base *base);
|
|||||||
|
|
||||||
/* Allocate a new event. */
|
/* Allocate a new event. */
|
||||||
sudo_dso_public struct sudo_event *sudo_ev_alloc_v1(int fd, short events, sudo_ev_callback_t callback, void *closure);
|
sudo_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))
|
sudo_dso_public struct sudo_event *sudo_ev_alloc_v2(int fd, int events, sudo_ev_callback_t callback, void *closure);
|
||||||
|
#define sudo_ev_alloc(_a, _b, _c, _d) sudo_ev_alloc_v2((_a), (_b), (_c), (_d))
|
||||||
|
|
||||||
/* Free an event. */
|
/* Free an event. */
|
||||||
sudo_dso_public void sudo_ev_free_v1(struct sudo_event *ev);
|
sudo_dso_public void sudo_ev_free_v1(struct sudo_event *ev);
|
||||||
@ -134,7 +135,8 @@ sudo_dso_public void sudo_ev_free_v1(struct sudo_event *ev);
|
|||||||
|
|
||||||
/* Set an event struct that was pre-allocated. */
|
/* Set an event struct that was pre-allocated. */
|
||||||
sudo_dso_public int sudo_ev_set_v1(struct sudo_event *ev, int fd, short events, sudo_ev_callback_t callback, void *closure);
|
sudo_dso_public int sudo_ev_set_v1(struct sudo_event *ev, int fd, short events, sudo_ev_callback_t callback, void *closure);
|
||||||
#define sudo_ev_set(_a, _b, _c, _d, _e) sudo_ev_set_v1((_a), (_b), (_c), (_d), (_e))
|
sudo_dso_public int sudo_ev_set_v2(struct sudo_event *ev, int fd, int events, sudo_ev_callback_t callback, void *closure);
|
||||||
|
#define sudo_ev_set(_a, _b, _c, _d, _e) sudo_ev_set_v2((_a), (_b), (_c), (_d), (_e))
|
||||||
|
|
||||||
/* Add an event, returns 0 on success, -1 on error */
|
/* Add an event, returns 0 on success, -1 on error */
|
||||||
sudo_dso_public int sudo_ev_add_v1(struct sudo_event_base *head, struct sudo_event *ev, const struct timeval *timo, bool tohead);
|
sudo_dso_public int sudo_ev_add_v1(struct sudo_event_base *head, struct sudo_event *ev, const struct timeval *timo, bool tohead);
|
||||||
@ -155,7 +157,8 @@ sudo_dso_public int sudo_ev_loop_v1(struct sudo_event_base *head, unsigned int f
|
|||||||
|
|
||||||
/* Return pending event types, fills in ts if non-NULL and there is a timeout */
|
/* Return pending event types, fills in ts if non-NULL and there is a timeout */
|
||||||
sudo_dso_public int sudo_ev_pending_v1(struct sudo_event *ev, short events, struct timespec *ts);
|
sudo_dso_public int sudo_ev_pending_v1(struct sudo_event *ev, short events, struct timespec *ts);
|
||||||
#define sudo_ev_pending(_a, _b, _c) sudo_ev_pending_v1((_a), (_b), (_c))
|
sudo_dso_public int sudo_ev_pending_v2(struct sudo_event *ev, int events, struct timespec *ts);
|
||||||
|
#define sudo_ev_pending(_a, _b, _c) sudo_ev_pending_v2((_a), (_b), (_c))
|
||||||
|
|
||||||
/* Return the remaining timeout associated with an event (deprecated). */
|
/* Return the remaining timeout associated with an event (deprecated). */
|
||||||
sudo_dso_public int sudo_ev_get_timeleft_v1(struct sudo_event *ev, struct timeval *tv);
|
sudo_dso_public int sudo_ev_get_timeleft_v1(struct sudo_event *ev, struct timeval *tv);
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
#include "sudo_event.h"
|
#include "sudo_event.h"
|
||||||
#include "sudo_util.h"
|
#include "sudo_util.h"
|
||||||
|
|
||||||
static void sudo_ev_init(struct sudo_event *ev, int fd, short events,
|
static void sudo_ev_init(struct sudo_event *ev, int fd, int events,
|
||||||
sudo_ev_callback_t callback, void *closure);
|
sudo_ev_callback_t callback, void *closure);
|
||||||
|
|
||||||
/* Default event base when none is specified. */
|
/* Default event base when none is specified. */
|
||||||
@ -263,7 +263,7 @@ sudo_ev_base_setdef_v1(struct sudo_event_base *base)
|
|||||||
* Clear and fill in a struct sudo_event.
|
* Clear and fill in a struct sudo_event.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
sudo_ev_init(struct sudo_event *ev, int fd, short events,
|
sudo_ev_init(struct sudo_event *ev, int fd, int events,
|
||||||
sudo_ev_callback_t callback, void *closure)
|
sudo_ev_callback_t callback, void *closure)
|
||||||
{
|
{
|
||||||
debug_decl(sudo_ev_init, SUDO_DEBUG_EVENT);
|
debug_decl(sudo_ev_init, SUDO_DEBUG_EVENT);
|
||||||
@ -283,7 +283,7 @@ sudo_ev_init(struct sudo_event *ev, int fd, short events,
|
|||||||
* Allocates space for siginfo_t for SUDO_EV_SIGINFO as needed.
|
* Allocates space for siginfo_t for SUDO_EV_SIGINFO as needed.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
sudo_ev_set_v1(struct sudo_event *ev, int fd, short events,
|
sudo_ev_set_v2(struct sudo_event *ev, int fd, int events,
|
||||||
sudo_ev_callback_t callback, void *closure)
|
sudo_ev_callback_t callback, void *closure)
|
||||||
{
|
{
|
||||||
debug_decl(sudo_ev_set, SUDO_DEBUG_EVENT);
|
debug_decl(sudo_ev_set, SUDO_DEBUG_EVENT);
|
||||||
@ -305,8 +305,15 @@ sudo_ev_set_v1(struct sudo_event *ev, int fd, short events,
|
|||||||
debug_return_int(0);
|
debug_return_int(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sudo_ev_set_v1(struct sudo_event *ev, int fd, short events,
|
||||||
|
sudo_ev_callback_t callback, void *closure)
|
||||||
|
{
|
||||||
|
return sudo_ev_set_v2(ev, fd, events, callback, closure);
|
||||||
|
}
|
||||||
|
|
||||||
struct sudo_event *
|
struct sudo_event *
|
||||||
sudo_ev_alloc_v1(int fd, short events, sudo_ev_callback_t callback, void *closure)
|
sudo_ev_alloc_v2(int fd, int events, sudo_ev_callback_t callback, void *closure)
|
||||||
{
|
{
|
||||||
struct sudo_event *ev;
|
struct sudo_event *ev;
|
||||||
debug_decl(sudo_ev_alloc, SUDO_DEBUG_EVENT);
|
debug_decl(sudo_ev_alloc, SUDO_DEBUG_EVENT);
|
||||||
@ -324,6 +331,12 @@ sudo_ev_alloc_v1(int fd, short events, sudo_ev_callback_t callback, void *closur
|
|||||||
debug_return_ptr(ev);
|
debug_return_ptr(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct sudo_event *
|
||||||
|
sudo_ev_alloc_v1(int fd, short events, sudo_ev_callback_t callback, void *closure)
|
||||||
|
{
|
||||||
|
return sudo_ev_alloc_v2(fd, events, callback, closure);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sudo_ev_free_v1(struct sudo_event *ev)
|
sudo_ev_free_v1(struct sudo_event *ev)
|
||||||
{
|
{
|
||||||
@ -833,7 +846,7 @@ sudo_ev_get_timeleft_v2(struct sudo_event *ev, struct timespec *ts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sudo_ev_pending_v1(struct sudo_event *ev, short events, struct timespec *ts)
|
sudo_ev_pending_v2(struct sudo_event *ev, int events, struct timespec *ts)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
debug_decl(sudo_ev_pending, SUDO_DEBUG_EVENT);
|
debug_decl(sudo_ev_pending, SUDO_DEBUG_EVENT);
|
||||||
@ -860,3 +873,9 @@ sudo_ev_pending_v1(struct sudo_event *ev, short events, struct timespec *ts)
|
|||||||
|
|
||||||
debug_return_int(ret);
|
debug_return_int(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sudo_ev_pending_v1(struct sudo_event *ev, short events, struct timespec *ts)
|
||||||
|
{
|
||||||
|
return sudo_ev_pending_v2(ev, events, ts);
|
||||||
|
}
|
||||||
|
@ -120,7 +120,7 @@ sudo_ev_add_impl(struct sudo_event_base *base, struct sudo_event *ev)
|
|||||||
/* Fill in pfd entry. */
|
/* Fill in pfd entry. */
|
||||||
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,
|
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,
|
||||||
"%s: choosing free slot %d", __func__, base->pfd_free);
|
"%s: choosing free slot %d", __func__, base->pfd_free);
|
||||||
ev->pfd_idx = base->pfd_free;
|
ev->pfd_idx = (short)base->pfd_free;
|
||||||
pfd = &base->pfds[ev->pfd_idx];
|
pfd = &base->pfds[ev->pfd_idx];
|
||||||
pfd->fd = ev->fd;
|
pfd->fd = ev->fd;
|
||||||
pfd->events = 0;
|
pfd->events = 0;
|
||||||
@ -226,7 +226,7 @@ sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags)
|
|||||||
sudo_debug_printf(SUDO_DEBUG_DEBUG,
|
sudo_debug_printf(SUDO_DEBUG_DEBUG,
|
||||||
"%s: polled fd %d, events %d, activating %p",
|
"%s: polled fd %d, events %d, activating %p",
|
||||||
__func__, ev->fd, what, ev);
|
__func__, ev->fd, what, ev);
|
||||||
ev->revents = what;
|
ev->revents = (short)what;
|
||||||
sudo_ev_activate(base, ev);
|
sudo_ev_activate(base, ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,14 +82,14 @@ sudo_ev_add_impl(struct sudo_event_base *base, struct sudo_event *ev)
|
|||||||
if (ev->fd > base->maxfd) {
|
if (ev->fd > base->maxfd) {
|
||||||
const int o = (base->maxfd + 1) / NFDBITS;
|
const int o = (base->maxfd + 1) / NFDBITS;
|
||||||
const int n = howmany(ev->fd + 1, NFDBITS);
|
const int n = howmany(ev->fd + 1, NFDBITS);
|
||||||
const size_t used_bytes = o * sizeof(fd_mask);
|
const size_t used_bytes = (size_t)o * sizeof(fd_mask);
|
||||||
const size_t new_bytes = (n - o) * sizeof(fd_mask);
|
const size_t new_bytes = (size_t)(n - o) * sizeof(fd_mask);
|
||||||
fd_set *rfds_in, *wfds_in, *rfds_out, *wfds_out;
|
fd_set *rfds_in, *wfds_in, *rfds_out, *wfds_out;
|
||||||
|
|
||||||
rfds_in = reallocarray(base->readfds_in, n, sizeof(fd_mask));
|
rfds_in = reallocarray(base->readfds_in, (size_t)n, sizeof(fd_mask));
|
||||||
wfds_in = reallocarray(base->writefds_in, n, sizeof(fd_mask));
|
wfds_in = reallocarray(base->writefds_in, (size_t)n, sizeof(fd_mask));
|
||||||
rfds_out = reallocarray(base->readfds_out, n, sizeof(fd_mask));
|
rfds_out = reallocarray(base->readfds_out, (size_t)n, sizeof(fd_mask));
|
||||||
wfds_out = reallocarray(base->writefds_out, n, sizeof(fd_mask));
|
wfds_out = reallocarray(base->writefds_out, (size_t)n, sizeof(fd_mask));
|
||||||
if (rfds_in == NULL || wfds_in == NULL ||
|
if (rfds_in == NULL || wfds_in == NULL ||
|
||||||
rfds_out == NULL || wfds_out == NULL) {
|
rfds_out == NULL || wfds_out == NULL) {
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||||
@ -209,7 +209,7 @@ sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* select() overwrites readfds/writefds so make a copy. */
|
/* select() overwrites readfds/writefds so make a copy. */
|
||||||
setsize = howmany(base->highfd + 1, NFDBITS) * sizeof(fd_mask);
|
setsize = (size_t)howmany(base->highfd + 1, NFDBITS) * sizeof(fd_mask);
|
||||||
memcpy(base->readfds_out, base->readfds_in, setsize);
|
memcpy(base->readfds_out, base->readfds_in, setsize);
|
||||||
memcpy(base->writefds_out, base->writefds_in, setsize);
|
memcpy(base->writefds_out, base->writefds_in, setsize);
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags)
|
|||||||
/* Activate each I/O event that fired. */
|
/* Activate each I/O event that fired. */
|
||||||
TAILQ_FOREACH(ev, &base->events, entries) {
|
TAILQ_FOREACH(ev, &base->events, entries) {
|
||||||
if (ev->fd >= 0) {
|
if (ev->fd >= 0) {
|
||||||
int what = 0;
|
short what = 0;
|
||||||
if (FD_ISSET(ev->fd, (fd_set *)base->readfds_out))
|
if (FD_ISSET(ev->fd, (fd_set *)base->readfds_out))
|
||||||
what |= (ev->events & SUDO_EV_READ);
|
what |= (ev->events & SUDO_EV_READ);
|
||||||
if (FD_ISSET(ev->fd, (fd_set *)base->writefds_out))
|
if (FD_ISSET(ev->fd, (fd_set *)base->writefds_out))
|
||||||
@ -237,7 +237,7 @@ sudo_ev_scan_impl(struct sudo_event_base *base, unsigned int flags)
|
|||||||
if (what != 0) {
|
if (what != 0) {
|
||||||
/* Make event active. */
|
/* Make event active. */
|
||||||
sudo_debug_printf(SUDO_DEBUG_DEBUG,
|
sudo_debug_printf(SUDO_DEBUG_DEBUG,
|
||||||
"%s: selected fd %d, events %d, activating %p",
|
"%s: selected fd %d, events %hd, activating %p",
|
||||||
__func__, ev->fd, what, ev);
|
__func__, ev->fd, what, ev);
|
||||||
ev->revents = what;
|
ev->revents = what;
|
||||||
sudo_ev_activate(base, ev);
|
sudo_ev_activate(base, ev);
|
||||||
|
@ -61,6 +61,7 @@ sudo_dso_unload_v1
|
|||||||
sudo_ev_add_v1
|
sudo_ev_add_v1
|
||||||
sudo_ev_add_v2
|
sudo_ev_add_v2
|
||||||
sudo_ev_alloc_v1
|
sudo_ev_alloc_v1
|
||||||
|
sudo_ev_alloc_v2
|
||||||
sudo_ev_base_alloc_v1
|
sudo_ev_base_alloc_v1
|
||||||
sudo_ev_base_free_v1
|
sudo_ev_base_free_v1
|
||||||
sudo_ev_base_setdef_v1
|
sudo_ev_base_setdef_v1
|
||||||
@ -76,7 +77,9 @@ sudo_ev_loopbreak_v1
|
|||||||
sudo_ev_loopcontinue_v1
|
sudo_ev_loopcontinue_v1
|
||||||
sudo_ev_loopexit_v1
|
sudo_ev_loopexit_v1
|
||||||
sudo_ev_pending_v1
|
sudo_ev_pending_v1
|
||||||
|
sudo_ev_pending_v2
|
||||||
sudo_ev_set_v1
|
sudo_ev_set_v1
|
||||||
|
sudo_ev_set_v2
|
||||||
sudo_fatal_callback_deregister_v1
|
sudo_fatal_callback_deregister_v1
|
||||||
sudo_fatal_callback_register_v1
|
sudo_fatal_callback_register_v1
|
||||||
sudo_fatal_nodebug_v1
|
sudo_fatal_nodebug_v1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user