ntdb->file->device = st.st_dev;
ntdb->file->inode = st.st_ino;
+
+ /* call their open hook if they gave us one. */
+ if (ntdb->openhook) {
+ ecode = ntdb->openhook(ntdb->file->fd, ntdb->openhook_data);
+ if (ecode != NTDB_SUCCESS) {
+ ntdb_logerr(ntdb, ecode, NTDB_LOG_ERROR,
+ "ntdb_open: open hook failed");
+ goto fail;
+ }
+ open_flags |= O_CREAT;
+ }
} else {
/* ensure there is only one process initialising at once */
ecode = ntdb_lock_open(ntdb, openlock,
}
}
- /* call their open hook if they gave us one. */
- if (ntdb->openhook) {
- ecode = ntdb->openhook(ntdb->file->fd, ntdb->openhook_data);
- if (ecode != NTDB_SUCCESS) {
- ntdb_logerr(ntdb, ecode, NTDB_LOG_ERROR,
- "ntdb_open: open hook failed");
- goto fail;
- }
- open_flags |= O_CREAT;
- }
-
/* If they used O_TRUNC, read will return 0. */
rlen = pread(ntdb->file->fd, &hdr, sizeof(hdr), 0);
if (rlen == 0 && (open_flags & O_CREAT)) {
int main(int argc, char *argv[])
{
unsigned int i;
- struct ntdb_context *ntdb;
+ struct ntdb_context *ntdb, *ntdb2;
struct agent *agent;
union ntdb_attribute cif;
NTDB_DATA key = ntdb_mkdata(KEY_STR, strlen(KEY_STR));
cif.openhook.data = clear_if_first;
agent = prepare_external_agent();
- plan_tests(sizeof(flags) / sizeof(flags[0]) * 13);
+ plan_tests(sizeof(flags) / sizeof(flags[0]) * 16);
for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
/* Create it */
ntdb = ntdb_open("run-83-openhook.ntdb", flags[i]|MAYBE_NOSYNC,
/* Still exists for us too. */
ok1(ntdb_exists(ntdb, key));
+ /* Nested open should not erase db. */
+ ntdb2 = ntdb_open("run-83-openhook.ntdb", flags[i]|MAYBE_NOSYNC,
+ O_RDWR, 0, &cif);
+ ok1(ntdb_exists(ntdb2, key));
+ ok1(ntdb_exists(ntdb, key));
+ ntdb_close(ntdb2);
+
+ ok1(ntdb_exists(ntdb, key));
+
/* Close it, now agent should clear it. */
ntdb_close(ntdb);