summaryrefslogtreecommitdiff
path: root/source/sys_unix.c
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2008-05-18 14:37:21 +0000
committerAndrey Nazarov <skuller@skuller.net>2008-05-18 14:37:21 +0000
commitcb43ed08c3cf6410fe4ce22dac3d07952db92893 (patch)
tree0b2b2790941743db47913cdf06b819c36b89e161 /source/sys_unix.c
parent179f701f7aec100ac1228fc02778fc4af47b75f0 (diff)
Accept `all' as special argument to `delstuffcmd' command.
Cleaned up Cvar_Get and fixed semantic bug. Accept `background keyword in menu scripts. Renamed `gl_fastsky' to `gl_drawsky'. If at least one of the sky env maps fails lo load, disable entire sky drawing. Reworked loading screen. Fixed Com_Quit argument string handling. Catch more signals on *nix. Updated server docs.
Diffstat (limited to 'source/sys_unix.c')
-rw-r--r--source/sys_unix.c65
1 files changed, 37 insertions, 28 deletions
diff --git a/source/sys_unix.c b/source/sys_unix.c
index 0311f21..009cd4f 100644
--- a/source/sys_unix.c
+++ b/source/sys_unix.c
@@ -87,8 +87,9 @@ static void Sys_ConsoleWrite( char *data, int count ) {
while( count ) {
ret = write( 1, data, count );
if( ret <= 0 ) {
- Com_Error( ERR_FATAL, "%s: %d bytes written: %s",
- __func__, ret, strerror( errno ) );
+ //Com_Error( ERR_FATAL, "%s: %d bytes written: %s",
+ // __func__, ret, strerror( errno ) );
+ break;
}
count -= ret;
data += ret;
@@ -375,7 +376,8 @@ void Sys_RunConsole( void ) {
tv.tv_sec = 0;
tv.tv_usec = 0;
if( select( 1, &fd, NULL, NULL, &tv ) == -1 ) {
- Com_Error( ERR_FATAL, "%s: select() failed", __func__ );
+ Com_Error( ERR_FATAL, "%s: select() failed: %s",
+ __func__, strerror( errno ) );
}
if( !FD_ISSET( 0, &fd ) ) {
@@ -390,7 +392,11 @@ void Sys_RunConsole( void ) {
return;
}
if( ret < 0 ) {
- Com_Error( ERR_FATAL, "%s: %d bytes read", __func__, ret );
+ if( errno == EINTR ) {
+ return;
+ }
+ Com_Error( ERR_FATAL, "%s: read() failed: %s",
+ __func__, strerror( errno ) );
}
text[ret] = 0;
@@ -734,28 +740,24 @@ void Sys_FixFPCW( void ) {
/*
=================
-Sys_Kill
+Sys_Term
=================
*/
-static void Sys_Kill( int signum ) {
- signal( SIGTERM, SIG_DFL );
- signal( SIGINT, SIG_DFL );
- signal( SIGSEGV, SIG_DFL );
-
+static void Sys_Term( int signum ) {
+#ifdef _GNU_SOURCE
+ Com_Printf( "%s\n", strsignal( signum ) );
+#else
Com_Printf( "Received signal %d, exiting\n", signum );
- Com_Quit();
+#endif
+ Com_Quit( NULL );
}
/*
=================
-Sys_Segv
+Sys_Kill
=================
*/
-static void Sys_Segv( int signum ) {
- signal( SIGTERM, SIG_DFL );
- signal( SIGINT, SIG_DFL );
- signal( SIGSEGV, SIG_DFL );
-
+static void Sys_Kill( int signum ) {
Sys_ShutdownTTY();
#if USE_SDL
@@ -764,7 +766,11 @@ static void Sys_Segv( int signum ) {
SDL_Quit();
#endif
- fprintf( stderr, "Received signal SIGSEGV, segmentation fault\n" );
+#ifdef _GNU_SOURCE
+ fprintf( stderr, "%s\n", strsignal( signum ) );
+#else
+ fprintf( stderr, "Received signal %d, aborting\n", signum );
+#endif
exit( 1 );
}
@@ -777,9 +783,12 @@ Sys_Init
void Sys_Init( void ) {
char *homedir;
- signal( SIGTERM, Sys_Kill );
- signal( SIGINT, Sys_Kill );
- signal( SIGSEGV, Sys_Segv );
+ signal( SIGTERM, Sys_Term );
+ signal( SIGINT, Sys_Term );
+ signal( SIGSEGV, Sys_Kill );
+ signal( SIGILL, Sys_Kill );
+ signal( SIGFPE, Sys_Kill );
+ signal( SIGTRAP, Sys_Kill );
signal( SIGTTIN, SIG_IGN );
signal( SIGTTOU, SIG_IGN );
@@ -807,7 +816,7 @@ void Sys_Init( void ) {
sys_stdio = Cvar_Get( "sys_stdio", "2", CVAR_NOSET );
if( sys_stdio->integer ) {
- // change stdin and stdout to non-blocking
+ // change stdin to non-blocking and stdout to blocking
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) | FNDELAY );
fcntl( 1, F_SETFL, fcntl( 1, F_GETFL, 0 ) & ~FNDELAY );
@@ -820,6 +829,9 @@ void Sys_Init( void ) {
Cvar_Set( "sys_stdio", "1" );
}
}
+ signal( SIGHUP, Sys_Term );
+ } else {
+ signal( SIGHUP, SIG_IGN );
}
Sys_FixFPCW();
@@ -855,8 +867,8 @@ void Sys_Error( const char *error, ... ) {
Sys_ShutdownTTY();
#if USE_SDL
- SDL_ShowCursor( SDL_ENABLE );
SDL_WM_GrabInput( SDL_GRAB_OFF );
+ SDL_ShowCursor( SDL_ENABLE );
SDL_Quit();
#endif
@@ -890,11 +902,8 @@ Sys_FreeLibrary
=================
*/
void Sys_FreeLibrary( void *handle ) {
- if( !handle ) {
- return;
- }
- if( dlclose( handle ) ) {
- Com_Error( ERR_FATAL, "dlclose failed on %p", handle );
+ if( handle && dlclose( handle ) ) {
+ Com_Error( ERR_FATAL, "dlclose failed on %p: %s", handle, dlerror() );
}
}