daemon: handle freopen() failure
Die if stderr couldn't be sent to /dev/null when operating in inetd mode and report the error message from the OS. This fixes a compiler warning about the return value of freopen() being ignored on Ubuntu 8.10. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 26, 2008 at 10:46 UTC
c569b1fee151e467854ca268997f4f3baaf73564
1 file changed
+3
-1
daemon.c
+3
-1
@@ -1118,7 +1118,9 @@ int main(int argc, char **argv)
1118
struct sockaddr *peer = (struct sockaddr *)&ss;
1119
socklen_t slen = sizeof(ss);
1120
1121
- freopen("/dev/null", "w", stderr);
1121
+ if (!freopen("/dev/null", "w", stderr))
1122
+ die("failed to redirect stderr to /dev/null: %s",
1123
+ strerror(errno));
1124
1125
if (getpeername(0, peer, &slen))
1126
peer = NULL;