Remove fifo file on shutdown

This commit is contained in:
def 2021-02-21 17:31:25 +01:00
parent a1fb94c6b7
commit 7f9110b67c
2 changed files with 14 additions and 9 deletions

View file

@ -19,36 +19,40 @@ void CFifo::Init(IConsole *pConsole, char *pFifoFile, int Flag)
if(pFifoFile[0] == '\0')
return;
str_copy(m_aFilename, pFifoFile, sizeof(m_aFilename));
m_Flag = Flag;
mkfifo(pFifoFile, 0600);
mkfifo(m_aFilename, 0600);
struct stat Attribute;
stat(pFifoFile, &Attribute);
stat(m_aFilename, &Attribute);
if(!S_ISFIFO(Attribute.st_mode))
{
dbg_msg("fifo", "'%s' is not a fifo, removing", pFifoFile);
fs_remove(pFifoFile);
mkfifo(pFifoFile, 0600);
stat(pFifoFile, &Attribute);
dbg_msg("fifo", "'%s' is not a fifo, removing", m_aFilename);
fs_remove(m_aFilename);
mkfifo(m_aFilename, 0600);
stat(m_aFilename, &Attribute);
if(!S_ISFIFO(Attribute.st_mode))
{
dbg_msg("fifo", "can't remove file '%s', quitting", pFifoFile);
dbg_msg("fifo", "can't remove file '%s', quitting", m_aFilename);
exit(2);
}
}
m_File = open(pFifoFile, O_RDONLY | O_NONBLOCK);
m_File = open(m_aFilename, O_RDONLY | O_NONBLOCK);
if(m_File < 0)
dbg_msg("fifo", "can't open file '%s'", pFifoFile);
dbg_msg("fifo", "can't open file '%s'", m_aFilename);
}
void CFifo::Shutdown()
{
if(m_File >= 0)
{
close(m_File);
fs_remove(m_aFilename);
}
}
void CFifo::Update()

View file

@ -8,6 +8,7 @@
class CFifo
{
IConsole *m_pConsole;
char m_aFilename[MAX_PATH_LENGTH];
int m_Flag;
int m_File;