dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

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

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