From 715a95c39d11be0c759ce3c0eb1ebc7acba37afb Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 25 Oct 2019 11:02:14 +0200 Subject: [PATCH] plugins: load from default location if no -o plugins is specified, load them from $PKGLIBEXECDIR (usually has the value /usr/libexec/fuse-overlayfs). Signed-off-by: Giuseppe Scrivano --- Makefile.am | 2 ++ main.c | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index c637f46..a56f137 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,6 +8,8 @@ EXTRA_DIST = m4/gnulib-cache.m4 rpm/fuse-overlayfs.spec.template autogen.sh fuse CLEANFILES = fuse-overlayfs.1 +AM_CPPFLAGS = -DPKGLIBEXECDIR='"$(pkglibexecdir)"' + fuse_overlayfs_CFLAGS = -I . -I $(abs_srcdir)/lib $(FUSE_CFLAGS) fuse_overlayfs_LDFLAGS = fuse_overlayfs_LDADD = lib/libgnu.a $(FUSE_LIBS) diff --git a/main.c b/main.c index 86b93b3..c519d5c 100644 --- a/main.c +++ b/main.c @@ -4938,6 +4938,36 @@ set_limits () error (EXIT_FAILURE, errno, "cannot set nofile rlimit"); } +static char * +load_default_plugins () +{ + DIR *dp = NULL; + char *plugins = strdup (""); + + dp = opendir (PKGLIBEXECDIR); + if (dp == NULL) + return plugins; + + for (;;) + { + struct dirent *dent; + + dent = readdir (dp); + if (dent == NULL) + break; + if (dent->d_type != DT_DIR) + { + char *new_plugins = NULL; + asprintf (&new_plugins, "%s/%s:%s", PKGLIBEXECDIR, dent->d_name, plugins); + free (plugins); + plugins = new_plugins; + } + } + closedir (dp); + + return plugins; +} + int main (int argc, char *argv[]) { @@ -5042,8 +5072,10 @@ main (int argc, char *argv[]) error (EXIT_FAILURE, errno, "cannot convert %s", lo.timeout_str); } - if (lo.plugins) - lo.plugins_ctx = load_plugins (lo.plugins); + if (lo.plugins == NULL) + lo.plugins = load_default_plugins (); + + lo.plugins_ctx = load_plugins (lo.plugins); layers = read_dirs (&lo, lo.lowerdir, true, NULL); if (layers == NULL) @@ -5133,8 +5165,7 @@ err_out1: hash_free (lo.inodes); - if (lo.plugins) - plugin_free_all (lo.plugins_ctx); + plugin_free_all (lo.plugins_ctx); free_mapping (lo.uid_mappings); free_mapping (lo.gid_mappings);