(#4925) - com_pipefile to create a named pipe for sending commands from other processes, patch by Chris Schwarz

This commit is contained in:
Thilo Schulz 2011-03-10 01:01:27 +00:00
parent a3def2744f
commit 3bf8ec2dab
6 changed files with 122 additions and 0 deletions

4
README
View File

@ -158,6 +158,10 @@ New cvars
com_maxfpsMinimized - Maximum frames per second when minimized
com_busyWait - Will use a busy loop to wait for rendering
next frame when set to non-zero value
com_pipefile - Specify filename to create a named pipe
through which other processes can control
the server while it is running.
Nonfunctional on Windows.
in_joystickNo - select which joystick to use
in_availableJoysticks - list of available Joysticks

View File

@ -50,6 +50,7 @@ jmp_buf abortframe; // an ERR_DROP occured, exit the entire frame
FILE *debuglogfile;
static fileHandle_t pipefile;
static fileHandle_t logfile;
fileHandle_t com_journalFile; // events are written here
fileHandle_t com_journalDataFile; // config files are written here
@ -66,6 +67,7 @@ cvar_t *com_timedemo;
cvar_t *com_sv_running;
cvar_t *com_cl_running;
cvar_t *com_logfile; // 1 = buffer log, 2 = flush after each print
cvar_t *com_pipefile;
cvar_t *com_showtrace;
cvar_t *com_version;
cvar_t *com_blood;
@ -2768,9 +2770,36 @@ void Com_Init( char *commandLine ) {
Com_Printf ("Altivec support is %s\n", com_altivec->integer ? "enabled" : "disabled");
#endif
com_pipefile = Cvar_Get( "com_pipefile", "", CVAR_ARCHIVE|CVAR_LATCH );
if( com_pipefile->string[0] )
{
pipefile = FS_FCreateOpenPipeFile( com_pipefile->string );
}
Com_Printf ("--- Common Initialization Complete ---\n");
}
/*
===============
Com_ReadFromPipe
Read whatever is in com_pipefile, if anything, and execute it
===============
*/
void Com_ReadFromPipe( void )
{
char buffer[MAX_STRING_CHARS] = {""};
qboolean read;
if( !pipefile )
return;
read = FS_Read( buffer, sizeof( buffer ), pipefile );
if( read )
Cbuf_ExecuteText( EXEC_APPEND, buffer );
}
//==================================================================
void Com_WriteConfigToFile( const char *filename ) {
@ -3097,6 +3126,8 @@ void Com_Frame( void ) {
c_pointcontents = 0;
}
Com_ReadFromPipe( );
com_frameNumber++;
}
@ -3116,6 +3147,11 @@ void Com_Shutdown (void) {
com_journalFile = 0;
}
if( pipefile ) {
FS_FCloseFile( pipefile );
FS_HomeRemove( com_pipefile->string );
}
}
//------------------------------------------------------------------------

View File

@ -905,6 +905,50 @@ fileHandle_t FS_FOpenFileAppend( const char *filename ) {
return f;
}
/*
===========
FS_FCreateOpenPipeFile
===========
*/
fileHandle_t FS_FCreateOpenPipeFile( const char *filename ) {
char *ospath;
FILE *fifo;
fileHandle_t f;
if ( !fs_searchpaths ) {
Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
}
f = FS_HandleForFile();
fsh[f].zipFile = qfalse;
Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) );
// don't let sound stutter
S_ClearSoundBuffer();
ospath = FS_BuildOSPath( fs_homepath->string, fs_gamedir, filename );
if ( fs_debug->integer ) {
Com_Printf( "FS_FCreateOpenPipeFile: %s\n", ospath );
}
FS_CheckFilenameIsNotExecutable( ospath, __func__ );
fifo = Sys_Mkfifo( ospath );
if( fifo ) {
fsh[f].handleFiles.file.o = fifo;
fsh[f].handleSync = qfalse;
}
else
{
f = 0;
}
return f;
}
/*
===========
FS_FilenameCompare

View File

@ -626,6 +626,7 @@ int FS_GetModList( char *listbuf, int bufsize );
fileHandle_t FS_FOpenFileWrite( const char *qpath );
fileHandle_t FS_FOpenFileAppend( const char *filename );
fileHandle_t FS_FCreateOpenPipeFile( const char *filename );
// will properly create any needed paths and deal with seperater character issues
fileHandle_t FS_SV_FOpenFileWrite( const char *filename );
@ -1094,6 +1095,7 @@ qboolean Sys_IsLANAddress (netadr_t adr);
void Sys_ShowIP(void);
qboolean Sys_Mkdir( const char *path );
FILE *Sys_Mkfifo( const char *ospath );
char *Sys_Cwd( void );
void Sys_SetDefaultInstallPath(const char *path);
char *Sys_DefaultInstallPath(void);

View File

@ -247,6 +247,31 @@ qboolean Sys_Mkdir( const char *path )
return qtrue;
}
/*
==================
Sys_Mkfifo
==================
*/
FILE *Sys_Mkfifo( const char *ospath )
{
FILE *fifo;
int result;
int fn;
result = mkfifo( ospath, 0600 );
if( result != 0 )
return NULL;
fifo = fopen( ospath, "w+" );
if( fifo )
{
fn = fileno( fifo );
fcntl( fn, F_SETFL, O_NONBLOCK );
}
return fifo;
}
/*
==================
Sys_Cwd

View File

@ -320,6 +320,17 @@ qboolean Sys_Mkdir( const char *path )
return qtrue;
}
/*
==================
Sys_Mkfifo
Noop on windows because named pipes do not function the same way
==================
*/
FILE *Sys_Mkfifo( const char *ospath )
{
return NULL;
}
/*
==============
Sys_Cwd