From: Michael Poole Date: Wed, 7 Mar 2007 05:19:10 +0000 (-0500) Subject: Check for additional functions during configure. X-Git-Tag: v1.4.0-rc1~65 X-Git-Url: http://git.pk910.de/?p=srvx.git;a=commitdiff_plain;h=6f22223d9d80a148babc60a6483dd50c74cce723 Check for additional functions during configure. 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. --- diff --git a/configure.in b/configure.in index ce1d911..a821044 100644 --- a/configure.in +++ b/configure.in @@ -83,7 +83,7 @@ AC_CHECK_MEMBER([struct addrinfo.ai_flags], #include ]) 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 diff --git a/src/compat.c b/src/compat.c index d1c253f..cc31324 100644 --- a/src/compat.c +++ b/src/compat.c @@ -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 diff --git a/src/compat.h b/src/compat.h index d1508e2..8a6e8e2 100644 --- a/src/compat.h +++ b/src/compat.h @@ -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 diff --git a/src/config.h.win32 b/src/config.h.win32 index d58ae4c..ef0902f 100644 --- a/src/config.h.win32 +++ b/src/config.h.win32 @@ -46,6 +46,9 @@ /* Define to 1 if you have the 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 header file. */ #define HAVE_FCNTL_H 1 @@ -76,8 +79,11 @@ /* 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 @@ -199,6 +205,9 @@ /* Define to 1 if you have the `sysconf' function. */ #undef HAVE_SYSCONF +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_EPOLL_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_MMAN_H @@ -229,6 +238,9 @@ /* Define to 1 if you have the 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 header file. */ #define HAVE_UNISTD_H 1 @@ -264,7 +276,7 @@ /* 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 */ @@ -288,6 +300,9 @@ /* 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 diff --git a/src/opserv.c b/src/opserv.c index a5ffb40..baaf654 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -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(), ×[0], ×[1], ×[2], ×[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; }