diff options
-rw-r--r-- | source3/include/proto.h | 5 | ||||
-rw-r--r-- | source3/printing/nt_printing.c | 9 | ||||
-rw-r--r-- | source3/printing/printing.c | 16 | ||||
-rw-r--r-- | source3/tdb/tdb.c | 25 |
4 files changed, 16 insertions, 39 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index 27fcb6a921..985a6efa0d 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -279,7 +279,6 @@ pid_t sys_fork(void); pid_t sys_getpid(void); int sys_popen(const char *command); int sys_pclose(int fd); -int fcntl64(int fd, int cmd, struct flock * lock); /*The following definitions come from lib/talloc.c */ @@ -3993,13 +3992,13 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag); TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode); int tdb_close(TDB_CONTEXT *tdb); -int tdb_writelock(TDB_CONTEXT *tdb); -int tdb_writeunlock(TDB_CONTEXT *tdb); int tdb_lockchain(TDB_CONTEXT *tdb, TDB_DATA key); int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key); /*The following definitions come from tdb/tdbutil.c */ +int tdb_lock_bystring(TDB_CONTEXT *tdb, char *keyval); +int tdb_unlock_bystring(TDB_CONTEXT *tdb, char *keyval); int tdb_fetch_int_byblob(TDB_CONTEXT *tdb, char *keyval, size_t len); int tdb_fetch_int(TDB_CONTEXT *tdb, char *keystr); int tdb_store_int_byblob(TDB_CONTEXT *tdb, char *keystr, size_t len, int v); diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index 69e9233d27..bd968c66ab 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -50,6 +50,7 @@ open the NT printing tdb BOOL nt_printing_init(void) { static pid_t local_pid; + char *vstring = "INFO/version"; if (tdb && local_pid == sys_getpid()) return True; tdb = tdb_open(lock_path("ntdrivers.tdb"), 0, 0, O_RDWR|O_CREAT, 0600); @@ -61,12 +62,12 @@ BOOL nt_printing_init(void) local_pid = sys_getpid(); /* handle a Samba upgrade */ - tdb_writelock(tdb); - if (tdb_fetch_int(tdb, "INFO/version") != DATABASE_VERSION) { + tdb_lock_bystring(tdb, vstring); + if (tdb_fetch_int(tdb, vstring) != DATABASE_VERSION) { tdb_traverse(tdb, (tdb_traverse_func)tdb_delete, NULL); - tdb_store_int(tdb, "INFO/version", DATABASE_VERSION); + tdb_store_int(tdb, vstring, DATABASE_VERSION); } - tdb_writeunlock(tdb); + tdb_unlock_bystring(tdb, vstring); return True; } diff --git a/source3/printing/printing.c b/source3/printing/printing.c index 28b5934c37..b884c5ac99 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -68,6 +68,8 @@ Does not survive a fork ****************************************************************************/ BOOL print_backend_init(void) { + char *sversion = "INFO/version"; + if (tdb && local_pid == sys_getpid()) return True; tdb = tdb_open(lock_path("printing.tdb"), 0, 0, O_RDWR|O_CREAT, 0600); if (!tdb) { @@ -76,12 +78,12 @@ BOOL print_backend_init(void) local_pid = sys_getpid(); /* handle a Samba upgrade */ - tdb_writelock(tdb); - if (tdb_fetch_int(tdb, "INFO/version") != PRINT_DATABASE_VERSION) { + tdb_lock_bystring(tdb, sversion); + if (tdb_fetch_int(tdb, sversion) != PRINT_DATABASE_VERSION) { tdb_traverse(tdb, (tdb_traverse_func)tdb_delete, NULL); - tdb_store_int(tdb, "INFO/version", PRINT_DATABASE_VERSION); + tdb_store_int(tdb, sversion, PRINT_DATABASE_VERSION); } - tdb_writeunlock(tdb); + tdb_unlock_bystring(tdb, sversion); return nt_printing_init(); } @@ -678,7 +680,7 @@ int print_job_start(struct current_user *user, int snum, char *jobname) fstrcpy(pjob.qname, lp_servicename(snum)); /* lock the database */ - tdb_writelock(tdb); + tdb_lock_bystring(tdb, "INFO/nextjob"); next_jobnum: next_jobid = tdb_fetch_int(tdb, "INFO/nextjob"); @@ -712,7 +714,7 @@ int print_job_start(struct current_user *user, int snum, char *jobname) print_job_store(jobid, &pjob); - tdb_writeunlock(tdb); + tdb_unlock_bystring(tdb, "INFO/nextjob"); /* * If the printer is marked as postscript output a leading @@ -732,7 +734,7 @@ int print_job_start(struct current_user *user, int snum, char *jobname) tdb_delete(tdb, print_key(jobid)); } - tdb_writeunlock(tdb); + tdb_unlock_bystring(tdb, "INFO/nextjob"); return -1; } diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c index 9c5e99e06b..45cbaf73ed 100644 --- a/source3/tdb/tdb.c +++ b/source3/tdb/tdb.c @@ -1278,31 +1278,6 @@ int tdb_close(TDB_CONTEXT *tdb) return 0; } -/* lock the database. If we already have it locked then don't do anything */ -int tdb_writelock(TDB_CONTEXT *tdb) -{ - if (tdb == NULL) { -#ifdef TDB_DEBUG - printf("tdb_writelock() called with null context\n"); -#endif - return -1; - } - - return tdb_lock(tdb, -1, F_WRLCK); -} - -/* unlock the database. */ -int tdb_writeunlock(TDB_CONTEXT *tdb) -{ - if (tdb == NULL) { -#ifdef TDB_DEBUG - printf("tdb_writeunlock() called with null context\n"); -#endif - return -1; - } - - return tdb_unlock(tdb, -1); -} /* lock one hash chain. This is meant to be used to reduce locking contention - it cannot guarantee how many records will be locked */ |