Fix slowdown because of enumerating all print queues on every smbd startup.
authorJeremy Allison <jra@samba.org>
Thu, 31 Oct 2002 23:41:02 +0000 (23:41 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 31 Oct 2002 23:41:02 +0000 (23:41 +0000)
Jeremy.
(This used to be commit d05b147fb3f32031a202cf61703dc2fd969f4617)

source3/printing/nt_printing.c
source3/printing/printing.c
source3/smbd/server.c

index 6e4bb1e977dbcf01e9561d09f0f3c2836d187e9b..7b19b74025d7fdcf1a420b4ec65f0001e2fe7cb1 100644 (file)
@@ -252,7 +252,7 @@ static BOOL upgrade_to_version_3(void)
 }
 
 /****************************************************************************
- Open the NT printing tdb.
+ Open the NT printing tdbs. Done once before fork().
 ****************************************************************************/
 
 BOOL nt_printing_init(void)
@@ -263,6 +263,8 @@ BOOL nt_printing_init(void)
        if (tdb_drivers && tdb_printers && tdb_forms && local_pid == sys_getpid())
                return True;
  
+       if (tdb_drivers)
+               tdb_close(tdb_drivers);
        tdb_drivers = tdb_open_log(lock_path("ntdrivers.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
        if (!tdb_drivers) {
                DEBUG(0,("nt_printing_init: Failed to open nt drivers database %s (%s)\n",
@@ -270,6 +272,8 @@ BOOL nt_printing_init(void)
                return False;
        }
  
+       if (tdb_printers)
+               tdb_close(tdb_printers);
        tdb_printers = tdb_open_log(lock_path("ntprinters.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
        if (!tdb_printers) {
                DEBUG(0,("nt_printing_init: Failed to open nt printers database %s (%s)\n",
@@ -277,6 +281,8 @@ BOOL nt_printing_init(void)
                return False;
        }
  
+       if (tdb_forms)
+               tdb_close(tdb_forms);
        tdb_forms = tdb_open_log(lock_path("ntforms.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
        if (!tdb_forms) {
                DEBUG(0,("nt_printing_init: Failed to open nt forms database %s (%s)\n",
index 2d75699ac522d54ff787e821c79bd0ededa0a1a6..2121fb20a370eb0c58eff730e87b7f7bdebfed7e 100644 (file)
@@ -154,6 +154,7 @@ static struct tdb_print_db *get_print_db_byname(const char *printername)
        struct tdb_print_db *p = NULL, *last_entry = NULL;
        int num_open = 0;
        pstring printdb_path;
+       BOOL done_become_root = False;
 
        for (p = print_db_head, last_entry = print_db_head; p; p = p->next) {
                /* Ensure the list terminates... JRA. */
@@ -209,9 +210,15 @@ static struct tdb_print_db *get_print_db_byname(const char *printername)
        pstrcat(printdb_path, printername);
        pstrcat(printdb_path, ".tdb");
 
-       become_root();
+       if (geteuid() != 0) {
+               become_root();
+               done_become_root = True;
+       }
+
        p->tdb = tdb_open_log(printdb_path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
-       unbecome_root();
+
+       if (done_become_root)
+               unbecome_root();
 
        if (!p->tdb) {
                DEBUG(0,("get_print_db: Failed to open printer backend database %s.\n",
@@ -255,8 +262,7 @@ static void close_all_print_db(void)
 }
 
 /****************************************************************************
- Initialise the printing backend. Called once at startup. 
- Does not survive a fork
+ Initialise the printing backend. Called once at startup before the fork().
 ****************************************************************************/
 
 BOOL print_backend_init(void)
@@ -316,16 +322,7 @@ BOOL print_backend_init(void)
 
 void printing_end(void)
 {
-       struct tdb_print_db *p;
-
-       for (p = print_db_head; p; ) {
-               struct tdb_print_db *next_p = p->next;
-               if (p->tdb)
-                       tdb_close(p->tdb);
-               DLIST_REMOVE(print_db_head, p);
-               SAFE_FREE(p);
-               p = next_p;
-       }
+       close_all_print_db(); /* Don't leave any open. */
 }
 
 /****************************************************************************
index 39d5e3bcd3f75922aab515e50b06574a31d69405..ad00794bd7206c56c5578b04439d53a1edce22bd 100644 (file)
@@ -370,7 +370,10 @@ static BOOL open_sockets_smbd(BOOL is_daemon,const char *smb_ports)
                                reset_globals_after_fork();
 
                                /* tdb needs special fork handling */
-                               tdb_reopen_all();
+                               if (tdb_reopen_all() == -1) {
+                                       DEBUG(0,("tdb_reopen_all failed.\n"));
+                                       return False;
+                               }
 
                                return True; 
                        }
@@ -859,6 +862,9 @@ static void usage(char *pname)
        register_msg_pool_usage();
        register_dmalloc_msgs();
 
+       if (!print_backend_init())
+               exit(1);
+
        /* Setup the main smbd so that we can get messages. */
        claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
 
@@ -881,9 +887,6 @@ static void usage(char *pname)
        if (!locking_init(0))
                exit(1);
 
-       if (!print_backend_init())
-               exit(1);
-
        if (!share_info_db_init())
                exit(1);