]> git.sur5r.net Git - openldap/commitdiff
ITS#5442 slapd_rq mutexes must always be used
authorHoward Chu <hyc@openldap.org>
Wed, 2 Apr 2008 03:08:06 +0000 (03:08 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 2 Apr 2008 03:08:06 +0000 (03:08 +0000)
servers/slapd/back-bdb/config.c
servers/slapd/overlays/accesslog.c
servers/slapd/syncrepl.c

index 184ebb64d595b380a4c1125861c9d0a0dcd40aa3..08ac6468a66c834990d172de1cef5a37f005b1b0 100644 (file)
@@ -483,9 +483,11 @@ bdb_cf_gen( ConfigArgs *c )
                        if ( bdb->bi_txn_cp_task ) {
                                struct re_s *re = bdb->bi_txn_cp_task;
                                bdb->bi_txn_cp_task = NULL;
+                               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
                                if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ) )
                                        ldap_pvt_runqueue_stoptask( &slapd_rq, re );
                                ldap_pvt_runqueue_remove( &slapd_rq, re );
+                               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
                        }
                        bdb->bi_txn_cp = 0;
                        break;
@@ -620,9 +622,11 @@ bdb_cf_gen( ConfigArgs *c )
                                                c->log );
                                        return 1;
                                }
+                               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
                                bdb->bi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq,
                                        bdb->bi_txn_cp_min * 60, bdb_checkpoint, bdb,
                                        LDAP_XSTRING(bdb_checkpoint), c->be->be_suffix[0].bv_val );
+                               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
                        }
                }
                } break;
@@ -747,9 +751,11 @@ bdb_cf_gen( ConfigArgs *c )
                                        c->log );
                                return 1;
                        }
+                       ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
                        bdb->bi_index_task = ldap_pvt_runqueue_insert( &slapd_rq, 36000,
                                bdb_online_index, c->be,
                                LDAP_XSTRING(bdb_online_index), c->be->be_suffix[0].bv_val );
+                       ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
                }
                break;
 
index d63b427229a0e491b2a4ce2ffea98eb2ea2e0c98..c77732a729bddb8cbeee112cb7e0b17eee7b6cb6 100644 (file)
@@ -769,9 +769,11 @@ log_cf_gen(ConfigArgs *c)
                        if ( li->li_task ) {
                                struct re_s *re = li->li_task;
                                li->li_task = NULL;
+                               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
                                if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
                                        ldap_pvt_runqueue_stoptask( &slapd_rq, re );
                                ldap_pvt_runqueue_remove( &slapd_rq, re );
+                               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
                        }
                        li->li_age = 0;
                        li->li_cycle = 0;
@@ -843,12 +845,15 @@ log_cf_gen(ConfigArgs *c)
                                        struct re_s *re = li->li_task;
                                        if ( re )
                                                re->interval.tv_sec = li->li_cycle;
-                                       else
+                                       else {
+                                               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
                                                li->li_task = ldap_pvt_runqueue_insert( &slapd_rq,
                                                        li->li_cycle, accesslog_purge, li,
                                                        "accesslog_purge", li->li_db ?
                                                                li->li_db->be_suffix[0].bv_val :
                                                                c->be->be_suffix[0].bv_val );
+                                               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
+                                       }
                                }
                        }
                        break;
@@ -2022,8 +2027,10 @@ accesslog_db_open(
                ber_dupbv( &li->li_db->be_rootndn, li->li_db->be_nsuffix );
        }
 
+       ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
        ldap_pvt_runqueue_insert( &slapd_rq, 3600, accesslog_db_root, on,
                "accesslog_db_root", li->li_db->be_suffix[0].bv_val );
+       ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
 
        return 0;
 }
index e8ddee979ae93582507bc97db7dc683f324cee4b..a3444b5c076a20e0377152bc55242fdf613dc28d 100644 (file)
@@ -3260,6 +3260,7 @@ syncinfo_free( syncinfo_t *sie, int free_all )
                }
        
                /* re-fetch it, in case it was already removed */
+               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
                sie->si_re = ldap_pvt_runqueue_find( &slapd_rq, do_syncrepl, sie );
                if ( sie->si_re ) {
                        if ( ldap_pvt_runqueue_isrunning( &slapd_rq, sie->si_re ) )
@@ -3267,6 +3268,7 @@ syncinfo_free( syncinfo_t *sie, int free_all )
                        ldap_pvt_runqueue_remove( &slapd_rq, sie->si_re );
                }
        
+               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
                ldap_pvt_thread_mutex_destroy( &sie->si_mutex );
        
                bindconf_free( &sie->si_bindconf );
@@ -3917,9 +3919,11 @@ add_syncrepl(
 
                        if ( !isMe ) {
                                init_syncrepl( si );
+                               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
                                si->si_re = ldap_pvt_runqueue_insert( &slapd_rq,
                                        si->si_interval, do_syncrepl, si, "do_syncrepl",
                                        si->si_ridtxt );
+                               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
                                if ( si->si_re )
                                        rc = config_sync_shadow( c ) ? -1 : 0;
                                else
@@ -4148,13 +4152,18 @@ syncrepl_config( ConfigArgs *c )
                        for ( sip = &c->be->be_syncinfo, i=0; *sip; i++ ) {
                                si = *sip;
                                if ( c->valx == -1 || i == c->valx ) {
+                                       int isrunning = 0;
                                        *sip = si->si_next;
                                        /* If the task is currently active, we have to leave
                                         * it running. It will exit on its own. This will only
                                         * happen when running on the cn=config DB.
                                         */
-                                       if ( si->si_re &&
-                                               ldap_pvt_runqueue_isrunning( &slapd_rq, si->si_re ) ) {
+                                       if ( si->si_re ) {
+                                               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
+                                               isrunning = ldap_pvt_runqueue_isrunning( &slapd_rq, si->si_re );
+                                               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
+                                       }
+                                       if ( si->si_re && isrunning ) {
                                                si->si_ctype = 0;
                                        } else {
                                                syncinfo_free( si, 0 );