mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 09:34:19 +00:00
Try to handle FIFO problems more graciously
This commit is contained in:
parent
7b5a738392
commit
08cb934e84
|
@ -1,14 +1,15 @@
|
|||
#include "fifoconsole.h"
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
|
||||
#include <engine/shared/config.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static LOCK gs_FifoLock = 0;
|
||||
static volatile bool gs_stopFifoThread = false;
|
||||
|
@ -40,7 +41,11 @@ void FifoConsole::ListenFifoThread(void *pUser)
|
|||
FifoConsole *pData = (FifoConsole *)pUser;
|
||||
|
||||
if(!gs_FifoLock)
|
||||
return;
|
||||
{
|
||||
dbg_msg("fifo", "FIFO not properly initialized");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
lock_wait(gs_FifoLock);
|
||||
if(gs_stopFifoThread)
|
||||
return;
|
||||
|
@ -50,10 +55,21 @@ void FifoConsole::ListenFifoThread(void *pUser)
|
|||
struct stat attribute;
|
||||
stat(pData->m_pFifoFile, &attribute);
|
||||
|
||||
lock_unlock(gs_FifoLock);
|
||||
|
||||
if(!S_ISFIFO(attribute.st_mode))
|
||||
return;
|
||||
{
|
||||
dbg_msg("fifo", "'%s' is not a FIFO, removing", pData->m_pFifoFile);
|
||||
fs_remove(pData->m_pFifoFile);
|
||||
mkfifo(pData->m_pFifoFile, 0600);
|
||||
stat(pData->m_pFifoFile, &attribute);
|
||||
|
||||
if(!S_ISFIFO(attribute.st_mode))
|
||||
{
|
||||
dbg_msg("fifo", "Can't remove file, quitting");
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
lock_unlock(gs_FifoLock);
|
||||
|
||||
std::ifstream f;
|
||||
char aBuf[8192];
|
||||
|
|
Loading…
Reference in a new issue