(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:
Assar Westerlund
1996-11-17 04:25:31 +00:00
parent dbca8c313e
commit b71880ea43

View File

@@ -43,27 +43,34 @@ RCSID("$Id$");
#include "otp_locl.h" #include "otp_locl.h"
#define RETRIES 5
void * void *
otp_db_open (void) otp_db_open (void)
{ {
int lock; int lock;
int i;
void *ret;
do { for(i = 0; i < RETRIES; ++i) {
struct stat statbuf; struct stat statbuf;
lock = open (OTP_DB_LOCK, O_WRONLY | O_CREAT | O_EXCL, 0666); lock = open (OTP_DB_LOCK, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (lock >= 0) { if (lock >= 0) {
close(lock); close(lock);
break; break;
} }
if (stat (OTP_DB_LOCK, &statbuf) < 0)
if (errno == ENOENT)
continue;
else
return NULL;
if (time(NULL) - statbuf.st_mtime > OTP_DB_TIMEOUT) if (time(NULL) - statbuf.st_mtime > OTP_DB_TIMEOUT)
unlink (OTP_DB_LOCK); unlink (OTP_DB_LOCK);
} while(1); else
return dbm_open (OTP_DB, O_RDWR | O_CREAT, 0600); 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 void