summaryrefslogtreecommitdiffabout
path: root/cache.c
Unidiff
Diffstat (limited to 'cache.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cache.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/cache.c b/cache.c
index add647e..6847202 100644
--- a/cache.c
+++ b/cache.c
@@ -67,10 +67,14 @@ static int open_slot(struct cache_slot *slot)
67 67
68/* Close the active cache slot */ 68/* Close the active cache slot */
69static void close_slot(struct cache_slot *slot) 69static int close_slot(struct cache_slot *slot)
70{ 70{
71 int err = 0;
71 if (slot->cache_fd > 0) { 72 if (slot->cache_fd > 0) {
72 close(slot->cache_fd); 73 if (close(slot->cache_fd))
73 slot->cache_fd = -1; 74 err = errno;
75 else
76 slot->cache_fd = -1;
74 } 77 }
78 return err;
75} 79}
76 80
@@ -117,10 +121,14 @@ static int is_modified(struct cache_slot *slot)
117 121
118/* Close an open lockfile */ 122/* Close an open lockfile */
119static void close_lock(struct cache_slot *slot) 123static int close_lock(struct cache_slot *slot)
120{ 124{
125 int err = 0;
121 if (slot->lock_fd > 0) { 126 if (slot->lock_fd > 0) {
122 close(slot->lock_fd); 127 if (close(slot->lock_fd))
123 slot->lock_fd = -1; 128 err = errno;
129 else
130 slot->lock_fd = -1;
124 } 131 }
132 return err;
125} 133}
126 134
@@ -135,5 +143,6 @@ static int lock_slot(struct cache_slot *slot)
135 if (slot->lock_fd == -1) 143 if (slot->lock_fd == -1)
136 return errno; 144 return errno;
137 write(slot->lock_fd, slot->key, slot->keylen + 1); 145 if (write(slot->lock_fd, slot->key, slot->keylen + 1) < 0)
146 return errno;
138 return 0; 147 return 0;
139} 148}
@@ -151,5 +160,9 @@ static int unlock_slot(struct cache_slot *slot, int replace_old_slot)
151 else 160 else
152 err = unlink(slot->lock_name); 161 err = unlink(slot->lock_name);
153 return err; 162
163 if (err)
164 return errno;
165
166 return 0;
154} 167}
155 168
@@ -178,5 +191,7 @@ static int fill_slot(struct cache_slot *slot)
178 191
179 /* Close the temporary filedescriptor */ 192 /* Close the temporary filedescriptor */
180 close(tmp); 193 if (close(tmp))
194 return errno;
195
181 return 0; 196 return 0;
182} 197}