summaryrefslogtreecommitdiffstats
path: root/src/Daemon/CrashWatcher.cpp
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-08-04 11:47:44 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-08-04 11:47:44 +0200
commit75e0fad94d0c32e2af7cbb73bed2cc837c5aa909 (patch)
tree98a0c39113c79caf1f8bddcef2b724bcde76b1e7 /src/Daemon/CrashWatcher.cpp
parent12b081bf63388b542727418512eaecbe1ba788ec (diff)
downloadabrt-75e0fad94d0c32e2af7cbb73bed2cc837c5aa909.tar.gz
abrt-75e0fad94d0c32e2af7cbb73bed2cc837c5aa909.tar.xz
abrt-75e0fad94d0c32e2af7cbb73bed2cc837c5aa909.zip
add error checks on lstat calls; add handling of DT_UNKNOWN
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src/Daemon/CrashWatcher.cpp')
-rw-r--r--src/Daemon/CrashWatcher.cpp34
1 files changed, 20 insertions, 14 deletions
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);