(otp_db_open): Do a few retries.
Unlock in case this file cannot be opened. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1005 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -43,27 +43,34 @@ RCSID("$Id$");
|
||||
|
||||
#include "otp_locl.h"
|
||||
|
||||
#define RETRIES 5
|
||||
|
||||
void *
|
||||
otp_db_open (void)
|
||||
{
|
||||
int lock;
|
||||
int i;
|
||||
void *ret;
|
||||
|
||||
do {
|
||||
for(i = 0; i < RETRIES; ++i) {
|
||||
struct stat statbuf;
|
||||
|
||||
lock = open (OTP_DB_LOCK, O_WRONLY | O_CREAT | O_EXCL, 0666);
|
||||
if (lock >= 0) {
|
||||
close(lock);
|
||||
break;
|
||||
}
|
||||
if (stat (OTP_DB_LOCK, &statbuf) < 0)
|
||||
if (errno == ENOENT)
|
||||
continue;
|
||||
else
|
||||
return NULL;
|
||||
if (time(NULL) - statbuf.st_mtime > OTP_DB_TIMEOUT)
|
||||
unlink (OTP_DB_LOCK);
|
||||
} while(1);
|
||||
return dbm_open (OTP_DB, O_RDWR | O_CREAT, 0600);
|
||||
else
|
||||
sleep (1);
|
||||
}
|
||||
if (i == RETRIES)
|
||||
return NULL;
|
||||
ret = dbm_open (OTP_DB, O_RDWR | O_CREAT, 0600);
|
||||
if (ret == NULL)
|
||||
unlink (OTP_DB_LOCK);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user