void FileReader::ReadUntilEof() { std::string line; while (std::getline(m_ifstream, line)) AddLine(line); if (m_ifstream.eof()) { m_ifstream.clear(); // clear EOF condition // resync to end of file, even if the file shrunk auto lastReadPosition = m_ifstream.tellg(); m_ifstream.seekg(0, m_ifstream.end); auto length = m_ifstream.tellg(); if (length > lastReadPosition) m_ifstream.seekg(lastReadPosition); else if (length != lastReadPosition) Add(stringbuilder() << "file shrank, resynced at offset " << length); } else { // Some error other then EOF occured Add("Stopped tailing " + m_filename); m_end = true; } }
void DBWinReader::Notify() { HANDLE handle = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, m_dbWinBuffer->processId); #ifdef OPENPROCESS_DEBUG if (handle == 0) { Win32Error error(GetLastError(), "OpenProcess"); std::string s = stringbuilder() << error.what() << " " << m_dbWinBuffer->data; Add(m_dbWinBuffer->processId, s.c_str(), handle); continue; } #endif Add(m_dbWinBuffer->processId, m_dbWinBuffer->data, handle); SetEvent(m_dbWinBufferReady.get()); }
Lines NewlineFilter::FlushLinesFromTerminatedProcess(DWORD pid, HANDLE handle) { Lines lines; if (m_lineBuffers.find(pid) != m_lineBuffers.end()) { if (!m_lineBuffers[pid].empty()) { // timestamp not filled, this will be done by the loopback source lines.push_back(Line(0, FILETIME(), pid, "<flush>", m_lineBuffers[pid], nullptr)); } m_lineBuffers.erase(pid); } auto processName = Str(ProcessInfo::GetProcessName(handle)).str(); auto info = ProcessInfo::GetProcessInfo(handle); std::string infoStr = stringbuilder() << "<process started at " << info << " has now terminated>"; lines.push_back(Line(0, FILETIME(), pid, processName, infoStr, nullptr)); return lines; }
void exceptionmessage(const char* what, const char * location) { auto trimmed = boost::trim_copy_if(std::string(what), boost::is_any_of("\r\n\t")); errormessage(stringbuilder() << "Exception '" << trimmed << "' occured at " << location, "Exception occurred"); }
void assertmessage(const std::string& assertion, const std::string& message, const char * location) { errormessage(stringbuilder() << "Assertion '" << assertion << "' failed (" << message << ") at " << location, "Exception occurred"); }