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

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