From bb5f28762083a48a886a0f6ee685f5a98380a5c2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 18 Feb 2009 22:46:01 +0100 Subject: [PATCH] blkid: blkid_evaluate_spec() shouldn't ignore $BLKID_FILE Signed-off-by: Karel Zak --- libs/blkid/src/blkidP.h | 1 + libs/blkid/src/cache.c | 34 +++++++++++++++++++++++----------- libs/blkid/src/evaluate.c | 9 ++++++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/libs/blkid/src/blkidP.h b/libs/blkid/src/blkidP.h index 240a983f..128c6df2 100644 --- a/libs/blkid/src/blkidP.h +++ b/libs/blkid/src/blkidP.h @@ -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 diff --git a/libs/blkid/src/cache.c b/libs/blkid/src/cache.c index 9897729e..96499228 100644 --- a/libs/blkid/src/cache.c +++ b/libs/blkid/src/cache.c @@ -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; } diff --git a/libs/blkid/src/evaluate.c b/libs/blkid/src/evaluate.c index e0e7f81e..a3aaf151 100644 --- a/libs/blkid/src/evaluate.c +++ b/libs/blkid/src/evaluate.c @@ -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; } -- 2.39.5