* Worker thread to transfer data from the pipe to the current logfile. * * We need this because on Windows, WaitForMultipleObjects does not work on * unnamed pipes: it always reports "signaled", so the blocking ReadFile won't * allow for SIGHUP; and select is for sockets only. */
| 1786 | * allow for SIGHUP; and select is for sockets only. |
| 1787 | */ |
| 1788 | static unsigned int __stdcall |
| 1789 | pipeThread(void *arg) |
| 1790 | { |
| 1791 | char logbuffer[READ_BUF_SIZE]; |
| 1792 | int bytes_in_logbuffer = 0; |
| 1793 | |
| 1794 | for (;;) |
| 1795 | { |
| 1796 | DWORD bytesRead; |
| 1797 | BOOL result; |
| 1798 | |
| 1799 | result = ReadFile(syslogPipe[0], |
| 1800 | logbuffer + bytes_in_logbuffer, |
| 1801 | sizeof(logbuffer) - bytes_in_logbuffer, |
| 1802 | &bytesRead, 0); |
| 1803 | |
| 1804 | /* |
| 1805 | * Enter critical section before doing anything that might touch |
| 1806 | * global state shared by the main thread. Anything that uses |
| 1807 | * palloc()/pfree() in particular are not safe outside the critical |
| 1808 | * section. |
| 1809 | */ |
| 1810 | EnterCriticalSection(&sysloggerSection); |
| 1811 | if (result) |
| 1812 | { |
| 1813 | DWORD error = GetLastError(); |
| 1814 | |
| 1815 | if (error == ERROR_HANDLE_EOF || |
| 1816 | error == ERROR_BROKEN_PIPE) |
| 1817 | break; |
| 1818 | _dosmaperr(error); |
| 1819 | ereport(LOG, |
| 1820 | (errcode_for_file_access(), |
| 1821 | errmsg("could not read from logger pipe: %m"))); |
| 1822 | } |
| 1823 | else if (bytesRead > 0) |
| 1824 | { |
| 1825 | bytes_in_logbuffer += bytesRead; |
| 1826 | process_pipe_input(logbuffer, &bytes_in_logbuffer); |
| 1827 | } |
| 1828 | |
| 1829 | /* |
| 1830 | * If we've filled the current logfile, nudge the main thread to do a |
| 1831 | * log rotation. |
| 1832 | */ |
| 1833 | if (Log_RotationSize > 0) |
| 1834 | { |
| 1835 | if (ftell(syslogFile) >= Log_RotationSize * 1024L || |
| 1836 | (csvlogFile != NULL && ftell(csvlogFile) >= Log_RotationSize * 1024L)) |
| 1837 | SetLatch(MyLatch); |
| 1838 | } |
| 1839 | LeaveCriticalSection(&sysloggerSection); |
| 1840 | } |
| 1841 | |
| 1842 | /* We exit the above loop only upon detecting pipe EOF */ |
| 1843 | pipe_eof_seen = true; |
| 1844 | |
| 1845 | /* if there's any data left then force it out now */ |
nothing calls this directly
no test coverage detected