Add a generic plugin for use by simple Collections
authorSteve Lawrence <slawrence@tresys.com>
Mon, 21 Jun 2010 21:04:40 +0000 (17:04 -0400)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 22 Jun 2010 08:12:43 +0000 (11:12 +0300)
This patch adds a generic plugin, exec.so, that should be sufficient for the
majority of Collection actions. After all packages in a Collection have been
installed/removed, this plugin executes the arguments by calling system(3),
allowing for a very generic and powerful method to perform many actions.

This also adds two sample macros as examples of the format, using the exec.so
plugin.

Makefile.am
configure.ac
macros.in
plugins/Makefile.am [new file with mode: 0644]
plugins/collection.h [new file with mode: 0644]
plugins/exec.c [new file with mode: 0644]

index 9daf00a..25cee70 100644 (file)
@@ -19,9 +19,9 @@ endif
 if WITH_LUAEXT
 SUBDIRS += luaext
 endif
-SUBDIRS += rpmio lib build python scripts fileattrs doc . tests
+SUBDIRS += rpmio lib build python scripts fileattrs doc . tests plugins
 
-DIST_SUBDIRS = po misc luaext rpmio lib build python scripts fileattrs doc tests
+DIST_SUBDIRS = po misc luaext rpmio lib build python scripts fileattrs doc tests plugins
 
 pkgconfigdir = $(libdir)/pkgconfig
 
index e5fd6ba..9929046 100644 (file)
@@ -811,5 +811,6 @@ AC_CONFIG_FILES([Makefile
        python/Makefile
        luaext/Makefile
        tests/Makefile
+       plugins/Makefile
   ])
 AC_OUTPUT
index 927f240..bf49d04 100644 (file)
--- a/macros.in
+++ b/macros.in
@@ -1159,6 +1159,11 @@ done \
 %__urlhelper_proxyopts   %{?_httpproxy:--proxy %{_httpproxy}%{?_httpport::%{_httpport}}}%{!?_httpproxy:%{nil}}
 %_urlhelper             %{__urlhelpercmd} %{?__urlhelper_localopts} %{?__urlhelper_proxyopts} %{__urlhelperopts}
 
+#------------------------------------------------------------------------------
+# Collection specific macros
+%__plugindir           %{_rpmconfigdir}/plugins
+%__collection_font     %{__plugindir}/exec.so /usr/bin/fc-cache
+%__collection_java     %{__plugindir}/exec.so /usr/bin/rebuild-gcj-db
 
 # \endverbatim
 #*/
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
new file mode 100644 (file)
index 0000000..b0af6b9
--- /dev/null
@@ -0,0 +1,19 @@
+# Makefile for rpm library.
+
+include $(top_srcdir)/rpm.am
+
+AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) -I$(top_builddir)/include/
+AM_CPPFLAGS += -I$(top_srcdir)/misc
+AM_CPPFLAGS += -DLOCALEDIR="\"$(localedir)\""
+AM_CPPFLAGS += -DSYSCONFDIR="\"$(sysconfdir)\""
+AM_CPPFLAGS += -DLOCALSTATEDIR="\"$(localstatedir)\""
+AM_CPPFLAGS += -DLIBRPMALIAS_FILENAME="\"rpmpopt-${VERSION}\""
+
+AM_LDFLAGS = -avoid-version -module -shared
+
+pluginsdir = $(rpmconfigdir)/plugins
+
+plugins_LTLIBRARIES = exec.la
+
+exec_la_SOURCES = collection.h ../lib/rpmchroot.c exec.c
+exec_la_LIBADD = $(top_builddir)/lib/librpm.la $(top_builddir)/rpmio/librpmio.la
diff --git a/plugins/collection.h b/plugins/collection.h
new file mode 100644 (file)
index 0000000..e0818d6
--- /dev/null
@@ -0,0 +1,12 @@
+#include "system.h"
+
+#include <rpm/rpmlib.h>
+#include <rpm/rpmlog.h>
+#include <rpm/rpmts.h>
+
+#include "lib/collections.h"
+#include "lib/rpmchroot.h"
+
+rpmRC COLLHOOK_POST_ANY_FUNC(rpmts ts, const char * collname, const char * options);
+rpmRC COLLHOOK_POST_ADD_FUNC(rpmts ts, const char * collname, const char * options);
+rpmRC COLLHOOK_PRE_REMOVE_FUNC(rpmts ts, const char * collname, const char * options);
diff --git a/plugins/exec.c b/plugins/exec.c
new file mode 100644 (file)
index 0000000..ab2536f
--- /dev/null
@@ -0,0 +1,32 @@
+#include "collection.h"
+
+#include <sys/wait.h>
+
+rpmCollHook COLLECTION_HOOKS = COLLHOOK_POST_ANY;
+
+rpmRC COLLHOOK_POST_ANY_FUNC(rpmts ts, const char *collname,
+                            const char *options)
+{
+    int rc = RPMRC_FAIL;
+
+    if (rpmChrootIn()) {
+       goto exit;
+    }
+
+    if (options) {
+       int status = system(options);
+       if (!WIFEXITED(status) || WEXITSTATUS(status)) {
+           rpmlog(RPMLOG_ERR, "%s collection action failed\n", collname);
+           goto exit;
+       }
+    }
+
+    rc = RPMRC_OK;
+
+  exit:
+    if (rpmChrootOut()) {
+       rc = RPMRC_FAIL;
+    }
+
+    return rc;
+}