From 3103303d2a78ef2d530083502280c1bba551c4bb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 26 Oct 2002 00:29:21 +0000 Subject: Fix problem where an fd would be left open for every printer queue. Jeremy. (This used to be commit 997c234e15a5f8d742320359a53e15a27661d456) --- source3/printing/printing.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source3/printing') diff --git a/source3/printing/printing.c b/source3/printing/printing.c index afcf0ee720..2d75699ac5 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -225,12 +225,35 @@ static struct tdb_print_db *get_print_db_byname(const char *printername) return p; } +/*************************************************************************** + Remove a reference count. +****************************************************************************/ + static void release_print_db( struct tdb_print_db *pdb) { pdb->ref_count--; SMB_ASSERT(pdb->ref_count >= 0); } +/*************************************************************************** + Close all open print db entries. +****************************************************************************/ + +static void close_all_print_db(void) +{ + struct tdb_print_db *p = NULL, *next_p = NULL; + + for (p = print_db_head; p; p = next_p) { + next_p = p->next; + + if (p->tdb) + tdb_close(p->tdb); + DLIST_REMOVE(print_db_head, p); + ZERO_STRUCTP(p); + SAFE_FREE(p); + } +} + /**************************************************************************** Initialise the printing backend. Called once at startup. Does not survive a fork @@ -264,6 +287,7 @@ BOOL print_backend_init(void) continue; if (tdb_lock_bystring(pdb->tdb, sversion, 0) == -1) { DEBUG(0,("print_backend_init: Failed to open printer %s database\n", lp_const_servicename(snum) )); + release_print_db(pdb); return False; } if (tdb_fetch_int32(pdb->tdb, sversion) != PRINT_DATABASE_VERSION) { @@ -271,8 +295,11 @@ BOOL print_backend_init(void) tdb_store_int32(pdb->tdb, sversion, PRINT_DATABASE_VERSION); } tdb_unlock_bystring(pdb->tdb, sversion); + release_print_db(pdb); } + close_all_print_db(); /* Don't leave any open. */ + /* select the appropriate printing interface... */ #ifdef HAVE_CUPS if (strcmp(lp_printcapname(), "cups") == 0) -- cgit