Use sudo_timeval macros and remove compat macros from missing.h
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include "fatal.h"
|
||||
#include "sudo_debug.h"
|
||||
#include "sudo_event.h"
|
||||
#include "sudo_util.h"
|
||||
|
||||
/* XXX - use non-exiting allocators? */
|
||||
|
||||
@@ -167,7 +168,7 @@ sudo_ev_add(struct sudo_event_base *base, struct sudo_event *ev,
|
||||
ev->timeout.tv_sec += timo->tv_sec;
|
||||
ev->timeout.tv_usec += timo->tv_usec;
|
||||
TAILQ_FOREACH(evtmp, &base->timeouts, timeouts_entries) {
|
||||
if (timevalcmp(timo, &evtmp->timeout, <))
|
||||
if (sudo_timevalcmp(timo, &evtmp->timeout, <))
|
||||
break;
|
||||
}
|
||||
if (evtmp != NULL) {
|
||||
@@ -275,7 +276,7 @@ rescan:
|
||||
/* Timed out, activate timeout events. */
|
||||
gettimeofday(&now, NULL);
|
||||
while ((ev = TAILQ_FIRST(&base->timeouts)) != NULL) {
|
||||
if (timevalcmp(&ev->timeout, &now, >))
|
||||
if (sudo_timevalcmp(&ev->timeout, &now, >))
|
||||
break;
|
||||
/* Remove from timeouts list. */
|
||||
CLR(ev->flags, SUDO_EVQ_TIMEOUTS);
|
||||
@@ -385,14 +386,13 @@ sudo_ev_get_timeleft(struct sudo_event *ev, struct timeval *tv)
|
||||
debug_decl(sudo_ev_get_timeleft, SUDO_DEBUG_EVENT)
|
||||
|
||||
if (!ISSET(ev->flags, SUDO_EVQ_TIMEOUTS)) {
|
||||
timevalclear(tv);
|
||||
sudo_timevalclear(tv);
|
||||
debug_return_int(-1);
|
||||
}
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
*tv = ev->timeout;
|
||||
timevalsub(tv, &now);
|
||||
sudo_timevalsub(&ev->timeout, &now, tv);
|
||||
if (tv->tv_sec < 0 || (tv->tv_sec == 0 && tv->tv_usec < 0))
|
||||
timevalclear(tv);
|
||||
sudo_timevalclear(tv);
|
||||
debug_return_int(0);
|
||||
}
|
||||
|
@@ -54,6 +54,7 @@
|
||||
#include "fatal.h"
|
||||
#include "sudo_debug.h"
|
||||
#include "sudo_event.h"
|
||||
#include "sudo_util.h"
|
||||
|
||||
/* XXX - use non-exiting allocators? */
|
||||
|
||||
@@ -155,14 +156,13 @@ sudo_ev_scan_impl(struct sudo_event_base *base, int flags)
|
||||
|
||||
if ((ev = TAILQ_FIRST(&base->timeouts)) != NULL) {
|
||||
gettimeofday(&now, NULL);
|
||||
tv = ev->timeout;
|
||||
timevalsub(&tv, &now);
|
||||
sudo_timevalsub(&ev->timeout, &now, &tv);
|
||||
if (tv.tv_sec < 0 || (tv.tv_sec == 0 && tv.tv_usec < 0))
|
||||
timevalclear(&tv);
|
||||
sudo_timevalclear(&tv);
|
||||
timeout = &tv;
|
||||
} else {
|
||||
if (ISSET(flags, SUDO_EVLOOP_NONBLOCK)) {
|
||||
timevalclear(&tv);
|
||||
sudo_timevalclear(&tv);
|
||||
timeout = &tv;
|
||||
} else {
|
||||
timeout = NULL;
|
||||
|
@@ -312,41 +312,6 @@ const char *getprogname(void);
|
||||
extern int errno;
|
||||
#endif /* !HAVE_DECL_ERRNO */
|
||||
|
||||
#ifndef timevalclear
|
||||
# define timevalclear(tv) ((tv)->tv_sec = (tv)->tv_usec = 0)
|
||||
#endif
|
||||
#ifndef timevalisset
|
||||
# define timevalisset(tv) ((tv)->tv_sec || (tv)->tv_usec)
|
||||
#endif
|
||||
#ifndef timevalcmp
|
||||
# define timevalcmp(tv1, tv2, op) \
|
||||
(((tv1)->tv_sec == (tv2)->tv_sec) ? \
|
||||
((tv1)->tv_usec op (tv2)->tv_usec) : \
|
||||
((tv1)->tv_sec op (tv2)->tv_sec))
|
||||
#endif
|
||||
#ifndef timevaladd
|
||||
# define timevaladd(tv1, tv2) \
|
||||
do { \
|
||||
(tv1)->tv_sec += (tv2)->tv_sec; \
|
||||
(tv1)->tv_usec += (tv2)->tv_usec; \
|
||||
if ((tv1)->tv_usec >= 1000000) { \
|
||||
(tv1)->tv_sec++; \
|
||||
(tv1)->tv_usec -= 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
#ifndef timevalsub
|
||||
# define timevalsub(tv1, tv2) \
|
||||
do { \
|
||||
(tv1)->tv_sec -= (tv2)->tv_sec; \
|
||||
(tv1)->tv_usec -= (tv2)->tv_usec; \
|
||||
if ((tv1)->tv_usec < 0) { \
|
||||
(tv1)->tv_sec--; \
|
||||
(tv1)->tv_usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/* Not all systems define NSIG in signal.h */
|
||||
#if !defined(NSIG)
|
||||
# if defined(_NSIG)
|
||||
|
@@ -700,9 +700,7 @@ sudoers_io_log(const char *buf, unsigned int len, int idx)
|
||||
else
|
||||
#endif
|
||||
ignore_result(fwrite(buf, 1, len, io_log_files[idx].fd.f));
|
||||
delay.tv_sec = now.tv_sec;
|
||||
delay.tv_usec = now.tv_usec;
|
||||
timevalsub(&delay, &last_time);
|
||||
sudo_timevalsub(&now, &last_time, &delay);
|
||||
#ifdef HAVE_ZLIB_H
|
||||
if (iolog_compress)
|
||||
gzprintf(io_log_files[IOFD_TIMING].fd.g, "%d %f %u\n", idx,
|
||||
|
@@ -1145,7 +1145,7 @@ check_input(int fd, int what, void *v)
|
||||
if (!paused) {
|
||||
/* Determine remaining timeout, if any. */
|
||||
sudo_ev_get_timeleft(ev, &tv);
|
||||
if (!timevalisset(&tv)) {
|
||||
if (!sudo_timevalisset(&tv)) {
|
||||
/* No time left, event is done. */
|
||||
debug_return;
|
||||
}
|
||||
|
@@ -442,16 +442,15 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno)
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Set modified bit if use changed the file. */
|
||||
/* Set modified bit if the user changed the file. */
|
||||
modified = true;
|
||||
mtim_get(&sb, &tv);
|
||||
if (orig_size == sb.st_size && timevalcmp(&orig_mtim, &tv, ==)) {
|
||||
if (orig_size == sb.st_size && sudo_timevalcmp(&orig_mtim, &tv, ==)) {
|
||||
/*
|
||||
* If mtime and size match but the user spent no measurable
|
||||
* time in the editor we can't tell if the file was changed.
|
||||
*/
|
||||
timevalsub(&tv1, &tv2);
|
||||
if (timevalisset(&tv2))
|
||||
if (sudo_timevalcmp(&tv1, &tv2, !=))
|
||||
modified = false;
|
||||
}
|
||||
|
||||
|
@@ -274,13 +274,12 @@ sudo_edit(struct command_details *command_details)
|
||||
continue;
|
||||
}
|
||||
mtim_get(&sb, &tv);
|
||||
if (tf[i].osize == sb.st_size && timevalcmp(&tf[i].omtim, &tv, ==)) {
|
||||
if (tf[i].osize == sb.st_size && sudo_timevalcmp(&tf[i].omtim, &tv, ==)) {
|
||||
/*
|
||||
* If mtime and size match but the user spent no measurable
|
||||
* time in the editor we can't tell if the file was changed.
|
||||
*/
|
||||
timevalsub(&tv1, &tv2);
|
||||
if (timevalisset(&tv2)) {
|
||||
if (sudo_timevalcmp(&tv1, &tv2, !=)) {
|
||||
warningx(U_("%s unchanged"), tf[i].ofile);
|
||||
unlink(tf[i].tfile);
|
||||
close(tfd);
|
||||
|
Reference in New Issue
Block a user