Problems with 0.9.1 on not so recent Linux kernels.

Igor Sysoev igor at sysoev.ru
Thu Dec 2 11:24:11 MSK 2010


On Thu, Dec 02, 2010 at 02:52:45AM +0300, Maxim Dounin wrote:

> Hello!
> 
> On Wed, Dec 01, 2010 at 10:38:58PM +0300, Igor Sysoev wrote:
> 
> > On Wed, Dec 01, 2010 at 06:01:22PM +0000, António P. P. Almeida wrote:
> > 
> > > > It seems that 2.6.26 kernel does not support this syscall.
> > > > In next release I will make fallback to standard accept(), if it
> > > > accept4() is not implemented in kernel. This will allow to use
> > > > on old kernels packages built on modern kernels.
> > > 
> > > Ok.
> > 
> > Could you try the attched patch ? It should report once
> >    accept4() failed (38: Function not implemented)
> > on old kernel and fallback to usual accept().
> 
> [...]
> 
> >  #if (NGX_HAVE_ACCEPT4)
> > -        s = accept4(lc->fd, (struct sockaddr *) sa, &socklen, SOCK_NONBLOCK);
> > +        if (use_accept4) {
> > +            s = accept4(lc->fd, (struct sockaddr *) sa, &socklen,
> > +                        SOCK_NONBLOCK);
> > +        } else {
> > +            s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
> > +        }
> >  #else
> >          s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
> >  #endif
> > @@ -63,8 +71,18 @@
> >  
> >              ngx_log_error((ngx_uint_t) ((err == NGX_ECONNABORTED) ?
> >                                               NGX_LOG_ERR : NGX_LOG_ALERT),
> > -                          ev->log, err, "accept() failed");
> > +                          ev->log, err,
> > +#if !(NGX_HAVE_ACCEPT4)
> > +                          "accept() failed");
> > +#else
> > +                          use_accept4 ? "accept4() failed" : "accept() failed");
> >  
> > +            if (use_accept4 && err == NGX_ENOSYS) {
> > +                use_accept4 = 0;
> > +                continue;
> 
> You have to reset ngx_inherited_nonblocking here as well.

You are right. Here is an updated patch.


-- 
Igor Sysoev
http://sysoev.ru/en/
-------------- next part --------------
Index: src/event/ngx_event_accept.c
===================================================================
--- src/event/ngx_event_accept.c	(revision 3131)
+++ src/event/ngx_event_accept.c	(working copy)
@@ -26,6 +26,9 @@
     ngx_connection_t  *c, *lc;
     ngx_event_conf_t  *ecf;
     u_char             sa[NGX_SOCKADDRLEN];
+#if (NGX_HAVE_ACCEPT4)
+    static ngx_uint_t  use_accept4 = 1;
+#endif
 
     ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module);
 
@@ -47,7 +50,12 @@
         socklen = NGX_SOCKADDRLEN;
 
 #if (NGX_HAVE_ACCEPT4)
-        s = accept4(lc->fd, (struct sockaddr *) sa, &socklen, SOCK_NONBLOCK);
+        if (use_accept4) {
+            s = accept4(lc->fd, (struct sockaddr *) sa, &socklen,
+                        SOCK_NONBLOCK);
+        } else {
+            s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
+        }
 #else
         s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
 #endif
@@ -63,8 +71,19 @@
 
             ngx_log_error((ngx_uint_t) ((err == NGX_ECONNABORTED) ?
                                              NGX_LOG_ERR : NGX_LOG_ALERT),
-                          ev->log, err, "accept() failed");
+                          ev->log, err,
+#if !(NGX_HAVE_ACCEPT4)
+                          "accept() failed");
+#else
+                          use_accept4 ? "accept4() failed" : "accept() failed");
 
+            if (use_accept4 && err == NGX_ENOSYS) {
+                use_accept4 = 0;
+                ngx_inherited_nonblocking = 0;
+                continue;
+            }
+#endif
+
             if (err == NGX_ECONNABORTED) {
                 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
                     ev->available--;


More information about the nginx mailing list