瀏覽代碼

AIX and HPUX build fixes, socklen_t 64bit fix for HPUX

Neither AIX 5 or HPUX 11 define va_copy or have a thread name
function.  Move existing va_copy #define out of a windows-only block
so that it can apply to any platform that needs it.

The HPUX system headers mistakenly define socklen_t as a 64bit value
on Itanium, and has function prototypes with socklen_t when compiling
with _XOPEN_SOURCE.  However, the socket functions actually expect a
pointer to a 32bit value.  Passing address of socklen_t rather than
int results in zero data returned, missing client net addresses from
the accept() and general badness.  Fix by forcing a redef of socklen_t
to int when building on HPUX.

Signed-off-by: David Loffredo <loffredo@steptools.com>
David Loffredo 10 年之前
父節點
當前提交
13f488bbd6
共有 1 個文件被更改,包括 24 次插入4 次删除
  1. 24 4
      src/civetweb.c

+ 24 - 4
src/civetweb.c

@@ -243,10 +243,6 @@ typedef long off_t;
 #define USE_TIMERS
 #endif
 
-#if !defined(va_copy)
-#define va_copy(x, y) x = y
-#endif /* !va_copy MINGW #defines va_copy */
-
 #if !defined(fileno)
 #define fileno(x) _fileno(x)
 #endif /* !fileno MINGW #defines fileno */
@@ -371,8 +367,30 @@ typedef unsigned short int in_port_t;
 typedef int SOCKET;
 #define WINCDECL
 
+#if defined(__hpux)
+/* HPUX 11 does not have monotonic, fall back to realtime */
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC CLOCK_REALTIME
+#endif
+
+/* HPUX defines socklen_t incorrectly as size_t which is 64bit on
+ * Itanium.  Without defining _XOPEN_SOURCE or _XOPEN_SOURCE_EXTENDED
+ * the prototypes use int* rather than socklen_t* which matches the
+ * actual library expectation.  When called with the wrong size arg
+ * accept() returns a zero client inet addr and check_acl() always
+ * fails.  Since socklen_t is widely used below, just force replace
+ * their typedef with int. - DTL
+ */
+#define socklen_t int
+#endif /* hpux */
+
 #endif /* End of Windows and UNIX specific includes */
 
+/* va_copy should always be a macro, C99 and C++11 - DTL */
+#ifndef va_copy
+#define va_copy(x, y) x = y
+#endif
+
 #ifdef _WIN32
 static CRITICAL_SECTION global_log_file_lock;
 static DWORD pthread_self(void)
@@ -1026,6 +1044,8 @@ void mg_set_thread_name(const char* name)
 #elif defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__)
    /* BSD (TODO: test) */
    pthread_set_name_np(pthread_self(), threadName);
+#elif defined(_AIX) ||  defined(__hpux)
+   /* no name function */
 #else
    /* POSIX */
    (void)pthread_setname_np(pthread_self(), threadName);