www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1999/11/24/20:57:03

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-developers-unsubscribe-archive-cygwin-developers=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
From: Chris Faylor <cgf AT cygnus DOT com>
Date: Wed, 24 Nov 1999 20:56:52 -0500
To: Kazuhiro Fujieda <fujieda AT jaist DOT ac DOT jp>
Cc: cygwin-developers AT sourceware DOT cygnus DOT com
Subject: Re: cygwin_bind bug.
Message-ID: <19991124205652.B15777@cygnus.com>
Mail-Followup-To: Kazuhiro Fujieda <fujieda AT jaist DOT ac DOT jp>,
cygwin-developers AT sourceware DOT cygnus DOT com
References: <s1s903npgry DOT fsf AT jaist DOT ac DOT jp> <19991124192413 DOT A12159 AT cygnus DOT com> <s1s4sebpcyz DOT fsf AT jaist DOT ac DOT jp>
Mime-Version: 1.0
X-Mailer: Mutt 1.0i
In-Reply-To: <s1s4sebpcyz.fsf@jaist.ac.jp>; from fujieda@jaist.ac.jp on Thu, Nov 25, 1999 at 10:38:28AM +0900

--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=us-ascii

On Thu, Nov 25, 1999 at 10:38:28AM +0900, Kazuhiro Fujieda wrote:
>>>> On Wed, 24 Nov 1999 19:24:13 -0500
>>>> Chris Faylor <cgf AT cygnus DOT com> said:
>
>> Is this patch against the latest snapshot?  Corinna has submitted
>> some changes to some of this code recently.  It is in the latest
>> snapshot.
>
>Yes, it is against the latest snapshot. Corinna's changes can't
>work properly by this bug. In her changes, cygwin_bind returns 0
>even though _open fails. Because `res' is set to 0 by `getsockname'.

In that case, why even use an intermediate variable?  Why not just check
the results from bind and getsockname directly?

cgf

--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=p

Index: net.cc
===================================================================
RCS file: /cvs/cvsfiles/devo/winsup/net.cc,v
retrieving revision 1.84
diff -u -p -r1.84 net.cc
--- net.cc	1999/11/23 22:55:27	1.84
+++ net.cc	1999/11/25 01:56:21
@@ -766,18 +766,16 @@ cygwin_bind (int fd, struct sockaddr *my
 	  sin.sin_family = AF_INET;
 	  sin.sin_port = 0;
 	  sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
-	  res = bind (sock->get_socket (), (sockaddr *) &sin, len);
-	  if (res)
+	  if (bind (sock->get_socket (), (sockaddr *) &sin, len))
 	    {
-	      set_winsock_errno ();
 	      syscall_printf ("AF_UNIX: bind failed %d", get_errno ());
+	      set_winsock_errno ();
 	      goto out;
 	    }
-	  res = getsockname (sock->get_socket (), (sockaddr *) &sin, &len);
-	  if (res)
+	  if (getsockname (sock->get_socket (), (sockaddr *) &sin, &len))
 	    {
-	      set_winsock_errno ();
 	      syscall_printf ("AF_UNIX: getsockname failed %d", get_errno ());
+	      set_winsock_errno ();
 	      goto out;
 	    }
 
@@ -803,27 +801,25 @@ cygwin_bind (int fd, struct sockaddr *my
           /* Note that the terminating nul is written.  */
           if (_write (fd, buf, len) != len)
             {
-              int saved_errno = get_errno ();
+	      save_errno here;
               _close (fd);
               _unlink (un_addr->sun_path);
-              set_errno (saved_errno);
             }
           else
             {
               _close (fd);
               chmod (un_addr->sun_path,
                 (S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO) & ~myself->umask);
-              res = 0;
             }
 #undef un_addr
 	}
-      else
+      else if (bind (sock->get_socket (), my_addr, addrlen))
 	{
-	  res = bind (sock->get_socket (), my_addr, addrlen);
-	  if (res)
-	    set_winsock_errno ();
+	  set_winsock_errno ();
+	  goto out;
 	}
     }
+
 out:
   syscall_printf ("%d = bind (%d, %x, %d)", res, fd, my_addr, addrlen);
   return res;

--KsGdsel6WgEHnImy--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019