globus_result_t globus_xio_string_cntl_string_list( void * attr, const char * key, const char * val, int cmd, globus_xio_driver_attr_cntl_t cntl_func) { int i = 0; globus_list_t * val_list; globus_list_t * list; char ** argv; int argc; globus_result_t result; int del; /* delimitor is the first character */ if(val == NULL) { return GLOBUS_SUCCESS; } del = (int)*val; val++; val_list = globus_list_from_string(val, del, NULL); list = val_list; argc = globus_list_size(list); argv = (char **) calloc(argc+1, sizeof(char *)); i = argc - 1; while(!globus_list_empty(list)) { argv[i] = (char *)globus_list_first(list); list = globus_list_rest(list); i--; } result = globus_xio_string_cntl_bouncer(cntl_func, attr, cmd, argv); globus_list_destroy_all(val_list, globus_libc_free); globus_free(argv); return result; }
int globus_gram_job_manager_staging_write_state( globus_gram_jobmanager_request_t * request, FILE * fp) { globus_list_t * tmp_list; globus_gram_job_manager_staging_info_t * info; char * tmp_str; int rc; rc = fprintf(fp, "%d\n", globus_list_size(request->stage_in_todo)); if (rc < 0) { return GLOBUS_FAILURE; } tmp_list = request->stage_in_todo; while(!globus_list_empty(tmp_list)) { info = globus_list_first(tmp_list); tmp_list = globus_list_rest(tmp_list); tmp_str = globus_rsl_value_unparse(info->from); rc = fprintf(fp, "%s\n", tmp_str); free(tmp_str); if (rc < 0) { return GLOBUS_FAILURE; } tmp_str = globus_rsl_value_unparse(info->to); rc = fprintf(fp, "%s\n", tmp_str); free(tmp_str); if (rc < 0) { return GLOBUS_FAILURE; } } rc = fprintf(fp, "%d\n", globus_list_size(request->stage_in_shared_todo)); if (rc < 0) { return GLOBUS_FAILURE; } tmp_list = request->stage_in_shared_todo; while(!globus_list_empty(tmp_list)) { info = globus_list_first(tmp_list); tmp_list = globus_list_rest(tmp_list); tmp_str = globus_rsl_value_unparse(info->from); rc = fprintf(fp, "%s\n", tmp_str); free(tmp_str); if (rc < 0) { return GLOBUS_FAILURE; } tmp_str = globus_rsl_value_unparse(info->to); rc = fprintf(fp, "%s\n", tmp_str); free(tmp_str); if (rc < 0) { return GLOBUS_FAILURE; } } rc = fprintf(fp, "%d\n", globus_list_size(request->stage_out_todo)); if (rc < 0) { return GLOBUS_FAILURE; } tmp_list = request->stage_out_todo; while(!globus_list_empty(tmp_list)) { info = globus_list_first(tmp_list); tmp_list = globus_list_rest(tmp_list); tmp_str = globus_rsl_value_unparse(info->from); rc = fprintf(fp, "%s\n", tmp_str); free(tmp_str); if (rc < 0) { return GLOBUS_FAILURE; } tmp_str = globus_rsl_value_unparse(info->to); rc = fprintf(fp, "%s\n", tmp_str); free(tmp_str); if (rc < 0) { return GLOBUS_FAILURE; } } rc = fprintf(fp, "%d\n", globus_list_size(request->stage_stream_todo)); tmp_list = request->stage_stream_todo; while(!globus_list_empty(tmp_list)) { info = globus_list_first(tmp_list); tmp_list = globus_list_rest(tmp_list); tmp_str = globus_rsl_value_unparse(info->from); rc = fprintf(fp, "%s\n", tmp_str); free(tmp_str); if (rc < 0) { return GLOBUS_FAILURE; } tmp_str = globus_rsl_value_unparse(info->to); rc = fprintf(fp, "%s\n", tmp_str); free(tmp_str); if (rc < 0) { return GLOBUS_FAILURE; } } return GLOBUS_SUCCESS; }
int globus_gram_job_manager_staging_create_list( globus_gram_jobmanager_request_t * request) { int i; int rc; globus_rsl_value_t * from; globus_rsl_value_t * to; globus_list_t * list; globus_list_t * pairs; char * can_stage_list[] = { GLOBUS_GRAM_PROTOCOL_FILE_STAGE_IN_PARAM, GLOBUS_GRAM_PROTOCOL_FILE_STAGE_IN_SHARED_PARAM, GLOBUS_GRAM_PROTOCOL_FILE_STAGE_OUT_PARAM, NULL }; int errors_list[] = { GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_STAGE_IN, GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_STAGE_IN_SHARED, GLOBUS_GRAM_PROTOCOL_ERROR_RSL_FILE_STAGE_OUT, 0 }; if(request->jm_restart) { return GLOBUS_SUCCESS; } for(i = 0; can_stage_list[i] != NULL; i++) { list = globus_rsl_param_get_values(request->rsl, can_stage_list[i]); if(!list) { continue; } while(!globus_list_empty(list)) { pairs = globus_rsl_value_sequence_get_value_list( globus_list_first(list)); list = globus_list_rest(list); if(globus_list_size(pairs) != 2) { rc = errors_list[i]; goto failed_adding_exit; } from = globus_list_first(pairs); to = globus_list_first(globus_list_rest(pairs)); rc = globus_l_gram_job_manager_staging_add_pair( request, from, to, can_stage_list[i]); if(rc != GLOBUS_SUCCESS) { goto failed_adding_exit; } } } rc = globus_gram_job_manager_streaming_list_replace(request); failed_adding_exit: if (rc != GLOBUS_SUCCESS) { globus_gram_job_manager_staging_free_all(request); } return rc; }
static int globus_l_staging_replace_stream( globus_gram_jobmanager_request_t * request, char * parameter, char * cached_destination) { globus_list_t * list; globus_rsl_value_t *to; globus_rsl_value_t from_cached; globus_bool_t single; int rc = GLOBUS_SUCCESS; list = globus_rsl_param_get_values( request->rsl, parameter); if (list == NULL) { /* Attempting to replace something that was never in the job * RSL---too bad */ return GLOBUS_SUCCESS; } from_cached.type = GLOBUS_RSL_VALUE_LITERAL; from_cached.value.literal.string = cached_destination; /* The stdout and stderr attributes can occur in two forms: * - stdout = destination [tag] * - stdout = (destination [tag])+ * That is, either as a sequence of 1 or 2 values, or as a sequence of * sequences. * * In either form, if there is only one destination, and it's a local file * or x-gass-cache URL, we can safely write directly to that file and don't * need it to be staged after the job completes. Otherwise, we'll have to * write to the stdout (stderr) file in the job directory and copy it * during the STAGE_OUT state. */ if (! globus_rsl_value_is_sequence(globus_list_first(list))) { rc = globus_l_staging_replace_one_stream( request, parameter, cached_destination, list, GLOBUS_TRUE); } else { single = (globus_list_size(list) == 1); while (!globus_list_empty(list)) { globus_list_t *sequence_list; to = globus_list_first(list); list = globus_list_rest(list); if (!globus_rsl_value_is_sequence(to)) { /* Bare value instead of a sequence */ rc = GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDOUT; goto bad_value; } sequence_list = globus_rsl_value_sequence_get_value_list(to); rc = globus_l_staging_replace_one_stream( request, parameter, cached_destination, sequence_list, single); if (rc != GLOBUS_SUCCESS) { goto bad_value; } } } if (rc != GLOBUS_SUCCESS) { bad_value: /* Normalize error types to match the RSL attribute that we are * processing */ if (strcmp(parameter, GLOBUS_GRAM_PROTOCOL_STDERR_PARAM) == 0) { switch (rc) { case GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDOUT: rc = GLOBUS_GRAM_PROTOCOL_ERROR_RSL_STDERR; break; case GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDOUT: rc = GLOBUS_GRAM_PROTOCOL_ERROR_OPENING_STDERR; break; default: break; } } } return rc; }
static void globus_l_gram_process_pending_restarts( void * arg) { globus_gram_job_manager_t * manager = arg; void * key; char gramid[64]; int i; int rc; int restarted=0; globus_gram_jobmanager_request_t * request; GlobusGramJobManagerLock(manager); globus_gram_job_manager_log( manager, GLOBUS_GRAM_JOB_MANAGER_LOG_DEBUG, "event=gram.process_pending_restarts.start " "level=DEBUG " "pending_restarts=%d " "\n", globus_list_size(manager->pending_restarts)); GlobusGramJobManagerUnlock(manager); for (i = 0; i < 20; i++) { GlobusGramJobManagerLock(manager); if (manager->pending_restarts == NULL) { GlobusGramJobManagerUnlock(manager); break; } key = globus_list_first(manager->pending_restarts); globus_assert(key != NULL); strncpy(gramid, key, sizeof(gramid)); GlobusGramJobManagerUnlock(manager); /* * This call below will remove the job from the list when it * reloads it and start the state machine. */ rc = globus_gram_job_manager_add_reference( manager, gramid, "restart job", &request); /* If this fails, then removing the reference will allow it * to potentially hit negative counts */ if (rc == GLOBUS_SUCCESS) { restarted++; /* XXX: What if this fails? */ rc = globus_gram_job_manager_remove_reference( manager, gramid, "restart job"); } } GlobusGramJobManagerLock(manager); globus_gram_job_manager_log( manager, GLOBUS_GRAM_JOB_MANAGER_LOG_DEBUG, "event=gram.process_pending_restarts.end " "level=DEBUG " "processed=%d " "pending_restarts=%d " "\n", restarted, globus_list_size(manager->pending_restarts)); if (manager->pending_restarts == NULL) { globus_callback_unregister( manager->pending_restart_handle, NULL, NULL, NULL); manager->pending_restart_handle = GLOBUS_NULL_HANDLE; GlobusGramJobManagerUnlock(manager); return; } GlobusGramJobManagerUnlock(manager); }
/** @brief Globus List Test Cases*/ int list_test(void) { globus_list_t *list = GLOBUS_NULL; int rc; void *ptr; int x1 = 1; int x2 = 2; int x3 = 3; int x4 = 4; int search_item; globus_list_t *sub_list; int size; printf("1..25\n"); globus_module_activate(GLOBUS_COMMON_MODULE); /** * @test * Call globus_list_size() with an empty list */ size = globus_list_size(list); ok(size == 0, "size_of_empty_list"); /** * @test * Insert a datum into a globus_list_t with globus_list_insert() */ rc = globus_list_insert(&list, &x1); ok(rc == 0, "insert_item_into_empty_list"); /** * @test * Add a datum to a globus_list_t with globus_list_cons() */ list = globus_list_cons(&x2, list); ok(list != NULL, "globus_list_cons"); /** * @test * Verify that globus_list_size() returns 2 after adding two data * items to a list. */ size = globus_list_size(list); ok(size == 2, "size_of_list_after_insert_and_cons"); /** * @test * Insert x3 into a list with globus_list_insert() */ ok(globus_list_insert(&list, &x3) == 0, "insert_x3"); /** * @test * Insert x4 into a list with globus_list_insert() */ ok(globus_list_insert(&list, &x4) == 0, "insert_x4"); /** * @test * Verify that the size of the list is now 4 with globus_list_size() */ ok(globus_list_size(list) == 4, "check_new_size"); /** * @test * Search for the first item in a list with globus_list_search() */ sub_list = globus_list_search(list, &x1); ok(sub_list != NULL, "search_first"); /** * @test * Use globus_list_first() to return the datum from the returned list node. * Verify that the search result matches the value searched for. */ ptr = globus_list_first(sub_list); ok(*((int *)ptr) == x1, "search_first_value"); /** * @test * Search for the third item in a list with globus_list_search() */ sub_list = globus_list_search(list, &x3); ok(sub_list != NULL, "search_third"); /** * @test * Use globus_list_first() to return the datum from the returned list node. * Verify that the search result matches the value searched for. */ ptr = globus_list_first(sub_list); ok(*((int *)ptr) == x3, "search_third_value"); /** * @test * Search for the fourth item in a list with globus_list_search() */ sub_list = globus_list_search(list, &x4); ok(sub_list != NULL, "search_last"); /** * @test * Use globus_list_first() to return the datum from the returned list node. * Verify that the search result matches the value searched for. */ ptr = globus_list_first(sub_list); ok(*((int *)ptr) == x4, "search_last_value"); /** * @test * Search for the second item in a list with globus_list_search() */ sub_list = globus_list_search(list, &x2); ok(sub_list != NULL, "search_second"); /** * @test * Use globus_list_first() to return the datum from the returned list node. * Verify that the search result matches the value searched for. */ ptr = globus_list_first(sub_list); ok(*((int *)ptr) == x2, "search_second_value"); /** * @test * Search for the fourth item in a list with globus_list_search_pred() */ search_item = 4; sub_list = globus_list_search_pred(list, matches, &search_item); ok(sub_list != NULL, "search_pred_4"); /** * @test * Search for the second item in a list with globus_list_search_pred() */ search_item = 2; sub_list = globus_list_search_pred(list, matches, &search_item); ok(sub_list != NULL, "search_pred_2"); /** * @test * Search for the third item in a list with globus_list_search_pred() */ search_item = 3; sub_list = globus_list_search_pred(list, matches, &search_item); ok(sub_list != NULL, "search_pred_3"); /** * @test * Search for the first item in a list with globus_list_search_pred() */ search_item = 1; sub_list = globus_list_search_pred(list, matches, &search_item); ok(sub_list != NULL, "search_pred_1"); /** * @test * Search for the second item in the list with globus_list_search() */ sub_list = globus_list_search(list, &x2); ok(sub_list != NULL, "search_2"); /** * @test * Remove the second item in the list with globus_list_remove() */ ok(globus_list_remove(&list, sub_list) == &x2, "remove_2"); /** * @test * Remove the first item in the list with globus_list_remove() */ ok(globus_list_remove(&list, list) == &x4, "remove_first"); /** * @test * Remove the first item in the list with globus_list_remove() */ ok(globus_list_remove(&list, list) == &x3, "remove_first_again"); /** * @test * Remove the first item in the list with globus_list_remove() */ ok(globus_list_remove(&list, list) == &x1, "remove_first_again"); /** * @test * Verify that the list is empty with globus_list_empty() */ ok(globus_list_empty(list), "empty_list"); globus_list_free(list); globus_module_deactivate(GLOBUS_COMMON_MODULE); return TEST_EXIT_CODE; }
int main(int argc, char * argv[]) { int rc = 0, c = 0, failed = 0; OM_uint32 major_status, minor_status; int name_equal; globus_list_t *i; compare_name_test_case_t * test_case; globus_module_descriptor_t *modules[] = { GLOBUS_COMMON_MODULE, GLOBUS_GSI_GSSAPI_MODULE, GLOBUS_GSI_CREDENTIAL_MODULE, NULL }, *failed_module = NULL; if (argc != 2) { fprintf(stderr, "%s test-case-file\n", argv[0]); exit(-1); } rc = globus_module_activate_array(modules, &failed_module); if (rc != 0) { exit(-1); } globus_l_gss_read_test_cases(argv[1]); import_names(); printf("1..%d\n", globus_list_size(test_cases)); for (i = test_cases; !globus_list_empty(i); i = globus_list_rest(i)) { test_case = globus_list_first(i); if ((!gss_l_host_ip_support) && (test_case->name_type1 == GSS_L_HOST_IP || test_case->name_type2 == GSS_L_HOST_IP)) { printf("ok %d # skip !gss_l_host_ip_support\n", ++c); fflush(stdout); continue; } if ((!gss_l_x509_support) && (test_case->name_type1 == GSS_L_X509 || test_case->name_type2 == GSS_L_X509)) { printf("ok %d # skip !gss_l_x509_support\n", ++c); fflush(stdout); continue; } rc = 0; major_status = gss_compare_name( &minor_status, test_case->name1, test_case->name2, &name_equal); if (GSS_ERROR(major_status)) { globus_gsi_gssapi_test_print_error( stderr, major_status, minor_status); rc = 1; } else if (name_equal != test_case->expectation) { globus_l_gss_test_print_name_error( stderr, test_case->name1, test_case->name_type1, test_case->name2, test_case->name_type2, test_case->expectation); rc = 2; } major_status = gss_compare_name( &minor_status, test_case->name2, test_case->name1, &name_equal); if (GSS_ERROR(major_status)) { globus_gsi_gssapi_test_print_error( stderr, major_status, minor_status); rc = 3; } else if (name_equal != test_case->expectation) { globus_l_gss_test_print_name_error( stderr, test_case->name2, test_case->name_type2, test_case->name1, test_case->name_type1, test_case->expectation); rc = 4; } c++; if (rc == 0) { printf("ok %s\n", test_case->test_name); } else { failed++; printf("not ok %d %s\n", c, test_case->test_name); } fflush(stdout); } globus_l_gss_free_test_cases(); return failed; }
static globus_result_t globus_l_xio_net_manager_attr_set_string_options( globus_l_xio_net_manager_attr_t *attr, const char *options_string) { globus_result_t result = GLOBUS_SUCCESS; globus_list_t *options = NULL; globus_list_t *rev_options; int num_options; globus_net_manager_attr_t *new_attrs; globus_net_manager_context_t new_context = NULL; char *scope = NULL; char *new_task_id = NULL; size_t attrnum = 0; rev_options = globus_list_from_string(options_string, ';', NULL); /* dislike that this func produces a reversed list */ while (!globus_list_empty(rev_options)) { globus_list_insert( &options, globus_list_remove(&rev_options, rev_options)); } num_options = globus_list_size(options); if (num_options == 0) { goto no_options; } new_attrs = calloc(num_options+1, sizeof(globus_net_manager_attr_t)); if (!new_attrs) { result = GlobusNetManagerErrorMemory("attr_array"); goto new_attrs_calloc_fail; } while (!globus_list_empty(options)) { char *opt, *val; opt = globus_list_remove(&options, options); if (*opt == '\0') { free(opt); continue; } val = strchr(opt, '='); if (!val) { result = GlobusNetManagerErrorParameter("Invalid option string."); free(opt); goto no_equals; } *val++ = '\0'; if (strcmp(opt, "manager") == 0) { result = globus_net_manager_attr_init( &new_attrs[attrnum++], "net_manager", opt, val); if (result) { free(opt); new_attrs[attrnum-1] = globus_net_manager_null_attr; goto new_attr_init_fail; } free(scope); scope = strdup(val); if (!scope) { result = GlobusNetManagerErrorMemory("scope"); free(opt); new_attrs[attrnum++] = globus_net_manager_null_attr; goto strdup_scope_fail; } } else if (strcmp(opt, "task-id") == 0) { free(new_task_id); new_task_id = strdup(val); if (!new_task_id) { result = GlobusNetManagerErrorMemory("task-id"); free(opt); new_attrs[attrnum++] = globus_net_manager_null_attr; goto strdup_task_id_fail; } } else { result = globus_net_manager_attr_init( &new_attrs[attrnum++], scope ? scope : "global", opt, val); if (result) { free(opt); new_attrs[attrnum-1] = globus_net_manager_null_attr; goto new_attr_init_fail; } } free(opt); } new_attrs[attrnum++] = globus_net_manager_null_attr; if (new_attrs) { result = globus_net_manager_context_init( &new_context, new_attrs); if (result) { goto new_context_fail; } globus_net_manager_context_destroy(attr->context); attr->context = new_context; } if (new_task_id) { free(attr->task_id); attr->task_id = new_task_id; new_task_id = NULL; } if (new_attrs) { globus_net_manager_attr_array_delete(attr->attr_array); attr->attr_array = new_attrs; new_attrs = NULL; } new_context_fail: new_attr_init_fail: strdup_task_id_fail: strdup_scope_fail: no_equals: free(new_task_id); free(scope); globus_net_manager_attr_array_delete(new_attrs); new_attrs_calloc_fail: globus_list_destroy_all(options, free); no_options: return result; }