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.
#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
#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)
{
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
}
#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
#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);
#endif
+#ifndef HAVE_GAI_STRERROR
+const char *gai_strerror(int errcode);
+#endif
+
#ifndef EINPROGRESS
# ifdef WSAEINPROGRESS
# define EINPROGRESS WSAEINPROGRESS
/* 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
}
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)
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;
}