2006-12-19 00:17:44 +01:00
|
|
|
Fix global (DB_PRIVATE) lock code: fix recursion counter, retry
|
|
|
|
failed lock operations for up to 3 minutes.
|
2008-09-12 20:37:28 +02:00
|
|
|
Index: rpmdb/db3.c
|
|
|
|
===================================================================
|
|
|
|
--- rpmdb/db3.c.orig
|
|
|
|
+++ rpmdb/db3.c
|
|
|
|
@@ -769,6 +769,8 @@ assert(db != NULL);
|
2006-12-19 00:17:44 +01:00
|
|
|
}
|
2006-12-19 00:17:44 +01:00
|
|
|
/*@=mustmod@*/
|
2006-12-19 00:17:44 +01:00
|
|
|
|
|
|
|
+static int _lockdbfd = 0;
|
|
|
|
+
|
2006-12-19 00:17:44 +01:00
|
|
|
/*@-moduncon@*/ /* FIX: annotate db3 methods */
|
|
|
|
static int db3close(/*@only@*/ dbiIndex dbi, /*@unused@*/ unsigned int flags)
|
|
|
|
/*@globals rpmGlobalMacroContext, h_errno,
|
2008-09-12 20:37:28 +02:00
|
|
|
@@ -828,6 +830,10 @@ static int db3close(/*@only@*/ dbiIndex
|
2011-05-16 18:07:44 +02:00
|
|
|
|
2006-12-19 00:17:44 +01:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("closed db index %s/%s\n"),
|
|
|
|
dbhome, (dbfile ? dbfile : tagName(dbi->dbi_rpmtag)));
|
|
|
|
+ if (dbi->dbi_lockdbfd &&
|
|
|
|
+ !((dbi->dbi_ecflags & DB_CLIENT) && dbi->dbi_host) &&
|
|
|
|
+ _lockdbfd)
|
2006-12-19 00:17:44 +01:00
|
|
|
+ _lockdbfd--;
|
2011-05-16 18:07:44 +02:00
|
|
|
|
2009-08-28 15:54:03 +02:00
|
|
|
}
|
2006-12-19 00:17:44 +01:00
|
|
|
|
2008-09-12 20:37:28 +02:00
|
|
|
@@ -1148,8 +1154,6 @@ static int db3open(rpmdb rpmdb, rpmTag r
|
2006-12-19 00:17:44 +01:00
|
|
|
prDbiOpenFlags(oflags, 0), dbi->dbi_mode);
|
2006-12-19 00:17:44 +01:00
|
|
|
|
2006-12-19 00:17:44 +01:00
|
|
|
if (rc == 0) {
|
|
|
|
- static int _lockdbfd = 0;
|
|
|
|
-
|
|
|
|
/*@-moduncon@*/ /* FIX: annotate db3 methods */
|
|
|
|
rc = db_create(&db, dbenv, dbi->dbi_cflags);
|
|
|
|
/*@=moduncon@*/
|
2008-09-12 20:37:28 +02:00
|
|
|
@@ -1366,6 +1370,7 @@ static int db3open(rpmdb rpmdb, rpmTag r
|
2006-12-19 00:17:44 +01:00
|
|
|
if (!(db->fd(db, &fdno) == 0 && fdno >= 0)) {
|
|
|
|
rc = 1;
|
|
|
|
} else {
|
|
|
|
+ int tries;
|
|
|
|
struct flock l;
|
|
|
|
/*@-boundswrite@*/
|
|
|
|
memset(&l, 0, sizeof(l));
|
2008-09-12 20:37:28 +02:00
|
|
|
@@ -1377,24 +1382,40 @@ static int db3open(rpmdb rpmdb, rpmTag r
|
2006-12-19 00:17:44 +01:00
|
|
|
? F_WRLCK : F_RDLCK;
|
|
|
|
l.l_pid = 0;
|
2011-05-16 18:07:44 +02:00
|
|
|
|
2006-12-19 00:17:44 +01:00
|
|
|
- rc = fcntl(fdno, F_SETLK, (void *) &l);
|
|
|
|
- if (rc) {
|
|
|
|
- /* Warning iff using non-private CDB locking. */
|
|
|
|
- rc = ((dbi->dbi_use_dbenv &&
|
|
|
|
- (dbi->dbi_eflags & DB_INIT_CDB) &&
|
|
|
|
- !(dbi->dbi_eflags & DB_PRIVATE))
|
|
|
|
- ? 0 : 1);
|
|
|
|
- rpmError( (rc ? RPMERR_FLOCK : RPMWARN_FLOCK),
|
|
|
|
- _("cannot get %s lock on %s/%s\n"),
|
|
|
|
- ((dbi->dbi_mode & (O_RDWR|O_WRONLY))
|
|
|
|
- ? _("exclusive") : _("shared")),
|
|
|
|
- dbhome, (dbfile ? dbfile : ""));
|
|
|
|
- } else if (dbfile) {
|
|
|
|
- rpmMessage(RPMMESS_DEBUG,
|
|
|
|
- _("locked db index %s/%s\n"),
|
|
|
|
- dbhome, dbfile);
|
|
|
|
+ for (tries = 0; ; tries++) {
|
|
|
|
+ rc = fcntl(fdno, F_SETLK, (void *) &l);
|
|
|
|
+ if (rc) {
|
|
|
|
+ /* Warning iff using non-private CDB locking. */
|
|
|
|
+ rc = ((dbi->dbi_use_dbenv &&
|
|
|
|
+ (dbi->dbi_eflags & DB_INIT_CDB) &&
|
|
|
|
+ !(dbi->dbi_eflags & DB_PRIVATE))
|
|
|
|
+ ? 0 : 1);
|
|
|
|
+ if (errno == EAGAIN && rc) {
|
|
|
|
+ struct timespec ts;
|
|
|
|
+ if (tries == 0)
|
|
|
|
+ rpmMessage(RPMMESS_WARNING, _("waiting for %s lock on %s/%s\n"), ((dbi->dbi_mode & (O_RDWR|O_WRONLY)) ? _("exclusive") : _("shared")), dbhome, (dbfile ? dbfile : ""));
|
|
|
|
+ ts.tv_sec = (time_t)0;
|
|
|
|
+ ts.tv_nsec = 100000000;
|
|
|
|
+ if (tries < 10*60*3) {
|
|
|
|
+ nanosleep(&ts, (struct timespec *)0);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ rpmError( (rc ? RPMERR_FLOCK : RPMWARN_FLOCK),
|
|
|
|
+ _("cannot get %s lock on %s/%s\n"),
|
|
|
|
+ ((dbi->dbi_mode & (O_RDWR|O_WRONLY))
|
|
|
|
+ ? _("exclusive") : _("shared")),
|
|
|
|
+ dbhome, (dbfile ? dbfile : ""));
|
|
|
|
+ } else if (dbfile) {
|
|
|
|
+ rpmMessage(RPMMESS_DEBUG,
|
|
|
|
+ _("locked db index %s/%s\n"),
|
|
|
|
+ dbhome, dbfile);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ if (rc && dbi->dbi_use_dbenv)
|
|
|
|
+ _lockdbfd--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|