Remove gencache_init/shutdown
authorVolker Lendecke <vl@samba.org>
Fri, 10 Jul 2009 10:24:56 +0000 (12:24 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 15 Jul 2009 08:55:20 +0000 (10:55 +0200)
gencache_get/set/del/iterate call gencache_init() internally anyway. And we've
been very lazy calling gencache_shutdown, so this seems not really required.

source3/include/proto.h
source3/lib/gencache.c
source3/lib/netapi/netapi.c
source3/libads/dns.c
source3/libsmb/dsgetdcname.c
source3/libsmb/libsmb_context.c
source3/libsmb/namecache.c
source3/libsmb/namequery.c
source3/libsmb/trustdom_cache.c
source3/torture/torture.c
source3/utils/net_cache.c

index 52ca7826ed1652bc4fa263aa2cc925567b42f206..23bd22aadcaa70d1667477844d7e90028a8d7886 100644 (file)
@@ -515,8 +515,6 @@ void pull_file_id_24(char *buf, struct file_id *id);
 
 /* The following definitions come from lib/gencache.c  */
 
-bool gencache_init(void);
-bool gencache_shutdown(void);
 bool gencache_set(const char *keystr, const char *value, time_t timeout);
 bool gencache_del(const char *keystr);
 bool gencache_get(const char *keystr, char **valstr, time_t *timeout);
index c94fb785419177cb7d659421a1dedaf76a4812c0..06eb29345b2f1b2c112df99b1307821e640ebc4d 100644 (file)
@@ -49,7 +49,7 @@ static struct tdb_context *cache;
  *         false on failure
  **/
 
-bool gencache_init(void)
+static bool gencache_init(void)
 {
        char* cache_fname = NULL;
 
@@ -78,25 +78,6 @@ bool gencache_init(void)
 }
 
 
-/**
- * Cache shutdown function. Closes opened cache tdb file.
- *
- * @return true on successful closing the cache or
- *         false on failure during cache shutdown
- **/
-
-bool gencache_shutdown(void)
-{
-       int ret;
-       /* tdb_close routine returns -1 on error */
-       if (!cache) return False;
-       DEBUG(5, ("Closing cache file\n"));
-       ret = tdb_close(cache);
-       cache = NULL;
-       return ret != -1;
-}
-
-
 /**
  * Set an entry in the cache file. If there's no such
  * one, then add it.
index 2f8474b37fdd0598abd1cb2e46aa10a87f9194fe..e80879a1d26677094cea7607ac00ee55f953e5b6 100644 (file)
@@ -170,7 +170,6 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx)
        gfree_charcnv();
        gfree_interfaces();
 
-       gencache_shutdown();
        secrets_shutdown();
 
        TALLOC_FREE(ctx);
index 3a9e8496685b165e40b1166931f99c793e4f48e0..5cf768de67241decbfe4f3ac42c81f35b5ae11d6 100644 (file)
@@ -754,10 +754,6 @@ bool sitename_store(const char *realm, const char *sitename)
        bool ret = False;
        char *key;
 
-       if (!gencache_init()) {
-               return False;
-       }
-
        if (!realm || (strlen(realm) == 0)) {
                DEBUG(0,("sitename_store: no realm\n"));
                return False;
@@ -795,10 +791,6 @@ char *sitename_fetch(const char *realm)
        const char *query_realm;
        char *key;
 
-       if (!gencache_init()) {
-               return NULL;
-       }
-
        if (!realm || (strlen(realm) == 0)) {
                query_realm = lp_realm();
        } else {
index 8dee6926d223a21259248a27bbad13f800399d26..9552ad1f225b83f537d2049f2726d080d87dc2c2 100644 (file)
@@ -133,10 +133,6 @@ static NTSTATUS dsgetdcname_cache_delete(TALLOC_CTX *mem_ctx,
 {
        char *key;
 
-       if (!gencache_init()) {
-               return NT_STATUS_INTERNAL_DB_ERROR;
-       }
-
        key = dsgetdcname_cache_key(mem_ctx, domain_name);
        if (!key) {
                return NT_STATUS_NO_MEMORY;
@@ -160,10 +156,6 @@ static NTSTATUS dsgetdcname_cache_store(TALLOC_CTX *mem_ctx,
        char *key;
        bool ret = false;
 
-       if (!gencache_init()) {
-               return NT_STATUS_INTERNAL_DB_ERROR;
-       }
-
        key = dsgetdcname_cache_key(mem_ctx, domain_name);
        if (!key) {
                return NT_STATUS_NO_MEMORY;
@@ -357,10 +349,6 @@ static NTSTATUS dsgetdcname_cache_fetch(TALLOC_CTX *mem_ctx,
        struct NETLOGON_SAM_LOGON_RESPONSE_EX r;
        NTSTATUS status;
 
-       if (!gencache_init()) {
-               return NT_STATUS_INTERNAL_DB_ERROR;
-       }
-
        key = dsgetdcname_cache_key(mem_ctx, domain_name);
        if (!key) {
                return NT_STATUS_NO_MEMORY;
index 98885876b3350939e1ab84a22eb5bfb81ef43502..8b22ee5023c121b0f8d81e6253b773439639cb8d 100644 (file)
@@ -123,7 +123,6 @@ SMBC_module_init(void * punused)
 static void
 SMBC_module_terminate(void)
 {
-    gencache_shutdown();
     secrets_shutdown();
     gfree_all();
     SMBC_initialized = false;
index d3230cffefb43548d199267a791467bf70c52f8c..dcfc609dcd6dcc4c2e05d6255d304ce06008e5e3 100644 (file)
@@ -45,14 +45,6 @@ bool namecache_enable(void)
                return False;
        }
 
-       /* Init namecache by calling gencache initialisation */
-
-       if (!gencache_init()) {
-               DEBUG(2, ("namecache_enable: "
-                       "Couldn't initialise namecache on top of gencache.\n"));
-               return False;
-       }
-
        /* I leave it for now, though I don't think we really
         * need this (mimir, 27.09.2002) */
        DEBUG(5, ("namecache_enable: enabling netbios namecache, timeout %d "
@@ -102,14 +94,6 @@ bool namecache_store(const char *name,
        int i;
        bool ret;
 
-       /*
-        * we use gecache call to avoid annoying debug messages about
-        * initialised namecache again and again...
-        */
-       if (!gencache_init()) {
-               return False;
-       }
-
        if (name_type > 255) {
                return False; /* Don't store non-real name types. */
        }
@@ -186,10 +170,6 @@ bool namecache_fetch(const char *name,
                return False;
        }
 
-       if (!gencache_init()) {
-               return False;
-       }
-
        if (name_type > 255) {
                return False; /* Don't fetch non-real name types. */
        }
@@ -233,9 +213,6 @@ bool namecache_delete(const char *name, int name_type)
        bool ret;
        char *key;
 
-       if (!gencache_init())
-               return False;
-
        if (name_type > 255) {
                return False; /* Don't fetch non-real name types. */
        }
@@ -274,10 +251,6 @@ static void flush_netbios_name(const char *key,
 
 void namecache_flush(void)
 {
-       if (!gencache_init()) {
-               return;
-       }
-
        /*
         * iterate through each NBT cache's entry and flush it
         * by flush_netbios_name function
@@ -312,10 +285,6 @@ bool namecache_status_store(const char *keyname, int keyname_type,
        time_t expiry;
        bool ret;
 
-       if (!gencache_init()) {
-               return False;
-       }
-
        key = namecache_status_record_key(keyname, keyname_type,
                        name_type, keyip);
        if (!key)
@@ -348,9 +317,6 @@ bool namecache_status_fetch(const char *keyname,
        char *value = NULL;
        time_t timeout;
 
-       if (!gencache_init())
-               return False;
-
        key = namecache_status_record_key(keyname, keyname_type,
                        name_type, keyip);
        if (!key)
index 50fb9f1620590aefde3144b26a9edc0154525328..05143270b9fd8ce2a9f9f8b35740092a1e6ca6d7 100644 (file)
@@ -76,9 +76,6 @@ bool saf_store( const char *domain, const char *servername )
                return False;
        }
 
-       if ( !gencache_init() )
-               return False;
-
        key = saf_key( domain );
        expire = time( NULL ) + lp_parm_int(-1, "saf","ttl", SAF_TTL);
 
@@ -108,9 +105,6 @@ bool saf_join_store( const char *domain, const char *servername )
                return False;
        }
 
-       if ( !gencache_init() )
-               return False;
-
        key = saf_join_key( domain );
        expire = time( NULL ) + lp_parm_int(-1, "saf","join ttl", SAFJOIN_TTL);
 
@@ -134,9 +128,6 @@ bool saf_delete( const char *domain )
                return False;
        }
 
-       if ( !gencache_init() )
-               return False;
-
        key = saf_join_key(domain);
        ret = gencache_del(key);
        SAFE_FREE(key);
@@ -171,9 +162,6 @@ char *saf_fetch( const char *domain )
                return NULL;
        }
 
-       if ( !gencache_init() )
-               return False;
-
        key = saf_join_key( domain );
 
        ret = gencache_get( key, &server, &timeout );
index d891c0768e1cbd733c4d0d791b14b662adcae21a..eb52b3588d58d1f4d6ca2d00164ccc64859b28d7 100644 (file)
 
 bool trustdom_cache_enable(void)
 {
-       /* Init trustdom cache by calling gencache initialisation */
-       if (!gencache_init()) {
-               DEBUG(2, ("trustdomcache_enable: Couldn't initialise trustdom cache on top of gencache.\n"));
-               return False;
-       }
-
        return True;
 }
 
@@ -68,12 +62,6 @@ bool trustdom_cache_enable(void)
 
 bool trustdom_cache_shutdown(void)
 {
-       /* Close trustdom cache by calling gencache shutdown */
-       if (!gencache_shutdown()) {
-               DEBUG(2, ("trustdomcache_shutdown: Couldn't shutdown trustdom cache on top of gencache.\n"));
-               return False;
-       }
-
        return True;
 }
 
@@ -114,13 +102,6 @@ bool trustdom_cache_store(char* name, char* alt_name, const DOM_SID *sid,
        fstring sid_string;
        bool ret;
 
-       /*
-        * we use gecache call to avoid annoying debug messages
-        * about initialised trustdom 
-        */
-       if (!gencache_init())
-               return False;
-
        DEBUG(5, ("trustdom_store: storing SID %s of domain %s\n",
                  sid_string_dbg(sid), name));
 
@@ -165,10 +146,6 @@ bool trustdom_cache_fetch(const char* name, DOM_SID* sid)
        char *key = NULL, *value = NULL;
        time_t timeout;
 
-       /* init the cache */
-       if (!gencache_init())
-               return False;
-
        /* exit now if null pointers were passed as they're required further */
        if (!sid)
                return False;
@@ -209,10 +186,6 @@ uint32 trustdom_cache_fetch_timestamp( void )
        time_t timeout;
        uint32 timestamp;
 
-       /* init the cache */
-       if (!gencache_init()) 
-               return False;
-
        if (!gencache_get(TDOMTSKEY, &value, &timeout)) {
                DEBUG(5, ("no timestamp for trusted domain cache located.\n"));
                SAFE_FREE(value);
@@ -233,10 +206,6 @@ bool trustdom_cache_store_timestamp( uint32 t, time_t timeout )
 {
        fstring value;
 
-       /* init the cache */
-       if (!gencache_init()) 
-               return False;
-
        fstr_sprintf(value, "%d", t );
 
        if (!gencache_set(TDOMTSKEY, value, timeout)) {
@@ -267,9 +236,6 @@ static void flush_trustdom_name(const char* key, const char *value, time_t timeo
 
 void trustdom_cache_flush(void)
 {
-       if (!gencache_init())
-               return;
-
        /* 
         * iterate through each TDOM cache's entry and flush it
         * by flush_trustdom_name function
index 8cebc2adcc6d78290735cf98b1a84a98d305b835..e3c4084e0cc3212f58afcc7da78a1a10219a2271 100644 (file)
@@ -5800,11 +5800,6 @@ static bool run_local_gencache(int dummy)
        time_t tm;
        DATA_BLOB blob;
 
-       if (!gencache_init()) {
-               d_printf("%s: gencache_init() failed\n", __location__);
-               return False;
-       }
-
        if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
                d_printf("%s: gencache_set() failed\n", __location__);
                return False;
@@ -5878,17 +5873,6 @@ static bool run_local_gencache(int dummy)
                return False;
        }
 
-       if (!gencache_shutdown()) {
-               d_printf("%s: gencache_shutdown() failed\n", __location__);
-               return False;
-       }
-
-       if (gencache_shutdown()) {
-               d_printf("%s: second gencache_shutdown() succeeded\n",
-                        __location__);
-               return False;
-       }
-
        return True;
 }
 
index 5e7db385155b75b38d9bc7591f4a6efe523c932a..74d8d29b4b5668e378b20b0fd454731cd16cde08 100644 (file)
@@ -171,12 +171,10 @@ static int net_cache_add(struct net_context *c, int argc, const char **argv)
 
        if (gencache_set(keystr, datastr, timeout)) {
                d_printf("New cache entry stored successfully.\n");
-               gencache_shutdown();
                return 0;
        }
 
        d_fprintf(stderr, "Entry couldn't be added. Perhaps there's already such a key.\n");
-       gencache_shutdown();
        return -1;
 }
 
@@ -275,7 +273,6 @@ static int net_cache_list(struct net_context *c, int argc, const char **argv)
                return 0;
        }
        gencache_iterate(print_cache_entry, NULL, pattern);
-       gencache_shutdown();
        return 0;
 }
 
@@ -297,7 +294,6 @@ static int net_cache_flush(struct net_context *c, int argc, const char **argv)
                return 0;
        }
        gencache_iterate(delete_cache_entry, NULL, pattern);
-       gencache_shutdown();
        return 0;
 }