aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2012-09-05 17:37:37 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-10 19:43:05 -0400
commit436473bc2173499ae274d0f50111d1e355006caf (patch)
tree41c867c12ad16af9f4f6c36bda78369f5d022c19 /tools
parent6bb22fea25624ab593eee376fa5fb82d1b13f45a (diff)
tools/hv: Check for read/write errors
hv_kvp_daemon currently does not check whether fread() or fwrite() succeed. Add the necessary checks. Also, remove the incorrect use of feof() before fread(). Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/hv/hv_kvp_daemon.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 01b3ca583baf..3922abc0daef 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -160,7 +160,12 @@ static void kvp_update_file(int pool)
160 sizeof(struct kvp_record), 160 sizeof(struct kvp_record),
161 kvp_file_info[pool].num_records, filep); 161 kvp_file_info[pool].num_records, filep);
162 162
163 fclose(filep); 163 if (ferror(filep) || fclose(filep)) {
164 kvp_release_lock(pool);
165 syslog(LOG_ERR, "Failed to write file, pool: %d", pool);
166 exit(EXIT_FAILURE);
167 }
168
164 kvp_release_lock(pool); 169 kvp_release_lock(pool);
165} 170}
166 171
@@ -181,12 +186,17 @@ static void kvp_update_mem_state(int pool)
181 syslog(LOG_ERR, "Failed to open file, pool: %d", pool); 186 syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
182 exit(EXIT_FAILURE); 187 exit(EXIT_FAILURE);
183 } 188 }
184 while (!feof(filep)) { 189 for (;;) {
185 readp = &record[records_read]; 190 readp = &record[records_read];
186 records_read += fread(readp, sizeof(struct kvp_record), 191 records_read += fread(readp, sizeof(struct kvp_record),
187 ENTRIES_PER_BLOCK * num_blocks, 192 ENTRIES_PER_BLOCK * num_blocks,
188 filep); 193 filep);
189 194
195 if (ferror(filep)) {
196 syslog(LOG_ERR, "Failed to read file, pool: %d", pool);
197 exit(EXIT_FAILURE);
198 }
199
190 if (!feof(filep)) { 200 if (!feof(filep)) {
191 /* 201 /*
192 * We have more data to read. 202 * We have more data to read.
@@ -249,12 +259,18 @@ static int kvp_file_init(void)
249 fclose(filep); 259 fclose(filep);
250 return 1; 260 return 1;
251 } 261 }
252 while (!feof(filep)) { 262 for (;;) {
253 readp = &record[records_read]; 263 readp = &record[records_read];
254 records_read += fread(readp, sizeof(struct kvp_record), 264 records_read += fread(readp, sizeof(struct kvp_record),
255 ENTRIES_PER_BLOCK, 265 ENTRIES_PER_BLOCK,
256 filep); 266 filep);
257 267
268 if (ferror(filep)) {
269 syslog(LOG_ERR, "Failed to read file, pool: %d",
270 i);
271 exit(EXIT_FAILURE);
272 }
273
258 if (!feof(filep)) { 274 if (!feof(filep)) {
259 /* 275 /*
260 * We have more data to read. 276 * We have more data to read.