diff options
author | Lars Hjemli <hjemli@gmail.com> | 2008-05-19 06:16:50 (JST) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-05-19 06:16:50 (JST) |
commit | d402811bd2db21c7868411a279fd2d220f54c294 (patch) | |
tree | 1d4c4ac9bec7673652c8771f1ae55f4806cbaf8b /cache.c | |
parent | 6102bcfce46fd357566941d565b95f78510af79b (diff) | |
download | cgit-d402811bd2db21c7868411a279fd2d220f54c294.zip cgit-d402811bd2db21c7868411a279fd2d220f54c294.tar.gz |
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>
Diffstat (limited to 'cache.c')
-rw-r--r-- | cache.c | 33 |
1 files changed, 24 insertions, 9 deletions
@@ -66,12 +66,16 @@ static int open_slot(struct cache_slot *slot) | |||
66 | } | 66 | } |
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 | ||
77 | /* Print the content of the active cache slot (but skip the key). */ | 81 | /* Print the content of the active cache slot (but skip the key). */ |
@@ -116,12 +120,16 @@ static int is_modified(struct cache_slot *slot) | |||
116 | } | 120 | } |
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 | ||
127 | /* Create a lockfile used to store the generated content for a cache | 135 | /* Create a lockfile used to store the generated content for a cache |
@@ -134,7 +142,8 @@ static int lock_slot(struct cache_slot *slot) | |||
134 | S_IRUSR|S_IWUSR); | 142 | S_IRUSR|S_IWUSR); |
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 | } |
140 | 149 | ||
@@ -150,7 +159,11 @@ static int unlock_slot(struct cache_slot *slot, int replace_old_slot) | |||
150 | err = rename(slot->lock_name, slot->cache_name); | 159 | err = rename(slot->lock_name, slot->cache_name); |
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 | ||
156 | /* Generate the content for the current cache slot by redirecting | 169 | /* Generate the content for the current cache slot by redirecting |
@@ -177,7 +190,9 @@ static int fill_slot(struct cache_slot *slot) | |||
177 | return errno; | 190 | return errno; |
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 | } |
183 | 198 | ||