Check for additional functions during configure.
authorMichael Poole <mdpoole@troilus.org>
Wed, 7 Mar 2007 05:19:10 +0000 (00:19 -0500)
committerMichael Poole <mdpoole@troilus.org>
Wed, 7 Mar 2007 05:19:10 +0000 (00:19 -0500)
If the operating system does not provide gai_strerror(), we must.
If the OS does not have a Unix-ish times(), we can use GetProcessTimes().
Update config.h.win32 based on the new configure script.

configure.in
src/compat.c
src/compat.h
src/config.h.win32
src/opserv.c

index ce1d911359a45d73e417dbf2b8de21f9b4ab575c..a821044a655a4fa87375427e9f59f8d80ac93dad 100644 (file)
@@ -83,7 +83,7 @@ AC_CHECK_MEMBER([struct addrinfo.ai_flags],
 #include <netdb.h>])
 
 dnl We have fallbacks in case these are missing, so just check for them.
-AC_CHECK_FUNCS(freeaddrinfo getaddrinfo getnameinfo getpagesize memcpy memset strdup strerror strsignal localtime_r setrlimit getopt getopt_long regcomp regexec regfree sysconf inet_aton epoll_create select gettimeofday,,)
+AC_CHECK_FUNCS(freeaddrinfo getaddrinfo gai_strerror getnameinfo getpagesize memcpy memset strdup strerror strsignal localtime_r setrlimit getopt getopt_long regcomp regexec regfree sysconf inet_aton epoll_create select gettimeofday times GetProcessTimes,,)
 
 dnl Check for the fallbacks for functions missing above.
 if test $ac_cv_func_gettimeofday = no; then
index d1c253f6b2ebf263287180f0515d733d5219c603..cc3132481cf376a3cdb1d2681039e0c93b70079c 100644 (file)
@@ -16,7 +16,7 @@
 #endif
 
 #if !defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME)
-extern gettimeofday(struct timeval * tv, struct timezone * tz);
+extern int gettimeofday(struct timeval * tv, struct timezone * tz)
 {
     if (!tv)
     {
@@ -30,13 +30,16 @@ extern gettimeofday(struct timeval * tv, struct timezone * tz);
 
     tv->tv_sec  = tb.time;
     tv->tv_usec = ((long)tb.millitm)*1000;
-    if (tz)
-    {
-        tz->tz_minuteswest = 0;
-        tz->tz_dsttime     = 0;
-    }
 
-    return 0;
+    return 0; (void)tz;
+}
+#endif
+
+#ifndef HAVE_GETLOCALTIME_R
+extern struct tm *localtime_r(const time_t *timep, struct tm *result)
+{
+    memcpy(result, localtime(timep), sizeof(*result));
+    return result;
 }
 #endif
 
@@ -416,3 +419,48 @@ void freeaddrinfo(struct addrinfo *res)
 }
 
 #endif
+
+#ifndef HAVE_GAI_STRERROR
+const char *gai_strerror(int errcode)
+{
+    switch (errcode) {
+#if defined(EAI_ADDRFAMILY)
+    case EAI_ADDRFAMILY: return "Address family not supported.";
+#endif
+#if defined(EAI_AGAIN)
+    case EAI_AGAIN: return "A temporary failure occurred during name resolution.";
+#endif
+#if defined(EAI_BADFLAGS)
+    case EAI_BADFLAGS: return "Invalid flags hint.";
+#endif
+#if defined(EAI_FAIL)
+    case EAI_FAIL: return "An unrecoverable failure occurred during name resolution.";
+#endif
+#if defined(EAI_FAMILY)
+    case EAI_FAMILY: return "Address family not supported.";
+#endif
+#if defined(EAI_MEMORY)
+    case EAI_MEMORY: return "Not enough memory.";
+#endif
+#if defined(EAI_NODATA)
+    case EAI_NODATA: return "The name resolves to an empty record.";
+#endif
+#if defined(EAI_NONAME)
+    case EAI_NONAME: return "The name does not resolve.";
+#endif
+#if defined(EAI_OVERFLOW)
+    case EAI_OVERFLOW: return "Resolved name was too large for buffer.";
+#endif
+#if defined(EAI_SERVICE)
+    case EAI_SERVICE: return "The socket type does not support the requested service.";
+#endif
+#if defined(EAI_SOCKTYPE)
+    case EAI_SOCKTYPE: return "Unknown socket type.";
+#endif
+#if defined(EAI_SYSTEM)
+    case EAI_SYSTEM: return "A system error occurred during name resolution.";
+#endif
+    }
+    return "Unknown GAI_* error";
+}
+#endif
index d1508e25b0127fc02f15839f7c9dd88f8483a61b..8a6e8e25ec4e3a328a937bef024fbabf1cc0d6e6 100644 (file)
@@ -84,9 +84,14 @@ char *alloca();
 #endif
 
 #ifndef HAVE_GETTIMEOFDAY
+struct timezone;
 extern int gettimeofday(struct timeval * tv, struct timezone * tz);
 #endif
 
+#ifndef HAVE_GETLOCALTIME_R
+extern struct tm *localtime_r(const time_t *timep, struct tm *result);
+#endif
+
 #ifndef HAVE_MEMCPY
 /* this should use size_t, but some systems don't define it */
 extern void * memcpy(void * dest, void const * src, unsigned long n);
@@ -132,6 +137,10 @@ void freeaddrinfo(struct addrinfo *res);
 
 #endif
 
+#ifndef HAVE_GAI_STRERROR
+const char *gai_strerror(int errcode);
+#endif
+
 #ifndef EINPROGRESS
 # ifdef WSAEINPROGRESS
 #  define EINPROGRESS WSAEINPROGRESS
index d58ae4c79896e6b2f5691e8d32b4b851da356813..ef0902f6f6a230881ca861aebac6ba852a5b99cb 100644 (file)
@@ -46,6 +46,9 @@
 /* Define to 1 if you have the <dmalloc.h> header file. */
 #undef HAVE_DMALLOC_H
 
+/* Define to 1 if you have the `epoll_create' function. */
+#undef HAVE_EPOLL_CREATE
+
 /* Define to 1 if you have the <fcntl.h> header file. */
 #define HAVE_FCNTL_H 1
 
 /* Define to 1 if you have the `getpagesize' function. */
 #undef HAVE_GETPAGESIZE
 
+/* Define to 1 if you have the `GetProcessTimes' function. */
+#define HAVE_GETPROCESSTIMES 1
+
 /* Define to 1 if you have the `gettimeofday' function. */
-#define HAVE_GETTIMEOFDAY 1
+#undef HAVE_GETTIMEOFDAY
 
 /* Define to 1 if you have the `inet_aton' function. */
 #undef HAVE_INET_ATON
 /* Define to 1 if you have the `sysconf' function. */
 #undef HAVE_SYSCONF
 
+/* Define to 1 if you have the <sys/epoll.h> header file. */
+#undef HAVE_SYS_EPOLL_H
+
 /* Define to 1 if you have the <sys/mman.h> header file. */
 #undef HAVE_SYS_MMAN_H
 
 /* Define to 1 if you have the <sys/wait.h> header file. */
 #undef HAVE_SYS_WAIT_H
 
+/* Define to 1 if you have the `times' function. */
+#undef HAVE_TIMES
+
 /* Define to 1 if you have the <unistd.h> header file. */
 #define HAVE_UNISTD_H 1
 
 
 /* If using the C implementation of alloca, define if you know the
    direction of stack growth for your system; otherwise it will be
-   automatically deduced at run-time.
+   automatically deduced at runtime.
        STACK_DIRECTION > 0 => grows toward higher addresses
        STACK_DIRECTION < 0 => grows toward lower addresses
        STACK_DIRECTION = 0 => direction of growth unknown */
 /* Define if using the epoll I/O backend */
 #undef WITH_IOSET_EPOLL
 
+/* Define if using the select() I/O backend */
+#undef WITH_IOSET_SELECT
+
 /* Define if using the Boehm GC to garbage collect and check memory leaks */
 #undef WITH_MALLOC_BOEHM_GC
 
index a5ffb401ef327ead6d214a041d66b3ca2e61ec05..baaf65436f5ec83a8a01092e5b06ce944e01a2bb 100644 (file)
@@ -1480,11 +1480,15 @@ static MODCMD_FUNC(cmd_stats_uplink) {
 }
 
 static MODCMD_FUNC(cmd_stats_uptime) {
+    extern int lines_processed;
+    extern time_t boot_time;
+    double kernel_time;
+    double user_time;
     char uptime[INTERVALLEN];
+
+#if defined(HAVE_TIMES)
+    static double clocks_per_sec;
     struct tms buf;
-    extern time_t boot_time;
-    extern int lines_processed;
-    static long clocks_per_sec;
 
     if (!clocks_per_sec) {
 #if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
@@ -1496,12 +1500,27 @@ static MODCMD_FUNC(cmd_stats_uptime) {
             clocks_per_sec = CLOCKS_PER_SEC;
         }
     }
-    intervalString(uptime, time(NULL)-boot_time, user->handle_info);
     times(&buf);
-    reply("OSMSG_UPTIME_STATS",
-          uptime, lines_processed,
-          buf.tms_utime/(double)clocks_per_sec,
-          buf.tms_stime/(double)clocks_per_sec);
+    user_time = buf.tms_utime / clocks_per_sec;
+    kernel_time = buf.tms_stime / clocks_per_sec;
+#elif defined(HAVE_GETPROCESSTIMES)
+    FILETIME times[4];
+    LARGE_INTEGER li[2];
+
+    GetProcessTimes(GetCurrentProcess(), &times[0], &times[1], &times[2], &times[3]);
+    li[0].LowPart = times[2].dwLowDateTime;
+    li[0].HighPart = times[2].dwHighDateTime;
+    kernel_time = li[0].QuadPart * 1e-7;
+    li[1].LowPart = times[3].dwLowDateTime;
+    li[1].HighPart = times[3].dwHighDateTime;
+    user_time = li[1].QuadPart * 1e-7;
+#else
+    user_time = NAN;
+    system_time = NAN;
+#endif
+
+    intervalString(uptime, time(NULL)-boot_time, user->handle_info);
+    reply("OSMSG_UPTIME_STATS", uptime, lines_processed, user_time, kernel_time);
     return 1;
 }