commit: r280 - in trunk: . daemon libspread

[email protected]
Newsgroups gmane.network.spread.cvs
Message-ID <[email protected]>
Author: jonathan
Date: 2005-09-23 13:09:01 -0400 (Fri, 23 Sep 2005)
New Revision: 280

Modified:
   trunk/configure
   trunk/configure.in
   trunk/daemon/data_link.c
   trunk/daemon/defines.h
   trunk/daemon/events.c
   trunk/daemon/session.c
   trunk/libspread/sp.c
Log:
Fixes for compile warnings and type misdetection in configure script. 
Fixes type-punning dereferences caught by new strict aliasing warning by using 
correct "struct timeval" for select calls timeout. 
Does NOT disable new gcc 4.0 strict-aliasing optimization, as it might be safe with these fixes.


Modified: trunk/configure
===================================================================
--- trunk/configure	2005-09-21 05:00:31 UTC (rev 279)
+++ trunk/configure	2005-09-23 17:09:01 UTC (rev 280)
@@ -6937,6 +6937,7 @@
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
  #include <time.h>
+		  #include <sys/time.h>
 		  #include <sys/types.h>
 int
 main ()

Modified: trunk/configure.in
===================================================================
--- trunk/configure.in	2005-09-21 05:00:31 UTC (rev 279)
+++ trunk/configure.in	2005-09-23 17:09:01 UTC (rev 280)
@@ -157,6 +157,7 @@
 AC_CACHE_CHECK([for struct timezone type], ac_cv_have_struct_timezone, [
 	AC_TRY_COMPILE(
 		[ #include <time.h>
+		  #include <sys/time.h>
 		  #include <sys/types.h> ], 
 		[ struct timezone opt; ],
 		[ ac_cv_have_struct_timezone="yes" ],

Modified: trunk/daemon/data_link.c
===================================================================
--- trunk/daemon/data_link.c	2005-09-21 05:00:31 UTC (rev 279)
+++ trunk/daemon/data_link.c	2005-09-23 17:09:01 UTC (rev 280)
@@ -166,7 +166,7 @@
 #endif	/* ARCH_SCATTER_NONE */
 	
 static	struct  sockaddr_in	soc_addr;
-static	sp_time			select_delay = { 0, 10000 };
+static	struct timeval 		select_delay = { 0, 10000 };
 	int			ret;
 	int			total_len;
 	int			i;
@@ -227,7 +227,7 @@
                         send_errormsg = sock_strerror(sock_errno);
 			Alarm( DATA_LINK, "DL_send: delaying after failure in send to %d.%d.%d.%d, ret is %d\n", 
 				IP1(address), IP2(address), IP3(address), IP4(address), ret);
-			select( 0, 0, 0, 0, (struct timeval *)&select_delay );
+			select( 0, 0, 0, 0, &select_delay );
 		}
 	}
 	if (ret < 0)

Modified: trunk/daemon/defines.h
===================================================================
--- trunk/daemon/defines.h	2005-09-21 05:00:31 UTC (rev 279)
+++ trunk/daemon/defines.h	2005-09-23 17:09:01 UTC (rev 280)
@@ -109,7 +109,11 @@
 /* (or die trying) */
 
 #ifndef HAVE_SOCKOPT_LEN_T
+# ifdef  __linux
+typedef socklen_t sockopt_len_t;
+# else
 typedef int sockopt_len_t;
+# endif
 #endif
 
 #ifndef HAVE_U_INT

Modified: trunk/daemon/events.c
===================================================================
--- trunk/daemon/events.c	2005-09-21 05:00:31 UTC (rev 279)
+++ trunk/daemon/events.c	2005-09-23 17:09:01 UTC (rev 280)
@@ -126,7 +126,7 @@
 
 sp_time	E_get_time(void)
 {
-
+        struct timeval  read_time;
 #ifndef	ARCH_PC_WIN95
 
 #if HAVE_STRUCT_TIMEZONE
@@ -136,8 +136,10 @@
 #endif
 	int		ret;
 
-	ret = gettimeofday( (struct timeval *)&Now, (void *)&dummy_tz );
+	ret = gettimeofday( &read_time, &dummy_tz );
 	if ( ret < 0 ) Alarm( EXIT, "E_get_time: gettimeofday problems.\n" );
+        Now.sec = read_time.tv_sec;
+        Now.usec = read_time.tv_usec;
 
 #else	/* ARCH_PC_WIN95 */
 
@@ -329,12 +331,13 @@
 
 void	E_delay( sp_time t )
 {
-	sp_time	tmp_t;
+	struct timeval 	tmp_t;
 
-	tmp_t = t;
+	tmp_t.tv_sec = t.sec;
+	tmp_t.tv_usec = t.usec;
 
 #ifndef ARCH_PC_WIN95
-        if (select(0, NULL, NULL, NULL, (struct timeval *)&tmp_t ) < 0)
+        if (select(0, NULL, NULL, NULL, &tmp_t ) < 0)
         {
                 Alarm( EVENTS, "E_delay: select delay returned error: %s\n", strerror(errno));
         }
@@ -562,7 +565,8 @@
 	int			fd;
 	int			fd_type;
 	int			i,j;
-	sp_time			timeout, wait_timeout;
+	sp_time			timeout;
+        struct timeval          sel_timeout, wait_timeout;
 	fd_set			current_mask[NUM_FDTYPES];
 	time_event		*temp_ptr;
         int                     first=1;
@@ -633,9 +637,10 @@
 #ifdef TESTTIME
         req_time = zero_sec;
 #endif
-        wait_timeout = zero_sec;
+        wait_timeout.tv_sec = zero_sec.sec;
+        wait_timeout.tv_usec = zero_sec.usec;
 	num_set = select( FD_SETSIZE, &current_mask[READ_FD], &current_mask[WRITE_FD], &current_mask[EXCEPT_FD], 
-			  (struct timeval *)&wait_timeout );
+			  &wait_timeout );
 	if (num_set == 0 && !Exit_events)
 	{
 #ifdef BADCLOCK
@@ -650,8 +655,10 @@
 #ifdef TESTTIME
                 req_time = E_add_time(req_time, timeout);
 #endif
+                sel_timeout.tv_sec = timeout.sec;
+                sel_timeout.tv_usec = timeout.usec;
 		num_set = select( FD_SETSIZE, &current_mask[READ_FD], &current_mask[WRITE_FD], 
-				  &current_mask[EXCEPT_FD], (struct timeval *)&timeout );
+				  &current_mask[EXCEPT_FD], &sel_timeout );
 	}
 #ifdef TESTTIME
         start = E_get_time();

Modified: trunk/daemon/session.c
===================================================================
--- trunk/daemon/session.c	2005-09-21 05:00:31 UTC (rev 279)
+++ trunk/daemon/session.c	2005-09-23 17:09:01 UTC (rev 280)
@@ -160,7 +160,7 @@
     unsigned char *c;
     session *tmp;
     
-    c = (char *) &ses->mbox;
+    c = (unsigned char *) &ses->mbox;
     i = c[0] ^ c[1] ^ c[2] ^ c[3];
     tmp = Sessions_hash_head[i];
     if (tmp == ses)

Modified: trunk/libspread/sp.c
===================================================================
--- trunk/libspread/sp.c	2005-09-21 05:00:31 UTC (rev 279)
+++ trunk/libspread/sp.c	2005-09-23 17:09:01 UTC (rev 280)
@@ -172,6 +172,8 @@
 /* We take the Struct_mutex in prepare to prevent inconsistent state 
  * in Session[] structs in child
  */
+#ifdef _REENTRANT
+
 #ifdef  HAVE_PTHREAD_ATFORK
 
 static  void    sp_atfork_prepare(void)
@@ -200,6 +202,7 @@
 }
 
 #endif  /* HAVE_PTHREAD_ATFORK */
+#endif /* _REENTRANT */
 
 static  void    sp_initialize_locks(void)
 {
@@ -242,6 +245,7 @@
         int ret, num_ready;
         fd_set rset,fixed_rset;
         sp_time start_time, temp_time, target_time, wait_time;
+        struct timeval  sel_time;
 
         if ( len == 0 )
                 return(0);
@@ -253,11 +257,15 @@
                 FD_ZERO(&fixed_rset);
                 FD_SET(s, &fixed_rset);
                 rset = fixed_rset;
-                while( ((num_ready = select(s+1, &rset, NULL, NULL, (struct timeval *)&wait_time)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
+                sel_time.tv_sec = wait_time.sec;
+                sel_time.tv_sec = wait_time.usec;
+                while( ((num_ready = select(s+1, &rset, NULL, NULL, &sel_time)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
                 {
                         temp_time = E_get_time();
                         if (E_compare_time(temp_time, target_time) < 0 ) {
                                 wait_time = E_sub_time(target_time, temp_time);
+                                sel_time.tv_sec = wait_time.sec;
+                                sel_time.tv_sec = wait_time.usec;
                         } else {
                                 printf("recv_nointr_timeout: Timed out when interrupted\n");
                                 sock_set_errno( ERR_TIMEDOUT );
@@ -293,6 +301,7 @@
     int         ret, num_ready;
     fd_set      rset,fixed_rset,wset;
     sp_time     start_time, temp_time, target_time, wait_time;
+    struct timeval sel_time;
     int         non_blocking = 0;
     int         err;
     int         on;
@@ -305,6 +314,8 @@
         start_time = E_get_time();
         target_time = E_add_time(start_time, *time_out);
         wait_time = *time_out;
+        sel_time.tv_sec = wait_time.sec;
+        sel_time.tv_sec = wait_time.usec;
         /* set file descriptor to non-blocking */
         on = 1;
         ret_ioctl = ioctl( s, FIONBIO, &on);
@@ -322,11 +333,13 @@
         wset = rset;
         Alarmp( SPLOG_DEBUG, SESSION, "connect_nointr_timeout: connect in progress for socket %d, now wait in select\n", s);
         /* wait for select to timeout (num_ready == 0), give a permanent error (num_ready < 0 && sock_errno != transient). If transient error, retry after checking to make sure timeout has not expired */
-        while( ((num_ready = select(s+1, &rset, &wset, NULL, (struct timeval *)&wait_time)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
+        while( ((num_ready = select(s+1, &rset, &wset, NULL, &sel_time)) == -1) && ((sock_errno == EINTR) || (sock_errno == EAGAIN) || (sock_errno == EWOULDBLOCK)) )
         {
             temp_time = E_get_time();
             if (E_compare_time(temp_time, target_time) < 0 ) {
                 wait_time = E_sub_time(target_time, temp_time);
+                sel_time.tv_sec = wait_time.sec;
+                sel_time.tv_sec = wait_time.usec;
             } else {
                 Alarmp( SPLOG_WARNING, SESSION, "connect_nointr_timeout: connect interrupted and select wait timesout during transient error: %s\n", sock_strerror(sock_errno));
                 close(s);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.