git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] configure.ac: check for clock_gettime and CLOCK_MONOTONIC

From
Reuben Hawkins <reubenhwk@gmail.com>
Date
Jan 8, 2015, 20:00 UTC
Message-ID
<1420747257-16132-2-git-send-email-reubenhwk@gmail.com>
In-Reply-To
<1420747257-16132-1-git-send-email-reubenhwk@gmail.com>

The checks will override and unset YesPlease settings for HAVE_CLOCK_GETTIME and HAVE_CLOCK_MONOTONIC in config.mak.uname.

CLOCK_MONOTONIC isn't available on RHEL3, but there are still RHEL3 systems being used in production.

Signed-off-by: Reuben Hawkins <reubenhwk@gmail.com>
---
 Makefile         |  6 ++++++
 config.mak.uname |  1 +
 configure.ac     | 22 ++++++++++++++++++++++
 trace.c          |  2 +-
 4 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 7482a4d..57e33f2 100644
--- a/Makefile
+++ b/Makefile
@@ -339,6 +339,8 @@ all::
 # return NULL when it receives a bogus time_t.
 #
 # Define HAVE_CLOCK_GETTIME if your platform has clock_gettime in librt.
+#
+# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC in librt.
 
 GIT-VERSION-FILE: FORCE
 	@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1382,6 +1384,10 @@ ifdef HAVE_CLOCK_GETTIME
 	EXTLIBS += -lrt
 endif
 
+ifdef HAVE_CLOCK_MONOTONIC
+	BASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK = NoThanks
 endif
diff --git a/config.mak.uname b/config.mak.uname
index a2f380f..926773e 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -35,6 +35,7 @@ ifeq ($(uname_S),Linux)
 	LIBC_CONTAINS_LIBINTL = YesPlease
 	HAVE_DEV_TTY = YesPlease
 	HAVE_CLOCK_GETTIME = YesPlease
+	HAVE_CLOCK_MONOTONIC = YesPlease
 endif
 ifeq ($(uname_S),GNU/kFreeBSD)
 	HAVE_ALLOCA_H = YesPlease
diff --git a/configure.ac b/configure.ac
index 210eb4e..c3293b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -924,6 +924,28 @@ AC_CHECK_LIB([iconv], [locale_charset],
                      [CHARSET_LIB=-lcharset])])
 GIT_CONF_SUBST([CHARSET_LIB])
 #
+# Define HAVE_CLOCK_GETTIME=YesPlease if clock_gettime is available.
+GIT_CHECK_FUNC(clock_gettime,
+	[HAVE_CLOCK_GETTIME=YesPlease],
+	[HAVE_CLOCK_GETTIME=])
+GIT_CONF_SUBST([HAVE_CLOCK_GETTIME])
+
+AC_DEFUN([CLOCK_MONOTONIC_SRC], [
+AC_LANG_PROGRAM([[
+#include <time.h>
+clockid_t id = CLOCK_MONOTONIC;
+]])])
+
+#
+# Define HAVE_CLOCK_MONOTONIC=YesPlease if CLOCK_MONOTONIC is available.
+AC_MSG_CHECKING([for CLOCK_MONOTONIC])
+AC_COMPILE_IFELSE([CLOCK_MONOTONIC_SRC],
+	[AC_MSG_RESULT([yes])
+	HAVE_CLOCK_MONOTONIC=YesPlease],
+	[AC_MSG_RESULT([no])
+	HAVE_CLOCK_MONOTONIC=])
+GIT_CONF_SUBST([HAVE_CLOCK_MONOTONIC])
+#
 # Define NO_SETITIMER if you don't have setitimer.
 GIT_CHECK_FUNC(setitimer,
 [NO_SETITIMER=],
diff --git a/trace.c b/trace.c
index 4778608..bfbd48f 100644
--- a/trace.c
+++ b/trace.c
@@ -324,7 +324,7 @@ int trace_want(struct trace_key *key)
 	return !!get_trace_fd(key);
 }
 
-#ifdef HAVE_CLOCK_GETTIME
+#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC)
 
 static inline uint64_t highres_nanos(void)
 {
-- 
2.2.0.68.g8f72f0c.dirty
Previous: Reuben HawkinsNext: Eric Sunshine
Message 2 of 6 in “configure.ac: check 'tv_nsec' field in 'struct stat'”
  1. 1/3 configure.ac: check 'tv_nsec' field in 'struct stat'Reuben Hawkins, Jan 8, 2015
  2. 2/3 configure.ac: check for clock_gettime and CLOCK_MONOTONICReuben Hawkins, Jan 8, 2015
  3. Eric SunshineJan 9, 2015
  4. 3/3 configure.ac: check for HMAC_CTX_cleanupReuben Hawkins, Jan 8, 2015
  5. Eric SunshineJan 9, 2015
  6. Eric SunshineJan 9, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.