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

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