Replace timerfoo macros with timevalfoo since the timer macros are known

to be busted on some systems.
This commit is contained in:
Todd C. Miller
2010-06-08 18:38:23 -04:00
parent 0be6bab05c
commit 79f178923e
9 changed files with 48 additions and 100 deletions

View File

@@ -41,14 +41,14 @@ nanosleep(const struct timespec *ts, struct timespec *rts)
timeout.tv_usec = ts->tv_nsec / 1000; timeout.tv_usec = ts->tv_nsec / 1000;
if (rts != NULL) { if (rts != NULL) {
gettimeofday(&endtime, NULL); gettimeofday(&endtime, NULL);
timeradd(&endtime, &timeout, &endtime); timevaladd(&endtime, &timeout);
} }
rval = select(0, NULL, NULL, NULL, &timeout); rval = select(0, NULL, NULL, NULL, &timeout);
if (rts != NULL && rval == -1 && errno == EINTR) { if (rts != NULL && rval == -1 && errno == EINTR) {
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
timersub(&endtime, &now, &timeout); timevalsub(&endtime, &now);
rts->tv_sec = timeout.tv_sec; rts->tv_sec = endtime.tv_sec;
rts->tv_nsec = timeout.tv_usec * 1000; rts->tv_nsec = endtime.tv_usec * 1000;
} }
return(rval); return(rval);
} }

View File

@@ -541,10 +541,6 @@
/* Define to 1 if you have the <termio.h> header file. */ /* Define to 1 if you have the <termio.h> header file. */
#undef HAVE_TERMIO_H #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 */ /* Define to 1 if you have struct timespec in sys/time.h */
#undef HAVE_TIMESPEC #undef HAVE_TIMESPEC

30
configure vendored
View File

@@ -15393,35 +15393,6 @@ fi
fi 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 fi
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
@@ -20407,6 +20378,5 @@ fi

View File

@@ -1980,15 +1980,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], [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_mtim.st__tim], AC_DEFINE(HAVE_ST__TIM))],
[AC_CHECK_MEMBER([struct stat.st_mtimespec], AC_DEFINE([HAVE_ST_MTIMESPEC]))]) [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 fi
dnl dnl
dnl Check for the dirfd function/macro. If not found, look for dd_fd in DIR. dnl Check for the dirfd function/macro. If not found, look for dd_fd in DIR.
@@ -2831,7 +2822,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_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_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_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(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(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]) AH_TEMPLATE(IGNORE_DOT_PATH, [Define to 1 if you want to ignore '.' and empty PATH elements])

View File

@@ -252,39 +252,39 @@ void setprogname(const char *);
#endif /* HAVE___PROGNAME */ #endif /* HAVE___PROGNAME */
#endif /* !HAVE_GETPROGNAME */ #endif /* !HAVE_GETPROGNAME */
#ifndef timerclear #ifndef timevalclear
# define timerclear(ts) (ts)->tv_sec = (ts)->tv_nsec = 0 # define timevalclear(tv) ((tv)->tv_sec = (tv)->tv_usec = 0)
#endif #endif
#ifndef timerisset #ifndef timevalisset
# define timerisset(ts) ((ts)->tv_sec || (ts)->tv_nsec) # define timevalisset(tv) ((tv)->tv_sec || (tv)->tv_usec)
#endif #endif
#ifndef timeradd #ifndef timevalcmp
# define timeradd(tv1, tv2, total) \ # define timevalcmp(tv1, tv2, op) \
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; \
} \
} while (0)
#endif
#ifndef timersub
# define timersub(minuend, subrahend, difference) \
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; \
} \
} while (0)
#endif
#ifndef timercmp
#define timercmp(tv1, tv2, cmp) \
(((tv1)->tv_sec == (tv2)->tv_sec) ? \ (((tv1)->tv_sec == (tv2)->tv_sec) ? \
((tv1)->tv_usec cmp (tv2)->tv_usec) : \ ((tv1)->tv_usec op (tv2)->tv_usec) : \
((tv1)->tv_sec cmp (tv2)->tv_sec)) ((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 #endif
#ifndef WCOREDUMP #ifndef WCOREDUMP

View File

@@ -612,7 +612,7 @@ timestamp_status(char *timestampdir, char *timestampfile, char *user, int flags)
else else
(void) rmdir(timestampdir); (void) rmdir(timestampdir);
status = TS_MISSING; status = TS_MISSING;
} else if (get_boottime(&boottime) && timercmp(&mtime, &boottime, <)) { } else if (get_boottime(&boottime) && timevalcmp(&mtime, &boottime, <)) {
status = TS_OLD; status = TS_OLD;
} else { } else {
status = TS_CURRENT; status = TS_CURRENT;
@@ -655,7 +655,7 @@ remove_timestamp(int remove)
remove = FALSE; remove = FALSE;
} }
} else { } else {
timerclear(&tv); timevalclear(&tv);
if (touch(-1, path, &tv) == -1) if (touch(-1, path, &tv) == -1)
error(1, "can't reset %s to Epoch", path); error(1, "can't reset %s to Epoch", path);
} }

View File

@@ -335,7 +335,7 @@ sudoers_io_version(int verbose)
static int static int
sudoers_io_log(const char *buf, unsigned int len, int idx) sudoers_io_log(const char *buf, unsigned int len, int idx)
{ {
struct timeval now, tv; struct timeval now, delay;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
@@ -345,15 +345,17 @@ sudoers_io_log(const char *buf, unsigned int len, int idx)
else else
#endif #endif
fwrite(buf, 1, len, io_fds[idx].f); 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 #ifdef HAVE_ZLIB
if (def_compress_io) if (def_compress_io)
gzprintf(io_fds[IOFD_TIMING].g, "%d %f %d\n", idx, 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 else
#endif #endif
fprintf(io_fds[IOFD_TIMING].f, "%d %f %d\n", idx, 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_sec = now.tv_sec;
last_time.tv_usec = now.tv_usec; last_time.tv_usec = now.tv_usec;

View File

@@ -365,19 +365,13 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno)
/* Set modified bit if use changed the file. */ /* Set modified bit if use changed the file. */
modified = TRUE; modified = TRUE;
mtim_get(&sb, &tv); mtim_get(&sb, &tv);
if (orig_size == sb.st_size && if (orig_size == sb.st_size && timevalcmp(&orig_mtim, &tv, ==)) {
orig_mtim.tv_sec == tv.tv_sec &&
orig_mtim.tv_usec == tv.tv_usec) {
/* /*
* If mtime and size match but the user spent no measurable * If mtime and size match but the user spent no measurable
* time in the editor we can't tell if the file was changed. * time in the editor we can't tell if the file was changed.
*/ */
#ifdef HAVE_TIMERSUB2 timevalsub(&tv1, &tv2);
timersub(&tv1, &tv2); if (timevalisset(&tv2))
#else
timersub(&tv1, &tv2, &tv2);
#endif
if (timerisset(&tv2))
modified = FALSE; modified = FALSE;
} }

View File

@@ -277,17 +277,13 @@ sudo_edit(struct command_details *command_details, char *argv[], char *envp[])
continue; continue;
} }
mtim_get(&sb, &tv); 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 * If mtime and size match but the user spent no measurable
* time in the editor we can't tell if the file was changed. * time in the editor we can't tell if the file was changed.
*/ */
#ifdef HAVE_TIMERSUB2 timevalsub(&tv1, &tv2);
timersub(&tv1, &tv2); if (timevalisset(&tv2)) {
#else
timersub(&tv1, &tv2, &tv2);
#endif
if (timerisset(&tv2)) {
warningx("%s unchanged", tf[i].ofile); warningx("%s unchanged", tf[i].ofile);
unlink(tf[i].tfile); unlink(tf[i].tfile);
close(tfd); close(tfd);