From: Karel Zak Date: Tue, 10 Jun 2025 10:15:28 +0000 (+0200) Subject: libmount: (monitor) cleanup op_process_event() return codes X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=89c310c9f4ce1f1d37eca489c0fb467cacbb01ff;p=thirdparty%2Futil-linux.git libmount: (monitor) cleanup op_process_event() return codes Let's use usual concept (<0 error; 0 success; 1 nothing). Signed-off-by: Karel Zak --- diff --git a/libmount/src/monitor.c b/libmount/src/monitor.c index f625dafb6..6bede6b58 100644 --- a/libmount/src/monitor.c +++ b/libmount/src/monitor.c @@ -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); diff --git a/libmount/src/monitor_mountinfo.c b/libmount/src/monitor_mountinfo.c index 0c05051b0..44f0ea46a 100644 --- a/libmount/src/monitor_mountinfo.c +++ b/libmount/src/monitor_mountinfo.c @@ -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; } /* diff --git a/libmount/src/monitor_utab.c b/libmount/src/monitor_utab.c index 4cc1b3acb..1b5815b4d 100644 --- a/libmount/src/monitor_utab.c +++ b/libmount/src/monitor_utab.c @@ -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; }