summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@dahyabhai.net>2013-08-07 10:26:32 -0400
committerNalin Dahyabhai <nalin@dahyabhai.net>2013-08-12 15:43:32 -0400
commit0c9d67d8154069c76e04e838bb30114080481cd2 (patch)
treeef6184a153de9baf41fb8ca0687035646ea31488
parente61e52d50460bf2a1c6d35e7d1f63d4392fc940b (diff)
downloadslapi-nis-0c9d67d8154069c76e04e838bb30114080481cd2.tar.gz
slapi-nis-0c9d67d8154069c76e04e838bb30114080481cd2.tar.xz
slapi-nis-0c9d67d8154069c76e04e838bb30114080481cd2.zip
Handle locking failures
Handle cases where we fail to acquire locks.
-rw-r--r--src/back-sch.c101
1 files changed, 64 insertions, 37 deletions
diff --git a/src/back-sch.c b/src/back-sch.c
index 0b90ff6..a2ea291 100644
--- a/src/back-sch.c
+++ b/src/back-sch.c
@@ -1291,8 +1291,7 @@ backend_search_cb(Slapi_PBlock *pb)
} else {
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
- "unable to acquire read lock, "
- "ignoring search\n");
+ "unable to acquire read lock\n");
}
wrap_dec_call_level();
#ifdef USE_NSSWITCH
@@ -1313,48 +1312,76 @@ backend_search_cb(Slapi_PBlock *pb)
}
staged = staged->next;
}
+ cbdata.nsswitch_buffer_len = 0;
+ free(cbdata.nsswitch_buffer);
/* Add the entries to the map cache */
wrap_inc_call_level();
- map_wrlock();
- staged = cbdata.staged;
- while (staged != NULL) {
- if (staged->entries != NULL) {
- cbdata.cur_staged = staged;
- /* We actually need to find the original set first */
- map_data_foreach_domain(cbdata.state, backend_search_find_set_data_cb, &cbdata);
- for (i = 0; i < staged->count ; i++) {
- if (staged->entries[i] != NULL) {
- if ((cbdata.cur_staged->set_data != NULL) &&
- !map_data_check_entry(cbdata.state,
- staged->map_group, staged->map_set,
- slapi_sdn_get_ndn(slapi_entry_get_sdn(staged->entries[i])))) {
- backend_set_entry_from(cbdata.pb, backend_entry_source_nsswitch,
- staged->entries[i], staged->set_data);
+ if (map_wrlock() == 0) {
+ staged = cbdata.staged;
+ while (staged != NULL) {
+ if (staged->entries != NULL) {
+ cbdata.cur_staged = staged;
+ /* We actually need to find the original set first */
+ map_data_foreach_domain(cbdata.state, backend_search_find_set_data_cb, &cbdata);
+ for (i = 0; i < staged->count; i++) {
+ if (staged->entries[i] != NULL) {
+ if ((cbdata.cur_staged->set_data != NULL) &&
+ !map_data_check_entry(cbdata.state,
+ staged->map_group, staged->map_set,
+ slapi_sdn_get_ndn(slapi_entry_get_sdn(staged->entries[i])))) {
+ backend_set_entry_from(cbdata.pb, backend_entry_source_nsswitch,
+ staged->entries[i], staged->set_data);
+ }
+ slapi_entry_free(staged->entries[i]);
+ staged->entries[i] = NULL;
}
- slapi_entry_free(staged->entries[i]);
- staged->entries[i] = NULL;
}
+ free(staged->entries);
+ staged->count = 0;
+ staged->entries = NULL;
+ }
+ slapi_ch_free_string(&staged->map_group);
+ slapi_ch_free_string(&staged->map_set);
+ slapi_ch_free_string(&staged->name);
+ slapi_ch_free_string(&staged->container_sdn);
+ next = staged->next;
+ free(staged);
+ staged = next;
+ }
+ cbdata.staged = NULL;
+ map_unlock();
+ } else {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata.state->plugin_desc->spd_id,
+ "unable to acquire write lock\n");
+ while (staged != NULL) {
+ for (i = 0;
+ (i < staged->count) &&
+ (staged->entries != NULL) &&
+ (staged->entries[i] != NULL);
+ i++) {
+ slapi_entry_free(staged->entries[i]);
+ staged->entries[i] = NULL;
}
- free(staged->entries);
- staged->count = 0;
- staged->entries = NULL;
+ slapi_ch_free_string(&staged->map_group);
+ slapi_ch_free_string(&staged->map_set);
+ slapi_ch_free_string(&staged->name);
+ slapi_ch_free_string(&staged->container_sdn);
+ next = staged->next;
+ free(staged);
+ staged = next;
}
- slapi_ch_free_string(&staged->map_group);
- slapi_ch_free_string(&staged->map_set);
- slapi_ch_free_string(&staged->name);
- slapi_ch_free_string(&staged->container_sdn);
- next = staged->next;
- free(staged);
- staged = next;
}
- cbdata.staged = NULL;
- map_unlock();
- cbdata.nsswitch_buffer_len = 0;
- free(cbdata.nsswitch_buffer);
/* Perform search again, this time to collect the data added by the NSSWITCH search */
- map_rdlock();
- map_data_foreach_domain(cbdata.state, backend_search_group_cb, &cbdata);
- map_unlock();
+ if (map_rdlock() == 0) {
+ map_data_foreach_domain(cbdata.state, backend_search_group_cb, &cbdata);
+ map_unlock();
+ } else {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata.state->plugin_desc->spd_id,
+ "unable to acquire read lock, "
+ "ignoring search\n");
+ }
wrap_dec_call_level();
}
#endif
@@ -1691,8 +1718,8 @@ backend_bind_cb(Slapi_PBlock *pb)
slapi_ch_free_string(&group);
slapi_ch_free_string(&username);
} else {
-done_with_lock:
map_unlock();
+done_with_lock:
wrap_dec_call_level();
if (backend_check_scope_pb(pb)) {
slapi_send_ldap_result(pb, LDAP_INVALID_CREDENTIALS,