|
Panu Matilainen |
748554 |
changeset: 6179:fb37e4dccbf3
|
|
Panu Matilainen |
748554 |
tag: tip
|
|
Panu Matilainen |
748554 |
user: Panu Matilainen <pmatilai@redhat.com>
|
|
Panu Matilainen |
748554 |
date: Sat Jul 21 15:05:19 2007 +0300
|
|
Panu Matilainen |
748554 |
files: python/rpmmodule.c rpmdb/rpmdb.c rpmdb/rpmdb.h
|
|
Panu Matilainen |
748554 |
description:
|
|
Panu Matilainen |
748554 |
Make rpmdbCheckTerminate() non-terminating.
|
|
Panu Matilainen |
748554 |
This allows use in exit handler without affecting exit code, and permits
|
|
Panu Matilainen |
748554 |
caller to do its own cleanup if necessary.
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
diff -r e9ced408b17f -r fb37e4dccbf3 python/rpmmodule.c
|
|
Panu Matilainen |
748554 |
--- a/python/rpmmodule.c Fri Jul 20 11:23:11 2007 +0300
|
|
Panu Matilainen |
748554 |
+++ b/python/rpmmodule.c Sat Jul 21 15:05:19 2007 +0300
|
|
Panu Matilainen |
748554 |
@@ -229,8 +229,6 @@ static PyMethodDef rpmModuleMethods[] =
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
/*
|
|
Panu Matilainen |
748554 |
* Force clean up of open iterators and dbs on exit.
|
|
Panu Matilainen |
748554 |
-* This ends up calling exit() while we're already exiting but exit
|
|
Panu Matilainen |
748554 |
-* handlers will only get called once so it wont loop.
|
|
Panu Matilainen |
748554 |
*/
|
|
Panu Matilainen |
748554 |
static void rpm_exithook(void)
|
|
Panu Matilainen |
748554 |
{
|
|
Panu Matilainen |
748554 |
diff -r e9ced408b17f -r fb37e4dccbf3 rpmdb/rpmdb.c
|
|
Panu Matilainen |
748554 |
--- a/rpmdb/rpmdb.c Fri Jul 20 11:23:11 2007 +0300
|
|
Panu Matilainen |
748554 |
+++ b/rpmdb/rpmdb.c Sat Jul 21 15:05:19 2007 +0300
|
|
Panu Matilainen |
748554 |
@@ -707,7 +707,7 @@ int rpmdbCheckTerminate(int terminate)
|
|
Panu Matilainen |
748554 |
sigset_t newMask, oldMask;
|
|
Panu Matilainen |
748554 |
static int terminating = 0;
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
- if (terminating) return 0;
|
|
Panu Matilainen |
748554 |
+ if (terminating) return 1;
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
(void) sigfillset(&newMask); /* block all signals */
|
|
Panu Matilainen |
748554 |
(void) sigprocmask(SIG_BLOCK, &newMask, &oldMask);
|
|
Panu Matilainen |
748554 |
@@ -724,10 +724,6 @@ int rpmdbCheckTerminate(int terminate)
|
|
Panu Matilainen |
748554 |
rpmdb db;
|
|
Panu Matilainen |
748554 |
rpmdbMatchIterator mi;
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
-/*@-abstract@*/ /* sigset_t is abstract type */
|
|
Panu Matilainen |
748554 |
- rpmMessage(RPMMESS_DEBUG, "Exiting on signal(0x%lx) ...\n", *((unsigned long *)&rpmsqCaught));
|
|
Panu Matilainen |
748554 |
-/*@=abstract@*/
|
|
Panu Matilainen |
748554 |
-
|
|
Panu Matilainen |
748554 |
/*@-branchstate@*/
|
|
Panu Matilainen |
748554 |
while ((mi = rpmmiRock) != NULL) {
|
|
Panu Matilainen |
748554 |
/*@i@*/ rpmmiRock = mi->mi_next;
|
|
Panu Matilainen |
748554 |
@@ -743,14 +739,20 @@ int rpmdbCheckTerminate(int terminate)
|
|
Panu Matilainen |
748554 |
(void) rpmdbClose(db);
|
|
Panu Matilainen |
748554 |
}
|
|
Panu Matilainen |
748554 |
/*@=newreftrans@*/
|
|
Panu Matilainen |
748554 |
+ }
|
|
Panu Matilainen |
748554 |
+ sigprocmask(SIG_SETMASK, &oldMask, NULL);
|
|
Panu Matilainen |
748554 |
+ return terminating;
|
|
Panu Matilainen |
748554 |
+}
|
|
Panu Matilainen |
748554 |
+
|
|
Panu Matilainen |
748554 |
+int rpmdbCheckSignals(void)
|
|
Panu Matilainen |
748554 |
+{
|
|
Panu Matilainen |
748554 |
+ if (rpmdbCheckTerminate(0)) {
|
|
Panu Matilainen |
748554 |
+/*@-abstract@*/ /* sigset_t is abstract type */
|
|
Panu Matilainen |
748554 |
+ rpmMessage(RPMMESS_DEBUG, "Exiting on signal(0x%lx) ...\n", *((unsigned long *)&rpmsqCaught));
|
|
Panu Matilainen |
748554 |
exit(EXIT_FAILURE);
|
|
Panu Matilainen |
748554 |
- }
|
|
Panu Matilainen |
748554 |
- return sigprocmask(SIG_SETMASK, &oldMask, NULL);
|
|
Panu Matilainen |
748554 |
-}
|
|
Panu Matilainen |
748554 |
-
|
|
Panu Matilainen |
748554 |
-int rpmdbCheckSignals(void)
|
|
Panu Matilainen |
748554 |
-{
|
|
Panu Matilainen |
748554 |
- return rpmdbCheckTerminate(0);
|
|
Panu Matilainen |
748554 |
+/*@=abstract@*/
|
|
Panu Matilainen |
748554 |
+ }
|
|
Panu Matilainen |
748554 |
+ return 0;
|
|
Panu Matilainen |
748554 |
}
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
/**
|
|
Panu Matilainen |
748554 |
diff -r e9ced408b17f -r fb37e4dccbf3 rpmdb/rpmdb.h
|
|
Panu Matilainen |
748554 |
--- a/rpmdb/rpmdb.h Fri Jul 20 11:23:11 2007 +0300
|
|
Panu Matilainen |
748554 |
+++ b/rpmdb/rpmdb.h Sat Jul 21 15:05:19 2007 +0300
|
|
Panu Matilainen |
748554 |
@@ -1039,8 +1039,7 @@ Header rpmdbNextIterator(/*@null@*/ rpmd
|
|
Panu Matilainen |
748554 |
/*@modifies mi, rpmGlobalMacroContext, fileSystem, internalState @*/;
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
/** \ingroup rpmdb
|
|
Panu Matilainen |
748554 |
- * Check rpmdb signal handler for trapped signal exit. Just a compatibility
|
|
Panu Matilainen |
748554 |
- * wrapper for rpmdbCheckTerminate()
|
|
Panu Matilainen |
748554 |
+ * Check for and exit on termination signals.
|
|
Panu Matilainen |
748554 |
*/
|
|
Panu Matilainen |
748554 |
/*@mayexit@*/
|
|
Panu Matilainen |
748554 |
int rpmdbCheckSignals(void)
|
|
Panu Matilainen |
748554 |
@@ -1048,10 +1047,13 @@ int rpmdbCheckSignals(void)
|
|
Panu Matilainen |
748554 |
/*@modifies fileSystem, internalState @*/;
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
/** \ingroup rpmdb
|
|
Panu Matilainen |
748554 |
- * Check rpmdb signal handler for trapped signal or requested exit.
|
|
Panu Matilainen |
748554 |
+ * Check rpmdb signal handler for trapped signal and/or requested exit,
|
|
Panu Matilainen |
748554 |
+ * clean up any open iterators and databases on termination condition.
|
|
Panu Matilainen |
748554 |
+ * On non-zero exit any open references to rpmdb are invalid and cannot
|
|
Panu Matilainen |
748554 |
+ * be accessed anymore, calling process should terminate immediately.
|
|
Panu Matilainen |
748554 |
* @param terminate 0 to only check for signals, 1 to terminate anyway
|
|
Panu Matilainen |
748554 |
- */
|
|
Panu Matilainen |
748554 |
-/*@mayexit@*/
|
|
Panu Matilainen |
748554 |
+ * @return 0 to continue, 1 if termination cleanup was done.
|
|
Panu Matilainen |
748554 |
+ */
|
|
Panu Matilainen |
748554 |
int rpmdbCheckTerminate(int terminate);
|
|
Panu Matilainen |
748554 |
|
|
Panu Matilainen |
748554 |
/** \ingroup rpmdb
|
|
Panu Matilainen |
748554 |
|