Changeset 895 for trunk/server/lib/tdb/common/open.c
- Timestamp:
- Mar 18, 2016, 7:53:30 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/lib/tdb/common/open.c
r866 r895 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 tdb->lock_fd = open(lock_name, tdb->open_flags | O_CREAT | O_TRUNC, 0777); 175 if (tdb->lock_fd == -1) { 176 TDB_LOG((tdb, TDB_DEBUG_ERROR, "os2_create_lockfile: cannot create lock file %s, errno=%d\n", 177 lock_name, errno)); 178 return -1; 179 } 180 181 return 0; 182 } 183 #endif 164 184 165 185 _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, … … 304 324 305 325 #ifdef __OS2__ 306 if (os2_cr tActiveLock(tdb, name, "tdb_open_ex") != 0)326 if (os2_create_lockfile(tdb, name, "tdb_open_ex") != 0) 307 327 goto fail; 308 328 #endif … … 476 496 477 497 #ifdef __OS2__ 478 close(tdb-> hActiveLock);479 tdb-> hActiveLock= -1;498 close(tdb->lock_fd); 499 tdb->lock_fd = -1; 480 500 #endif 481 501 if (!tdb) … … 548 568 549 569 #ifdef __OS2__ 550 close(tdb-> hActiveLock);551 tdb-> hActiveLock= -1;570 close(tdb->lock_fd); 571 tdb->lock_fd = -1; 552 572 #endif 553 573 … … 620 640 621 641 #ifdef __OS2__ 622 close(tdb-> hActiveLock);623 tdb-> hActiveLock= -1;624 625 if (os2_cr tActiveLock(tdb, tdb->name, "tdb_reopen") != 0)642 close(tdb->lock_fd); 643 tdb->lock_fd = -1; 644 645 if (os2_create_lockfile(tdb, tdb->name, "tdb_reopen") != 0) 626 646 goto fail; 627 647 #endif … … 679 699 return 0; 680 700 } 681 #ifdef __OS2__682 int os2_crtActiveLock(struct tdb_context *tdb, const char *name, const char *origin)683 {684 // name could be null, so handle it685 if (name == NULL)686 return 0;687 688 struct stat st;689 bool emptytdb = false;690 char activeLockName[_MAX_PATH];691 char *emptyString = "used for active lock\n\0";692 sprintf(activeLockName, "%s_AL", name);693 694 if ((stat(activeLockName, &st) == -1) || (st.st_size < strlen(emptyString)))695 emptytdb = true;696 697 tdb->hActiveLock = open(activeLockName, tdb->open_flags | O_CREAT, 0777);698 if (tdb->hActiveLock == -1) {699 TDB_LOG((tdb, TDB_DEBUG_ERROR, "os2_crtActiveLock: cannot create activeLock %s called from %s %s\n",700 activeLockName, origin, strerror(errno)));701 errno = EINVAL;702 return -1;703 }704 705 // we try to truncate the db when called from tdb_open_ex706 // but if it's not working it's ok as well707 if (emptytdb)708 tdb_write_all(tdb->hActiveLock, emptyString, strlen(emptyString));709 710 return 0;711 }712 #endif
Note:
See TracChangeset
for help on using the changeset viewer.