osaf/libs/agents/saf/gla/gla_init.c    |   9 ++----
 osaf/services/saf/glsv/glnd/glnd_api.c |  41 +++++++++++++++++++--------------
 2 files changed, 26 insertions(+), 24 deletions(-)


The select() function cannot handle file descriptors larger than 1023. To avoid
this limitation, we replace all usages of select() with poll().

diff --git a/osaf/libs/agents/saf/gla/gla_init.c 
b/osaf/libs/agents/saf/gla/gla_init.c
--- a/osaf/libs/agents/saf/gla/gla_init.c
+++ b/osaf/libs/agents/saf/gla/gla_init.c
@@ -32,8 +32,9 @@
 
 #include "gla.h"
 #include <pthread.h>
+#include "glnd.h"
 #include "osaf_utility.h"
-#include "glnd.h"
+#include "osaf_poll.h"
 
 /* global cb handle */
 uint32_t gl_gla_hdl = 0;
@@ -96,8 +97,6 @@ uint32_t gla_lib_req(NCS_LIB_REQ_INFO *r
 **********************************************************************/
 void gla_sync_with_glnd(GLA_CB *cb)
 {
-       NCS_SEL_OBJ_SET set;
-       uint32_t timeout = 3000;
        TRACE_ENTER();
 
        m_NCS_LOCK(&cb->glnd_sync_lock, NCS_LOCK_WRITE);
@@ -112,9 +111,7 @@ void gla_sync_with_glnd(GLA_CB *cb)
        m_NCS_UNLOCK(&cb->glnd_sync_lock, NCS_LOCK_WRITE);
 
        /* Await indication from MDS saying GLND is up */
-       m_NCS_SEL_OBJ_ZERO(&set);
-       m_NCS_SEL_OBJ_SET(cb->glnd_sync_sel, &set);
-       m_NCS_SEL_OBJ_SELECT(cb->glnd_sync_sel, &set, 0, 0, &timeout);
+       osaf_poll_one_fd(m_GET_FD_FROM_SEL_OBJ(cb->glnd_sync_sel), 30000);
 
        /* Destroy the sync - object */
        m_NCS_LOCK(&cb->glnd_sync_lock, NCS_LOCK_WRITE);
diff --git a/osaf/services/saf/glsv/glnd/glnd_api.c 
b/osaf/services/saf/glsv/glnd/glnd_api.c
--- a/osaf/services/saf/glsv/glnd/glnd_api.c
+++ b/osaf/services/saf/glsv/glnd/glnd_api.c
@@ -31,6 +31,12 @@
 ******************************************************************************/
 
 #include "glnd.h"
+#include "osaf_poll.h"
+
+enum {
+       FD_AMF,
+       FD_MBX
+};
 
 void glnd_main_process(SYSF_MBX *mbx);
 
@@ -182,13 +188,12 @@ void glnd_main_process(SYSF_MBX *mbx)
        GLND_CB *glnd_cb = NULL;
        TRACE_ENTER();  
        
-       NCS_SEL_OBJ_SET all_sel_obj;
        SaAmfHandleT amf_hdl;
 
        SaSelectionObjectT amf_sel_obj;
        SaAisErrorT amf_error;
 
-       NCS_SEL_OBJ amf_ncs_sel_obj, highest_sel_obj;
+       struct pollfd sel[2];
 
        /* take the handle */
        glnd_cb = (GLND_CB *)m_GLND_TAKE_GLND_CB;
@@ -202,22 +207,27 @@ void glnd_main_process(SYSF_MBX *mbx)
        /*giveup the handle */
        m_GLND_GIVEUP_GLND_CB;
 
-       m_NCS_SEL_OBJ_ZERO(&all_sel_obj);
-       m_NCS_SEL_OBJ_SET(mbx_fd, &all_sel_obj);
-
        amf_error = saAmfSelectionObjectGet(amf_hdl, &amf_sel_obj);
        if (amf_error != SA_AIS_OK) {
                LOG_ER("GLND amf get sel obj error");
                goto end;
        }
-       m_SET_FD_IN_SEL_OBJ((uint32_t)amf_sel_obj, amf_ncs_sel_obj);
-       m_NCS_SEL_OBJ_SET(amf_ncs_sel_obj, &all_sel_obj);
 
-       highest_sel_obj = m_GET_HIGHER_SEL_OBJ(amf_ncs_sel_obj, mbx_fd);
+       sel[FD_AMF].fd = amf_sel_obj;
+       sel[FD_AMF].events = POLLIN;
+       sel[FD_MBX].fd = m_GET_FD_FROM_SEL_OBJ(mbx_fd);
+       sel[FD_MBX].events = POLLIN;
 
-       while (m_NCS_SEL_OBJ_SELECT(highest_sel_obj, &all_sel_obj, 0, 0, 0) != 
-1) {
+       while (osaf_poll(&sel[0], 2, -1) > 0) {
+               if (((sel[FD_AMF].revents | sel[FD_MBX].revents) &
+                       (POLLERR | POLLHUP | POLLNVAL)) != 0) {
+                       LOG_ER("GLND poll() failure: %hd %hd",
+                               sel[FD_AMF].revents, sel[FD_MBX].revents);
+                       TRACE_LEAVE();
+                       return;
+               }
                /* process all the AMF messages */
-               if (m_NCS_SEL_OBJ_ISSET(amf_ncs_sel_obj, &all_sel_obj)) {
+               if (sel[FD_AMF].revents & POLLIN) {
                        /* dispatch all the AMF pending function */
                        amf_error = saAmfDispatch(amf_hdl, SA_DISPATCH_ALL);
                        if (amf_error != SA_AIS_OK) {
@@ -225,7 +235,7 @@ void glnd_main_process(SYSF_MBX *mbx)
                        }
                }
                /* process the GLND Mail box */
-               if (m_NCS_SEL_OBJ_ISSET(mbx_fd, &all_sel_obj)) {
+               if (sel[FD_MBX].revents & POLLIN) {
                        glnd_cb = (GLND_CB *)m_GLND_TAKE_GLND_CB;
                        if (glnd_cb) {
                                /* now got the IPC mail box event */
@@ -233,14 +243,9 @@ void glnd_main_process(SYSF_MBX *mbx)
                                m_GLND_GIVEUP_GLND_CB;  /* giveup the handle */
                        } else
                                break;
+               }
+       }
 
-               }
-
-               /* do the fd set for the select obj */
-               m_NCS_SEL_OBJ_SET(amf_ncs_sel_obj, &all_sel_obj);
-               m_NCS_SEL_OBJ_SET(mbx_fd, &all_sel_obj);
-
-       }
        TRACE("DANGER: Exiting the Select loop of GLND");
 end:
        TRACE_LEAVE();

------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to