RPM Community Forums

Mailing List Message of <rpm-devel>

Re: rpmdb.c blockSignals()

From: Jeff Johnson <n3npq@mac.com>
Date: Sat 16 Aug 2008 - 19:55:02 CEST
Message-id: <DEA16D0D-C90C-4867-9798-11E351A4FBD2@mac.com>

On Aug 16, 2008, at 12:33 PM, Jeff Johnson wrote:

> On Aug 16, 2008, at 12:12 PM, Jeff Johnson wrote:
>> No exit is undertaken until the caught signal mask is tested. db->put
>> is still atomic, and no re-entry is undertaken.
> Lest we wander off into definitions ...
> Whether db-put is interruptible is the property of interest if the  
> patch
> is applied; atomic and re-entrant properties do not matter.

Here's an example that illustrates "responsiveness" and what could/ 
be done. unlocking ^C is just a teensy part of a much larger "feature".

Currently, almost all rpmdb retrieval iterations cannot be interrupted.
That means that
     sudo rpm -qa
will not exit until after the iteration completes.

The patch below unlocks signals, and tests for exit in the middle of  
iteration during a query.

Here's a simple reproducer for the behavior that needs fixing with  
the patch

     [jbj@wellfleet wdj51]$ sudo rpm -qa > /dev/null
     [jbj@wellfleet wdj51]$ sudo rpm -qa > /dev/null
     Freeing read locks for locker 0x70f: 1117/3086350176
     Freeing read locks for locker 0x711: 1117/3086350176
     [jbj@wellfleet wdj51]$

(aside) One quick-and-dirty fix is to stop printing the error message,
the stale rpmdb locks are detected and cleaned on next execution
harmlessly. There are stale futexes that can be left behind however, and
stale futexes cannot be reaped without modifying Berkeley DB to handle
"robust mutexes".

  The better engineering fix is to close the dbcursor while exiting.

There's a snarl of linked db & dbcursor pointers used for rpmdb  
cleanup already
implemented, just not perfect yet.

And there's also nothing wrong with not exiting while iterating, most
iterations are not very time consuming, rpm -qa is the worst case  

73 de Jeff

Index: rpmdb/rpmdb.c
RCS file: /v/rpm/cvs/rpm/rpmdb/rpmdb.c,v
retrieving revision
diff -u -b -B -w -p -r1.246.2.3 rpmdb.c
--- rpmdb/rpmdb.c       16 Aug 2008 17:20:56 -0000
+++ rpmdb/rpmdb.c       16 Aug 2008 17:40:15 -0000
@@ -822,7 +822,7 @@ static int blockSignals(/*@unused@*/ rpm
      (void) sigdelset(&newMask, SIGHUP);
      (void) sigdelset(&newMask, SIGTERM);
      (void) sigdelset(&newMask, SIGPIPE);
-    return sigprocmask(SIG_BLOCK, &newMask, NULL);
+    return sigprocmask(SIG_SETMASK, &newMask, NULL);

Index: lib/query.c
RCS file: /v/rpm/cvs/rpm/lib/query.c,v
retrieving revision 2.201
diff -u -b -B -w -p -r2.201 query.c
--- lib/query.c 10 Mar 2008 04:46:13 -0000      2.201
+++ lib/query.c 16 Aug 2008 17:40:15 -0000
@@ -385,6 +385,8 @@ static int rpmgiShowMatches(QVA_t qva, r
         Header h;
         int rc;

+       (void) rpmdbCheckSignals();
         h = rpmgiHeader(gi);
         if (h == NULL)          /* XXX perhaps stricter break  
instead? */
Received on Sat Aug 16 19:55:24 2008
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.