]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Solaris: fix errcode hiding and inconsistent usage.
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 9 Aug 2010 10:48:17 +0000 (22:48 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 9 Aug 2010 10:48:17 +0000 (22:48 +1200)
src/comm/ListenStateData.cc
src/comm/ListenStateData.h
src/ftp.cc

index 8c03c5616153c82a896b7f9d6649d45f10d1e531..bc77e465b90c378c3289b80cc0a5cb780cce74a2 100644 (file)
 /**
  * New-style listen and accept routines
  *
- * Listen simply registers our interest in an FD for listening,
- * and accept takes a callback to call when an FD has been
- * accept()ed.
+ * setListen simply registers our interest in an FD for listening.
+ * The constructor takes a callback to call when an FD has been
+ * accept()ed some time later.
  */
 void
 Comm::ListenStateData::setListen()
 {
-    int x;
-
-    if ((x = listen(fd, Squid_MaxFD >> 2)) < 0) {
+    errcode = 0; // reset local errno copy.
+    if (listen(fd, Squid_MaxFD >> 2) < 0) {
         debugs(50, 0, HERE << "listen(FD " << fd << ", " << (Squid_MaxFD >> 2) << "): " << xstrerror());
-        errcode = x;
+        errcode = errno;
         return;
     }
 
@@ -66,15 +65,13 @@ Comm::ListenStateData::setListen()
         bzero(&afa, sizeof(afa));
         debugs(5, DBG_IMPORTANT, "Installing accept filter '" << Config.accept_filter << "' on FD " << fd);
         xstrncpy(afa.af_name, Config.accept_filter, sizeof(afa.af_name));
-        x = setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa));
-        if (x < 0)
+        if (setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa)) < 0)
             debugs(5, DBG_CRITICAL, "SO_ACCEPTFILTER '" << Config.accept_filter << "': '" << xstrerror());
 #elif defined(TCP_DEFER_ACCEPT)
         int seconds = 30;
         if (strncmp(Config.accept_filter, "data=", 5) == 0)
             seconds = atoi(Config.accept_filter + 5);
-        x = setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &seconds, sizeof(seconds));
-        if (x < 0)
+        if (setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &seconds, sizeof(seconds) < 0)
             debugs(5, DBG_CRITICAL, "TCP_DEFER_ACCEPT '" << Config.accept_filter << "': '" << xstrerror());
 #else
         debugs(5, DBG_CRITICAL, "accept_filter not supported on your OS");
@@ -166,7 +163,7 @@ Comm::ListenStateData::acceptOne()
 
         // A non-recoverable error; notify the caller */
         debugs(5, 5, HERE << "non-recoverable error: FD " << fd << " handler: " << theCallback);
-        notify(-1, COMM_ERROR, errno, connDetails);
+        notify(-1, COMM_ERROR, connDetails);
         mayAcceptMore = false;
         return;
     }
@@ -174,7 +171,7 @@ Comm::ListenStateData::acceptOne()
     debugs(5, 5, HERE << "accepted: FD " << fd <<
            " newfd: " << newfd << " from: " << connDetails.peer <<
            " handler: " << theCallback);
-    notify(newfd, COMM_OK, 0, connDetails);
+    notify(newfd, COMM_OK, connDetails);
 }
 
 void
@@ -186,11 +183,11 @@ Comm::ListenStateData::acceptNext()
 }
 
 void
-Comm::ListenStateData::notify(int newfd, comm_err_t errcode, int xerrno, const ConnectionDetail &connDetails)
+Comm::ListenStateData::notify(int newfd, comm_err_t flag, const ConnectionDetail &connDetails)
 {
     // listener socket handlers just abandon the port with COMM_ERR_CLOSING
     // it should only happen when this object is deleted...
-    if (errcode == COMM_ERR_CLOSING) {
+    if (flag == COMM_ERR_CLOSING) {
         return;
     }
 
@@ -200,8 +197,8 @@ Comm::ListenStateData::notify(int newfd, comm_err_t errcode, int xerrno, const C
         params.fd = fd;
         params.nfd = newfd;
         params.details = connDetails;
-        params.flag = errcode;
-        params.xerrno = xerrno;
+        params.flag = flag;
+        params.xerrno = errcode;
         ScheduleCallHere(theCallback);
         if (!mayAcceptMore)
             theCallback = NULL;
@@ -221,7 +218,9 @@ Comm::ListenStateData::oldAccept(ConnectionDetail &details)
     struct addrinfo *gai = NULL;
     details.me.InitAddrInfo(gai);
 
+    errcode = 0; // reset local errno copy.
     if ((sock = accept(fd, gai->ai_addr, &gai->ai_addrlen)) < 0) {
+        errcode = errno; // store last accept errno locally.
 
         details.me.FreeAddrInfo(gai);
 
index 66ed358786c465fe090d8c2c6912cdc19a4bd706..b8e3c9057b2a0c8bb5bab16ea013068646642148 100644 (file)
@@ -23,11 +23,11 @@ public:
 
     void subscribe(AsyncCall::Pointer &call);
     void acceptNext();
-    void notify(int newfd, comm_err_t, int xerrno, const ConnectionDetail &);
+    void notify(int newfd, comm_err_t flag, const ConnectionDetail &details);
 
     int fd;
 
-    /// errno code if any happened so far.
+    /// errno code of the last accept() or listen() action if one occurred.
     int errcode;
 
     /// whether this socket is delayed and on the AcceptLimiter queue.
index 33a8cb8791d54192658ee2689764b631a8b94681..0ecbe623a065b88d43947ab94592472be58fbc84 100644 (file)
@@ -2768,7 +2768,7 @@ ftpOpenListenSocket(FtpStateData * ftpState, int fallback)
                                     acceptDialer(ftpState, &FtpStateData::ftpAcceptDataConnection));
     ftpState->data.listener = new Comm::ListenStateData(fd, acceptCall, false);
 
-    if (!ftpState->data.listener || ftpState->data.listener->errcode < 0) {
+    if (!ftpState->data.listener || ftpState->data.listener->errcode != 0) {
         comm_close(fd);
         return -1;
     }