[Rpm-maint] [PATCH 5/5] Add a generic plugin for use by simple Collections
Steve Lawrence
slawrence at tresys.com
Thu Jun 17 19:55:27 UTC 2010
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 | 4 ++--
collections/Makefile.am | 19 +++++++++++++++++++
collections/collection.h | 12 ++++++++++++
collections/exec.c | 31 +++++++++++++++++++++++++++++++
configure.ac | 1 +
macros.in | 5 +++++
6 files changed, 70 insertions(+), 2 deletions(-)
create mode 100644 collections/Makefile.am
create mode 100644 collections/collection.h
create mode 100644 collections/exec.c
diff --git a/Makefile.am b/Makefile.am
index 9daf00a..f2e1db2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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 collections
-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 collections
pkgconfigdir = $(libdir)/pkgconfig
diff --git a/collections/Makefile.am b/collections/Makefile.am
new file mode 100644
index 0000000..2a998ba
--- /dev/null
+++ b/collections/Makefile.am
@@ -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
+
+collectionsdir = $(rpmconfigdir)/collections
+
+collections_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/collections/collection.h b/collections/collection.h
new file mode 100644
index 0000000..e0818d6
--- /dev/null
+++ b/collections/collection.h
@@ -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/collections/exec.c b/collections/exec.c
new file mode 100644
index 0000000..e7a1217
--- /dev/null
+++ b/collections/exec.c
@@ -0,0 +1,31 @@
+#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 (rpmChrootSet(rpmtsRootDir(ts)) || 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() || rpmChrootSet(NULL)) {
+ rc = RPMRC_FAIL;
+ }
+
+ return rc;
+}
diff --git a/configure.ac b/configure.ac
index e5fd6ba..2e99e53 100644
--- a/configure.ac
+++ b/configure.ac
@@ -811,5 +811,6 @@ AC_CONFIG_FILES([Makefile
python/Makefile
luaext/Makefile
tests/Makefile
+ collections/Makefile
])
AC_OUTPUT
diff --git a/macros.in b/macros.in
index 927f240..389e41c 100644
--- 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
+%__collectiondir %{_rpmconfigdir}/collections
+%__collection_font %{__collectiondir}/exec.so /usr/bin/fc-cache
+%__collection_java %{__collectiondir}/exec.so /usr/bin/rebuild-gcj-db
# \endverbatim
#*/
--
1.6.2.5
More information about the Rpm-maint
mailing list