]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: (monitor) cleanup op_process_event() return codes
authorKarel Zak <kzak@redhat.com>
Tue, 10 Jun 2025 10:15:28 +0000 (12:15 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Aug 2025 12:52:59 +0000 (14:52 +0200)
Let's use usual concept (<0 error; 0 success; 1 nothing).

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/monitor.c
libmount/src/monitor_mountinfo.c
libmount/src/monitor_utab.c

index f625dafb6a31bf6e58d8724d2b3a526c3941e999..6bede6b58f9a2af5feef3a11c5fb146bdf012ef7 100644 (file)
@@ -339,11 +339,11 @@ static int read_epoll_events(struct libmnt_monitor *mn, int timeout, struct moni
                        goto failed;
                }
 
-               /* rc: 1 event accepted; 0 ignored; <0 error */
+               /* rc: <0 error; 0 accepted; 1 nothing */
                rc = me->opers->op_process_event(mn, me);
                if (rc < 0)
                        goto failed;
-               if (rc == 1)
+               if (rc == 0)
                        break;
                /* TODO" recalculate timeout */
        } while (1);
index 0c05051b06aab6fde32b44c012c55829890f132e..44f0ea46ac35470af75faa966d326454e747fe12 100644 (file)
@@ -54,19 +54,18 @@ err:
        return rc;
 }
 
+/* Returns: <0 error; 0 success; 1 nothing */
 static int kernel_process_event(struct libmnt_monitor *mn,
                                struct monitor_entry *me)
 {
-       int status = 1;
-
        if (!mn || !me || me->fd < 0)
-               return 0;
+               return -EINVAL;
 
        if (mn->kernel_veiled && access(MNT_PATH_UTAB ".act", F_OK) == 0) {
-               status = 0;
                DBG(MONITOR, ul_debugobj(mn, "kernel event veiled"));
+               return 1;
        }
-       return status;
+       return 0;
 }
 
 /*
index 4cc1b3acb4c9d773c01fae0f4caa257da1601d84..1b5815b4d68cfd7ee10c41fdf567967e9371c2fb 100644 (file)
@@ -56,7 +56,7 @@ static int userspace_add_watch(struct monitor_entry *me, int *final, int *fd)
                DBG(MONITOR, ul_debug(" added inotify watch for %s [fd=%d]", filename, wd));
                rc = 0;
                if (final)
-                       *final = 1;
+                       *final = 0;     /* success */
                if (fd)
                        *fd = wd;
                goto done;
@@ -123,15 +123,17 @@ err:
 
 /*
  * verify and drain inotify buffer
+ *
+ * Returns: <0 error; 0 success; 1 nothing
  */
 static int userspace_process_event(struct libmnt_monitor *mn,
                                        struct monitor_entry *me)
 {
        char buf[sizeof(struct inotify_event) + NAME_MAX + 1];
-       int status = 0;
+       int status = 1;         /* nothing by default */
 
        if (!me || me->fd < 0)
-               return 0;
+               return -EINVAL;
 
        DBG(MONITOR, ul_debugobj(mn, "process utab event"));
 
@@ -154,7 +156,7 @@ static int userspace_process_event(struct libmnt_monitor *mn,
                        DBG(MONITOR, ul_debugobj(mn, " inotify event 0x%x [%s]\n", e->mask, e->len ? e->name : ""));
 
                        if (e->mask & IN_CLOSE_WRITE)
-                               status = 1;
+                               status = 0;
                        else {
                                /* add watch for the event file */
                                userspace_add_watch(me, &status, &fd);
@@ -167,7 +169,8 @@ static int userspace_process_event(struct libmnt_monitor *mn,
                }
        } while (1);
 
-       DBG(MONITOR, ul_debugobj(mn, "%s", status == 1 ? " success" : " nothing"));
+       DBG(MONITOR, ul_debugobj(mn, "%s", status < 0  ? " failed" :
+                                          status == 0 ? " success" : " nothing"));
        return status;
 }