Replace a static variable and alarm() calls by using sys_select()
authorVolker Lendecke <vl@samba.org>
Thu, 25 Dec 2008 13:37:33 +0000 (14:37 +0100)
committerVolker Lendecke <vl@samba.org>
Wed, 31 Dec 2008 18:33:26 +0000 (19:33 +0100)
Günther, please check!

source3/libads/cldap.c

index 35fb9316f87e1dba678b7307137d123c9b239602..d66e35cacb89a4eca68430a8ee6677b2ce14f7e3 100644 (file)
@@ -106,17 +106,6 @@ static int send_cldap_netlogon(TALLOC_CTX *mem_ctx, int sock, const char *domain
        return 0;
 }
 
-static SIG_ATOMIC_T gotalarm;
-
-/***************************************************************
- Signal function to tell us we timed out.
-****************************************************************/
-
-static void gotalarm_sig(void)
-{
-       gotalarm = 1;
-}
-
 /*
   receive a cldap netlogon reply
 */
@@ -132,11 +121,12 @@ static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx,
        DATA_BLOB os2 = data_blob_null;
        DATA_BLOB os3 = data_blob_null;
        int i1;
-       /* half the time of a regular ldap timeout, not less than 3 seconds. */
-       unsigned int al_secs = MAX(3,lp_ldap_timeout()/2);
        struct netlogon_samlogon_response *r = NULL;
        NTSTATUS status;
 
+       fd_set r_fds;
+       struct timeval timeout;
+
        blob = data_blob(NULL, 8192);
        if (blob.data == NULL) {
                DEBUG(1, ("data_blob failed\n"));
@@ -144,18 +134,29 @@ static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx,
                return -1;
        }
 
-       /* Setup timeout */
-       gotalarm = 0;
-       CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
-       alarm(al_secs);
-       /* End setup timeout. */
-       ret = read(sock, blob.data, blob.length);
+       FD_ZERO(&r_fds);
+       FD_SET(sock, &r_fds);
+
+       /*
+        * half the time of a regular ldap timeout, not less than 3 seconds.
+        */
+       timeout.tv_sec = MAX(3,lp_ldap_timeout()/2);
+       timeout.tv_usec = 0;
+
+       ret = sys_select(sock+1, &r_fds, NULL, NULL, &timeout);
+       if (ret == -1) {
+               DEBUG(10, ("select failed: %s\n", strerror(errno)));
+               data_blob_free(&blob);
+               return -1;
+       }
 
-       /* Teardown timeout. */
-       CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
-       alarm(0);
+       if (ret == 0) {
+               DEBUG(1,("no reply received to cldap netlogon\n"));
+               data_blob_free(&blob);
+               return -1;
+       }
 
+       ret = read(sock, blob.data, blob.length);
        if (ret <= 0) {
                DEBUG(1,("no reply received to cldap netlogon\n"));
                data_blob_free(&blob);