Commit 33e88ff8 authored by Max Kellermann's avatar Max Kellermann Committed by Eric Wong

zero is a valid file descriptor

Although it may not happen in mpd code, it is perfectly possible for a newly allocated file descriptor to be zero. For theoretical correctness, allow 0. git-svn-id: https://svn.musicpd.org/mpd/trunk@7194 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent c6ceceae
...@@ -604,7 +604,7 @@ static void closeAllInterfaces(void) ...@@ -604,7 +604,7 @@ static void closeAllInterfaces(void)
int i; int i;
for (i = 0; i < interface_max_connections; i++) { for (i = 0; i < interface_max_connections; i++) {
if (interfaces[i].fd > 0) if (interfaces[i].fd >= 0)
closeInterface(&(interfaces[i])); closeInterface(&(interfaces[i]));
if (interfaces[i].send_buf) if (interfaces[i].send_buf)
free(interfaces[i].send_buf); free(interfaces[i].send_buf);
...@@ -626,7 +626,7 @@ void closeOldInterfaces(void) ...@@ -626,7 +626,7 @@ void closeOldInterfaces(void)
int i; int i;
for (i = 0; i < interface_max_connections; i++) { for (i = 0; i < interface_max_connections; i++) {
if (interfaces[i].fd > 0) { if (interfaces[i].fd >= 0) {
if (interfaces[i].expired) { if (interfaces[i].expired) {
DEBUG("interface %i: expired\n", i); DEBUG("interface %i: expired\n", i);
closeInterface(&(interfaces[i])); closeInterface(&(interfaces[i]));
...@@ -690,7 +690,7 @@ int interfacePrintWithFD(int fd, char *buffer, int buflen) ...@@ -690,7 +690,7 @@ int interfacePrintWithFD(int fd, char *buffer, int buflen)
int copylen; int copylen;
Interface *interface; Interface *interface;
assert(fd > 0); assert(fd >= 0);
if (i >= interface_max_connections || if (i >= interface_max_connections ||
interfaces[i].fd < 0 || interfaces[i].fd != fd) { interfaces[i].fd < 0 || interfaces[i].fd != fd) {
......
...@@ -36,8 +36,8 @@ static const char *err_filename; ...@@ -36,8 +36,8 @@ static const char *err_filename;
static void redirect_logs(void) static void redirect_logs(void)
{ {
assert(out_fd > 0); assert(out_fd >= 0);
assert(err_fd > 0); assert(err_fd >= 0);
if (dup2(out_fd, STDOUT_FILENO) < 0) if (dup2(out_fd, STDOUT_FILENO) < 0)
FATAL("problems dup2 stdout : %s\n", strerror(errno)); FATAL("problems dup2 stdout : %s\n", strerror(errno));
if (dup2(err_fd, STDERR_FILENO) < 0) if (dup2(err_fd, STDERR_FILENO) < 0)
...@@ -241,8 +241,8 @@ void close_log_files(void) ...@@ -241,8 +241,8 @@ void close_log_files(void)
{ {
if (stdout_mode) if (stdout_mode)
return; return;
assert(out_fd > 0); assert(out_fd >= 0);
assert(err_fd > 0); assert(err_fd >= 0);
xclose(out_fd); xclose(out_fd);
xclose(err_fd); xclose(err_fd);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment