[LIBREPORT PATCH] ignore directories without type element - rhbz#958968

Jiri Moskovcak jmoskovc at redhat.com
Wed Aug 21 12:45:36 UTC 2013


Signed-off-by: Jiri Moskovcak <jmoskovc at redhat.com>
---
 src/include/dump_dir.h |  1 +
 src/lib/dump_dir.c     | 19 ++++++++++++++++++-
 tests/is_text_file.at  |  3 ++-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/include/dump_dir.h b/src/include/dump_dir.h
index b533a97..a094988 100644
--- a/src/include/dump_dir.h
+++ b/src/include/dump_dir.h
@@ -51,6 +51,7 @@ struct dump_dir {
     /* mode of saved files */
     mode_t mode;
     time_t dd_time;
+    char *dd_type;
 };
 
 void dd_close(struct dump_dir *dd);
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index c1037b3..3054899 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -256,6 +256,8 @@ static int dd_lock(struct dump_dir *dd, unsigned sleep_usec, int flags)
     strcpy(lock_buf + dirname_len, "/.lock");
 
     unsigned count = NO_TIME_FILE_COUNT;
+    const char *missing_file = NULL;
+
  retry:
     while (1)
     {
@@ -280,9 +282,24 @@ static int dd_lock(struct dump_dir *dd, unsigned sleep_usec, int flags)
              * by delete_file_dir.
              * Unlock and back off.
              */
+            missing_file = FILENAME_TIME;
+            goto incomplete_dd;  // don't need to bother to check for other files
+        }
+
+        strcpy(lock_buf + dirname_len, "/"FILENAME_TYPE);
+        dd->dd_type = load_text_file(lock_buf, DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE);
+        if (!dd->dd_type)
+        {
+            missing_file = FILENAME_TYPE;
+            goto incomplete_dd;
+        }
+
+incomplete_dd:
+        if (missing_file)
+        {
             strcpy(lock_buf + dirname_len, "/.lock");
             xunlink(lock_buf);
-            VERB1 log("Unlocked '%s' (no or corrupted time file)", lock_buf);
+            VERB1 log("Unlocked '%s' (no or corrupted '%s' file)", lock_buf, missing_file);
             if (--count == 0 || flags & DD_DONT_WAIT_FOR_LOCK)
             {
                 errno = EISDIR; /* "this is an ordinary dir, not dump dir" */
diff --git a/tests/is_text_file.at b/tests/is_text_file.at
index 0a3add5..0c4649d 100644
--- a/tests/is_text_file.at
+++ b/tests/is_text_file.at
@@ -17,7 +17,8 @@ int main(void)
     assert(chdir(dir) == 0);
     struct dump_dir *dd = dd_create("test", -1, -1);
     assert(dd);
-    dd_save_text(dd, "time", "12345678");
+    dd_save_text(dd, FILENAME_TIME, "12345678");
+    dd_save_text(dd, FILENAME_TYPE, "testing_type");
 
     dd_save_text(dd, "os_release", "Fedora release 19 (Schrödinger's Cat)");
     //dd_save_text(dd, "cat", "Schrödinger's Cat");
-- 
1.8.3.1



More information about the Crash-catcher mailing list