From 9a781a8c6de9513ba5f4cafef41379fae96807c1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2000 23:00:27 +0000 Subject: - added tdb_flags option to tdb_open() - added TDB_CLEAR_IF_FIRST flag to clear the database if this is the first attached process. Useful for non-persistent databases like our locking area (this will also make upgrades to new database layouts easier) - use lock_path() in a couple of places - leave connections database open while smbd running - cleaned up some tdb code a little, using macros for constants (This used to be commit 00e9da3ca577527db392aced62f02c69cfee8f4f) --- source3/smbd/connection.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'source3/smbd') diff --git a/source3/smbd/connection.c b/source3/smbd/connection.c index 5b5ab005c8..13c051a5a3 100644 --- a/source3/smbd/connection.c +++ b/source3/smbd/connection.c @@ -23,6 +23,7 @@ extern fstring remote_machine; +static TDB_CONTEXT *tdb; extern int DEBUGLEVEL; @@ -33,9 +34,7 @@ BOOL yield_connection(connection_struct *conn,char *name,int max_connections) { struct connections_key key; TDB_DATA kbuf; - TDB_CONTEXT *tdb; - tdb = tdb_open(lock_path("connections.tdb"), 0, O_RDWR | O_CREAT, 0644); if (!tdb) return False; DEBUG(3,("Yielding connection to %s\n",name)); @@ -49,23 +48,10 @@ BOOL yield_connection(connection_struct *conn,char *name,int max_connections) kbuf.dsize = sizeof(key); tdb_delete(tdb, kbuf); - tdb_close(tdb); return(True); } -/**************************************************************************** -claim an entry in the connections database -****************************************************************************/ -int delete_dead(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) -{ - struct connections_key key; - memcpy(&key, kbuf.dptr, sizeof(key)); - if (!process_exists(key.pid)) tdb_delete(tdb, kbuf); - return 0; -} - - /**************************************************************************** claim an entry in the connections database ****************************************************************************/ @@ -74,13 +60,15 @@ BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOO struct connections_key key; struct connections_data crec; TDB_DATA kbuf, dbuf; - TDB_CONTEXT *tdb; extern int Client; if (max_connections <= 0) return(True); - - tdb = tdb_open(lock_path("connections.tdb"), 0, O_RDWR | O_CREAT, 0644); + + if (!tdb) { + tdb = tdb_open(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST, + O_RDWR | O_CREAT, 0644); + } if (!tdb) return False; DEBUG(5,("claiming %s %d\n",name,max_connections)); @@ -93,10 +81,6 @@ BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOO kbuf.dptr = (char *)&key; kbuf.dsize = sizeof(key); - if (Clear) { - tdb_traverse(tdb, delete_dead); - } - /* fill in the crec */ ZERO_STRUCT(crec); crec.magic = 0x280267; -- cgit