aboutsummaryrefslogtreecommitdiff
path: root/e2fsprogs/blkid/save.c
diff options
context:
space:
mode:
Diffstat (limited to 'e2fsprogs/blkid/save.c')
-rw-r--r--e2fsprogs/blkid/save.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/e2fsprogs/blkid/save.c b/e2fsprogs/blkid/save.c
index a2fbd7b45..1830e459a 100644
--- a/e2fsprogs/blkid/save.c
+++ b/e2fsprogs/blkid/save.c
@@ -90,16 +90,14 @@ int blkid_flush_cache(blkid_cache cache)
90 * a temporary file then we open it directly. 90 * a temporary file then we open it directly.
91 */ 91 */
92 if (ret == 0 && S_ISREG(st.st_mode)) { 92 if (ret == 0 && S_ISREG(st.st_mode)) {
93 tmp = malloc(strlen(filename) + 8); 93 tmp = xmalloc(strlen(filename) + 8);
94 if (tmp) { 94 sprintf(tmp, "%s-XXXXXX", filename);
95 sprintf(tmp, "%s-XXXXXX", filename); 95 fd = mkstemp(tmp);
96 fd = mkstemp(tmp); 96 if (fd >= 0) {
97 if (fd >= 0) { 97 file = fdopen(fd, "w");
98 file = fdopen(fd, "w"); 98 opened = tmp;
99 opened = tmp;
100 }
101 fchmod(fd, 0644);
102 } 99 }
100 fchmod(fd, 0644);
103 } 101 }
104 102
105 if (!file) { 103 if (!file) {
@@ -138,13 +136,11 @@ int blkid_flush_cache(blkid_cache cache)
138 } else { 136 } else {
139 char *backup; 137 char *backup;
140 138
141 backup = malloc(strlen(filename) + 5); 139 backup = xmalloc(strlen(filename) + 5);
142 if (backup) { 140 sprintf(backup, "%s.old", filename);
143 sprintf(backup, "%s.old", filename); 141 unlink(backup);
144 unlink(backup); 142 link(filename, backup);
145 link(filename, backup); 143 free(backup);
146 free(backup);
147 }
148 rename(opened, filename); 144 rename(opened, filename);
149 DBG(DEBUG_SAVE, 145 DBG(DEBUG_SAVE,
150 printf("moved temp cache %s\n", opened)); 146 printf("moved temp cache %s\n", opened));