summaryrefslogtreecommitdiff
path: root/lib/blkid/save.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/blkid/save.c')
-rw-r--r--lib/blkid/save.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/blkid/save.c b/lib/blkid/save.c
index 6c20168b..762ffefd 100644
--- a/lib/blkid/save.c
+++ b/lib/blkid/save.c
@@ -94,8 +94,10 @@ int blkid_flush_cache(blkid_cache cache)
if (ret == 0 && S_ISREG(st.st_mode)) {
tmp = malloc(strlen(filename) + 8);
if (tmp) {
+ mode_t save_umask = umask(022);
sprintf(tmp, "%s-XXXXXX", filename);
fd = mkstemp(tmp);
+ umask(save_umask);
if (fd >= 0) {
file = fdopen(fd, "w");
opened = tmp;
@@ -134,7 +136,7 @@ int blkid_flush_cache(blkid_cache cache)
fclose(file);
if (opened != filename) {
if (ret < 0) {
- unlink(opened);
+ (void) unlink(opened);
DBG(DEBUG_SAVE,
printf("unlinked temp cache %s\n", opened));
} else {
@@ -144,10 +146,11 @@ int blkid_flush_cache(blkid_cache cache)
if (backup) {
sprintf(backup, "%s.old", filename);
unlink(backup);
- link(filename, backup);
+ (void) link(filename, backup);
free(backup);
}
- rename(opened, filename);
+ if (rename(opened, filename) < 0)
+ (void) unlink(opened);
DBG(DEBUG_SAVE,
printf("moved temp cache %s\n", opened));
}