Browse Source

#define HAVE_SETPROCTITLE

ithewei 3 years ago
parent
commit
33bb6bb91c
7 changed files with 17 additions and 7 deletions
  1. 1 0
      CMakeLists.txt
  2. 4 4
      base/hmain.c
  3. 2 2
      base/hmain.h
  4. 1 0
      configure
  5. 1 1
      docs/API.md
  6. 4 0
      hconfig.h
  7. 4 0
      hconfig.h.in

+ 1 - 0
CMakeLists.txt

@@ -72,6 +72,7 @@ check_function("sem_timedwait" "semaphore.h")
 check_function("pipe" "unistd.h")
 check_function("socketpair" "sys/socket.h")
 check_function("eventfd" "sys/eventfd.h")
+check_function("setproctitle" "unistd.h")
 
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hconfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/hconfig.h)
 

+ 4 - 4
base/hmain.c

@@ -318,12 +318,12 @@ int parse_opt_long(int argc, char** argv, const option_t* long_options, int size
     return 0;
 }
 
-#ifdef OS_UNIX
+#if defined(OS_UNIX) && !HAVE_SETPROCTITLE
 /*
  * memory layout
  * argv[0]\0argv[1]\0argv[n]\0env[0]\0env[1]\0env[n]\0
  */
-void hv_setproctitle(const char* fmt, ...) {
+void setproctitle(const char* fmt, ...) {
     char buf[256] = {0};
     va_list ap;
     va_start(ap, fmt);
@@ -578,7 +578,7 @@ static HTHREAD_ROUTINE(worker_thread) {
 
 static void worker_init(void* userdata) {
 #ifdef OS_UNIX
-    hv_setproctitle("%s: worker process", g_main_ctx.program_name);
+    setproctitle("%s: worker process", g_main_ctx.program_name);
     signal(SIGNAL_RELOAD, signal_handler);
 #endif
 }
@@ -626,7 +626,7 @@ int master_workers_run(procedure_t worker_fn, void* worker_userdata,
         }
         // master-workers processes
 #ifdef OS_UNIX
-        hv_setproctitle("%s: master process", g_main_ctx.program_name);
+        setproctitle("%s: master process", g_main_ctx.program_name);
         signal(SIGNAL_RELOAD, signal_handler);
 #endif
         g_main_ctx.worker_processes = worker_processes;

+ 2 - 2
base/hmain.h

@@ -78,8 +78,8 @@ HV_EXPORT int parse_opt_long(int argc, char** argv, const option_t* long_options
 HV_EXPORT const char* get_arg(const char* key);
 HV_EXPORT const char* get_env(const char* key);
 
-#ifdef OS_UNIX
-HV_EXPORT void hv_setproctitle(const char* fmt, ...);
+#if defined(OS_UNIX) && !HAVE_SETPROCTITLE
+HV_EXPORT void setproctitle(const char* fmt, ...);
 #endif
 
 // pidfile

+ 1 - 0
configure

@@ -268,6 +268,7 @@ function=sem_timedwait && header=semaphore.h && check_function
 function=pipe && header=unistd.h && check_function
 function=socketpair && header=sys/socket.h && check_function
 function=eventfd && header=sys/eventfd.h && check_function
+function=setproctitle && header=unistd.h && check_function
 
 # Checks for options
 source config.mk 2>/dev/null

+ 1 - 1
docs/API.md

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

+ 4 - 0
hconfig.h

@@ -85,6 +85,10 @@
 #define HAVE_EVENTFD 1
 #endif
 
+#ifndef HAVE_SETPROCTITLE
+#define HAVE_SETPROCTITLE 0
+#endif
+
 /* #undef WITH_OPENSSL */
 /* #undef WITH_GNUTLS */
 /* #undef WITH_MBEDTLS */

+ 4 - 0
hconfig.h.in

@@ -85,6 +85,10 @@
 #define HAVE_EVENTFD @HAVE_EVENTFD@
 #endif
 
+#ifndef HAVE_SETPROCTITLE
+#define HAVE_SETPROCTITLE @HAVE_SETPROCTITLE@
+#endif
+
 #cmakedefine WITH_OPENSSL   1
 #cmakedefine WITH_GNUTLS    1
 #cmakedefine WITH_MBEDTLS   1