Use sudo_timeval macros and remove compat macros from missing.h
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 30 Jan 2014 22:51:59 +0000 (15:51 -0700)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 30 Jan 2014 22:51:59 +0000 (15:51 -0700)
common/event.c
common/event_select.c
include/missing.h
plugins/sudoers/iolog.c
plugins/sudoers/sudoreplay.c
plugins/sudoers/visudo.c
src/sudo_edit.c

index 6135c71dc7530412e081241a682957dedac45eca..f1fdf14cd66bd6135698c3ec24d0803bba865fb5 100644 (file)
@@ -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);
 }
index 1d3179dbc1a03d289908634fee7f16cac76f3c8a..bac3b4d9f888b96def04fad06cc5b0d3e3d686fe 100644 (file)
@@ -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;
index 26cf5062b8f9b71d70822825371dc1ea5b046df8..65512c953b52207a66f4c721ff6694552394b64c 100644 (file)
@@ -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)
index f322bcaae861b8a821ef8576292fd56e564ae021..488d2348466ae059bc78f191c26ce316439db304 100644 (file)
@@ -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,
index 024e4cdc9001a059e81135345025ba10339aa71e..aac879236c2be733d40fbfb31a10ad947e723367 100644 (file)
@@ -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;
            }
index 841322bf39ce7e92045c78ca859f71ec14e84131..e80064188b3934dca7cf57e9bf8ecb18c649478f 100644 (file)
@@ -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;
     }
 
index 0489dec22d97e424f68d878fa5d6ae6201534bd4..6d2542dc4fc629f89976be88b61036a4aac12b75 100644 (file)
@@ -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);