[PATCH] Use ngx_socket_errno where appropriate.

Piotr Sikora piotr at cloudflare.com
Fri Jan 31 00:16:04 UTC 2014


Hello guys,
as Ruslan & Maxim noticed in the other thread, we're sometimes using
ngx_errno in places where we should be using ngx_socket_errno.

I might be overdoing it a little in src/os/unix/ngx_process.c, but
rest should be pretty obvious.

Best regards,
Piotr Sikora


# HG changeset patch
# User Piotr Sikora <piotr at cloudflare.com>
# Date 1391126566 28800
#      Thu Jan 30 16:02:46 2014 -0800
# Node ID fe4a9b7ca5985b0bde46fa78bd96de80e03d988b
# Parent  2e40188f83ef5bf1ae5afe0dd445689049f46a5c
Use ngx_socket_errno where appropriate.

Signed-off-by: Piotr Sikora <piotr at cloudflare.com>

diff -r 2e40188f83ef -r fe4a9b7ca598 src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Thu Jan 30 19:13:12 2014 +0400
+++ b/src/core/ngx_connection.c Thu Jan 30 16:02:46 2014 -0800
@@ -239,9 +239,9 @@ ngx_set_inherited_sockets(ngx_cycle_t *c

         if (getsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER, &af, &olen)
             == -1)
         {
-            err = ngx_errno;
+            err = ngx_socket_errno;

             if (err == NGX_EINVAL) {
                 continue;
             }
@@ -272,9 +272,9 @@ ngx_set_inherited_sockets(ngx_cycle_t *c

         if (getsockopt(ls[i].fd, IPPROTO_TCP, TCP_DEFER_ACCEPT,
&timeout, &olen)
             == -1)
         {
-            err = ngx_errno;
+            err = ngx_socket_errno;

             if (err == NGX_EOPNOTSUPP) {
                 continue;
             }
@@ -656,9 +656,9 @@ ngx_configure_listening_sockets(ngx_cycl
         if (ls[i].delete_deferred) {
             if (setsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER, NULL, 0)
                 == -1)
             {
-                ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                               "setsockopt(SO_ACCEPTFILTER, NULL) "
                               "for %V failed, ignored",
                               &ls[i].addr_text);

@@ -683,9 +683,9 @@ ngx_configure_listening_sockets(ngx_cycl
             if (setsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER,
                            &af, sizeof(struct accept_filter_arg))
                 == -1)
             {
-                ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                               "setsockopt(SO_ACCEPTFILTER, \"%s\") "
                               "for %V failed, ignored",
                               ls[i].accept_filter, &ls[i].addr_text);
                 continue;
@@ -716,9 +716,9 @@ ngx_configure_listening_sockets(ngx_cycl
             if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_DEFER_ACCEPT,
                            &value, sizeof(int))
                 == -1)
             {
-                ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                               "setsockopt(TCP_DEFER_ACCEPT, %d) for
%V failed, "
                               "ignored",
                               value, &ls[i].addr_text);

diff -r 2e40188f83ef -r fe4a9b7ca598 src/event/modules/ngx_epoll_module.c
--- a/src/event/modules/ngx_epoll_module.c Thu Jan 30 19:13:12 2014 +0400
+++ b/src/event/modules/ngx_epoll_module.c Thu Jan 30 16:02:46 2014 -0800
@@ -241,9 +241,9 @@ ngx_epoll_aio_init(ngx_cycle_t *cycle, n

     n = 1;

     if (ioctl(ngx_eventfd, FIONBIO, &n) == -1) {
-        ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+        ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
                       "ioctl(eventfd, FIONBIO) failed");
         goto failed;
     }

diff -r 2e40188f83ef -r fe4a9b7ca598 src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c Thu Jan 30 19:13:12 2014 +0400
+++ b/src/http/ngx_http_request.c Thu Jan 30 16:02:46 2014 -0800
@@ -2702,9 +2702,9 @@ ngx_http_test_reading(ngx_http_request_t

         if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
             == -1)
         {
-            err = ngx_errno;
+            err = ngx_socket_errno;
         }

         goto closed;
     }
diff -r 2e40188f83ef -r fe4a9b7ca598 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Thu Jan 30 19:13:12 2014 +0400
+++ b/src/http/ngx_http_upstream.c Thu Jan 30 16:02:46 2014 -0800
@@ -1095,9 +1095,9 @@ ngx_http_upstream_check_broken_connectio

         if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
             == -1)
         {
-            err = ngx_errno;
+            err = ngx_socket_errno;
         }

         if (err) {
             ev->error = 1;
@@ -1976,9 +1976,9 @@ ngx_http_upstream_test_connect(ngx_conne

         if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
             == -1)
         {
-            err = ngx_errno;
+            err = ngx_socket_errno;
         }

         if (err) {
             c->log->action = "connecting to upstream";
diff -r 2e40188f83ef -r fe4a9b7ca598 src/os/unix/ngx_freebsd_sendfile_chain.c
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c Thu Jan 30 19:13:12 2014 +0400
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c Thu Jan 30 16:02:46 2014 -0800
@@ -230,9 +230,9 @@ ngx_freebsd_sendfile_chain(ngx_connectio
             if (ngx_freebsd_use_tcp_nopush
                 && c->tcp_nopush == NGX_TCP_NOPUSH_UNSET)
             {
                 if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
-                    err = ngx_errno;
+                    err = ngx_socket_errno;

                     /*
                      * there is a tiny chance to be interrupted, however,
                      * we continue a processing without the TCP_NOPUSH
diff -r 2e40188f83ef -r fe4a9b7ca598 src/os/unix/ngx_linux_sendfile_chain.c
--- a/src/os/unix/ngx_linux_sendfile_chain.c Thu Jan 30 19:13:12 2014 +0400
+++ b/src/os/unix/ngx_linux_sendfile_chain.c Thu Jan 30 16:02:46 2014 -0800
@@ -162,9 +162,9 @@ ngx_linux_sendfile_chain(ngx_connection_

                 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,
                                (const void *) &tcp_nodelay, sizeof(int)) == -1)
                 {
-                    err = ngx_errno;
+                    err = ngx_socket_errno;

                     /*
                      * there is a tiny chance to be interrupted, however,
                      * we continue a processing with the TCP_NODELAY
@@ -188,9 +188,9 @@ ngx_linux_sendfile_chain(ngx_connection_

             if (c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {

                 if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
-                    err = ngx_errno;
+                    err = ngx_socket_errno;

                     /*
                      * there is a tiny chance to be interrupted, however,
                      * we continue a processing without the TCP_CORK
diff -r 2e40188f83ef -r fe4a9b7ca598 src/os/unix/ngx_process.c
--- a/src/os/unix/ngx_process.c Thu Jan 30 19:13:12 2014 +0400
+++ b/src/os/unix/ngx_process.c Thu Jan 30 16:02:46 2014 -0800
@@ -115,9 +115,9 @@ ngx_spawn_process(ngx_cycle_t *cycle, ng
         /* Solaris 9 still has no AF_LOCAL */

         if (socketpair(AF_UNIX, SOCK_STREAM, 0,
ngx_processes[s].channel) == -1)
         {
-            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                           "socketpair() failed while spawning \"%s\"", name);
             return NGX_INVALID_PID;
         }

@@ -126,48 +126,48 @@ ngx_spawn_process(ngx_cycle_t *cycle, ng
                        ngx_processes[s].channel[0],
                        ngx_processes[s].channel[1]);

         if (ngx_nonblocking(ngx_processes[s].channel[0]) == -1) {
-            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                           ngx_nonblocking_n " failed while spawning \"%s\"",
                           name);
             ngx_close_channel(ngx_processes[s].channel, cycle->log);
             return NGX_INVALID_PID;
         }

         if (ngx_nonblocking(ngx_processes[s].channel[1]) == -1) {
-            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                           ngx_nonblocking_n " failed while spawning \"%s\"",
                           name);
             ngx_close_channel(ngx_processes[s].channel, cycle->log);
             return NGX_INVALID_PID;
         }

         on = 1;
         if (ioctl(ngx_processes[s].channel[0], FIOASYNC, &on) == -1) {
-            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                           "ioctl(FIOASYNC) failed while spawning
\"%s\"", name);
             ngx_close_channel(ngx_processes[s].channel, cycle->log);
             return NGX_INVALID_PID;
         }

         if (fcntl(ngx_processes[s].channel[0], F_SETOWN, ngx_pid) == -1) {
-            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                           "fcntl(F_SETOWN) failed while spawning
\"%s\"", name);
             ngx_close_channel(ngx_processes[s].channel, cycle->log);
             return NGX_INVALID_PID;
         }

         if (fcntl(ngx_processes[s].channel[0], F_SETFD, FD_CLOEXEC) == -1) {
-            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                           "fcntl(FD_CLOEXEC) failed while spawning \"%s\"",
                            name);
             ngx_close_channel(ngx_processes[s].channel, cycle->log);
             return NGX_INVALID_PID;
         }

         if (fcntl(ngx_processes[s].channel[1], F_SETFD, FD_CLOEXEC) == -1) {
-            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
                           "fcntl(FD_CLOEXEC) failed while spawning \"%s\"",
                            name);
             ngx_close_channel(ngx_processes[s].channel, cycle->log);
             return NGX_INVALID_PID;



More information about the nginx-devel mailing list