Blame SOURCES/0074-util-inotify-fixed-bug-in-inotify-event-processing.patch

73eb8e
From 758b99590a8e1f69b4487fad9cf343525797e05f Mon Sep 17 00:00:00 2001
73eb8e
From: Alexey Tikhonov <atikhono@redhat.com>
73eb8e
Date: Fri, 12 Jun 2020 20:45:23 +0200
73eb8e
Subject: [PATCH] util/inotify: fixed bug in inotify event processing
73eb8e
MIME-Version: 1.0
73eb8e
Content-Type: text/plain; charset=UTF-8
73eb8e
Content-Transfer-Encoding: 8bit
73eb8e
73eb8e
Error was spotted with the help of the following warning:
73eb8e
```
73eb8e
Error: CLANG_WARNING:
73eb8e
sssd-2.3.1/src/util/inotify.c:327:21: warning: Value stored to 'rewatch' is never read
73eb8e
 #                    rewatch = true;
73eb8e
 #                    ^         ~~~~
73eb8e
```
73eb8e
73eb8e
First part of the issue was that EAGAIN returned by the process_dir_event()
73eb8e
didn't trigger snotify_rewatch() (as suggested by the comments).
73eb8e
Fixing this part is already enough to resolve issue #1031 (as it was
73eb8e
reported).
73eb8e
73eb8e
Another part of the issue was that process_file_event() return code wasn't
73eb8e
checked against EAGAIN (again, as suggested by the DEBUG message).
73eb8e
Strictly speaking, I'm not sure if this part is really required or
73eb8e
if processing DIR events would cover all cases, but rebuilding watches
73eb8e
on IN_IGNORED won't hurt.
73eb8e
73eb8e
Resolves: https://github.com/SSSD/sssd/issues/1031
73eb8e
73eb8e
Reviewed-by: Tomáš Halman <thalman@redhat.com>
73eb8e
(cherry picked from commit 0c5711f9bae1cb46d4cd3fbe5d86d8688087be13)
73eb8e
73eb8e
Reviewed-by: Tomáš Halman <thalman@redhat.com>
73eb8e
---
73eb8e
 src/util/inotify.c | 29 ++++++++++++-----------------
73eb8e
 1 file changed, 12 insertions(+), 17 deletions(-)
73eb8e
73eb8e
diff --git a/src/util/inotify.c b/src/util/inotify.c
73eb8e
index ffc15ad4d..11a2e0f32 100644
73eb8e
--- a/src/util/inotify.c
73eb8e
+++ b/src/util/inotify.c
73eb8e
@@ -286,7 +286,7 @@ static void snotify_internal_cb(struct tevent_context *ev,
73eb8e
     struct snotify_ctx *snctx;
73eb8e
     ssize_t len;
73eb8e
     errno_t ret;
73eb8e
-    bool rewatch;
73eb8e
+    bool rewatch = false;
73eb8e
 
73eb8e
     snctx = talloc_get_type(data, struct snotify_ctx);
73eb8e
     if (snctx == NULL) {
73eb8e
@@ -305,7 +305,7 @@ static void snotify_internal_cb(struct tevent_context *ev,
73eb8e
             } else {
73eb8e
                 DEBUG(SSSDBG_TRACE_INTERNAL, "All inotify events processed\n");
73eb8e
             }
73eb8e
-            return;
73eb8e
+            break;
73eb8e
         }
73eb8e
 
73eb8e
         if ((size_t) len < sizeof(struct inotify_event)) {
73eb8e
@@ -323,28 +323,23 @@ static void snotify_internal_cb(struct tevent_context *ev,
73eb8e
 
73eb8e
             if (snctx->wctx->dir_wd == in_event->wd) {
73eb8e
                 ret = process_dir_event(snctx, in_event);
73eb8e
-                if (ret == EAGAIN) {
73eb8e
-                    rewatch = true;
73eb8e
-                    /* Continue with the loop and read all the events from
73eb8e
-                     * this descriptor first, then rewatch when done
73eb8e
-                     */
73eb8e
-                } else if (ret != EOK) {
73eb8e
-                    DEBUG(SSSDBG_MINOR_FAILURE,
73eb8e
-                        "Failed to process inotify event\n");
73eb8e
-                    continue;
73eb8e
-                }
73eb8e
             } else if (snctx->wctx->file_wd == in_event->wd) {
73eb8e
                 ret = process_file_event(snctx, in_event);
73eb8e
-                if (ret != EOK) {
73eb8e
-                    DEBUG(SSSDBG_MINOR_FAILURE,
73eb8e
-                        "Failed to process inotify event\n");
73eb8e
-                    continue;
73eb8e
-                }
73eb8e
             } else {
73eb8e
                 DEBUG(SSSDBG_MINOR_FAILURE,
73eb8e
                       "Unknown watch %d\n", in_event->wd);
73eb8e
                 ret = EOK;
73eb8e
             }
73eb8e
+
73eb8e
+            if (ret == EAGAIN) {
73eb8e
+                rewatch = true;
73eb8e
+                /* Continue with the loop and read all the events from
73eb8e
+                 * this descriptor first, then rewatch when done
73eb8e
+                 */
73eb8e
+            } else if (ret != EOK) {
73eb8e
+                DEBUG(SSSDBG_MINOR_FAILURE,
73eb8e
+                      "Failed to process inotify event\n");
73eb8e
+            }
73eb8e
         }
73eb8e
     }
73eb8e
 
73eb8e
-- 
73eb8e
2.26.3
73eb8e