[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: database locking woes part 2



On Mon, Jul 29, 2002 at 05:21:59PM -0400, Ian Peters wrote:
> On Mon, 2002-07-29 at 17:08, Jeff Johnson wrote:
> > > # ./lock-breaker
> > > error: cannot get shared lock on /var/lib/rpm/Packages
> > > error: cannot open Packages index using db3 - Operation not permitted (1)
> > > Failed to open rpm database O_RDONLY
> > > Opened rpm database O_RDONLY
> > > 
> > > That second open really should not have succeeded.
> > > 
> > > Am I totally off-base, or missing something obvious here?
> > 
> > Without (yet) looking at the lock-breaker code, I'd guess that an rpmdbOpen()
> > return code is screwed.
> > 
> > Running with strace should show the fcntl errno. If success, then fcntl has
> > weird semantics, if fail, then I've screwed up an rpmdbOpen() return code.
> 
> If it helps, here's a revised version of lock-breaker that actually runs
> a query after it succeeds in opening the database.  This should prove
> that it's not just an error in return codes, that this actually is
> getting a valid database handle.
> 

OK, here's lock-{maker,breaker}.c that closes most of the root-root
window solely through macro configuration.

Basically, replace (appending should work too) /etc/rpm/macros.cdb with
	%__dbi_cdb	%{nil}
	%__dbi_other	%{?_tmppath:tmpdir=%{_tmppath}} usedbenv create \
			joinenv mpool mp_mmapsize=8Mb mp_size=512kb verify

I have no idea (yet) why a 2nd rpmdbOpen() in the same exec succeeds, but
will try to understand the problem better when I look at 4.1 vs. 4.0.x
locking purty soon now.

HTH

73 de Jeff

-- 
Jeff Johnson	ARS N3NPQ
jbj@redhat.com (jbj@jbj.org)
Chapel Hill, NC
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <rpm/rpmlib.h>

int
main (int argc, char **argv)
{
    rpmdb db;
    int dbi_mode = O_RDWR;
    int rc;

    rpmReadConfigFiles (NULL, NULL);

    rpmIncreaseVerbosity();
    rpmIncreaseVerbosity();

    /* XXX Avoid stale lock __db file unlink, before/after. */
    /* XXX Put in /etc/rpm/macros.cdb to affect all rpmdb opens. */
    (void) addMacro(NULL, "__dbi_cdb", NULL, "%{nil}", -1);
    (void) addMacro(NULL, "__dbi_other", NULL, "%{?_tmppath:tmpdir=%{_tmppath}} usedbenv create joinenv mpool mp_mmapsize=8Mb mp_size=512kb verify", -1);

    if ((rc = rpmdbOpen ("/", &db, dbi_mode, 0645)))
        printf ("Failed to open rpm database O_RDWR\n");
    else
        printf ("Opened rpm database O_RDWR\n");

    sleep (10000);
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <rpm/rpmlib.h>

static void
query_all (rpmdb db)
{
    rpmdbMatchIterator mi = NULL;
    Header header;
    char *name;

    mi = rpmdbInitIterator (db, RPMDBI_PACKAGES, NULL, 0);

    while ((header = rpmdbNextIterator (mi))) {
        headerGetEntry (header, RPMTAG_NAME, NULL, (void **)&name, NULL);
        printf ("%s\n", name);
	break;
    }

    rpmdbFreeIterator (mi);
}

int
main (int argc, char **argv)
{
    rpmdb db;
    int dbi_mode = O_RDONLY;
    int rc;

    rpmReadConfigFiles (NULL, NULL);

    rpmIncreaseVerbosity();
    rpmIncreaseVerbosity();

    /* XXX Avoid stale lock __db file unlink, before/after. */
    /* XXX Put in /etc/rpm/macros.cdb to affect all rpmdb opens. */
    (void) addMacro(NULL, "__dbi_cdb", NULL, "%{nil}", -1);
    (void) addMacro(NULL, "__dbi_other", NULL, "%{?_tmppath:tmpdir=%{_tmppath}} usedbenv create joinenv mpool mp_mmapsize=8Mb mp_size=512kb verify", -1);

    if ((rc = rpmdbOpen ("/", &db, O_RDONLY, 0644))) {
        printf ("Failed to open rpm database O_RDONLY\n");
#if 0
	/* XXX WTFO? this succeeds.
	 * XXX FWIW, I don't know of any rpm application (through rpm-4.0.4)
	 * that reopens the database in a single execution.
	 */
        if ((rc = rpmdbOpen ("/", &db, dbi_mode, 0644)))
            printf ("Failed to open rpm database O_RDONLY\n");
        else {
            printf ("Opened rpm database O_RDONLY\n");
            query_all (db);
        }
#endif
    } else {
        printf ("Opened rpm database O_RDONLY\n");
        query_all (db);
    }
}

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []