From: Willy Tarreau Date: Sun, 29 Apr 2012 12:11:38 +0000 (+0200) Subject: CLEANUP: remove a few warning about unchecked return values in debug code X-Git-Tag: v1.5-dev9~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21337825c0346e78c80ff42dcdd319611d49f959;p=thirdparty%2Fhaproxy.git 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 1d442ca2f2..ec97336e3f 100644 --- a/src/appsession.c +++ b/src/appsession.c @@ -103,7 +103,7 @@ static struct task *appsession_refresh(struct task *t) */ 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 12f55ad2b6..e5d847bc9c 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -181,7 +181,7 @@ int frontend_accept(struct session *s) 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 d0ea713184..fdc6acc137 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1292,14 +1292,13 @@ int main(int argc, char **argv) /* 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 22623c058a..88226d19a9 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -7347,7 +7347,7 @@ void debug_hdr(const char *dir, struct session *t, const char *start, const char 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 e814903aab..017ac2672c 100644 --- a/src/session.c +++ b/src/session.c @@ -2063,7 +2063,7 @@ struct task *process_session(struct task *t) 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 @@ struct task *process_session(struct task *t) 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 @@ struct task *process_session(struct task *t) 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);