]> git.kaiwu.me - nginx.git/commitdiff
Control API: fixed socket inheritance on binary upgrade
authorSergey Kandaurov <pluknet@nginx.com>
Thu, 10 Sep 2026 21:07:12 +0000 (21:07 +0000)
committerSergey Kandaurov <pluknet@nginx.com>
Fri, 11 Sep 2026 12:27:35 +0000 (16:27 +0400)
The environment may be replaced while parsing configuration, as it
happens with the perl module, which calls ngx_set_environment() when
creating an interpreter.  As a result, the control socket was not
inherited on binary upgrade.

The variable is now read before ngx_init_cycle(), similarly to
inherited listening sockets.

src/core/nginx.c
src/os/unix/ngx_control.c
src/os/unix/ngx_control.h

index 2d619c6e35e9c06ca1790e150346b919aabd7973..d827f3fc9051c53626b3a4ccda511171e59dd296 100644 (file)
@@ -289,6 +289,10 @@ main(int argc, char *const *argv)
         return 1;
     }
 
+#if (NGX_CONTROL_API)
+    ngx_control_preinit();
+#endif
+
     if (ngx_preinit_modules() != NGX_OK) {
         return 1;
     }
index 8a6167077b41a64de1de19b82f1df479b34e566b..08b2d0195acc341537ad543548e20c516d199487 100644 (file)
@@ -77,6 +77,7 @@ static struct pollfd          ngx_control_pollfd[NGX_CTRL_MAX_FD];
 static ngx_uint_t             ngx_control_pollfd_n;
 static char                   ngx_control_unix_path[NGX_UNIX_ADDRSTRLEN];
 static ngx_uint_t             ngx_control_inherited;
+static u_char                *ngx_control_env;
 ngx_uint_t                    ngx_control_api_enabled;
 
 
@@ -131,6 +132,18 @@ static ngx_data_decl_t  ngx_control_config_fields[] = {
 };
 
 
+void
+ngx_control_preinit(void)
+{
+    /*
+     * the variable is read before ngx_init_cycle(), which may replace
+     * the environment while parsing configuration
+     */
+
+    ngx_control_env = (u_char *) getenv(NGX_CTRL_ENV);
+}
+
+
 ngx_int_t
 ngx_control_init(u_char *addr)
 {
@@ -382,7 +395,7 @@ ngx_control_inherit(void)
     u_char    *env;
     ngx_fd_t   fd;
 
-    env = (u_char *) getenv(NGX_CTRL_ENV);
+    env = ngx_control_env;
     if (env == NULL) {
         return NGX_DECLINED;
     }
index 9b6c9b8dcdf800f39e3c2d525a37258ea6272bfa..ade08151fa59266489da1010b282372fb4273a7b 100644 (file)
@@ -12,6 +12,7 @@
 #include <ngx_core.h>
 
 
+void ngx_control_preinit(void);
 ngx_int_t ngx_control_init(u_char *addr);
 void ngx_control_uninit(void);
 void ngx_control_close_sockets(void);