r1325: Always use GetTimeOfDay() (wrapper). Ensure ldap replication
authorJeremy Allison <jra@samba.org>
Thu, 1 Jul 2004 22:55:38 +0000 (22:55 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:52:06 +0000 (10:52 -0500)
sleep time is not more than 5 seconds. Should fix issue
reported by Chris Garrigues <cwg@deepeddy.com>.
Jeremy.
(This used to be commit fbc06831d3a7e8645409158ee1ae1f9f192913a7)

source3/include/local.h
source3/lib/smbldap.c
source3/printing/notify.c
source3/smbd/utmp.c
source3/torture/torture.c

index ee8d672553591a94d139ba89b7b5958de8493be5..7ac2e256120ac1892c37c5b86ec514c7d8e485d6 100644 (file)
 /* Number of microseconds to wait before a sharing violation. */
 #define SHARING_VIOLATION_USEC_WAIT 950000
 
+#define MAX_LDAP_REPLICATION_SLEEP_TIME 5000 /* In milliseconds. */
+
 #endif
index 6e233fe9904b52cf71e7a7ffa7f1ac84fb67fbce..d058613f004e8a9c5a1f7989d721f27ed5a99dab 100644 (file)
@@ -676,7 +676,7 @@ static int rebindproc_with_state  (LDAP * ld, char **whop, char **credp,
                *methodp = LDAP_AUTH_SIMPLE;
        }
 
-       gettimeofday(&(ldap_state->last_rebind),NULL);
+       GetTimeOfDay(&ldap_state->last_rebind);
                
        return 0;
 }
@@ -704,7 +704,7 @@ static int rebindproc_connect_with_state (LDAP *ldap_struct,
 
        rc = ldap_simple_bind_s(ldap_struct, ldap_state->bind_dn, ldap_state->bind_secret);
        
-       gettimeofday(&(ldap_state->last_rebind),NULL);
+       GetTimeOfDay(&ldap_state->last_rebind);
 
        return rc;
 }
@@ -755,8 +755,7 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * ldap_
        char *ldap_secret;
 
        /* get the password */
-       if (!fetch_ldap_pw(&ldap_dn, &ldap_secret))
-       {
+       if (!fetch_ldap_pw(&ldap_dn, &ldap_secret)) {
                DEBUG(0, ("ldap_connect_system: Failed to retrieve password from secrets.tdb\n"));
                return LDAP_INVALID_CREDENTIALS;
        }
@@ -854,7 +853,7 @@ static int smbldap_open(struct smbldap_state *ldap_state)
 
 
        ldap_state->last_ping = time(NULL);
-       DEBUG(4,("The LDAP server is succesful connected\n"));
+       DEBUG(4,("The LDAP server is succesfully connected\n"));
 
        return LDAP_SUCCESS;
 }
@@ -933,25 +932,25 @@ int smbldap_search(struct smbldap_state *ldap_state,
 
        if (ldap_state->last_rebind.tv_sec > 0) {
                struct timeval  tval;
-               int             tdiff = 0;
+               SMB_BIG_INT     tdiff = 0;
                int             sleep_time = 0;
 
                ZERO_STRUCT(tval);
+               GetTimeOfDay(&tval);
 
-               gettimeofday(&tval,NULL);
-
-               tdiff = 1000000 *(tval.tv_sec - ldap_state->last_rebind.tv_sec) + 
-                       (tval.tv_usec - ldap_state->last_rebind.tv_usec);
+               tdiff = usec_time_diff(&tval, &ldap_state->last_rebind.tv_sec);
+               tdiff /= 1000; /* Convert to milliseconds. */
 
-               sleep_time = ((1000*lp_ldap_replication_sleep())-tdiff)/1000;
+               sleep_time = lp_ldap_replication_sleep()-(int)tdiff;
+               sleep_time = MIN(sleep_time, MAX_LDAP_REPLICATION_SLEEP_TIME);
 
                if (sleep_time > 0) {
                        /* we wait for the LDAP replication */
                        DEBUG(5,("smbldap_search: waiting %d milliseconds for LDAP replication.\n",sleep_time));
                        smb_msleep(sleep_time);
                        DEBUG(5,("smbldap_search: go on!\n"));
-                       ZERO_STRUCT(ldap_state->last_rebind);
                }
+               ZERO_STRUCT(ldap_state->last_rebind);
        }
 
        if (push_utf8_allocate(&utf8_filter, filter) == (size_t)-1) {
index 26ef191f877a4c9d1b5b363493d196573ae61c1b..8d5be136071eba9a4a04a060416a077e4525ab4e 100644 (file)
@@ -278,7 +278,7 @@ in notify_queue\n", msg->type, msg->field, msg->printer));
                return;
        }
        copy_notify2_msg(pnqueue->msg, msg);
-       gettimeofday(&pnqueue->tv, NULL);
+       GetTimeOfDay(&pnqueue->tv);
        pnqueue->buf = NULL;
        pnqueue->buflen = 0;
 
index a521d0113d469501d3fbe11c2efa763e35dbbbb7..b1735dfcc49c1e48e0d7fe3851db0b4bdccbee05 100644 (file)
@@ -514,10 +514,10 @@ static BOOL sys_utmp_fill(struct utmp *u,
  *     But note that we do the more precise ut_tv as the final assignment.
  */
 #if defined(HAVE_UT_UT_TIME)
-       gettimeofday(&timeval, NULL);
+       GetTimeOfDay(&timeval);
        u->ut_time = timeval.tv_sec;
 #elif defined(HAVE_UT_UT_TV)
-       gettimeofday(&timeval, NULL);
+       GetTimeOfDay(&timeval);
        u->ut_tv = timeval;
 #else
 #error "with-utmp must have UT_TIME or UT_TV"
index 161aa2cd73b1fcb9252c8944a0f13c6f62380fce..cd797c5a8f388d3c505e88ccb677ebe70aff6c1b 100644 (file)
@@ -45,12 +45,12 @@ static struct timeval tp1,tp2;
 
 void start_timer(void)
 {
-       gettimeofday(&tp1,NULL);
+       GetTimeOfDay(&tp1
 }
 
 double end_timer(void)
 {
-       gettimeofday(&tp2,NULL);
+       GetTimeOfDay(&tp2);
        return((tp2.tv_sec - tp1.tv_sec) + 
               (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
 }