From 33db4b2edb2cc4f80b23d349f340b62bb367cfc9 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 25 Nov 2004 17:09:31 +0000 Subject: [PATCH] Add check for 2-argument form of timespecsub (FreeBSD and BSD/OS) and fix a typo in the gettimeofday check. --- config.h.in | 8 ++- configure | 162 +++++++++++++++++++-------------------------------- configure.in | 12 +++- sudo_edit.c | 4 ++ visudo.c | 4 ++ 5 files changed, 84 insertions(+), 106 deletions(-) diff --git a/config.h.in b/config.h.in index c60cbc6b1..be7c2109a 100644 --- a/config.h.in +++ b/config.h.in @@ -150,8 +150,8 @@ passwords) */ #undef HAVE_GETSPWUID -/* Define to 1 if you have the `getttimeofday' function. */ -#undef HAVE_GETTTIMEOFDAY +/* Define to 1 if you have the `gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY /* Define to 1 if you have the `glob' function. */ #undef HAVE_GLOB @@ -371,6 +371,10 @@ /* Define to 1 if you have struct timespec in sys/time.h */ #undef HAVE_TIMESPEC +/* Define to 1 if you have a timespecsub macro or function that takes + two arguments (not three) */ +#undef HAVE_TIMESPECSUB2 + /* Define to 1 if you have the `tzset' function. */ #undef HAVE_TZSET diff --git a/configure b/configure index 3d3abf638..3d6f02dd0 100755 --- a/configure +++ b/configure @@ -25610,8 +25610,9 @@ esac + for ac_func in strchr strrchr memchr memcpy memset sysconf tzset \ - strftime setrlimit initgroups getgroups fstat + strftime setrlimit initgroups getgroups fstat gettimeofday do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -27588,105 +27589,8 @@ else fi done - -for ac_func in getttimeofday -do -as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` -echo "$as_me:$LINENO: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$as_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -{ -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -char (*f) () = $ac_func; -#endif -#ifdef __cplusplus -} -#endif - -int -main () -{ -return f != $ac_func; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$as_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -eval "$as_ac_var=no" -fi -rm -f conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 -if test `eval echo '${'$as_ac_var'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - echo "$as_me:$LINENO: checking for struct stat.st_mtim" >&5 +if test X"$ac_cv_type_struct_timespec" != X"no"; then + echo "$as_me:$LINENO: checking for struct stat.st_mtim" >&5 echo $ECHO_N "checking for struct stat.st_mtim... $ECHO_C" >&6 if test "${ac_cv_member_struct_stat_st_mtim+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 @@ -27903,9 +27807,61 @@ fi fi -fi -done + echo "$as_me:$LINENO: checking for two-parameter timespecsub" >&5 +echo $ECHO_N "checking for two-parameter timespecsub... $ECHO_C" >&6 + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +int +main () +{ +struct timespec ts1, ts2; ts1.tv_sec = 1; ts1.tv_nsec = 0; ts2.tv_sec = 0; ts2.tv_nsec = 0; timespecsub(&ts1, &ts2); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + cat >>confdefs.h <<\_ACEOF +#define HAVE_TIMESPECSUB2 1 +_ACEOF + + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 +echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF @@ -33521,6 +33477,8 @@ fi + + diff --git a/configure.in b/configure.in index 62cf1d702..7853b4139 100644 --- a/configure.in +++ b/configure.in @@ -1674,7 +1674,7 @@ dnl dnl Function checks dnl AC_CHECK_FUNCS(strchr strrchr memchr memcpy memset sysconf tzset \ - strftime setrlimit initgroups getgroups fstat) + strftime setrlimit initgroups getgroups fstat gettimeofday) if test -z "$SKIP_SETRESUID"; then AC_CHECK_FUNCS(setresuid, [SKIP_SETREUID=yes]) fi @@ -1703,7 +1703,14 @@ SUDO_FUNC_FNMATCH([AC_DEFINE(HAVE_FNMATCH)], [AC_LIBOBJ(fnmatch)]) SUDO_FUNC_ISBLANK AC_REPLACE_FUNCS(strerror strcasecmp sigaction strlcpy strlcat closefrom) AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf, , [NEED_SNPRINTF=1]) -AC_CHECK_FUNCS(getttimeofday, [AC_CHECK_MEMBER([struct stat.st_mtim], AC_DEFINE(HAVE_ST_MTIM), [AC_CHECK_MEMBER([struct stat.st_mtimespec], AC_DEFINE([HAVE_ST_MTIMESPEC]))])]) +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_mtimespec], AC_DEFINE([HAVE_ST_MTIMESPEC]))]) + AC_MSG_CHECKING([for two-parameter timespecsub]) + AC_TRY_COMPILE([#include +#include ], [struct timespec ts1, ts2; ts1.tv_sec = 1; ts1.tv_nsec = 0; ts2.tv_sec = 0; ts2.tv_nsec = 0; timespecsub(&ts1, &ts2);], + [AC_DEFINE(HAVE_TIMESPECSUB2) + 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. dnl @@ -2266,6 +2273,7 @@ AH_TEMPLATE(HAVE_ST_MTIMESPEC, [Define to 1 if your struct stat has an st_mtimes AH_TEMPLATE(HAVE_SYSTRACE, [Define to 1 to build support for tracing subprocesses using systrace(4)]) AH_TEMPLATE(HAVE_TERMIOS_H, [Define to 1 if you have the 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_TIMESPECSUB2, [Define to 1 if you have a timespecsub 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/sudo_edit.c b/sudo_edit.c index 2858a1294..f60c11529 100644 --- a/sudo_edit.c +++ b/sudo_edit.c @@ -294,7 +294,11 @@ int sudo_edit(argc, argv) * 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); +#else timespecsub(&ts1, &ts2, &ts2); +#endif if (timespecisset(&ts2)) { warningx("%s unchanged", tf[i].ofile); unlink(tf[i].tfile); diff --git a/visudo.c b/visudo.c index 160fbe4e0..679590926 100644 --- a/visudo.c +++ b/visudo.c @@ -362,7 +362,11 @@ edit_sudoers(sp, editor, args, lineno) * 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); +#else timespecsub(&ts1, &ts2, &ts2); +#endif if (timespecisset(&ts2)) modified = FALSE; } -- 2.40.0