From 87f9f245f1e41b6db111cfa5248f19fa6a9af48f Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Thu, 19 Jan 2012 09:55:28 -0500 Subject: [PATCH] Ticket #49 - better handling for server shutdown while long running tasks are active https://fedorahosted.org/389/ticket/49 Bug Description: tasks like memberOf fix-up do not check for shutdown events. In my test this causes a shutdown to hang until the task is complete. I did not get crash in my tests. Fix Description: The only plugins that appear to have lengthy tasks are: usn, linkedattrtrs, and memberOf. Added checks for g_get_shutdown. Also cleaned up some code & fixed some indentation issues. --- ldap/servers/plugins/linkedattrs/fixup_task.c | 79 +++++++++++++------------ ldap/servers/plugins/memberof/memberof.c | 15 ++++- ldap/servers/plugins/usn/usn_cleanup.c | 10 +++- 3 files changed, 63 insertions(+), 41 deletions(-) diff --git a/ldap/servers/plugins/linkedattrs/fixup_task.c b/ldap/servers/plugins/linkedattrs/fixup_task.c index ef2c7e0..ee64d71 100644 --- a/ldap/servers/plugins/linkedattrs/fixup_task.c +++ b/ldap/servers/plugins/linkedattrs/fixup_task.c @@ -130,8 +130,8 @@ linked_attrs_fixup_task_thread(void *arg) int rc = 0; Slapi_Task *task = (Slapi_Task *)arg; task_data *td = NULL; - PRCList *main_config = NULL; - int found_config = 0; + PRCList *main_config = NULL; + int found_config = 0; /* Fetch our task data from the task */ td = (task_data *)slapi_task_get_data(task); @@ -144,51 +144,50 @@ linked_attrs_fixup_task_thread(void *arg) "Syntax validate task starting (link dn: \"%s\") ...\n", td->linkdn ? td->linkdn : ""); - linked_attrs_read_lock(); - main_config = linked_attrs_get_config(); - if (!PR_CLIST_IS_EMPTY(main_config)) { - struct configEntry *config_entry = NULL; - PRCList *list = PR_LIST_HEAD(main_config); - - while (list != main_config) { - config_entry = (struct configEntry *) list; - - /* See if this is the requested config and fix up if so. */ - if (td->linkdn) { - if (strcasecmp(td->linkdn, config_entry->dn) == 0) { - found_config = 1; - slapi_task_log_notice(task, "Fixing up linked attribute pair (%s)\n", - config_entry->dn); - slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM, - "Fixing up linked attribute pair (%s)\n", - config_entry->dn); - - linked_attrs_fixup_links(config_entry, NULL); - break; - } - } else { - /* No config DN was supplied, so fix up all configured links. */ + linked_attrs_read_lock(); + main_config = linked_attrs_get_config(); + if (!PR_CLIST_IS_EMPTY(main_config)) { + struct configEntry *config_entry = NULL; + PRCList *list = PR_LIST_HEAD(main_config); + + while (list != main_config) { + config_entry = (struct configEntry *) list; + + /* See if this is the requested config and fix up if so. */ + if (td->linkdn) { + if (strcasecmp(td->linkdn, config_entry->dn) == 0) { + found_config = 1; slapi_task_log_notice(task, "Fixing up linked attribute pair (%s)\n", - config_entry->dn); + config_entry->dn); slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM, - "Fixing up linked attribute pair (%s)\n", config_entry->dn); + "Fixing up linked attribute pair (%s)\n", config_entry->dn); linked_attrs_fixup_links(config_entry, NULL); + break; } - - list = PR_NEXT_LINK(list); + } else { + /* No config DN was supplied, so fix up all configured links. */ + slapi_task_log_notice(task, "Fixing up linked attribute pair (%s)\n", + config_entry->dn); + slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM, + "Fixing up linked attribute pair (%s)\n", config_entry->dn); + + linked_attrs_fixup_links(config_entry, NULL); } - } - /* Log a message if we didn't find the requested attribute pair. */ - if (td->linkdn && !found_config) { - slapi_task_log_notice(task, "Requested link config DN not found (%s)\n", - td->linkdn); - slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM, - "Requested link config DN not found (%s)\n", td->linkdn); + list = PR_NEXT_LINK(list); } + } - linked_attrs_unlock(); + /* Log a message if we didn't find the requested attribute pair. */ + if (td->linkdn && !found_config) { + slapi_task_log_notice(task, "Requested link config DN not found (%s)\n", + td->linkdn); + slapi_log_error(SLAPI_LOG_FATAL, LINK_PLUGIN_SUBSYSTEM, + "Requested link config DN not found (%s)\n", td->linkdn); + } + + linked_attrs_unlock(); /* Log finished message. */ slapi_task_log_notice(task, "Linked attributes fixup task complete.\n"); @@ -364,6 +363,10 @@ linked_attrs_add_backlinks_callback(Slapi_Entry *e, void *callback_data) int perform_update = 0; Slapi_DN *targetsdn = slapi_sdn_new_dn_byref(targetdn); + if (g_get_shutdown()) { + return -1; + } + if (config->scope) { /* Check if the target is within the scope. */ perform_update = slapi_dn_issuffix(targetdn, config->scope); diff --git a/ldap/servers/plugins/memberof/memberof.c b/ldap/servers/plugins/memberof/memberof.c index 9956dfe..db6cd3e 100644 --- a/ldap/servers/plugins/memberof/memberof.c +++ b/ldap/servers/plugins/memberof/memberof.c @@ -667,7 +667,9 @@ int memberof_postop_modrdn(Slapi_PBlock *pb) { if(0 == slapi_entry_attr_find(post_e, configCopy.groupattrs[i], &attr)) { - memberof_moddn_attr_list(pb, &configCopy, pre_dn, post_dn, attr, txn); + if(memberof_moddn_attr_list(pb, &configCopy, pre_dn, post_dn, attr, txn) != 0){ + break; + } } } } @@ -1266,7 +1268,10 @@ int memberof_modop_one_replace_r(Slapi_PBlock *pb, MemberOfConfig *config, slapi_entry_attr_find( e, config->groupattrs[i], &members ); if(members) { - memberof_mod_attr_list_r(pb, config, mod_op, group_dn, op_this, members, ll, txn); + if(memberof_mod_attr_list_r(pb, config, mod_op, group_dn, op_this, members, ll, txn) != 0){ + rc = -1; + goto bail; + } } } @@ -1668,6 +1673,11 @@ int memberof_get_groups_callback(Slapi_Entry *e, void *callback_data) Slapi_ValueSet *groupvals = *((memberof_get_groups_data*)callback_data)->groupvals; int rc = 0; + if(g_get_shutdown()){ + rc = -1; + goto bail; + } + if (!groupvals) { slapi_log_error( SLAPI_LOG_PLUGIN, MEMBEROF_PLUGIN_SUBSYSTEM, @@ -2441,6 +2451,7 @@ int memberof_fix_memberof_callback(Slapi_Entry *e, void *callback_data) memberof_del_dn_type_callback(e, &del_data); } +bail: slapi_valueset_free(groups); return rc; diff --git a/ldap/servers/plugins/usn/usn_cleanup.c b/ldap/servers/plugins/usn/usn_cleanup.c index 3152975..16e6a95 100644 --- a/ldap/servers/plugins/usn/usn_cleanup.c +++ b/ldap/servers/plugins/usn/usn_cleanup.c @@ -46,7 +46,6 @@ struct usn_cleanup_data { char *maxusn_to_delete; }; - static int usn_cleanup_add(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg); @@ -143,6 +142,15 @@ usn_cleanup_thread(void *arg) int delrv = 0; const Slapi_DN *sdn = slapi_entry_get_sdn_const(*ep); + /* check for shutdown */ + if(g_get_shutdown()){ + slapi_task_log_notice(task, "USN tombstone cleanup task aborted due to shutdown."); + slapi_task_log_status(task, "USN tombstone cleanup task aborted due to shutdown."); + slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM, + "USN tombstone cleanup task aborted due to shutdown.\n"); + goto bail; + } + slapi_delete_internal_set_pb(delete_pb, slapi_sdn_get_dn(sdn), NULL, NULL, usn_get_identity(), 0); slapi_delete_internal_pb(delete_pb); -- 1.7.1