1
0
Эх сурвалжийг харах

fix #170: build error on FreeBSD

ithewei 3 жил өмнө
parent
commit
6fc90ffdcf
8 өөрчлөгдсөн 37 нэмэгдсэн , 12 устгасан
  1. 2 0
      CMakeLists.txt
  2. 5 1
      base/hendian.h
  3. 10 9
      base/hmain.c
  4. 1 1
      base/hmain.h
  5. 2 0
      configure
  6. 1 1
      docs/API.md
  7. 8 0
      hconfig.h
  8. 8 0
      hconfig.h.in

+ 2 - 0
CMakeLists.txt

@@ -54,6 +54,8 @@ check_header("sys/stat.h")
 check_header("sys/time.h")
 check_header("fcntl.h")
 check_header("pthread.h")
+check_header("endian.h")
+check_header("sys/endian.h")
 
 # Checks for functions
 if(NOT MSVC)

+ 5 - 1
base/hendian.h

@@ -40,8 +40,12 @@
 #define le32toh(v) __builtin_bswap32(v)
 #define le64toh(v) __builtin_bswap64(v)
 #endif
-#else
+#elif HAVE_ENDIAN_H
 #include <endian.h>
+#elif HAVE_SYS_ENDIAN_H
+#include <sys/endian.h>
+#else
+#warning "Not found endian.h!"
 #endif
 
 #define PI8(p)      *(int8_t*)(p)

+ 10 - 9
base/hmain.c

@@ -323,11 +323,16 @@ int parse_opt_long(int argc, char** argv, const option_t* long_options, int size
  * memory layout
  * argv[0]\0argv[1]\0argv[n]\0env[0]\0env[1]\0env[n]\0
  */
-void setproctitle(const char* title) {
-    //printf("proctitle=%s\n", title);
+void hv_setproctitle(const char* fmt, ...) {
+    char buf[256] = {0};
+    va_list ap;
+    va_start(ap, fmt);
+    vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
+    va_end(ap);
+
     int len = g_main_ctx.arg_len + g_main_ctx.env_len;
     if (g_main_ctx.os_argv && len) {
-        strncpy(g_main_ctx.os_argv[0], title, len-1);
+        strncpy(g_main_ctx.os_argv[0], buf, len-1);
     }
 }
 #endif
@@ -573,9 +578,7 @@ static HTHREAD_ROUTINE(worker_thread) {
 
 static void worker_init(void* userdata) {
 #ifdef OS_UNIX
-    char proctitle[256] = {0};
-    snprintf(proctitle, sizeof(proctitle), "%s: worker process", g_main_ctx.program_name);
-    setproctitle(proctitle);
+    hv_setproctitle("%s: worker process", g_main_ctx.program_name);
     signal(SIGNAL_RELOAD, signal_handler);
 #endif
 }
@@ -623,9 +626,7 @@ int master_workers_run(procedure_t worker_fn, void* worker_userdata,
         }
         // master-workers processes
 #ifdef OS_UNIX
-        char proctitle[256] = {0};
-        snprintf(proctitle, sizeof(proctitle), "%s: master process", g_main_ctx.program_name);
-        setproctitle(proctitle);
+        hv_setproctitle("%s: master process", g_main_ctx.program_name);
         signal(SIGNAL_RELOAD, signal_handler);
 #endif
         g_main_ctx.worker_processes = worker_processes;

+ 1 - 1
base/hmain.h

@@ -79,7 +79,7 @@ HV_EXPORT const char* get_arg(const char* key);
 HV_EXPORT const char* get_env(const char* key);
 
 #ifdef OS_UNIX
-HV_EXPORT void setproctitle(const char* title);
+HV_EXPORT void hv_setproctitle(const char* fmt, ...);
 #endif
 
 // pidfile

+ 2 - 0
configure

@@ -253,6 +253,8 @@ header=sys/stat.h && check_header
 header=sys/time.h && check_header
 header=fcntl.h && check_header
 header=pthread.h && check_header
+header=endian.h && check_header
+header=sys/endian.h && check_header
 
 # Checks for functions
 function=gettid && header=unistd.h && check_function

+ 1 - 1
docs/API.md

@@ -259,7 +259,7 @@
 - parse_opt_long
 - get_arg
 - get_env
-- setproctitle
+- hv_setproctitle
 - signal_init
 - signal_handle
 - create_pidfile

+ 8 - 0
hconfig.h

@@ -33,6 +33,14 @@
 #define HAVE_PTHREAD_H 1
 #endif
 
+#ifndef HAVE_ENDIAN_H
+#define HAVE_ENDIAN_H 1
+#endif
+
+#ifndef HAVE_SYS_ENDIAN_H
+#define HAVE_SYS_ENDIAN_H 0
+#endif
+
 #ifndef HAVE_GETTID
 #define HAVE_GETTID 0
 #endif

+ 8 - 0
hconfig.h.in

@@ -33,6 +33,14 @@
 #define HAVE_PTHREAD_H @HAVE_PTHREAD_H@
 #endif
 
+#ifndef HAVE_ENDIAN_H
+#define HAVE_ENDIAN_H @HAVE_ENDIAN_H@
+#endif
+
+#ifndef HAVE_SYS_ENDIAN_H
+#define HAVE_SYS_ENDIAN_H @HAVE_SYS_ENDIAN_H@
+#endif
+
 #ifndef HAVE_GETTID
 #define HAVE_GETTID @HAVE_GETTID@
 #endif