From d16343bddc5e690ed3a160c04405d9bddf5aa131 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Thu, 21 Aug 2025 23:50:00 +0200 Subject: [PATCH] [scan] Revert libmount commits due to MacOS/FreeBSD build errors Reverts 3be8e4f and e607019 --- configure.ac | 3 - src/Makefile.am | 1 - src/library/filescanner.c | 95 ++++------------ src/library/filescanner.h | 16 --- src/library/filescanner_mountwatch.c | 161 --------------------------- 5 files changed, 21 insertions(+), 255 deletions(-) delete mode 100644 src/library/filescanner_mountwatch.c diff --git a/configure.ac b/configure.ac index c0887ec5..e2c25e04 100644 --- a/configure.ac +++ b/configure.ac @@ -103,9 +103,6 @@ AC_SEARCH_LIBS([copy_file_range], [c], AC_SEARCH_LIBS([fcopyfile], [c], [AC_DEFINE([HAVE_FCOPYFILE], 1, [Define to 1 if you have fcopyfile])]) -AC_SEARCH_LIBS([mnt_new_monitor], [mount], - [AC_DEFINE([HAVE_LIBMOUNT], 1, - [Define to 1 if you have libmount])]) AC_SEARCH_LIBS([log10], [m]) AC_SEARCH_LIBS([lrint], [m]) diff --git a/src/Makefile.am b/src/Makefile.am index ee93e0a7..9dd91b70 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -88,7 +88,6 @@ owntone_SOURCES = main.c \ library/filescanner.c library/filescanner.h \ library/filescanner_ffmpeg.c library/filescanner_playlist.c \ library/filescanner_smartpl.c library/filescanner_itunes.c \ - library/filescanner_mountwatch.c \ library/rssscanner.c \ library.c library.h \ $(MDNS_SRC) mdns.h \ diff --git a/src/library/filescanner.c b/src/library/filescanner.c index c7134f3e..ffcf9e59 100644 --- a/src/library/filescanner.c +++ b/src/library/filescanner.c @@ -115,7 +115,6 @@ struct stacked_dir { static int inofd; static struct event *inoev; -static struct event *mntev; static struct deferred_pl *playlists; static struct stacked_dir *dirstack; @@ -1131,6 +1130,13 @@ process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie) DPRINTF(E_DBG, L_SCAN, "Directory event: 0x%08x, cookie 0x%08x, wd %d\n", ie->mask, ie->cookie, wi->wd); + if (ie->mask & IN_UNMOUNT) + { + db_file_disable_bymatch(path, STRIP_NONE, 0); + db_pl_disable_bymatch(path, STRIP_NONE, 0); + db_directory_disable_bymatch(path, STRIP_NONE, 0); + } + if (ie->mask & IN_MOVE_SELF) { /* A directory we know about, that got moved from a place @@ -1502,7 +1508,6 @@ inotify_cb(int fd, short event, void *arg) { struct inotify_event *ie; struct watch_info wi; - struct stat sb; uint8_t *buf; uint8_t *ptr; char path[PATH_MAX]; @@ -1560,16 +1565,8 @@ inotify_cb(int fd, short event, void *arg) DPRINTF(E_DBG, L_SCAN, "%s deleted or backing filesystem unmounted!\n", wi.path); db_watch_delete_bywd(ie->wd); - - // Is the directory gone? - if (! (lstat(wi.path, &sb) == 0 && S_ISDIR(sb.st_mode))) - { - free_wi(&wi, 1); - continue; - } - - // After an unmount event the mount point is a regular dir that we must process - ie->mask |= IN_CREATE; + free_wi(&wi, 1); + continue; } path[0] = '\0'; @@ -1617,73 +1614,28 @@ inotify_cb(int fd, short event, void *arg) event_add(inoev, NULL); } -static void -mount_cb(int fd, short event, void *arg) -{ - struct watch_info wi = { 0 }; - char *path = NULL; - enum mountwatch_event mev; - int parent_id; - int ret; - - mev = mountwatch_event_get(&path); - if (mev == MOUNTWATCH_ERR || mev == MOUNTWATCH_NONE) - goto readd; - - // Check if this is a location we are watching - ret = db_watch_get_bypath(&wi, path); - if (ret < 0) - goto readd; - - if (mev == MOUNTWATCH_MOUNT) - { - DPRINTF(E_DBG, L_SCAN, "MNT_MOUNT path %s\n", path); - - // After a mount, the inotify watch we had on the mount point will no - // longer be working, so remove. - inotify_rm_watch(inofd, wi.wd); - db_watch_delete_bywd(wi.wd); - - // Adds watches, scans and sets disabled = 0 - parent_id = get_parent_dir_id(path); - process_directories(path, parent_id, 0); - } - else if (mev == MOUNTWATCH_UNMOUNT) - { - DPRINTF(E_DBG, L_SCAN, "MNT_UNMOUNT path %s\n", path); - - db_file_disable_bymatch(path, STRIP_NONE, 0); - db_pl_disable_bymatch(path, STRIP_NONE, 0); - db_directory_disable_bymatch(path, STRIP_NONE, 0); - } - - readd: - free_wi(&wi, 1); - free(path); - event_add(mntev, NULL); -} - /* Thread: main & scan */ static int inofd_event_set(void) { - int mntfd; - inofd = inotify_init1(IN_CLOEXEC); if (inofd < 0) { DPRINTF(E_FATAL, L_SCAN, "Could not create inotify fd: %s\n", strerror(errno)); + return -1; } - else - CHECK_NULL(L_SCAN, inoev = event_new(evbase_lib, inofd, EV_READ, inotify_cb, NULL)); - mntfd = mountwatch_init(); - if (mntfd >= 0) - CHECK_NULL(L_SCAN, mntev = event_new(evbase_lib, mntfd, EV_READ, mount_cb, NULL)); + inoev = event_new(evbase_lib, inofd, EV_READ, inotify_cb, NULL); #ifndef __linux__ - CHECK_NULL(L_SCAN, deferred_inoev = evtimer_new(evbase_lib, inotify_deferred_cb, NULL)); + deferred_inoev = evtimer_new(evbase_lib, inotify_deferred_cb, NULL); + if (!deferred_inoev) + { + DPRINTF(E_LOG, L_SCAN, "Could not create deferred inotify event\n"); + + return -1; + } #endif return 0; @@ -1696,9 +1648,6 @@ inofd_event_unset(void) #ifndef __linux__ event_free(deferred_inoev); #endif - event_free(mntev); - mountwatch_deinit(); - event_free(inoev); close(inofd); } @@ -1725,7 +1674,6 @@ filescanner_initscan() { /* Enable inotify */ event_add(inoev, NULL); - event_add(mntev, NULL); } return 0; } @@ -1744,7 +1692,6 @@ filescanner_rescan() { /* Enable inotify */ event_add(inoev, NULL); - event_add(mntev, NULL); } return 0; } @@ -1763,7 +1710,6 @@ filescanner_metarescan() { /* Enable inotify */ event_add(inoev, NULL); - event_add(mntev, NULL); } return 0; } @@ -1781,7 +1727,6 @@ filescanner_fullrescan() { /* Enable inotify */ event_add(inoev, NULL); - event_add(mntev, NULL); } return 0; } @@ -2265,7 +2210,9 @@ filescanner_init(void) ret = inofd_event_set(); if (ret < 0) - return -1; + { + return -1; + } return 0; } diff --git a/src/library/filescanner.h b/src/library/filescanner.h index ac749516..52370c1e 100644 --- a/src/library/filescanner.h +++ b/src/library/filescanner.h @@ -4,13 +4,6 @@ #include "db.h" -enum mountwatch_event -{ - MOUNTWATCH_ERR = -1, - MOUNTWATCH_NONE = 0, - MOUNTWATCH_MOUNT = 1, - MOUNTWATCH_UNMOUNT = 2, -}; /* --------------------------- Actual scanners ---------------------------- */ @@ -91,13 +84,4 @@ playlist_add(const char *path); int write_metadata_ffmpeg(const struct media_file_info *mfi); -int -mountwatch_event_get(char **path); - -void -mountwatch_deinit(void); - -int -mountwatch_init(void); - #endif /* !__FILESCANNER_H__ */ diff --git a/src/library/filescanner_mountwatch.c b/src/library/filescanner_mountwatch.c deleted file mode 100644 index 1c88140c..00000000 --- a/src/library/filescanner_mountwatch.c +++ /dev/null @@ -1,161 +0,0 @@ -#include -#include -#include -#include -#include - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "filescanner.h" -#include "config.h" -#include "misc.h" -#include "logger.h" - -#ifdef HAVE_LIBMOUNT -#include - -static struct libmnt_monitor *mountwatch_monitor; -static struct libmnt_table *mountwatch_table; - -// path is allocated if a change is found -static int -compare_tables(char **path, struct libmnt_table *old_tab, struct libmnt_table *new_tab) -{ - struct libmnt_iter *iter; - struct libmnt_fs *fs; - const char *target; - - *path = NULL; - - CHECK_NULL(L_SCAN, iter = mnt_new_iter(MNT_ITER_FORWARD)); - - // Find new mounts (in new_tab but not in old_tab) - mnt_reset_iter(iter, MNT_ITER_FORWARD); - while (mnt_table_next_fs(new_tab, iter, &fs) == 0) - { - target = mnt_fs_get_target(fs); - if (!target || mnt_table_find_target(old_tab, target, MNT_ITER_FORWARD)) - continue; - - *path = strdup(target); - return MOUNTWATCH_MOUNT; - } - - // Find removed mounts (in old_tab but not in new_tab) - mnt_reset_iter(iter, MNT_ITER_FORWARD); - while (mnt_table_next_fs(old_tab, iter, &fs) == 0) - { - target = mnt_fs_get_target(fs); - if (!target || mnt_table_find_target(new_tab, target, MNT_ITER_FORWARD)) - continue; - - *path = strdup(target); - return MOUNTWATCH_UNMOUNT; - } - - mnt_free_iter(iter); - return MOUNTWATCH_NONE; -} - -int -mountwatch_event_get(char **path) -{ - struct libmnt_table *newtable = NULL; - enum mountwatch_event event; - int ret; - - *path = NULL; - - ret = mnt_monitor_event_cleanup(mountwatch_monitor); - if (ret < 0) - { - DPRINTF(E_WARN, L_SCAN, "Monitor cleanup failed: %s\n", strerror(-ret)); - goto error; - } - - CHECK_NULL(L_SCAN, newtable = mnt_new_table()); - - ret = mnt_table_parse_mtab(newtable, NULL); - if (ret < 0) - { - DPRINTF(E_WARN, L_SCAN, "Failed to reload mount table: %s\n", strerror(-ret)); - goto error; - } - - event = compare_tables(path, mountwatch_table, newtable); - - mnt_unref_table(mountwatch_table); - mountwatch_table = newtable; - - return event; - - error: - if (newtable) - mnt_unref_table(newtable); - - return MOUNTWATCH_ERR; -} - -void -mountwatch_deinit(void) -{ - mnt_unref_table(mountwatch_table); - mountwatch_table = NULL; - - mnt_unref_monitor(mountwatch_monitor); - mountwatch_monitor = NULL; -} - -int -mountwatch_init(void) -{ - int ret, fd; - - CHECK_NULL(L_SCAN, mountwatch_monitor = mnt_new_monitor()); - - ret = mnt_monitor_enable_kernel(mountwatch_monitor, 1); - if (ret < 0) - goto error; - - fd = mnt_monitor_get_fd(mountwatch_monitor); - if (fd < 0) - goto error; - - mountwatch_table = mnt_new_table(); - if (!mountwatch_table) - goto error; - - ret = mnt_table_parse_mtab(mountwatch_table, NULL); - if (ret < 0) - goto error; - - return fd; - - error: - DPRINTF(E_LOG, L_SCAN, "Error initializing libmount, mount/unmount events won't be detected\n"); - mountwatch_deinit(); - errno = -ret; //TODO - return -1; -} -#else -int -mountwatch_event_get(char **path) -{ - return -1; -} - -void -mountwatch_deinit(void) -{ - return; -} - -int -mountwatch_init(void) -{ - DPRINTF(E_LOG, L_SCAN, "No libmount on this platform, mount/unmount events won't be detected\n"); - return -1; -} -#endif