[quake3-commits] r1758 - in trunk/code: qcommon sys

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Dec 23 19:40:39 EST 2009


Author: tma
Date: 2009-12-23 19:40:39 -0500 (Wed, 23 Dec 2009)
New Revision: 1758

Modified:
   trunk/code/qcommon/common.c
   trunk/code/sys/con_tty.c
   trunk/code/sys/sys_unix.c
Log:
* (bug #4346) Dedicated server uses 100% CPU when stdin is not a TTY
* com_speeds reports misleading values on dedicated server (Guillaume Bougard)


Modified: trunk/code/qcommon/common.c
===================================================================
--- trunk/code/qcommon/common.c	2009-12-18 21:57:56 UTC (rev 1757)
+++ trunk/code/qcommon/common.c	2009-12-24 00:40:39 UTC (rev 1758)
@@ -3065,6 +3065,12 @@
 	if ( com_speeds->integer ) {
 		timeAfter = Sys_Milliseconds ();
 	}
+#else
+	if ( com_speeds->integer ) {
+		timeAfter = Sys_Milliseconds ();
+		timeBeforeEvents = timeAfter;
+		timeBeforeClient = timeAfter;
+	}
 #endif
 
 	//

Modified: trunk/code/sys/con_tty.c
===================================================================
--- trunk/code/sys/con_tty.c	2009-12-18 21:57:56 UTC (rev 1757)
+++ trunk/code/sys/con_tty.c	2009-12-24 00:40:39 UTC (rev 1758)
@@ -40,6 +40,7 @@
 =============================================================
 */
 
+extern qboolean stdinIsATTY;
 static qboolean stdin_active;
 // general flag to tell about tty console mode
 static qboolean ttycon_on = qfalse;
@@ -268,21 +269,19 @@
 void CON_Init( void )
 {
 	struct termios tc;
-	const char* term = getenv("TERM");
 
 	// If the process is backgrounded (running non interactively)
 	// then SIGTTIN or SIGTOU is emitted, if not caught, turns into a SIGSTP
 	signal(SIGTTIN, SIG_IGN);
 	signal(SIGTTOU, SIG_IGN);
-	
+
 	// If SIGCONT is received, reinitialize console
 	signal(SIGCONT, CON_SigCont);
 
 	// Make stdin reads non-blocking
 	fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK );
 
-	if (isatty(STDIN_FILENO) != 1
-	|| (term && (!strcmp(term, "raw") || !strcmp(term, "dumb"))))
+	if (!stdinIsATTY)
 	{
 		Com_Printf("tty console mode disabled\n");
 		ttycon_on = qfalse;

Modified: trunk/code/sys/sys_unix.c
===================================================================
--- trunk/code/sys/sys_unix.c	2009-12-18 21:57:56 UTC (rev 1757)
+++ trunk/code/sys/sys_unix.c	2009-12-24 00:40:39 UTC (rev 1758)
@@ -37,6 +37,8 @@
 #include <libgen.h>
 #include <fcntl.h>
 
+qboolean stdinIsATTY;
+
 // Used to determine where to store user-specific files
 static char homePath[ MAX_OSPATH ] = { 0 };
 
@@ -354,7 +356,7 @@
 	}
 
 	extLen = strlen( extension );
-	
+
 	// search
 	nfiles = 0;
 
@@ -464,24 +466,35 @@
 */
 void Sys_Sleep( int msec )
 {
-	fd_set fdset;
-
 	if( msec == 0 )
 		return;
 
-	FD_ZERO(&fdset);
-	FD_SET(fileno(stdin), &fdset);
-	if( msec < 0 )
+	if( stdinIsATTY )
 	{
-		select((fileno(stdin) + 1), &fdset, NULL, NULL, NULL);
+		fd_set fdset;
+
+		FD_ZERO(&fdset);
+		FD_SET(STDIN_FILENO, &fdset);
+		if( msec < 0 )
+		{
+			select(STDIN_FILENO + 1, &fdset, NULL, NULL, NULL);
+		}
+		else
+		{
+			struct timeval timeout;
+
+			timeout.tv_sec = msec/1000;
+			timeout.tv_usec = (msec%1000)*1000;
+			select(STDIN_FILENO + 1, &fdset, NULL, NULL, &timeout);
+		}
 	}
 	else
 	{
-		struct timeval timeout;
+		// With nothing to select() on, we can't wait indefinitely
+		if( msec < 0 )
+			msec = 10;
 
-		timeout.tv_sec = msec/1000;
-		timeout.tv_usec = (msec%1000)*1000;
-		select((fileno(stdin) + 1), &fdset, NULL, NULL, &timeout);
+		usleep( msec * 1000 );
 	}
 }
 
@@ -571,11 +584,16 @@
 */
 void Sys_PlatformInit( void )
 {
+	const char* term = getenv( "TERM" );
+
 	signal( SIGHUP, Sys_SigHandler );
 	signal( SIGQUIT, Sys_SigHandler );
 	signal( SIGTRAP, Sys_SigHandler );
 	signal( SIGIOT, Sys_SigHandler );
 	signal( SIGBUS, Sys_SigHandler );
+
+	stdinIsATTY = isatty( STDIN_FILENO ) &&
+		!( term && ( !strcmp( term, "raw" ) || !strcmp( term, "dumb" ) ) );
 }
 
 /*



More information about the quake3-commits mailing list