int cl_host_alias_list_cleanup(cl_raw_list_t** list_p) { cl_host_alias_list_elem_t* elem = NULL; int ret_val = CL_RETVAL_OK; if (list_p == NULL) { /* we expect an address of an pointer */ return CL_RETVAL_PARAMS; } if (*list_p == NULL) { /* we expect an initalized pointer */ return CL_RETVAL_PARAMS; } /* delete all entries in list */ cl_raw_list_lock(*list_p); while ( (elem = cl_host_alias_list_get_first_elem(*list_p)) != NULL) { cl_raw_list_remove_elem(*list_p, elem->raw_elem); sge_free(&(elem->local_resolved_hostname)); sge_free(&(elem->alias_name)); sge_free(&elem); } cl_raw_list_unlock(*list_p); ret_val = cl_raw_list_cleanup(list_p); CL_LOG(CL_LOG_INFO,"host alias cleanup done"); return ret_val; }
int cl_host_alias_list_remove_host(cl_raw_list_t* list_p, cl_host_alias_list_elem_t* element, int lock_list) { cl_host_alias_list_elem_t* elem = NULL; int ret_val = CL_RETVAL_OK; int function_return = CL_RETVAL_UNKNOWN; if ( list_p == NULL || element == NULL) { return CL_RETVAL_PARAMS; } if (lock_list != 0) { /* lock list */ if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) { return ret_val; } } elem = cl_host_alias_list_get_first_elem(list_p); while ( elem != NULL) { if (elem == element) { /* found matching element */ cl_raw_list_remove_elem(list_p, elem->raw_elem); function_return = CL_RETVAL_OK; sge_free(&(elem->local_resolved_hostname)); sge_free(&(elem->alias_name)); sge_free(&elem); elem = NULL; break; } elem = cl_host_alias_list_get_next_elem(elem); } if (lock_list != 0) { /* unlock list */ if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) { return ret_val; } } return function_return; }
int cl_host_alias_list_get_local_resolved_name(cl_raw_list_t* list_p, char* alias_name,char** local_resolved_name ) { cl_host_alias_list_elem_t* elem = NULL; int ret_val; if (list_p == NULL || alias_name == NULL || local_resolved_name == NULL) { return CL_RETVAL_PARAMS; } if (*local_resolved_name != NULL) { CL_LOG(CL_LOG_ERROR,"need empty pointer pointer"); return CL_RETVAL_PARAMS; } if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) { return ret_val; } elem = cl_host_alias_list_get_first_elem(list_p); while ( elem != NULL) { if ( strcasecmp(alias_name,elem->alias_name) == 0) { *local_resolved_name = strdup(elem->local_resolved_hostname); if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) { sge_free(local_resolved_name); return ret_val; } if (*local_resolved_name == NULL) { return CL_RETVAL_MALLOC; } return CL_RETVAL_OK; } elem = cl_host_alias_list_get_next_elem(elem); } if ( (ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) { return ret_val; } return CL_RETVAL_UNKNOWN; }
int cl_host_list_copy(cl_raw_list_t** destination, cl_raw_list_t* source, cl_bool_t create_hash) { int ret_val = CL_RETVAL_OK; cl_host_list_data_t* ldata_source = NULL; cl_host_list_data_t* ldata_dest = NULL; cl_host_alias_list_elem_t* alias_elem = NULL; cl_host_list_elem_t* host_elem = NULL; if (source == NULL) { return CL_RETVAL_PARAMS; } ret_val = cl_raw_list_lock(source); if (ret_val != CL_RETVAL_OK) { return ret_val; } /* create a new host list */ ldata_source = (cl_host_list_data_t*) source->list_data; if (ldata_source != NULL) { ret_val = cl_host_list_setup(destination, source->list_name, ldata_source->resolve_method, ldata_source->host_alias_file, ldata_source->local_domain_name, ldata_source->entry_life_time, ldata_source->entry_update_time, ldata_source->entry_reresolve_time, create_hash); } else { CL_LOG(CL_LOG_ERROR,"not list data specified"); ret_val = CL_RETVAL_UNKNOWN; } if (ret_val != CL_RETVAL_OK) { cl_raw_list_unlock(source); cl_host_list_cleanup(destination); return ret_val; } /* list created, now get private data structures */ ldata_dest = (cl_host_list_data_t*) (*destination)->list_data; ldata_dest->alias_file_changed = ldata_source->alias_file_changed; ldata_dest->last_refresh_time = ldata_source->last_refresh_time; /* now copy alias list */ cl_raw_list_lock(ldata_source->host_alias_list); alias_elem = cl_host_alias_list_get_first_elem(ldata_source->host_alias_list); while(alias_elem) { ret_val = cl_host_alias_list_append_host(ldata_dest->host_alias_list, alias_elem->local_resolved_hostname, alias_elem->alias_name, 0); if (ret_val != CL_RETVAL_OK) { cl_raw_list_unlock(ldata_source->host_alias_list); cl_raw_list_unlock(source); cl_host_list_cleanup(destination); return ret_val; } alias_elem = cl_host_alias_list_get_next_elem(alias_elem); } cl_raw_list_unlock(ldata_source->host_alias_list); /* ok, now copy the entries */ host_elem = cl_host_list_get_first_elem(source); while(host_elem) { cl_com_host_spec_t* new_host_spec = NULL; new_host_spec = ( cl_com_host_spec_t*) malloc( sizeof(cl_com_host_spec_t) ); if (new_host_spec == NULL) { cl_raw_list_unlock(source); cl_host_list_cleanup(destination); return CL_RETVAL_MALLOC; } /* copy host_spec_ type */ new_host_spec->resolve_error = host_elem->host_spec->resolve_error; new_host_spec->last_resolve_time = host_elem->host_spec->last_resolve_time; new_host_spec->creation_time = host_elem->host_spec->creation_time; if ( host_elem->host_spec->resolved_name ) { new_host_spec->resolved_name = strdup(host_elem->host_spec->resolved_name); if ( new_host_spec->resolved_name == NULL) { cl_com_free_hostspec(&new_host_spec); cl_raw_list_unlock(source); cl_host_list_cleanup(destination); return CL_RETVAL_MALLOC; } } else { new_host_spec->resolved_name = NULL; } if ( host_elem->host_spec->unresolved_name ) { new_host_spec->unresolved_name = strdup(host_elem->host_spec->unresolved_name); if ( new_host_spec->unresolved_name == NULL) { cl_com_free_hostspec(&new_host_spec); cl_raw_list_unlock(source); cl_host_list_cleanup(destination); return CL_RETVAL_MALLOC; } } else { new_host_spec->unresolved_name = NULL; } if ( host_elem->host_spec->in_addr) { new_host_spec->in_addr = cl_com_copy_in_addr(host_elem->host_spec->in_addr); if ( new_host_spec->in_addr == NULL) { cl_com_free_hostspec(&new_host_spec); cl_raw_list_unlock(source); cl_host_list_cleanup(destination); return CL_RETVAL_MALLOC; } } else { new_host_spec->in_addr = NULL; } if ( host_elem->host_spec->hostent) { new_host_spec->hostent = cl_com_copy_hostent(host_elem->host_spec->hostent); if ( new_host_spec->hostent == NULL) { cl_com_free_hostspec(&new_host_spec); cl_raw_list_unlock(source); cl_host_list_cleanup(destination); return CL_RETVAL_MALLOC; } } else { new_host_spec->hostent = NULL; } cl_host_list_append_host((*destination), new_host_spec, 0); host_elem = cl_host_list_get_next_elem(host_elem); } ret_val = cl_raw_list_unlock( source ); return ret_val; }