Permalink
Browse files

check return value

Coverity Scan defect 719426
  • Loading branch information...
1 parent f34790f commit 2f99e8c13d453232bceb57eeb98e41e84087653a @kr committed Sep 5, 2012
Showing with 24 additions and 7 deletions.
  1. +1 −1 dat.h
  2. +6 −2 integ-test.c
  3. +5 −1 main.c
  4. +12 −3 prot.c
View
2 dat.h
@@ -257,7 +257,7 @@ void enqueue_reserved_jobs(Conn *c);
void enter_drain_mode(int sig);
void h_accept(const int fd, const short which, Server* srv);
void prot_remove_tube(tube t);
-void prot_replay(Server *s, job list);
+int prot_replay(Server *s, job list);
int make_server_socket(char *host_addr, char *port);
View
@@ -96,7 +96,7 @@ mustdiallocal(int port)
static int
mustforksrv()
{
- int r, len, port;
+ int r, len, port, ok;
struct sockaddr_in addr;
srv.sock.fd = make_server_socket("127.0.0.1", "0");
@@ -140,7 +140,11 @@ mustforksrv()
list.prev = list.next = &list;
walinit(&srv.wal, &list);
- prot_replay(&srv, &list);
+ ok = prot_replay(&srv, &list);
+ if (!ok) {
+ twarnx("failed to replay log");
+ exit(11);
+ }
}
srvserve(&srv); /* does not return */
View
6 main.c
@@ -80,7 +80,11 @@ main(int argc, char **argv)
list.prev = list.next = &list;
walinit(&srv.wal, &list);
- prot_replay(&srv, &list);
+ r = prot_replay(&srv, &list);
+ if (!r) {
+ twarnx("failed to replay log");
+ return 1;
+ }
}
srvserve(&srv);
View
15 prot.c
@@ -1908,17 +1908,25 @@ prot_init()
if (!default_tube) twarnx("Out of memory during startup!");
}
-void
+// For each job in list, inserts the job into the appropriate data
+// structures and adds it to the log.
+//
+// Returns 1 on success, 0 on failure.
+int
prot_replay(Server *s, job list)
{
job j, nj;
int64 t, delay;
- int r;
+ int r, z;
for (j = list->next ; j != list ; j = nj) {
nj = j->next;
job_remove(j);
- walresvupdate(&s->wal, j); /* reserve space for a delete */
+ z = walresvupdate(&s->wal, j);
+ if (!z) {
+ twarnx("failed to reserve space");
+ return 0;
+ }
delay = 0;
switch (j->r.state) {
case Buried:
@@ -1935,4 +1943,5 @@ prot_replay(Server *s, job list)
if (r < 1) twarnx("error recovering job %"PRIu64, j->r.id);
}
}
+ return 1;
}

0 comments on commit 2f99e8c

Please sign in to comment.