Fixed infinite recursion of writing crashlog because we're out of file handles.

Fixes Bugzilla #3772.
This commit is contained in:
Ryan C. Gordon 2009-09-15 00:19:22 +00:00
parent 76b7468a9d
commit 5079343ecd
3 changed files with 26 additions and 8 deletions

View file

@ -478,7 +478,7 @@ FS_CreatePath
Creates any directories needed to store the given filename Creates any directories needed to store the given filename
============ ============
*/ */
static qboolean FS_CreatePath (char *OSPath) { qboolean FS_CreatePath (char *OSPath) {
char *ofs; char *ofs;
// make absolutely sure that it can't back up the path // make absolutely sure that it can't back up the path

View file

@ -602,6 +602,7 @@ void FS_FreeFileList( char **list );
qboolean FS_FileExists( const char *file ); qboolean FS_FileExists( const char *file );
qboolean FS_CreatePath (char *OSPath);
char *FS_BuildOSPath( const char *base, const char *game, const char *qpath ); char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
int FS_LoadStack( void ); int FS_LoadStack( void );

View file

@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <sys/time.h> #include <sys/time.h>
#include <pwd.h> #include <pwd.h>
#include <libgen.h> #include <libgen.h>
#include <fcntl.h>
// Used to determine where to store user-specific files // Used to determine where to store user-specific files
static char homePath[ MAX_OSPATH ] = { 0 }; static char homePath[ MAX_OSPATH ] = { 0 };
@ -501,23 +502,39 @@ void Sys_ErrorDialog( const char *error )
{ {
char buffer[ 1024 ]; char buffer[ 1024 ];
unsigned int size; unsigned int size;
fileHandle_t f; int f = -1;
const char *homepath = Cvar_VariableString( "fs_homepath" );
const char *gamedir = Cvar_VariableString( "fs_gamedir" );
const char *fileName = "crashlog.txt"; const char *fileName = "crashlog.txt";
char *ospath = FS_BuildOSPath( homepath, gamedir, fileName );
Sys_Print( va( "%s\n", error ) ); Sys_Print( va( "%s\n", error ) );
// Write console log to file /* make sure the write path for the crashlog exists... */
f = FS_FOpenFileWrite( fileName ); if( FS_CreatePath( ospath ) ) {
if( !f ) Com_Printf( "ERROR: couldn't create path '%s' for crash log.\n", ospath );
return;
}
/* we might be crashing because we maxed out the Quake MAX_FILE_HANDLES,
which will come through here, so we don't want to recurse forever by
calling FS_FOpenFileWrite()...use the Unix system APIs instead. */
f = open(ospath, O_CREAT | O_TRUNC | O_WRONLY, 0640);
if( f == -1 )
{ {
Com_Printf( "ERROR: couldn't open %s\n", fileName ); Com_Printf( "ERROR: couldn't open %s\n", fileName );
return; return;
} }
while( ( size = CON_LogRead( buffer, sizeof( buffer ) ) ) > 0 ) /* We're crashing, so we don't care much if write() or close() fails. */
FS_Write( buffer, size, f ); while( ( size = CON_LogRead( buffer, sizeof( buffer ) ) ) > 0 ) {
if (write( f, buffer, size ) != size) {
Com_Printf( "ERROR: couldn't fully write to %s\n", fileName );
break;
}
}
FS_FCloseFile( f ); close(f);
} }
/* /*