CLEANUP: remove a few warning about unchecked return values in debug code
There were a few unchecked write() calls in the debug code that cause
gcc 4.x to emit warnings on recent libc. We don't want to check them
as we can't make anything from the result, let's simply surround them
with an empty if statement.
Note that one of the warnings was for chdir("/") which normally cannot
fail since it follows a successful chroot (which means the perms are
necessarily there). Anyway let's move the call uppe to protect it too.
diff --git a/src/appsession.c b/src/appsession.c
index 1d442ca..ec97336 100644
--- a/src/appsession.c
+++ b/src/appsession.c
@@ -103,7 +103,7 @@
*/
len = sprintf(trash, "appsession_refresh: cleaning up expired Session '%s' on Server %s\n",
element->sessid, element->serverid?element->serverid:"(null)");
- write(1, trash, len);
+ if (write(1, trash, len) < 0) /* shut gcc warning */;
}
/* delete the expired element from within the hash table */
LIST_DEL(&element->hash_list);
diff --git a/src/frontend.c b/src/frontend.c
index 12f55ad..e5d847b 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -181,7 +181,7 @@
break;
}
- write(1, trash, len);
+ if (write(1, trash, len) < 0) /* shut gcc warning */;
}
if (s->fe->mode == PR_MODE_HTTP)
diff --git a/src/haproxy.c b/src/haproxy.c
index d0ea713..fdc6acc 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1292,14 +1292,13 @@
/* chroot if needed */
if (global.chroot != NULL) {
- if (chroot(global.chroot) == -1) {
+ if (chroot(global.chroot) == -1 || chdir("/") == -1) {
Alert("[%s.main()] Cannot chroot(%s).\n", argv[0], global.chroot);
if (nb_oldpids)
tell_old_pids(SIGTTIN);
protocol_unbind_all();
exit(1);
}
- chdir("/");
}
if (nb_oldpids)
diff --git a/src/proto_http.c b/src/proto_http.c
index 22623c0..88226d1 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -7347,7 +7347,7 @@
UBOUND(max, sizeof(trash) - len - 1);
len += strlcpy2(trash + len, start, max + 1);
trash[len++] = '\n';
- write(1, trash, len);
+ if (write(1, trash, len) < 0) /* shut gcc warning */;
}
/*
diff --git a/src/session.c b/src/session.c
index e814903..017ac26 100644
--- a/src/session.c
+++ b/src/session.c
@@ -2063,7 +2063,7 @@
s->uniq_id, s->be->id,
(unsigned short)s->si[0].fd,
(unsigned short)s->si[1].fd);
- write(1, trash, len);
+ if (write(1, trash, len) < 0) /* shut gcc warning */;
}
if (s->si[0].state == SI_ST_CLO &&
@@ -2072,7 +2072,7 @@
s->uniq_id, s->be->id,
(unsigned short)s->si[0].fd,
(unsigned short)s->si[1].fd);
- write(1, trash, len);
+ if (write(1, trash, len) < 0) /* shut gcc warning */;
}
}
@@ -2179,7 +2179,7 @@
len = sprintf(trash, "%08x:%s.closed[%04x:%04x]\n",
s->uniq_id, s->be->id,
(unsigned short)s->req->prod->fd, (unsigned short)s->req->cons->fd);
- write(1, trash, len);
+ if (write(1, trash, len) < 0) /* shut gcc warning */;
}
s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);