Bug 3632 - samba-3.0.20b/source/lib/util_sock.c
samba-3.0.20b/source/lib/util_sock.c
Status: RESOLVED FIXED
Product: Samba 3.0
Classification: Unclassified
Component: Build environment
3.0.20b
PPC AIX
: P3 normal
: none
Assigned To: William Jojo
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-03-27 06:00 UTC by Wolfgang Rinau
Modified: 2007-04-11 20:09 UTC (History)
0 users

See Also:


Attachments
Patch for EISCONN in open_any_socket_out to match open_socket_out (368 bytes, patch)
2007-04-11 14:58 UTC, William Jojo
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Rinau 2006-03-27 06:00:55 UTC
Testet with AIX4.3.3
==========================================
diff -cr samba-3.0.20b.orig/source/lib/util_sock.c samba-3.0.20b/source/lib/util_sock.c
*** samba-3.0.20b.orig/source/lib/util_sock.c	Wed Oct 12 19:03:30 2005
--- samba-3.0.20b/source/lib/util_sock.c	Tue Mar 14 14:59:13 2006
***************
*** 4,9 ****
--- 4,10 ----
     Copyright (C) Andrew Tridgell 1992-1998
     Copyright (C) Tim Potter      2000-2001
     Copyright (C) Jeremy Allison  1992-2005
+    extended by Rudolf Jakfalvi   2006
     
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
***************
*** 967,978 ****
--- 968,986 ----
  		}
  
  		if (errno == EINPROGRESS || errno == EALREADY ||
+ #if defined(AIX)
+ 		    errno == EAGAIN || errno == EISCONN ) {		/* extended by Rudolf Jakfalvi */
+ #else /* defined(AIX) */
  		    errno == EAGAIN) {
+ #endif /* defined(AIX) */
  			/* These are the error messages that something is
  			   progressing. */
  			good_connect = True;
  		} else if (errno != 0) {
  			/* There was a direct error */
+ 			DEBUG(10,("open_any_socket_out: connect(%s#%d) failed [%d/%d] %s\n", 
+ 										inet_ntoa(addrs[i].sin_addr), addrs[i].sin_port, 
+ 										i, num_addrs, strerror(errno) ));
  			close(sockets[i]);
  			sockets[i] = -1;
  		}
***************
*** 980,985 ****
--- 988,994 ----
  
  	if (!good_connect) {
  		/* All of the connect's resulted in real error conditions */
+ 		DEBUG(10,("open_any_socket_out: no connect in progress. [%d/%d]\n", i, num_addrs ));
  		goto done;
  	}
  
***************
*** 1003,1010 ****
  
  	res = sys_select(maxfd+1, &r_fds, &wr_fds, NULL, &tv);
  
! 	if (res < 0)
  		goto done;
  
  	if (res == 0)
  		goto next_round;
--- 1012,1022 ----
  
  	res = sys_select(maxfd+1, &r_fds, &wr_fds, NULL, &tv);
  
! 	if (res < 0) {
! 		DEBUG(10,("open_any_socket_out: select(maxfd#%d) failed [%d] %s\n", 
! 									maxfd, num_addrs, strerror(errno) ));
  		goto done;
+ 	}
  
  	if (res == 0)
  		goto next_round;
***************
*** 1029,1037 ****
--- 1041,1062 ----
  		if (!FD_ISSET(sockets[i], &r_fds) &&
  		    FD_ISSET(sockets[i], &wr_fds)) {
  			/* Only writable, so it's connected */
+ #if defined(AIX)
+ 			/* Only writable doesn't always mean connected on AIX 4.3, however */
+ 			/* extended by Rudolf Jakfalvi */
+ 			struct sockaddr peeraddr;
+ 			socklen_t peeraddr_len = sizeof(peeraddr);
+ 			struct sockaddr_in *peeraddr_in = (struct sockaddr_in *)&peeraddr;
+ 
+ 			if ((getpeername(sockets[i], &peeraddr, &peeraddr_len) != 0) ||
+ 							(peeraddr_len != sizeof(struct sockaddr_in)) ||
+ 							(peeraddr_in->sin_family != PF_INET))
+ 				continue;
+ #endif /* defined(AIX) */
  			resulting_index = i;
  			goto done;
  		}
+ 
  	}
  
   next_round:
***************
*** 1053,1058 ****
--- 1078,1087 ----
  	}
  
  	if (resulting_index >= 0) {
+ 		DEBUG(10,("open_any_socket_out: '%s#%d' connected. [%d/%d]\n", 
+ 										inet_ntoa(addrs[resulting_index].sin_addr), 
+ 										addrs[resulting_index].sin_port,
+ 										resulting_index, num_addrs ));
  		*fd_index = resulting_index;
  		*fd = sockets[*fd_index];
  		set_blocking(*fd, True);
Comment 1 Derrell Lipman 2006-03-27 07:56:32 UTC
Instead of adding #if lines with braces, please try to find ways to leave matching braces so they continue to match.  Non-matching braces, even though they are "commented out" in a #if statement, confuse editors when they are asked to jump to a matching brace.  The following patch section which addes EISCONN to the list of trapped errors:

*** 967,978 ****
--- 968,986 ----
                }

                if (errno == EINPROGRESS || errno == EALREADY ||
+ #if defined(AIX)
+                   errno == EAGAIN || errno == EISCONN ) {             /*
extended by Rudolf Jakfalvi */
+ #else /* defined(AIX) */
                    errno == EAGAIN) {
+ #endif /* defined(AIX) */
                        /* These are the error messages that something is
                           progressing. */
                        good_connect = True;
                } else if (errno != 0) {
                        /* There was a direct error */
+                       DEBUG(10,("open_any_socket_out: connect(%s#%d) failed
[%d/%d] %s\n", 
+                                                                              
inet_ntoa(addrs[i].sin_addr), addrs[i].sin_port, 
+                                                                              
i, num_addrs, strerror(errno) ));
                        close(sockets[i]);
                        sockets[i] = -1;
                }
***************


can be easily rewritten something like this (hand-modified alteration) so that no additional braces are added:


*** 967,978 ****
--- 968,986 ----
                }

                if (errno == EINPROGRESS || errno == EALREADY ||
+ #if defined(AIX)
+                   errno == EISCONN || /* extended by Rudolf Jakfalvi */
+ #endif /* defined(AIX) */
                    errno == EAGAIN) {
                        /* These are the error messages that something is
                           progressing. */
                        good_connect = True;
                } else if (errno != 0) {
                        /* There was a direct error */
+                       DEBUG(10,("open_any_socket_out: connect(%s#%d) failed
[%d/%d] %s\n", 
+                                                                              
inet_ntoa(addrs[i].sin_addr), addrs[i].sin_port, 
+                                                                              
i, num_addrs, strerror(errno) ));
                        close(sockets[i]);
                        sockets[i] = -1;
                }
***************
Comment 2 Gerald (Jerry) Carter 2006-04-20 08:03:40 UTC
severity should be determined by the developers and not the reporter.
Comment 3 William Jojo 2007-04-11 14:58:31 UTC
Created attachment 2381 [details]
Patch for EISCONN in open_any_socket_out to match open_socket_out

Agree that EISCONN should be considered, but not convinced that getpeername is also necessary to prove connection. If the peer closes the connection, a subsequent write() will detect this anyway.
Comment 4 Gerald (Jerry) Carter 2007-04-11 15:18:02 UTC
Assigning to Bill :-)
Comment 5 Jeremy Allison 2007-04-11 20:09:43 UTC
Applied, thanks !
Jeremy.