Changeset 905 for trunk/server/lib/tdb/common/open.c
- Timestamp:
- May 19, 2016, 2:25:59 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/lib/tdb/common/open.c
r901 r905 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 … … 120 120 } 121 121 122 /* open the database, creating it if necessary 122 /* open the database, creating it if necessary 123 123 124 124 The open_flags and mode are passed straight to the open call on the … … 126 126 is advisory, use zero for a default value. 127 127 128 Return is NULL on error, in which case errno is also set. Don't 128 Return is NULL on error, in which case errno is also set. Don't 129 129 try to call tdb_error or tdb_errname, just do strerror(errno). 130 130 … … 162 162 return check_header_hash(tdb, false, m1, m2); 163 163 } 164 165 #ifdef __OS2__166 static int os2_create_lockfile(struct tdb_context *tdb, const char *name, const char *origin)167 {168 /* name could be null, so handle it */169 if (name == NULL)170 return 0;171 172 char lock_name[_MAX_PATH + 5];173 snprintf(lock_name, sizeof(lock_name), "%s.lock", name);174 /*175 * First try to O_TRUNC it to make sure the file is empty (this176 * will succeed on first open), but ignore the error that will177 * happen if some bytes are already locked.178 */179 tdb->lock_fd = open(lock_name, tdb->open_flags | O_CREAT | O_TRUNC, 0777);180 if (tdb->lock_fd == -1 && errno == EACCES)181 tdb->lock_fd = open(lock_name, tdb->open_flags | O_CREAT, 0777);182 if (tdb->lock_fd == -1) {183 TDB_LOG((tdb, TDB_DEBUG_ERROR, "os2_create_lockfile: cannot create lock file %s, errno=%d\n",184 lock_name, errno));185 return -1;186 }187 188 return 0;189 }190 #endif191 164 192 165 _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, … … 333 306 fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC); 334 307 335 #ifdef __OS2__336 if (os2_create_lockfile(tdb, name, "tdb_open_ex") != 0)337 goto fail;338 #endif339 340 308 /* ensure there is only one process initialising at once */ 341 309 if (tdb_nest_lock(tdb, OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) { … … 505 473 { int save_errno = errno; 506 474 507 #ifdef __OS2__508 close(tdb->lock_fd);509 tdb->lock_fd = -1;510 #endif511 475 if (!tdb) 512 476 return NULL; … … 577 541 } 578 542 579 #ifdef __OS2__580 close(tdb->lock_fd);581 tdb->lock_fd = -1;582 #endif583 584 543 #ifdef TDB_TRACE 585 544 close(tdb->tracefd); … … 649 608 #endif /* fake pread or pwrite */ 650 609 651 #ifdef __OS2__652 close(tdb->lock_fd);653 tdb->lock_fd = -1;654 655 if (os2_create_lockfile(tdb, tdb->name, "tdb_reopen") != 0)656 goto fail;657 #endif658 610 /* We may still think we hold the active lock. */ 659 611 tdb->num_lockrecs = 0;
Note:
See TracChangeset
for help on using the changeset viewer.