refined _wait_for_lock patch

This commit is contained in:
Дмитрий Левин 2002-08-04 18:34:23 +00:00
parent 878c7ffd55
commit 8d43c2a8b0

View File

@ -819,20 +819,13 @@ static inline int parseYesNo( const char *s )
return 1; return 1;
} }
static int do_wait_for_lock( void ) static int wait_for_lock (void)
{ {
const char *str = rpmExpand ("%{_wait_for_lock}", NULL); const char *str = rpmExpand ("%{_wait_for_lock}", NULL);
int lock = ( str && *str != '%' ) ? parseYesNo( str ) : 1; int val = (str && *str != '%') ? parseYesNo (str) : 1;
str = _free (str); str = _free (str);
if ( lock ) return val;
{
struct timespec t = { 0, 100000000 };
nanosleep( &t, 0 );
return 1;
}
else
return 0;
} }
static int db3open(/*@keep@*/ rpmdb rpmdb, int rpmtag, dbiIndex * dbip) static int db3open(/*@keep@*/ rpmdb rpmdb, int rpmtag, dbiIndex * dbip)
@ -1240,6 +1233,9 @@ static int db3open(/*@keep@*/ rpmdb rpmdb, int rpmtag, dbiIndex * dbip)
if (!(db->fd(db, &fdno) == 0 && fdno >= 0)) { if (!(db->fd(db, &fdno) == 0 && fdno >= 0)) {
rc = 1; rc = 1;
} else { } else {
int ignore_lock = dbi->dbi_use_dbenv && (dbi->dbi_eflags & DB_INIT_CDB);
int wait_lock = wait_for_lock();
int cmd = (ignore_lock || !wait_lock) ? F_SETLK : F_SETLKW;
struct flock l; struct flock l;
memset(&l, 0, sizeof(l)); memset(&l, 0, sizeof(l));
l.l_whence = 0; l.l_whence = 0;
@ -1250,13 +1246,15 @@ static int db3open(/*@keep@*/ rpmdb rpmdb, int rpmtag, dbiIndex * dbip)
l.l_pid = 0; l.l_pid = 0;
for (;;) { for (;;) {
rc = fcntl(fdno, F_SETLK, (void *) &l); rc = fcntl(fdno, cmd, (void *) &l);
if (rc) { if (rc) {
if (EINTR == errno)
continue;
/* Warning only if using CDB locking. */ /* Warning only if using CDB locking. */
rc = ((dbi->dbi_use_dbenv && if (ignore_lock)
(dbi->dbi_eflags & DB_INIT_CDB)) rc = 0;
? 0 : 1); else if (wait_lock && (EACCES == errno || EAGAIN == errno || ENOLCK == errno))
if ( rc && (EACCES == errno || EAGAIN == errno || EDEADLK == errno || EINTR == errno || ENOLCK == errno) && do_wait_for_lock() )
continue; continue;
rpmError( (rc ? RPMERR_FLOCK : RPMWARN_FLOCK), rpmError( (rc ? RPMERR_FLOCK : RPMWARN_FLOCK),
_("cannot get %s lock on %s/%s\n"), _("cannot get %s lock on %s/%s\n"),