summaryrefslogtreecommitdiffstats
path: root/libblkid/src/save.c
diff options
context:
space:
mode:
authorKarel Zak2012-01-25 12:56:39 +0100
committerKarel Zak2012-01-25 13:20:37 +0100
commitb82590ad46acf9fe8d332b53875e24c3c31e2482 (patch)
tree6e2f7e53424393b1925a896a309d2913ae48c136 /libblkid/src/save.c
parentblkid: remove -w option from man page and usage() output (diff)
downloadkernel-qcow2-util-linux-b82590ad46acf9fe8d332b53875e24c3c31e2482.tar.gz
kernel-qcow2-util-linux-b82590ad46acf9fe8d332b53875e24c3c31e2482.tar.xz
kernel-qcow2-util-linux-b82590ad46acf9fe8d332b53875e24c3c31e2482.zip
blkid: move cache to /run on new systems
Why? * read-only root * /etc is pretty bad place for caches * all is usually cached by udev in /dev/disk/by-* and libblkid is able to use these symlinks * boot persistent cache is attractive for very small subset of Linux machines (and they already need extra udev tunning otherwise udev will probe all block devices during boot) * the default is possible to override in /etc/blkid.conf The systems without /run directory will not be affected by this change. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libblkid/src/save.c')
-rw-r--r--libblkid/src/save.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/libblkid/src/save.c b/libblkid/src/save.c
index a71b06878..7673ab42e 100644
--- a/libblkid/src/save.c
+++ b/libblkid/src/save.c
@@ -57,8 +57,8 @@ int blkid_flush_cache(blkid_cache cache)
{
struct list_head *p;
char *tmp = NULL;
- const char *opened = NULL;
- const char *filename;
+ char *opened = NULL;
+ char *filename;
FILE *file = NULL;
int fd, ret = 0;
struct stat st;
@@ -72,7 +72,20 @@ int blkid_flush_cache(blkid_cache cache)
return 0;
}
- filename = cache->bic_filename ? cache->bic_filename: BLKID_CACHE_FILE;
+ filename = cache->bic_filename ? cache->bic_filename :
+ blkid_get_cache_filename(NULL);
+
+ if (filename && strncmp(filename,
+ BLKID_RUNTIME_DIR "/", sizeof(BLKID_RUNTIME_DIR)) == 0) {
+
+ /* default destination, create the directory if necessary */
+ if (stat(BLKID_RUNTIME_DIR, &st) && errno == ENOENT) {
+
+ mkdir(BLKID_RUNTIME_DIR, S_IWUSR|
+ S_IRUSR|S_IRGRP|S_IROTH|
+ S_IXUSR|S_IXGRP|S_IXOTH);
+ }
+ }
/* If we can't write to the cache file, then don't even try */
if (((ret = stat(filename, &st)) < 0 && errno != ENOENT) ||
@@ -157,6 +170,8 @@ int blkid_flush_cache(blkid_cache cache)
errout:
free(tmp);
+ if (filename != cache->bic_filename)
+ free(filename);
return ret;
}