Blame SOURCES/0229-dd-extend-the-scope-of-DD_DONT_WAIT_FOR_LOCK.patch

28bab8
From 23b5331ef181f0ab81c5fd30ec3aae3d2f86c69d Mon Sep 17 00:00:00 2001
28bab8
From: Matej Habrnal <mhabrnal@redhat.com>
28bab8
Date: Fri, 21 Sep 2018 15:39:21 +0200
28bab8
Subject: [PATCH] dd: extend the scope of DD_DONT_WAIT_FOR_LOCK
28bab8
28bab8
The current implementation uses the flag only to ignore *unlocked or
28bab8
broken* problems that misses some of the required files. If the dump
28bab8
directory is locked by an existing process, dd_lock() waits until
28bab8
the
28bab8
process unlocks it and that causes problems in UI.
28bab8
28bab8
Example:
28bab8
1. abrt-hook-ccpp creates a new dump directory and goes to generate
28bab8
core_backtrace, which blocks it for several seconds.
28bab8
2. An user wants to get list of all problems from abrt-dbus.
28bab8
3. abrt-dbus got stucked on the new problem locked by
28bab8
abrt-hook-ccpp.
28bab8
4. D-Bus connection time-outs, abrt-dbus becomes unreachable.
28bab8
28bab8
This patch adds a new condition which breaks the loop wait for lock
28bab8
if
28bab8
the problem directory is locked by existing process. All other cases
28bab8
are already handled and dd_lock() either returns an error or steals
28bab8
the
28bab8
lock file if the locking process seems to not exist. Transitional
28bab8
states
28bab8
like when the locking process just unlocked the directory are
28bab8
handled too.
28bab8
28bab8
errno is set to EAGAIN that is used by standard functions when an
28bab8
operation failed but it is possible that a next call can be
28bab8
successful.
28bab8
It should inform the calling function that the failure is not fatal
28bab8
and
28bab8
the function can silently continue.
28bab8
28bab8
Related: rhbz#1588272
28bab8
28bab8
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
28bab8
---
28bab8
 src/lib/dump_dir.c | 9 +++++++++
28bab8
 1 file changed, 9 insertions(+)
28bab8
28bab8
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
28bab8
index d7ddec7a..acc5e561 100644
28bab8
--- a/src/lib/dump_dir.c
28bab8
+++ b/src/lib/dump_dir.c
28bab8
@@ -341,6 +341,11 @@ static int dd_lock(struct dump_dir *dd, unsigned sleep_usec, int flags)
28bab8
             return r; /* error */
28bab8
         if (r > 0)
28bab8
             break; /* locked successfully */
28bab8
+        if (flags & DD_DONT_WAIT_FOR_LOCK)
28bab8
+        {
28bab8
+            errno = EAGAIN;
28bab8
+            return -1;
28bab8
+        }
28bab8
         /* Other process has the lock, wait for it to go away */
28bab8
         usleep(sleep_usec);
28bab8
     }
28bab8
@@ -473,6 +478,10 @@ static struct dump_dir *dd_do_open(struct dump_dir *dd, int flags)
28bab8
              */
28bab8
             error_msg("'%s' is not a problem directory", dd->dd_dirname);
28bab8
         }
28bab8
+        else if (errno == EAGAIN && (flags & DD_DONT_WAIT_FOR_LOCK))
28bab8
+        {
28bab8
+            log_debug("Can't access locked directory '%s'", dd->dd_dirname);
28bab8
+        }
28bab8
         else
28bab8
         {
28bab8
  cant_access:
28bab8
-- 
28bab8
2.17.2
28bab8