From: Todd C. Miller Date: Tue, 20 Apr 2010 20:44:02 +0000 (-0400) Subject: Use timeval directly instead of converting to timespec when dealing X-Git-Tag: SUDO_1_8_0~712 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4a26b7691fd8c3a91cff21acaabaee6500b0f68;p=sudo Use timeval directly instead of converting to timespec when dealing with file times and time of day. --- diff --git a/config.h.in b/config.h.in index 85fbb7779..ac410948f 100644 --- a/config.h.in +++ b/config.h.in @@ -543,7 +543,7 @@ /* Define to 1 if you have a timespecsub macro or function that takes two arguments (not three) */ -#undef HAVE_TIMESPECSUB2 +#undef HAVE_TIMERSUB2 /* Define to 1 if you have the `tzset' function. */ #undef HAVE_TZSET @@ -778,25 +778,23 @@ #undef volatile /* - * Macros to pull sec and nsec parts of mtime from struct stat. - * We need to be able to convert between timeval and timespec - * so the last 3 digits of tv_nsec are not significant. + * Macros to convert ctime and mtime into timevals. */ #ifdef HAVE_ST_MTIM # ifdef HAVE_ST__TIM -# define mtim_getsec(_x) ((_x).st_mtim.st__tim.tv_sec) -# define mtim_getnsec(_x) (((_x).st_mtim.st__tim.tv_nsec / 1000) * 1000) +# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctim.st__tim.tv_sec; (_y)->tv_usec = (_x)->st_ctim.st__tim.tv_usec / 1000; } while (0) +# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtim.st__tim.tv_sec; (_y)->tv_usec = (_x)->st_mtim.st__tim.tv_usec / 1000; } while (0) # else -# define mtim_getsec(_x) ((_x).st_mtim.tv_sec) -# define mtim_getnsec(_x) (((_x).st_mtim.tv_nsec / 1000) * 1000) +# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctim.tv_sec; (_y)->tv_usec = (_x)->st_ctim.tv_usec / 1000; } while (0) +# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtim.tv_sec; (_y)->tv_usec = (_x)->st_mtim.tv_usec / 1000; } while (0) # endif #else # ifdef HAVE_ST_MTIMESPEC -# define mtim_getsec(_x) ((_x).st_mtimespec.tv_sec) -# define mtim_getnsec(_x) (((_x).st_mtimespec.tv_nsec / 1000) * 1000) +# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctimespec.tv_sec; (_y)->tv_usec = (_x)->st_ctimespec.tv_usec / 1000; } while (0) +# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtimespec.tv_sec; (_y)->tv_usec = (_x)->st_mtimespec.tv_usec / 1000; } while (0) # else -# define mtim_getsec(_x) ((_x).st_mtime) -# define mtim_getnsec(_x) (0) +# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctime; (_y)->tv_usec = 0; } while (0) +# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtime; (_y)->tv_usec = 0; } while (0) # endif /* HAVE_ST_MTIMESPEC */ #endif /* HAVE_ST_MTIM */ diff --git a/configure b/configure index c5faf6db7..07cbb657b 100755 --- a/configure +++ b/configure @@ -1460,7 +1460,7 @@ Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] - --sysconfdir=DIR read-only single-machine data [etc] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] @@ -6871,7 +6871,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else ac_cv_header_stdc=no fi -rm -f conftest* +rm -f -r conftest* fi @@ -6892,7 +6892,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else ac_cv_header_stdc=no fi -rm -f conftest* +rm -f -r conftest* fi @@ -13184,7 +13184,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else ac_cv_prog_gcc_traditional=no fi -rm -f conftest* +rm -f -r conftest* if test $ac_cv_prog_gcc_traditional = no; then @@ -13201,7 +13201,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "$ac_pattern" >/dev/null 2>&1; then ac_cv_prog_gcc_traditional=yes fi -rm -f conftest* +rm -f -r conftest* fi fi @@ -13723,7 +13723,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else ac_cv_header_stdc=no fi -rm -f conftest* +rm -f -r conftest* fi @@ -13744,7 +13744,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else ac_cv_header_stdc=no fi -rm -f conftest* +rm -f -r conftest* fi @@ -14873,7 +14873,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else ac_cv_type_uid_t=no fi -rm -f conftest* +rm -f -r conftest* fi { echo "$as_me:$LINENO: result: $ac_cv_type_uid_t" >&5 @@ -15303,7 +15303,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else sudo_cv_type_size_t=no fi -rm -f conftest* +rm -f -r conftest* fi { echo "$as_me:$LINENO: result: $sudo_cv_type_size_t" >&5 @@ -15342,7 +15342,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else sudo_cv_type_ssize_t=no fi -rm -f conftest* +rm -f -r conftest* fi { echo "$as_me:$LINENO: result: $sudo_cv_type_ssize_t" >&5 @@ -15381,7 +15381,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else sudo_cv_type_dev_t=no fi -rm -f conftest* +rm -f -r conftest* fi { echo "$as_me:$LINENO: result: $sudo_cv_type_dev_t" >&5 @@ -15420,7 +15420,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else sudo_cv_type_ino_t=no fi -rm -f conftest* +rm -f -r conftest* fi { echo "$as_me:$LINENO: result: $sudo_cv_type_ino_t" >&5 @@ -15862,7 +15862,7 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | else ac_cv_type_getgroups=int fi -rm -f conftest* +rm -f -r conftest* fi fi @@ -20522,8 +20522,8 @@ fi fi - { echo "$as_me:$LINENO: checking for two-parameter timespecsub" >&5 -echo $ECHO_N "checking for two-parameter timespecsub... $ECHO_C" >&6; } + { echo "$as_me:$LINENO: checking for two-parameter timersub" >&5 +echo $ECHO_N "checking for two-parameter timersub... $ECHO_C" >&6; } cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF @@ -20535,12 +20535,12 @@ cat >>conftest.$ac_ext <<_ACEOF int main () { -struct timespec ts1, ts2; -ts1.tv_sec = 1; ts1.tv_nsec = 0; ts2.tv_sec = 0; ts2.tv_nsec = 0; -#ifndef timespecsub -#error missing timespecsub +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 -timespecsub(&ts1, &ts2); +timersub(&ts1, &ts2); ; return 0; } @@ -20563,7 +20563,7 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 test ! -s conftest.err } && test -s conftest.$ac_objext; then cat >>confdefs.h <<\_ACEOF -#define HAVE_TIMESPECSUB2 1 +#define HAVE_TIMERSUB2 1 _ACEOF { echo "$as_me:$LINENO: result: yes" >&5 @@ -20895,7 +20895,7 @@ else echo "$as_me: WARNING: unable to find socket() trying -lsocket -lnsl" >&2;} { echo "$as_me:$LINENO: checking for socket in -lsocket" >&5 echo $ECHO_N "checking for socket in -lsocket... $ECHO_C" >&6; } -if test "${ac_cv_lib_socket_socket_lnsl+set}" = set; then +if test "${ac_cv_lib_socket_socket+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else ac_check_lib_save_LIBS=$LIBS @@ -20940,21 +20940,21 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && $as_test_x conftest$ac_exeext; then - ac_cv_lib_socket_socket_lnsl=yes + ac_cv_lib_socket_socket=yes else echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_cv_lib_socket_socket_lnsl=no + ac_cv_lib_socket_socket=no fi rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ echo "$as_me:$LINENO: result: $ac_cv_lib_socket_socket_lnsl" >&5 -echo "${ECHO_T}$ac_cv_lib_socket_socket_lnsl" >&6; } -if test $ac_cv_lib_socket_socket_lnsl = yes; then +{ echo "$as_me:$LINENO: result: $ac_cv_lib_socket_socket" >&5 +echo "${ECHO_T}$ac_cv_lib_socket_socket" >&6; } +if test $ac_cv_lib_socket_socket = yes; then NET_LIBS="${NET_LIBS} -lsocket -lnsl"; LIBS="${LIBS} -lsocket -lnsl" fi @@ -21264,7 +21264,7 @@ else echo "$as_me: WARNING: unable to find inet_addr() trying -lsocket -lnsl" >&2;} { echo "$as_me:$LINENO: checking for inet_addr in -lsocket" >&5 echo $ECHO_N "checking for inet_addr in -lsocket... $ECHO_C" >&6; } -if test "${ac_cv_lib_socket_inet_addr_lnsl+set}" = set; then +if test "${ac_cv_lib_socket_inet_addr+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else ac_check_lib_save_LIBS=$LIBS @@ -21309,21 +21309,21 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && $as_test_x conftest$ac_exeext; then - ac_cv_lib_socket_inet_addr_lnsl=yes + ac_cv_lib_socket_inet_addr=yes else echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_cv_lib_socket_inet_addr_lnsl=no + ac_cv_lib_socket_inet_addr=no fi rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ echo "$as_me:$LINENO: result: $ac_cv_lib_socket_inet_addr_lnsl" >&5 -echo "${ECHO_T}$ac_cv_lib_socket_inet_addr_lnsl" >&6; } -if test $ac_cv_lib_socket_inet_addr_lnsl = yes; then +{ echo "$as_me:$LINENO: result: $ac_cv_lib_socket_inet_addr" >&5 +echo "${ECHO_T}$ac_cv_lib_socket_inet_addr" >&6; } +if test $ac_cv_lib_socket_inet_addr = yes; then NET_LIBS="${NET_LIBS} -lsocket -lnsl"; LIBS="${LIBS} -lsocket -lnsl" fi @@ -22820,7 +22820,7 @@ if test ${with_SecurID-'no'} != "no"; then # { echo "$as_me:$LINENO: checking for SD_Init in -laceclnt" >&5 echo $ECHO_N "checking for SD_Init in -laceclnt... $ECHO_C" >&6; } -if test "${ac_cv_lib_aceclnt_SD_Init_______lpthread_______+set}" = set; then +if test "${ac_cv_lib_aceclnt_SD_Init+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else ac_check_lib_save_LIBS=$LIBS @@ -22868,21 +22868,21 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && $as_test_x conftest$ac_exeext; then - ac_cv_lib_aceclnt_SD_Init_______lpthread_______=yes + ac_cv_lib_aceclnt_SD_Init=yes else echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_cv_lib_aceclnt_SD_Init_______lpthread_______=no + ac_cv_lib_aceclnt_SD_Init=no fi rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ echo "$as_me:$LINENO: result: $ac_cv_lib_aceclnt_SD_Init_______lpthread_______" >&5 -echo "${ECHO_T}$ac_cv_lib_aceclnt_SD_Init_______lpthread_______" >&6; } -if test $ac_cv_lib_aceclnt_SD_Init_______lpthread_______ = yes; then +{ echo "$as_me:$LINENO: result: $ac_cv_lib_aceclnt_SD_Init" >&5 +echo "${ECHO_T}$ac_cv_lib_aceclnt_SD_Init" >&6; } +if test $ac_cv_lib_aceclnt_SD_Init = yes; then AUTH_OBJS="$AUTH_OBJS securid5.lo"; SUDO_LIBS="${SUDO_LIBS} -laceclnt -lpthread" @@ -23369,10 +23369,9 @@ echo "${ECHO_T}no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - as_ac_Lib=`echo "ac_cv_lib_krb_main$K4LIBS" | $as_tr_sh` -{ echo "$as_me:$LINENO: checking for main in -lkrb" >&5 + { echo "$as_me:$LINENO: checking for main in -lkrb" >&5 echo $ECHO_N "checking for main in -lkrb... $ECHO_C" >&6; } -if { as_var=$as_ac_Lib; eval "test \"\${$as_var+set}\" = set"; }; then +if test "${ac_cv_lib_krb_main+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else ac_check_lib_save_LIBS=$LIBS @@ -23411,29 +23410,27 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && $as_test_x conftest$ac_exeext; then - eval "$as_ac_Lib=yes" + ac_cv_lib_krb_main=yes else echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - eval "$as_ac_Lib=no" + ac_cv_lib_krb_main=no fi rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -ac_res=`eval echo '${'$as_ac_Lib'}'` - { echo "$as_me:$LINENO: result: $ac_res" >&5 -echo "${ECHO_T}$ac_res" >&6; } -if test `eval echo '${'$as_ac_Lib'}'` = yes; then +{ echo "$as_me:$LINENO: result: $ac_cv_lib_krb_main" >&5 +echo "${ECHO_T}$ac_cv_lib_krb_main" >&6; } +if test $ac_cv_lib_krb_main = yes; then K4LIBS="-lkrb $K4LIBS" else - as_ac_Lib=`echo "ac_cv_lib_krb4_main$K4LIBS" | $as_tr_sh` -{ echo "$as_me:$LINENO: checking for main in -lkrb4" >&5 + { echo "$as_me:$LINENO: checking for main in -lkrb4" >&5 echo $ECHO_N "checking for main in -lkrb4... $ECHO_C" >&6; } -if { as_var=$as_ac_Lib; eval "test \"\${$as_var+set}\" = set"; }; then +if test "${ac_cv_lib_krb4_main+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else ac_check_lib_save_LIBS=$LIBS @@ -23472,22 +23469,21 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 test ! -s conftest.err } && test -s conftest$ac_exeext && $as_test_x conftest$ac_exeext; then - eval "$as_ac_Lib=yes" + ac_cv_lib_krb4_main=yes else echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - eval "$as_ac_Lib=no" + ac_cv_lib_krb4_main=no fi rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -ac_res=`eval echo '${'$as_ac_Lib'}'` - { echo "$as_me:$LINENO: result: $ac_res" >&5 -echo "${ECHO_T}$ac_res" >&6; } -if test `eval echo '${'$as_ac_Lib'}'` = yes; then +{ echo "$as_me:$LINENO: result: $ac_cv_lib_krb4_main" >&5 +echo "${ECHO_T}$ac_cv_lib_krb4_main" >&6; } +if test $ac_cv_lib_krb4_main = yes; then K4LIBS="-lkrb4 $K4LIBS" else K4LIBS="-lkrb $K4LIBS" diff --git a/configure.in b/configure.in index d811a3d10..10ac91810 100644 --- a/configure.in +++ b/configure.in @@ -1964,14 +1964,14 @@ 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 timespecsub]) + AC_MSG_CHECKING([for two-parameter timersub]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include -#include ]], [[struct timespec ts1, ts2; -ts1.tv_sec = 1; ts1.tv_nsec = 0; ts2.tv_sec = 0; ts2.tv_nsec = 0; -#ifndef timespecsub -#error missing timespecsub +#include ]], [[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 -timespecsub(&ts1, &ts2);]])], [AC_DEFINE(HAVE_TIMESPECSUB2) +timersub(&ts1, &ts2);]])], [AC_DEFINE(HAVE_TIMERSUB2) AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)]) fi dnl @@ -2825,25 +2825,23 @@ AH_TOP([#ifndef _SUDO_CONFIG_H #define _SUDO_CONFIG_H]) AH_BOTTOM([/* - * Macros to pull sec and nsec parts of mtime from struct stat. - * We need to be able to convert between timeval and timespec - * so the last 3 digits of tv_nsec are not significant. + * Macros to convert ctime and mtime into timevals. */ #ifdef HAVE_ST_MTIM # ifdef HAVE_ST__TIM -# define mtim_getsec(_x) ((_x).st_mtim.st__tim.tv_sec) -# define mtim_getnsec(_x) (((_x).st_mtim.st__tim.tv_nsec / 1000) * 1000) +# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctim.st__tim.tv_sec; (_y)->tv_usec = (_x)->st_ctim.st__tim.tv_usec / 1000; } while (0) +# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtim.st__tim.tv_sec; (_y)->tv_usec = (_x)->st_mtim.st__tim.tv_usec / 1000; } while (0) # else -# define mtim_getsec(_x) ((_x).st_mtim.tv_sec) -# define mtim_getnsec(_x) (((_x).st_mtim.tv_nsec / 1000) * 1000) +# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctim.tv_sec; (_y)->tv_usec = (_x)->st_ctim.tv_usec / 1000; } while (0) +# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtim.tv_sec; (_y)->tv_usec = (_x)->st_mtim.tv_usec / 1000; } while (0) # endif #else # ifdef HAVE_ST_MTIMESPEC -# define mtim_getsec(_x) ((_x).st_mtimespec.tv_sec) -# define mtim_getnsec(_x) (((_x).st_mtimespec.tv_nsec / 1000) * 1000) +# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctimespec.tv_sec; (_y)->tv_usec = (_x)->st_ctimespec.tv_usec / 1000; } while (0) +# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtimespec.tv_sec; (_y)->tv_usec = (_x)->st_mtimespec.tv_usec / 1000; } while (0) # else -# define mtim_getsec(_x) ((_x).st_mtime) -# define mtim_getnsec(_x) (0) +# define ctim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_ctime; (_y)->tv_usec = 0; } while (0) +# define mtim_get(_x, _y) do { (_y)->tv_sec = (_x)->st_mtime; (_y)->tv_usec = 0; } while (0) # endif /* HAVE_ST_MTIMESPEC */ #endif /* HAVE_ST_MTIM */ diff --git a/include/compat.h b/include/compat.h index 2fc9ad446..3e332ca52 100644 --- a/include/compat.h +++ b/include/compat.h @@ -252,24 +252,12 @@ void setprogname(const char *); #endif /* HAVE___PROGNAME */ #endif /* !HAVE_GETPROGNAME */ -#ifndef timespecclear -# define timespecclear(ts) (ts)->tv_sec = (ts)->tv_nsec = 0 +#ifndef timerclear +# define timerclear(ts) (ts)->tv_sec = (ts)->tv_nsec = 0 #endif -#ifndef timespecisset -# define timespecisset(ts) ((ts)->tv_sec || (ts)->tv_nsec) +#ifndef timerisset +# define timerisset(ts) ((ts)->tv_sec || (ts)->tv_nsec) #endif -#ifndef timespecsub -# define timespecsub(minuend, subrahend, difference) \ - do { \ - (difference)->tv_sec = (minuend)->tv_sec - (subrahend)->tv_sec; \ - (difference)->tv_nsec = (minuend)->tv_nsec - (subrahend)->tv_nsec; \ - if ((difference)->tv_nsec < 0) { \ - (difference)->tv_nsec += 1000000000L; \ - (difference)->tv_sec--; \ - } \ - } while (0) -#endif - #ifndef timeradd # define timeradd(tv1, tv2, total) \ do { \ @@ -281,7 +269,6 @@ void setprogname(const char *); } \ } while (0) #endif - #ifndef timersub # define timersub(minuend, subrahend, difference) \ do { \ diff --git a/plugins/sudoers/check.c b/plugins/sudoers/check.c index 8aafa28aa..84576ff99 100644 --- a/plugins/sudoers/check.c +++ b/plugins/sudoers/check.c @@ -23,6 +23,7 @@ #include #include +#include #include #ifndef __TANDEM # include @@ -46,15 +47,14 @@ #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ +#if TIME_WITH_SYS_TIME +# include +#endif #include #include #include -#include #include #include -#ifndef HAVE_TIMESPEC -# include -#endif #include "sudoers.h" @@ -560,7 +560,7 @@ timestamp_status(timestampdir, timestampfile, user, flags) if (def_timestamp_timeout < 0 && sb.st_mtime != 0) status = TS_CURRENT; else { - /* XXX - should use timespec here */ + /* XXX - should use timeval here */ now = time(NULL); boottime = get_boottime(); if (def_timestamp_timeout && @@ -600,7 +600,7 @@ void remove_timestamp(remove) int remove; { - struct timespec ts; + struct timeval tv; char *timestampdir, *timestampfile, *path; int status; @@ -622,8 +622,8 @@ remove_timestamp(remove) remove = FALSE; } } else { - timespecclear(&ts); - if (touch(-1, path, &ts) == -1) + timerclear(&tv); + if (touch(-1, path, &tv) == -1) error(1, "can't reset %s to Epoch", path); } } diff --git a/plugins/sudoers/gettime.c b/plugins/sudoers/gettime.c index 3e9ec43ae..1f498dbc4 100644 --- a/plugins/sudoers/gettime.c +++ b/plugins/sudoers/gettime.c @@ -22,9 +22,6 @@ #if TIME_WITH_SYS_TIME # include #endif -#ifndef HAVE_TIMESPEC -# include -#endif #include @@ -33,19 +30,15 @@ * timespecs in struct stat or, otherwise, using time(). */ int -gettime(ts) - struct timespec *ts; +gettime(tv) + struct timeval *tv; { int rval; #if defined(HAVE_GETTIMEOFDAY) && (defined(HAVE_ST_MTIM) || defined(HAVE_ST_MTIMESPEC)) - struct timeval tv; - - rval = gettimeofday(&tv, NULL); - ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec * 1000; + rval = gettimeofday(tv, NULL); #else - rval = (int)time(&ts->tv_sec); - ts->tv_nsec = 0; + rval = (int)time(&tv->tv_sec); + tv->tv_usec = 0; #endif return (rval); } diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index 2776953af..494a15fd2 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -247,13 +247,13 @@ void pass_warn(void); void dump_defaults(void); void dump_auth_methods(void); int lock_file(int, int); -int touch(int, char *, struct timespec *); +int touch(int, char *, struct timeval *); int user_is_exempt(void); void set_fqdn(void); char *sudo_getepw(const struct passwd *); int pam_prep_user(struct passwd *); void zero_bytes(volatile void *, size_t); -int gettime(struct timespec *); +int gettime(struct timeval *); FILE *open_sudoers(const char *, int, int *); void display_privs(struct sudo_nss_list *, struct passwd *); int display_cmnd(struct sudo_nss_list *, struct passwd *); diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 5d20135a1..9a7b14692 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -76,9 +76,6 @@ #else # include #endif -#ifndef HAVE_TIMESPEC -# include -#endif #include "sudoers.h" #include "interfaces.h" @@ -266,8 +263,8 @@ edit_sudoers(sp, editor, args, lineno) char *cp; /* scratch char pointer */ char buf[PATH_MAX*2]; /* buffer used for copying files */ char linestr[64]; /* string version of lineno */ - struct timespec ts1, ts2; /* time before and after edit */ - struct timespec orig_mtim; /* starting mtime of sudoers file */ + struct timeval tv, tv1, tv2; /* time before and after edit */ + struct timeval orig_mtim; /* starting mtime of sudoers file */ off_t orig_size; /* starting size of sudoers file */ ssize_t nread; /* number of bytes read */ struct stat sb; /* stat buffer */ @@ -279,8 +276,7 @@ edit_sudoers(sp, editor, args, lineno) #endif error(1, "can't stat %s", sp->path); orig_size = sb.st_size; - orig_mtim.tv_sec = mtim_getsec(sb); - orig_mtim.tv_nsec = mtim_getnsec(sb); + mtim_get(&sb, &orig_mtim); /* Create the temp file if needed and set timestamp. */ if (sp->tpath == NULL) { @@ -346,9 +342,9 @@ edit_sudoers(sp, editor, args, lineno) * XPG4 specifies that vi's exit value is a function of the * number of errors during editing (?!?!). */ - gettime(&ts1); + gettime(&tv1); if (run_command(editor, av) != -1) { - gettime(&ts2); + gettime(&tv2); /* * Sanity checks. */ @@ -370,19 +366,20 @@ 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 == mtim_getsec(sb) && - orig_mtim.tv_nsec == mtim_getnsec(sb)) { + 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 * time in the editor we can't tell if the file was changed. */ -#ifdef HAVE_TIMESPECSUB2 - timespecsub(&ts1, &ts2); +#ifdef HAVE_TIMERSUB2 + timersub(&tv1, &tv2); #else - timespecsub(&ts1, &ts2, &ts2); + timersub(&tv1, &tv2, &tv2); #endif - if (timespecisset(&ts2)) + if (timerisset(&tv2)) modified = FALSE; } diff --git a/src/fileops.c b/src/fileops.c index af942c511..50c7cbc10 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -57,22 +57,22 @@ * Update the access and modify times on an fd or file. */ int -touch(int fd, char *path, struct timespec *tsp) +touch(int fd, char *path, struct timeval *tvp) { struct timeval times[2]; - if (tsp != NULL) { - times[0].tv_sec = times[1].tv_sec = tsp->tv_sec; - times[0].tv_usec = times[1].tv_usec = tsp->tv_nsec / 1000; + if (tvp != NULL) { + times[0].tv_sec = times[1].tv_sec = tvp->tv_sec; + times[0].tv_usec = times[1].tv_usec = tvp->tv_usec; } #if defined(HAVE_FUTIME) || defined(HAVE_FUTIMES) if (fd != -1) - return(futimes(fd, tsp ? times : NULL)); + return(futimes(fd, tvp ? times : NULL)); else #endif if (path != NULL) - return(utimes(path, tsp ? times : NULL)); + return(utimes(path, tvp ? times : NULL)); else return(-1); }