From dadec9a00ee5546d6bdbcaf8b15877b064e0b243 Mon Sep 17 00:00:00 2001 From: Walter Doekes Date: Tue, 4 Jun 2019 21:32:37 +0200 Subject: [PATCH] Fix incorrect "Failed to shutdown socket 0" warning at exit Broken in 5c15e77ce, but did not show itself in all circumstances. Closes #404 reported by @nicknaychov. --- src/screen.cpp | 2 +- src/socket.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/screen.cpp b/src/screen.cpp index 24d76783..8dd2c15b 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -69,7 +69,7 @@ void screen_show_errors() { return; } - fprintf(stderr, "%sx\n", screen_last_error); + fprintf(stderr, "%s\n", screen_last_error); if (screen_errors > 1) { if (screen_logfile[0] != '\0') { fprintf(stderr, diff --git a/src/socket.cpp b/src/socket.cpp index a45fbaa6..2a0ffab2 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -954,6 +954,8 @@ void SIPpSocket::invalidate() WARNING_NO("Failed to delete FD from epoll"); } #endif + } + if (ss_fd != -1 && ss_fd != stdin_fileno) { if (ss_transport != T_UDP) { if (shutdown(ss_fd, SHUT_RDWR) < 0) { WARNING_NO("Failed to shutdown socket %d", ss_fd); @@ -969,18 +971,16 @@ void SIPpSocket::invalidate() } #endif - if (ss_fd == stdin_fileno) { - /* don't close stdin, breaks interactive terminals */ - } else if (::close(ss_fd) < 0) { + if (::close(ss_fd) < 0) { WARNING_NO("Failed to close socket %d", ss_fd); } - ss_fd = -1; } if ((pollidx = ss_pollidx) >= pollnfds) { ERROR("Pollset error: index %d is greater than number of fds %d!", pollidx, pollnfds); } + ss_fd = -1; ss_invalid = true; ss_pollidx = -1;