🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.x
Article #37989

the elusive select() bug ...

#37989
From: Jordan Hayes
Date: Mon, 12 Mar 1990 15:47
67 lines
3117 bytes
Sun4/110, X11R4 patches 1-5 installed, SunOS 4.0.3 ... but i've seen it
since R3 about a year ago.

Symptom: Xt clients enter spin loop warning select() failed: errno 22

-----

I got some mail about this from someone who tipped me off.  Somehow
(don't ask me!) ntpd (the network time protocol daemon) is screwing up
the system time on Sparcs so that the return from gettimeofday()
contains an unusable time.  The macros ADD_TIME and TIME_DELTA in
mit/lib/Xt/NextEvent.c do a good job of sanity checking the two time
values, but don't go far enough in the face of stupid input.  This is
not their fault.  However, here's a more bullet-proof version of these
macros, ones that will avoid similar problems in the future.

After adjusting for the border conditions, if there are still negative
numbers involved in tv_sec or tv_usec (refused as invalid input for the
timeout argument to select()) they are quashed.

*** NextEvent.c	Mon Mar 12 10:44:29 1990
--- NextEvent.c.old	Mon Mar 12 10:37:19 1990
***************
*** 53,71 ****
   * Private routines
   */
  #define ADD_TIME(dest, src1, src2) { \
! 	if(((dest).tv_usec = (src1).tv_usec + (src2).tv_usec) >= 1000000) {\
! 	      (dest).tv_usec -= 1000000;\
! 	      (dest).tv_sec = (src1).tv_sec + (src2).tv_sec + 1 ; \
! 	} else { (dest).tv_sec = (src1).tv_sec + (src2).tv_sec ; \
! 	   if(((dest).tv_sec >= 1) && (((dest).tv_usec <0))) { \
! 	    (dest).tv_sec --;(dest).tv_usec += 1000000; } } }
  
- 
  #define TIMEDELTA(dest, src1, src2) { \
! 	if(((dest).tv_usec = (src1).tv_usec - (src2).tv_usec) < 0) {\
! 	      (dest).tv_usec += 1000000;\
! 	      (dest).tv_sec = (src1).tv_sec - (src2).tv_sec - 1;\
! 	} else 	(dest).tv_sec = (src1).tv_sec - (src2).tv_sec;  }
  
  #define IS_AFTER(t1, t2) (((t2).tv_sec > (t1).tv_sec) \
  	|| (((t2).tv_sec == (t1).tv_sec)&& ((t2).tv_usec > (t1).tv_usec)))
--- 53,71 ----
   * Private routines
   */
  #define ADD_TIME(dest, src1, src2) { \
! 	(dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
! 	(dest).tv_usec = (src1).tv_usec + (src2).tv_usec; \
! 	while ((dest).tv_usec >= 1000000) { \
! 		(dest).tv_usec -= 1000000; (dest).tv_sec++; } \
! 	if ((dest).tv_sec < 0) (dest)tv_sec = 0; \
! 	if ((dest).tv_usec < 0) (dest)tv_usec = 0; }
  
  #define TIMEDELTA(dest, src1, src2) { \
! 	(dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
! 	(dest).tv_usec = (src1).tv_usec - (src2).tv_usec; \
! 	while ((dest).tv_usec < 0) { \
! 		(dest).tv_usec += 1000000; (dest).tv_sec--; } \
! 	if ((dest).tv_sec < 0) (dest)tv_sec = 0; }
  
  #define IS_AFTER(t1, t2) (((t2).tv_sec > (t1).tv_sec) \
  	|| (((t2).tv_sec == (t1).tv_sec)&& ((t2).tv_usec > (t1).tv_usec)))

-----

/jordan
Technical Details
Message-ID: <9003121547.AA08265@Morgan.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!snorkelwacker!bloom-beacon!morgan.COM!jordan

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!snorkelwacker!bloom-beacon!morgan.COM!jordan
From: jordan@morgan.COM (Jordan Hayes)
Newsgroups: comp.windows.x
Subject: the elusive select() bug ...
Message-ID: <9003121547.AA08265@Morgan.COM>
Date: 12 Mar 90 15:47:56 GMT
Sender: daemon@athena.mit.edu (Mr Background)
Organization: The Internet
Lines: 67