| 12 | #include <cstdlib> |
| 13 | |
| 14 | void CFifo::Init(IConsole *pConsole, const char *pFifoFile, int Flag) |
| 15 | { |
| 16 | m_File = -1; |
| 17 | |
| 18 | m_pConsole = pConsole; |
| 19 | m_IsInit = true; |
| 20 | if(pFifoFile[0] == '\0') |
| 21 | return; |
| 22 | |
| 23 | str_copy(m_aFilename, pFifoFile); |
| 24 | m_Flag = Flag; |
| 25 | |
| 26 | bool IsFifo; |
| 27 | if(mkfifo(m_aFilename, 0600) == 0) |
| 28 | { |
| 29 | struct stat Attribute; |
| 30 | if(stat(m_aFilename, &Attribute) == 0) |
| 31 | { |
| 32 | IsFifo = S_ISFIFO(Attribute.st_mode); |
| 33 | } |
| 34 | else |
| 35 | { |
| 36 | log_warn("fifo", "Failed to stat fifo '%s' (%d '%s')", m_aFilename, errno, strerror(errno)); |
| 37 | IsFifo = false; |
| 38 | } |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | log_warn("fifo", "Failed to create fifo '%s' (%d '%s')", m_aFilename, errno, strerror(errno)); |
| 43 | IsFifo = false; |
| 44 | } |
| 45 | if(!IsFifo) |
| 46 | { |
| 47 | log_warn("fifo", "File '%s' is not a fifo, removing", m_aFilename); |
| 48 | if(fs_remove(m_aFilename) != 0) |
| 49 | { |
| 50 | log_error("fifo", "Failed to remove non-fifo '%s'", m_aFilename); // details logged in fs_remove |
| 51 | return; |
| 52 | } |
| 53 | if(mkfifo(m_aFilename, 0600) != 0) |
| 54 | { |
| 55 | log_error("fifo", "Failed to create fifo '%s' (%d '%s')", m_aFilename, errno, strerror(errno)); |
| 56 | return; |
| 57 | } |
| 58 | struct stat Attribute; |
| 59 | if(stat(m_aFilename, &Attribute) != 0) |
| 60 | { |
| 61 | log_error("fifo", "Failed to stat fifo '%s' (%d '%s')", m_aFilename, errno, strerror(errno)); |
| 62 | return; |
| 63 | } |
| 64 | if(!S_ISFIFO(Attribute.st_mode)) |
| 65 | { |
| 66 | log_error("fifo", "File '%s' is not a fifo", m_aFilename); |
| 67 | return; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | m_File = open(m_aFilename, O_RDONLY | O_NONBLOCK); |
no test coverage detected