]> err.no Git - util-linux/commitdiff
blkid: blkid_evaluate_spec() shouldn't ignore $BLKID_FILE
authorKarel Zak <kzak@redhat.com>
Wed, 18 Feb 2009 21:46:01 +0000 (22:46 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 18 Feb 2009 21:46:01 +0000 (22:46 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libs/blkid/src/blkidP.h
libs/blkid/src/cache.c
libs/blkid/src/evaluate.c

index 240a983f308ba7c9eadf0aadea784ae814e07b9d..128c6df2205986c9d981d915fe299dc4f6f78300 100644 (file)
@@ -293,6 +293,7 @@ extern int blkid_flush_cache(blkid_cache cache);
 
 /* cache */
 extern char *blkid_safe_getenv(const char *arg);
+extern char *blkid_get_cache_filename(struct blkid_config *conf);
 
 /*
  * Functions to create and find a specific tag type: tag.c
index 9897729e400fe5389bc8994376c18851a9fe0f45..964992285785bcd449ee31c67532049c0f1c2700 100644 (file)
@@ -97,6 +97,27 @@ void blkid_debug_init(int mask)
 }
 #endif
 
+/* returns allocated path to cache */
+char *blkid_get_cache_filename(struct blkid_config *conf)
+{
+       char *filename;
+
+       filename = blkid_safe_getenv("BLKID_FILE");
+       if (filename)
+               filename = blkid_strdup(filename);
+       else if (conf)
+               filename = blkid_strdup(conf->cachefile);
+       else {
+               struct blkid_config *c = blkid_read_config(NULL);
+               if (!c)
+                       return -BLKID_ERR_PARAM;
+               filename = c->cachefile;  /* already allocated */
+               c->cachefile = NULL;
+               blkid_free_config(c);
+       }
+       return filename;
+}
+
 int blkid_get_cache(blkid_cache *ret_cache, const char *filename)
 {
        blkid_cache cache;
@@ -114,21 +135,12 @@ int blkid_get_cache(blkid_cache *ret_cache, const char *filename)
 
        if (filename && !*filename)
                filename = NULL;
-       if (!filename)
-               filename = blkid_safe_getenv("BLKID_FILE");
        if (filename)
                cache->bic_filename = blkid_strdup(filename);
-       else {
-               struct blkid_config *conf = blkid_read_config(NULL);
-               if (!conf)
-                       return -BLKID_ERR_PARAM;
-               cache->bic_filename = conf->cachefile;
-               conf->cachefile = NULL;
-               blkid_free_config(conf);
-       }
+       else
+               cache->bic_filename = blkid_get_cache_filename(NULL);
 
        blkid_read_cache(cache);
-
        *ret_cache = cache;
        return 0;
 }
index e0e7f81ebf842b42c4cc6e904827901a4d97c907..a3aaf151dd581b486cf3be8a30eff09e8b18c3fc 100644 (file)
@@ -158,7 +158,7 @@ failed:
 }
 
 static char *evaluate_by_scan(const char *token, const char *value,
-               blkid_cache *cache, const char *cachefile)
+               blkid_cache *cache, struct blkid_config *conf)
 {
        blkid_cache c = cache ? *cache : NULL;
        char *res;
@@ -166,8 +166,11 @@ static char *evaluate_by_scan(const char *token, const char *value,
        DBG(DEBUG_EVALUATE,
            printf("evaluating by blkid scan %s=%s\n", token, value));
 
-       if (!c)
+       if (!c) {
+               char *cachefile = blkid_get_cache_filename(conf);
                blkid_get_cache(&c, cachefile);
+               free(cachefile);
+       }
        if (!c)
                return NULL;
 
@@ -226,7 +229,7 @@ char *blkid_evaluate_spec(const char *token, const char *value, blkid_cache *cac
                if (conf->eval[i] == BLKID_EVAL_UDEV)
                        ret = evaluate_by_udev(token, value, conf->uevent);
                else if (conf->eval[i] == BLKID_EVAL_SCAN)
-                       ret = evaluate_by_scan(token, value, cache, conf->cachefile);
+                       ret = evaluate_by_scan(token, value, cache, conf);
                if (ret)
                        break;
        }