diff options
-rw-r--r-- | lib/Utils/DebugDump.cpp | 26 | ||||
-rw-r--r-- | src/Daemon/CrashWatcher.cpp | 34 |
2 files changed, 35 insertions, 25 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp index b2767bad..d239ba1b 100644 --- a/lib/Utils/DebugDump.cpp +++ b/lib/Utils/DebugDump.cpp @@ -40,6 +40,7 @@ #include <stdlib.h> #include "CommLayerInner.h" +// BUG? in C/C++, compiler may assume that function address is never NULL #pragma weak comm_layer_inner_debug #define comm_layer_inner_debug(msg) ({\ if (comm_layer_inner_debug)\ @@ -64,7 +65,6 @@ void CDebugDump::Open(const std::string& pDir) throw CABRTException(EXCEP_ERROR, "CDebugDump::CDebugDump(): DebugDump is already opened."); } m_sDebugDumpDir = RemoveBackSlashes(pDir); - std::string lockPath = m_sDebugDumpDir + "/.lock"; if (!ExistFileDir(m_sDebugDumpDir)) { throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::CDebugDump(): "+m_sDebugDumpDir+" does not exist."); @@ -100,7 +100,7 @@ bool CDebugDump::GetAndSetLock(const std::string& pLockFile, const std::string& { if (errno != EEXIST) { - throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::GetAndSetLock(): cannot create lock file"); + throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::GetAndSetLock(): cannot create lock file"); } fd = open(pLockFile.c_str(), O_RDONLY); if (fd == -1) @@ -111,7 +111,7 @@ bool CDebugDump::GetAndSetLock(const std::string& pLockFile, const std::string& int r = read(fd, pid, sizeof(pid) - 1); if (r == -1) { - close(fd); + close(fd); throw CABRTException(EXCEP_DD_OPEN, "CDebugDump::GetAndSetLock(): cannot get a pid"); } pid[r] = '\0'; @@ -242,7 +242,7 @@ void CDebugDump::DeleteFileDir(const std::string& pDir) } if (remove(fullPath.c_str()) == -1) { - closedir(dir); + closedir(dir); throw CABRTException(EXCEP_DD_DELETE, "CDebugDump::DeleteFileDir(): Cannot remove file: " + fullPath); } } @@ -331,10 +331,6 @@ void CDebugDump::SaveTime() { std::stringstream ss; time_t t = time(NULL); - if (((time_t) -1) == t) /* isn't it a bit TOO paranoid? :) */ - { - throw CABRTException(EXCEP_ERROR, "CDebugDump::SaveTime(): Cannot get local time."); - } ss << t; SaveText(FILENAME_TIME, ss.str()); } @@ -494,10 +490,18 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool } while ((dent = readdir(m_pGetNextFileDir)) != NULL) { - if (dent->d_type == DT_REG) - { + struct stat statbuf; + std::string fullname = m_sDebugDumpDir + "/" + dent->d_name; + + /* some filesystems do not report the type! they report DT_UNKNOWN */ + if (dent->d_type == DT_REG + || (dent->d_type == DT_UNKNOWN + && lstat(fullname.c_str(), &statbuf) == 0 + && S_ISREG(statbuf.st_mode) + ) + ) { pFileName = dent->d_name; - if (IsTextFile(m_sDebugDumpDir + "/" + pFileName)) + if (IsTextFile(fullname)) { LoadText(pFileName, pContent); pIsTextFile = true; diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 13e12d0d..3163d851 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -18,18 +18,12 @@ */ #include "abrtlib.h" #include "CrashWatcher.h" -//#include <unistd.h> #include <iostream> #include <climits> #include <cstdlib> -//#include <sys/types.h> -//#include <pwd.h> -//#include <sys/stat.h> -//#include <fcntl.h> #include <cstring> #include <csignal> #include <sstream> -//#include <dirent.h> #include <cstring> #include "ABRTException.h" @@ -47,6 +41,16 @@ to_string( T x ) } */ +/* Is it "." or ".."? */ +static bool dot_or_dotdot(const char *filename) +{ + if (filename[0] != '.') return false; + if (filename[1] == '\0') return true; + if (filename[1] != '.') return false; + if (filename[2] == '\0') return true; + return false; +} + gboolean CCrashWatcher::handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointer daemon) { GIOError err; @@ -408,12 +412,13 @@ double CCrashWatcher::GetDirSize(const std::string &pPath) dp = opendir(pPath.c_str()); if (dp != NULL) { - while ((ep = readdir(dp))) + while ((ep = readdir(dp)) != NULL) { - if (strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0) + if (dot_or_dotdot(ep->d_name)) + continue; + dname = pPath + "/" + ep->d_name; + if (lstat(dname.c_str(), &stats) == 0) { - dname = pPath + "/" + ep->d_name; - lstat(dname.c_str(), &stats); if (S_ISDIR(stats.st_mode)) { size += GetDirSize(dname); @@ -515,16 +520,17 @@ void CCrashWatcher::FindNewDumps(const std::string& pPath) DIR *dp; std::vector<std::string> dirs; std::string dname; - // get potencial unsaved debugdumps + // get potential unsaved debugdumps dp = opendir(pPath.c_str()); if (dp != NULL) { while ((ep = readdir(dp))) { - if(strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0) + if (dot_or_dotdot(ep->d_name)) + continue; + dname = pPath + "/" + ep->d_name; + if (lstat(dname.c_str(), &stats) == 0) { - dname = pPath + "/" + ep->d_name; - lstat(dname.c_str(), &stats); if (S_ISDIR(stats.st_mode)) { dirs.push_back(dname); |