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,25 +1246,27 @@ 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) {
/* Warning only if using CDB locking. */ if (EINTR == errno)
rc = ((dbi->dbi_use_dbenv && continue;
(dbi->dbi_eflags & DB_INIT_CDB))
? 0 : 1); /* Warning only if using CDB locking. */
if ( rc && (EACCES == errno || EAGAIN == errno || EDEADLK == errno || EINTR == errno || ENOLCK == errno) && do_wait_for_lock() ) if (ignore_lock)
continue; rc = 0;
rpmError( (rc ? RPMERR_FLOCK : RPMWARN_FLOCK), else if (wait_lock && (EACCES == errno || EAGAIN == errno || ENOLCK == errno))
_("cannot get %s lock on %s/%s\n"), continue;
((dbi->dbi_mode & (O_RDWR|O_WRONLY)) rpmError( (rc ? RPMERR_FLOCK : RPMWARN_FLOCK),
_("cannot get %s lock on %s/%s\n"),
((dbi->dbi_mode & (O_RDWR|O_WRONLY))
? _("exclusive") : _("shared")), ? _("exclusive") : _("shared")),
dbhome, (dbfile ? dbfile : "")); dbhome, (dbfile ? dbfile : ""));
} else if (dbfile) { } else if (dbfile) {
rpmMessage(RPMMESS_DEBUG, rpmMessage(RPMMESS_DEBUG,
_("locked db index %s/%s\n"), _("locked db index %s/%s\n"),
dbhome, dbfile); dbhome, dbfile);
} }
break; break;
} }
} }
} }