if ( readonly ) {
db->readonly=1;
db->fd = open(file, O_RDONLY);
+ if ( db->fd < 0 ) {
+ tlog(TL_CRIT,"FDBOpen: open failed: %s",strerror(errno));
+ return FDB_ERROR;
+ }
if ( flock( db->fd, LOCK_SH ) < 0 ) {
tlog(TL_CRIT,"FDBOpen: flock failed: %s",strerror(errno));
close(db->fd);
return FDB_ERROR;
}
} else {
- db->fd = open(file, O_CREAT | O_RDWR, 0666);
+ db->fd = open(file, O_CREAT | O_RDWR);
+ if ( db->fd < 0 ) {
+ tlog(TL_CRIT,"FDBOpen: open failed: %s",strerror(errno));
+ return FDB_ERROR;
+ }
if ( flock( db->fd, LOCK_EX ) < 0 ) {
tlog(TL_CRIT,"FDBOpen: flock failed: %s",strerror(errno));
close(db->fd);
}
}
- if ( db->fd < 0 ) {
- memset(db, 0, sizeof(FDB));
- tlog(TL_CRIT,"FDBOpen: open failed: %s", strerror(errno));
- return FDB_ERROR;
- }
-
rc = read(db->fd, &header, sizeof(FDBHeader));
if ( rc<0 ) {