author | Lars Hjemli <hjemli@gmail.com> | 2008-05-18 21:16:50 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-05-18 21:16:50 (UTC) |
commit | d402811bd2db21c7868411a279fd2d220f54c294 (patch) (unidiff) | |
tree | 1d4c4ac9bec7673652c8771f1ae55f4806cbaf8b | |
parent | 6102bcfce46fd357566941d565b95f78510af79b (diff) | |
download | cgit-d402811bd2db21c7868411a279fd2d220f54c294.zip cgit-d402811bd2db21c7868411a279fd2d220f54c294.tar.gz cgit-d402811bd2db21c7868411a279fd2d220f54c294.tar.bz2 |
cache.c: make all io-related functions return errno on error
We'll need proper return-values from these functions to make the cache
behave correctly (which includes giving proper error messages).
Noticed-by: Jim Meyering <jim@meyering.net>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cache.c | 33 |
1 files changed, 24 insertions, 9 deletions
@@ -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 */ |
69 | static void close_slot(struct cache_slot *slot) | 69 | static 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 */ |
119 | static void close_lock(struct cache_slot *slot) | 123 | static 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 | } |