]> granicus.if.org Git - sudo/commitdiff
Replace timerfoo macros with timevalfoo since the timer macros are known
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 8 Jun 2010 22:50:10 +0000 (18:50 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 8 Jun 2010 22:50:10 +0000 (18:50 -0400)
to be busted on some systems.

--HG--
branch : 1.7

check.c
compat.h
config.h.in
configure
configure.in
iolog.c
nanosleep.c
sudo_edit.c
visudo.c

diff --git a/check.c b/check.c
index c462682d7f405f9d1367edea5a7ed6a1f9ce06c8..9f799e50eca298f2422150f2dd1ccec88ab14cbf 100644 (file)
--- a/check.c
+++ b/check.c
@@ -600,7 +600,7 @@ timestamp_status(timestampdir, timestampfile, user, flags)
                    else
                        (void) rmdir(timestampdir);
                    status = TS_MISSING;
-               } else if (get_boottime(&boottime) && timercmp(&mtime, &boottime, <)) {
+               } else if (get_boottime(&boottime) && timevalcmp(&mtime, &boottime, <)) {
                    status = TS_OLD;
                } else {
                    status = TS_CURRENT;
@@ -642,7 +642,7 @@ remove_timestamp(remove)
                remove = FALSE;
            }
        } else {
-           timerclear(&tv);
+           timevalclear(&tv);
            if (touch(-1, path, &tv) == -1)
                error(1, "can't reset %s to Epoch", path);
        }
index b5da2639c4d61dabc3c7e618b7cca3e9d1f24c4b..adba862d4fa20ca0fd9af096aee5e6b3653bbbcb 100644 (file)
--- a/compat.h
+++ b/compat.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 1998-2005, 2008
+ * Copyright (c) 1996, 1998-2005, 2008, 2010
  *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -260,31 +260,37 @@ const char *getprogname __P((void));
 #endif /* HAVE___PROGNAME */
 #endif /* !HAVE_GETPROGNAME */
 
-#ifndef timerclear
-# define timerclear(ts)        (ts)->tv_sec = (ts)->tv_nsec = 0
+#ifndef timevalclear
+# define timevalclear(tv)      ((tv)->tv_sec = (tv)->tv_usec = 0)
 #endif
-#ifndef timerisset
-# define timerisset(ts)        ((ts)->tv_sec || (ts)->tv_nsec)
+#ifndef timevalisset
+# define timevalisset(tv)      ((tv)->tv_sec || (tv)->tv_usec)
 #endif
-#ifndef timeradd
-# define timeradd(tv1, tv2, total)                                            \
+#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 {                                                                      \
-       (total)->tv_sec = (tv1)->tv_sec + (tv2)->tv_sec;                       \
-       (total)->tv_usec = (tv1)->tv_usec + (tv2)->tv_usec;                    \
-       if ((total)->tv_usec >= 1000000) {                                     \
-           (total)->tv_sec++;                                                 \
-           (total)->tv_usec -= 1000000;                                       \
+       (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 timersub
-# define timersub(minuend, subrahend, difference)                             \
+#ifndef timevalsub
+# define timevalsub(tv1, tv2)                                                 \
     do {                                                                      \
-       (difference)->tv_sec = (minuend)->tv_sec - (subrahend)->tv_sec;        \
-       (difference)->tv_usec = (minuend)->tv_usec - (subrahend)->tv_usec;     \
-       if ((difference)->tv_usec < 0) {                                       \
-           (difference)->tv_sec--;                                            \
-           (difference)->tv_usec += 1000000;                                  \
+       (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
index 4ebc7c5ed2acbd4bdbc57109c0ec175bc4e461f2..776ad8a4751d9aa904d3c2e1359ea0e1db403328 100644 (file)
 /* Define to 1 if you have the <termio.h> header file. */
 #undef HAVE_TERMIO_H
 
-/* Define to 1 if you have a timersub macro or function that takes two
-   arguments (not three) */
-#undef HAVE_TIMERSUB2
-
 /* Define to 1 if you have struct timespec in sys/time.h */
 #undef HAVE_TIMESPEC
 
index c1f80a423bf23da4e991759e51f44a78e2ee0352..7ae3b4546ffb64e74072841ef445b84afdb0de24 100755 (executable)
--- a/configure
+++ b/configure
 
 fi
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for two-parameter timersub" >&5
-$as_echo_n "checking for two-parameter timersub... " >&6; }
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/types.h>
-#include <sys/time.h>
-int
-main ()
-{
-struct timeval ts1, ts2;
-ts1.tv_sec = 1; ts1.tv_usec = 0; ts2.tv_sec = 0; ts2.tv_usec = 0;
-#ifndef timersub
-#error missing timersub
-#endif
-timersub(&ts1, &ts2);
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  $as_echo "#define HAVE_TIMERSUB2 1" >>confdefs.h
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -20403,6 +20374,5 @@ fi
 
 
 
-
 
 
index 46e085ad0f8d50033585bbac0442acc1d4fc933b..aa018104b6a6a6e7aba971b9bb1996739079acc6 100644 (file)
@@ -1941,15 +1941,6 @@ if test X"$ac_cv_type_struct_timespec" != X"no"; then
     AC_CHECK_MEMBER([struct stat.st_mtim], [AC_DEFINE(HAVE_ST_MTIM)]
        [AC_CHECK_MEMBER([struct stat.st_mtim.st__tim], AC_DEFINE(HAVE_ST__TIM))],
        [AC_CHECK_MEMBER([struct stat.st_mtimespec], AC_DEFINE([HAVE_ST_MTIMESPEC]))])
-    AC_MSG_CHECKING([for two-parameter timersub])
-    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
-#include <sys/time.h>]], [[struct timeval ts1, ts2;
-ts1.tv_sec = 1; ts1.tv_usec = 0; ts2.tv_sec = 0; ts2.tv_usec = 0;
-#ifndef timersub
-#error missing timersub
-#endif
-timersub(&ts1, &ts2);]])], [AC_DEFINE(HAVE_TIMERSUB2)
-    AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])
 fi
 dnl
 dnl Check for the dirfd function/macro.  If not found, look for dd_fd in DIR.
@@ -2811,7 +2802,6 @@ AH_TEMPLATE(HAVE_ST_MTIM, [Define to 1 if your struct stat has an st_mtim member
 AH_TEMPLATE(HAVE_ST_MTIMESPEC, [Define to 1 if your struct stat has an st_mtimespec member])
 AH_TEMPLATE(HAVE_TERMIOS_H, [Define to 1 if you have the <termios.h> header file and the `tcgetattr' function.])
 AH_TEMPLATE(HAVE_TIMESPEC, [Define to 1 if you have struct timespec in sys/time.h])
-AH_TEMPLATE(HAVE_TIMERSUB2, [Define to 1 if you have a timersub macro or function that takes two arguments (not three)])
 AH_TEMPLATE(HAVE___PROGNAME, [Define to 1 if your crt0.o defines the __progname symbol for you.])
 AH_TEMPLATE(HOST_IN_LOG, [Define to 1 if you want the hostname to be entered into the log file.])
 AH_TEMPLATE(IGNORE_DOT_PATH, [Define to 1 if you want to ignore '.' and empty PATH elements])
diff --git a/iolog.c b/iolog.c
index 51287602fc52f30cc929b9a989db5605bf04a159..e67bd3fed5da5b967d16107cf13d5b84c8bd08f6 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -322,7 +322,7 @@ log_io(buf, len, idx)
     unsigned int len;
     int idx;
 {
-    struct timeval now, tv;
+    struct timeval now, delay;
     sigset_t omask;
 
     gettimeofday(&now, NULL);
@@ -335,15 +335,17 @@ log_io(buf, len, idx)
     else
 #endif
        fwrite(buf, 1, len, io_fds[idx].f);
-    timersub(&now, &last_time, &tv);
+    delay.tv_sec = now.tv_sec;
+    delay.tv_usec = now.tv_usec;
+    timevalsub(&delay, &last_time);
 #ifdef HAVE_ZLIB
     if (def_compress_io)
        gzprintf(io_fds[IOFD_TIMING].g, "%d %f %d\n", idx,
-           tv.tv_sec + ((double)tv.tv_usec / 1000000), len);
+           delay.tv_sec + ((double)delay.tv_usec / 1000000), len);
     else
 #endif
        fprintf(io_fds[IOFD_TIMING].f, "%d %f %d\n", idx,
-           tv.tv_sec + ((double)tv.tv_usec / 1000000), len);
+           delay.tv_sec + ((double)delay.tv_usec / 1000000), len);
     last_time.tv_sec = now.tv_sec;
     last_time.tv_usec = now.tv_usec;
 
index 24aca7579c88eeebc2c2e97a8ae06442331261f3..932f342ea83717319585c27046110b0a858b92e2 100644 (file)
@@ -43,14 +43,14 @@ nanosleep(ts, rts)
     timeout.tv_usec = ts->tv_nsec / 1000;
     if (rts != NULL) {
        gettimeofday(&endtime, NULL);
-       timeradd(&endtime, &timeout, &endtime);
+       timevaladd(&endtime, &timeout);
     }
     rval = select(0, NULL, NULL, NULL, &timeout);
     if (rts != NULL && rval == -1 && errno == EINTR) {
        gettimeofday(&now, NULL);
-       timersub(&endtime, &now, &timeout);
-       rts->tv_sec = timeout.tv_sec;
-       rts->tv_nsec = timeout.tv_usec * 1000;
+       timevalsub(&endtime, &now);
+       rts->tv_sec = endtime.tv_sec;
+       rts->tv_nsec = endtime.tv_usec * 1000;
     }
     return(rval);
 }
index 80e053567b536418d6a0b7ac8fc9b4e9ad1e0147..59dbd9db94bd1fea2acd3c0da33c2360d59af002 100644 (file)
@@ -231,17 +231,13 @@ sudo_edit(argc, argv, envp)
            continue;
        }
        mtim_get(&sb, &tv);
-       if (tf[i].osize == sb.st_size && timercmp(&tf[i].omtim, &tv, ==)) {
+       if (tf[i].osize == sb.st_size && 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.
             */
-#ifdef HAVE_TIMERSUB2
-           timersub(&tv1, &tv2);
-#else
-           timersub(&tv1, &tv2, &tv2);
-#endif
-           if (timerisset(&tv2)) {
+           timevalsub(&tv1, &tv2);
+           if (timevalisset(&tv2)) {
                warningx("%s unchanged", tf[i].ofile);
                unlink(tf[i].tfile);
                close(tfd);
index 2ecf269625991ab3f09c0f61ebeb2db2a84f5652..8fe920b2d8d3cef8db23ed1000fd2b1be5633842 100644 (file)
--- a/visudo.c
+++ b/visudo.c
@@ -368,19 +368,13 @@ edit_sudoers(sp, editor, args, lineno)
     /* Set modified bit if use changed the file. */
     modified = TRUE;
     mtim_get(&sb, &tv);
-    if (orig_size == sb.st_size &&
-       orig_mtim.tv_sec == tv.tv_sec &&
-       orig_mtim.tv_usec == tv.tv_usec) {
+    if (orig_size == sb.st_size && 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.
         */
-#ifdef HAVE_TIMERSUB2
-       timersub(&tv1, &tv2);
-#else
-       timersub(&tv1, &tv2, &tv2);
-#endif
-       if (timerisset(&tv2))
+       timevalsub(&tv1, &tv2);
+       if (timevalisset(&tv2))
            modified = FALSE;
     }