[openib-general] [PATCH] opensm: osm_console: don't poll invalid file descriptors

Sasha Khapyorsky sashak at voltaire.com
Thu Jan 18 02:41:00 PST 2007


Don't poll invalid file descriptors (-1), when listening socket is
disabled or connection is not accepted yet.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 osm/opensm/osm_console.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/osm/opensm/osm_console.c b/osm/opensm/osm_console.c
index 9610e21..c6566af 100644
--- a/osm/opensm/osm_console.c
+++ b/osm/opensm/osm_console.c
@@ -446,6 +446,8 @@ void osm_console(osm_opensm_t *p_osm)
 	char          *p_line;
 	size_t         len;
 	ssize_t        n;
+	struct pollfd *fds;
+	nfds_t nfds;
 
 	pollfd[0].fd = p_osm->console.socket;
 	pollfd[0].events = POLLIN|POLLOUT;
@@ -455,7 +457,10 @@ void osm_console(osm_opensm_t *p_osm)
 	pollfd[1].events = POLLIN|POLLOUT;
 	pollfd[1].revents = 0;
 
-	if (poll(pollfd, pollfd[1].fd >= 0 ? 2 : 1, 10000) <= 0)
+	fds = p_osm->console.socket < 0 ? &pollfd[1] : pollfd;
+	nfds = p_osm->console.socket < 0 || pollfd[1].fd < 0 ? 1 : 2;
+
+	if (poll(fds, nfds, 10000) <= 0)
 		return;
 
 #ifdef ENABLE_OSM_CONSOLE_SOCKET
-- 
1.5.0.rc0.g2484-dirty





More information about the general mailing list