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

Re: database locking woes part 2



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.

Ian

-- 
Ian Peters <itp@ximian.com>
Ximian, Inc.
#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);
    }

    rpmdbFreeIterator (mi);
}

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

    rpmReadConfigFiles (NULL, NULL);

    if ((rc = rpmdbOpen ("/", &db, O_RDONLY, 0644))) {
        printf ("Failed to open rpm database O_RDONLY\n");
        if ((rc = rpmdbOpen ("/", &db, O_RDONLY, 0644)))
            printf ("Failed to open rpm database O_RDONLY\n");
        else {
            printf ("Opened rpm database O_RDONLY\n");
            query_all (db);
        }
    } 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] []