diff options
Diffstat (limited to 'libblkid/src/cache.c')
-rw-r--r-- | libblkid/src/cache.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libblkid/src/cache.c b/libblkid/src/cache.c index c100cfa20..2eab2d329 100644 --- a/libblkid/src/cache.c +++ b/libblkid/src/cache.c @@ -31,7 +31,7 @@ int blkid_debug_mask = 0; * @title: Cache * @short_description: basic routines to work with libblkid cache * - * Block device information is normally kept in a cache file /etc/blkid.tab and is + * Block device information is normally kept in a cache file blkid.tab and is * verified to still be valid before being returned to the user (if the user has * read permission on the raw block device, otherwise not). The cache file also * allows unprivileged users (normally anyone other than root, or those not in the @@ -95,6 +95,16 @@ void blkid_init_debug(int mask) } #endif +static const char *get_default_cache_filename(void) +{ + struct stat st; + + if (stat(BLKID_RUNTIME_TOPDIR, &st) == 0 && S_ISDIR(st.st_mode)) + return BLKID_CACHE_FILE; /* cache in /run */ + + return BLKID_CACHE_FILE_OLD; /* cache in /etc */ +} + /* returns allocated path to cache */ char *blkid_get_cache_filename(struct blkid_config *conf) { @@ -108,7 +118,7 @@ char *blkid_get_cache_filename(struct blkid_config *conf) else { struct blkid_config *c = blkid_read_config(NULL); if (!c) - filename = blkid_strdup(BLKID_CACHE_FILE); + filename = blkid_strdup(get_default_cache_filename()); else { filename = c->cachefile; /* already allocated */ c->cachefile = NULL; @@ -244,7 +254,7 @@ int main(int argc, char** argv) if ((ret = blkid_get_cache(&cache, argv[1])) < 0) { fprintf(stderr, "error %d parsing cache file %s\n", ret, - argv[1] ? argv[1] : BLKID_CACHE_FILE); + argv[1] ? argv[1] : blkid_get_cache_filename(NULL)); exit(1); } if ((ret = blkid_get_cache(&cache, "/dev/null")) != 0) { |