[nginx] Ensure "listen" exists in a mail or stream server (ticket #1049).

Roman Arutyunyan arut at nginx.com
Thu Aug 18 14:15:30 UTC 2016


details:   http://hg.nginx.org/nginx/rev/3d5202c71f94
branches:  
changeset: 6657:3d5202c71f94
user:      Roman Arutyunyan <arut at nginx.com>
date:      Wed Aug 17 11:26:51 2016 +0300
description:
Ensure "listen" exists in a mail or stream server (ticket #1049).

diffstat:

 src/mail/ngx_mail.h                 |   2 ++
 src/mail/ngx_mail_core_module.c     |   9 +++++++++
 src/stream/ngx_stream.h             |   2 ++
 src/stream/ngx_stream_core_module.c |  11 +++++++++++
 4 files changed, 24 insertions(+), 0 deletions(-)

diffs (84 lines):

diff -r a2f57dfa65a9 -r 3d5202c71f94 src/mail/ngx_mail.h
--- a/src/mail/ngx_mail.h	Thu Aug 18 17:13:07 2016 +0300
+++ b/src/mail/ngx_mail.h	Wed Aug 17 11:26:51 2016 +0300
@@ -124,6 +124,8 @@ typedef struct {
 
     /* server ctx */
     ngx_mail_conf_ctx_t    *ctx;
+
+    ngx_uint_t              listen;  /* unsigned  listen:1; */
 } ngx_mail_core_srv_conf_t;
 
 
diff -r a2f57dfa65a9 -r 3d5202c71f94 src/mail/ngx_mail_core_module.c
--- a/src/mail/ngx_mail_core_module.c	Thu Aug 18 17:13:07 2016 +0300
+++ b/src/mail/ngx_mail_core_module.c	Wed Aug 17 11:26:51 2016 +0300
@@ -279,6 +279,13 @@ ngx_mail_core_server(ngx_conf_t *cf, ngx
 
     *cf = pcf;
 
+    if (rv == NGX_CONF_OK && !cscf->listen) {
+        ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+                      "no \"listen\" is defined for server in %s:%ui",
+                      cscf->file_name, cscf->line);
+        return NGX_CONF_ERROR;
+    }
+
     return rv;
 }
 
@@ -295,6 +302,8 @@ ngx_mail_core_listen(ngx_conf_t *cf, ngx
     ngx_mail_module_t          *module;
     ngx_mail_core_main_conf_t  *cmcf;
 
+    cscf->listen = 1;
+
     value = cf->args->elts;
 
     ngx_memzero(&u, sizeof(ngx_url_t));
diff -r a2f57dfa65a9 -r 3d5202c71f94 src/stream/ngx_stream.h
--- a/src/stream/ngx_stream.h	Thu Aug 18 17:13:07 2016 +0300
+++ b/src/stream/ngx_stream.h	Wed Aug 17 11:26:51 2016 +0300
@@ -144,6 +144,8 @@ typedef struct {
 
     ngx_msec_t                     resolver_timeout;
     ngx_resolver_t                *resolver;
+
+    ngx_uint_t                     listen;  /* unsigned  listen:1; */
 } ngx_stream_core_srv_conf_t;
 
 
diff -r a2f57dfa65a9 -r 3d5202c71f94 src/stream/ngx_stream_core_module.c
--- a/src/stream/ngx_stream_core_module.c	Thu Aug 18 17:13:07 2016 +0300
+++ b/src/stream/ngx_stream_core_module.c	Wed Aug 17 11:26:51 2016 +0300
@@ -325,6 +325,13 @@ ngx_stream_core_server(ngx_conf_t *cf, n
 
     *cf = pcf;
 
+    if (rv == NGX_CONF_OK && !cscf->listen) {
+        ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+                      "no \"listen\" is defined for server in %s:%ui",
+                      cscf->file_name, cscf->line);
+        return NGX_CONF_ERROR;
+    }
+
     return rv;
 }
 
@@ -332,12 +339,16 @@ ngx_stream_core_server(ngx_conf_t *cf, n
 static char *
 ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
+    ngx_stream_core_srv_conf_t  *cscf = conf;
+
     ngx_str_t                    *value;
     ngx_url_t                     u;
     ngx_uint_t                    i, backlog;
     ngx_stream_listen_t          *ls, *als;
     ngx_stream_core_main_conf_t  *cmcf;
 
+    cscf->listen = 1;
+
     value = cf->args->elts;
 
     ngx_memzero(&u, sizeof(ngx_url_t));



More information about the nginx-devel mailing list