Signed-off-by: Nicolas Morey-Chaisemartin 
<[email protected]>
---
When opensm is called after a pipe to execute a command in the local console, 
it uses 100% CPU as osm_console poll returns as if there was something to read 
from stdin where there isn't.
This patch fixes by closing the local console when the end of osm_console 
function has been reached, meaning poll returned a positive value but actually 
nothing to read. osm_console will return an error code which will unset the 
console_init_flag so it won't be reopened.
For socket, the osm_console_close is called as it means the socket isn't in a 
proper state.


 opensm/include/opensm/osm_console.h |    2 +-
 opensm/opensm/main.c                |    6 ++++--
 opensm/opensm/osm_console.c         |   19 +++++++++++++++----
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/opensm/include/opensm/osm_console.h 
b/opensm/include/opensm/osm_console.h
index 3ea8fa5..dcce1e4 100644
--- a/opensm/include/opensm/osm_console.h
+++ b/opensm/include/opensm/osm_console.h
@@ -46,6 +46,6 @@
 
 BEGIN_C_DECLS
 // TODO replace p_osm
-void osm_console(osm_opensm_t * p_osm);
+int osm_console(osm_opensm_t * p_osm);
 END_C_DECLS
 #endif                         /* _OSM_CONSOLE_H_ */
diff --git a/opensm/opensm/main.c b/opensm/opensm/main.c
index 2271634..5a39f84 100644
--- a/opensm/opensm/main.c
+++ b/opensm/opensm/main.c
@@ -494,8 +494,10 @@ int osm_manager_loop(osm_subn_opt_t * p_opt, osm_opensm_t 
* p_osm)
           Sit here forever - dwell or do console i/o & cmds
         */
        while (!osm_exit_flag) {
-               if (console_init_flag)
-                       osm_console(p_osm);
+               if (console_init_flag){
+                       if(osm_console(p_osm))
+                               console_init_flag = 0;
+               }
                else
                        cl_thread_suspend(10000);
 
diff --git a/opensm/opensm/osm_console.c b/opensm/opensm/osm_console.c
index 63c5ea8..b6a8689 100644
--- a/opensm/opensm/osm_console.c
+++ b/opensm/opensm/osm_console.c
@@ -1376,7 +1376,7 @@ static void parse_cmd_line(char *line, osm_opensm_t * 
p_osm)
        }
 }
 
-void osm_console(osm_opensm_t * p_osm)
+int osm_console(osm_opensm_t * p_osm)
 {
        struct pollfd pollfd[2];
        char *p_line;
@@ -1409,7 +1409,7 @@ void osm_console(osm_opensm_t * p_osm)
        }
 
        if (poll(fds, nfds, 1000) <= 0)
-               return;
+               return 0;
 
 #ifdef ENABLE_OSM_CONSOLE_SOCKET
        if (pollfd[0].revents & POLLIN) {
@@ -1422,7 +1422,7 @@ void osm_console(osm_opensm_t * p_osm)
                                "ERR 4B04: Failed to accept console socket: 
%s\n",
                                strerror(errno));
                        p_oct->in_fd = -1;
-                       return;
+                       return 0;
                }
                if (inet_ntop
                    (AF_INET, &sin.sin_addr, p_oct->client_ip,
@@ -1444,7 +1444,7 @@ void osm_console(osm_opensm_t * p_osm)
                                p_oct->client_hn, p_oct->client_ip);
                        close(new_fd);
                }
-               return;
+               return 0;
        }
 #endif
 
@@ -1462,5 +1462,16 @@ void osm_console(osm_opensm_t * p_osm)
                        osm_console_exit(p_oct, p_log);
                if (p_line)
                        free(p_line);
+               return 0;
        }
+       /* If we are here, there has been a problem with poll
+        * so we exit the console not to eat up all the CPU
+        * if it was a local console
+        * If it was a socket, we just close it.
+        */
+       if( p_oct->socket < 0 )
+               return -1;
+
+       osm_console_exit(p_oct, p_log);
+       return 0;
 }
-- 
1.5.6.3

_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to