static void globus_l_gsc_send_perf_marker_cb( void * user_arg) { globus_i_gsc_op_t * op; globus_i_gsc_event_data_t * event; op = (globus_i_gsc_op_t *) user_arg; event = &op->event; globus_mutex_lock(&op->server_handle->mutex); { if(event->perf_running) { event->user_cb( op, GLOBUS_GRIDFTP_SERVER_CONTROL_EVENT_PERF, event->user_arg); } } globus_mutex_unlock(&op->server_handle->mutex); }
void thread_ids_destruct( void * thread_arg) { globus_mutex_lock(&common_mutex); { thread_ids_destruct_cnt++; } globus_mutex_unlock(&common_mutex); # if (DEBUG_LEVEL > 0) { globus_stdio_lock(); { printf("%04ld: thread_ids_destruct() - complete\n", (long) thread_arg); } globus_stdio_unlock(); } # endif }
static void done_cb( void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err) { char * tmpstr; if(err) tmpstr = " an"; else tmpstr = "out"; if(err) { printf("done with%s error: %s\n", tmpstr, globus_object_printable_to_string(err)); error++; } globus_mutex_lock(&lock); done = GLOBUS_TRUE; globus_cond_signal(&cond); globus_mutex_unlock(&lock); }
globus_result_t globus_gfork_broadcast( gfork_child_handle_t in_handle, globus_xio_iovec_t * iov, int iovc, globus_xio_iovec_callback_t cb, void * user_arg) { globus_result_t result; gfork_i_lib_handle_t * handle; handle = (gfork_i_lib_handle_t *) in_handle; globus_mutex_lock(&handle->mutex); { result = globus_l_gfork_send(handle, -1, iov, iovc, cb, user_arg); } globus_mutex_unlock(&handle->mutex); return result; }
static void done_cb( void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err) { char * tmpstr; if(err) { tmpstr = globus_object_printable_to_string(err); printf("%s\n", tmpstr); error = GLOBUS_TRUE; globus_libc_free(tmpstr); } globus_mutex_lock(&lock); done = GLOBUS_TRUE; globus_cond_signal(&cond); globus_mutex_unlock(&lock); }
static void data_cb( globus_xio_handle_t handle, globus_result_t result, globus_byte_t * buffer, globus_size_t len, globus_size_t nbytes, globus_xio_data_descriptor_t data_desc, void * user_arg) { globus_result_t res; char * timeout_type; timeout_type = (char *) user_arg; if(strcmp(timeout_type, "D") == 0) { if(!result_is_cancel(result)) { failed_exit("Read/Write was not canceled."); } } globus_mutex_lock(&globus_l_mutex); { res = globus_xio_register_close( handle, NULL, close_cb, user_arg); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); if(strcmp(timeout_type, "C") == 0) { res = globus_xio_handle_cancel_operations( handle, GLOBUS_XIO_CANCEL_CLOSE); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); } } globus_mutex_unlock(&globus_l_mutex); }
static void globus_l_xio_win32_unregister_poll_cb( void * user_arg) { globus_l_shutdown_info_t * info; GlobusXIOName(globus_l_xio_win32_unregister_poll_cb); GlobusXIOSystemDebugEnter(); info = (globus_l_shutdown_info_t *) user_arg; globus_mutex_lock(&info->mutex); { CloseHandle(globus_l_xio_win32_poll_event); globus_l_xio_win32_poll_event = 0; globus_cond_signal(&info->cond); } globus_mutex_unlock(&info->mutex); GlobusXIOSystemDebugExit(); }
globus_result_t globus_gridftp_server_control_get_buffer_size( globus_gridftp_server_control_op_t op, globus_size_t * out_recv_bs, globus_size_t * out_send_bs) { GlobusGridFTPServerName(globus_gridftp_server_control_get_buffer_size); if(op == NULL) { return GlobusGridFTPServerErrorParameter("op"); } globus_mutex_lock(&op->server_handle->mutex); { *out_recv_bs = op->server_handle->opts.receive_buf; *out_send_bs = op->server_handle->opts.send_buf; } globus_mutex_unlock(&op->server_handle->mutex); return GLOBUS_SUCCESS; }
globus_result_t globus_gridftp_server_control_get_layout( globus_gridftp_server_control_op_t op, globus_gsc_layout_t * layout_type, globus_size_t * block_size) { GlobusGridFTPServerName(globus_gridftp_server_control_get_layout); if(op == NULL) { return GlobusGridFTPServerErrorParameter("op"); } globus_mutex_lock(&op->server_handle->mutex); { *layout_type = op->server_handle->opts.layout; *block_size = op->server_handle->opts.block_size; } globus_mutex_unlock(&op->server_handle->mutex); return GLOBUS_SUCCESS; }
static void globus_l_io_authorization_test_connect_callback( void * arg, globus_io_handle_t * handle, globus_result_t result) { globus_l_io_authorization_test_monitor_t * monitor; monitor = (globus_l_io_authorization_test_monitor_t *) arg; if(result != GLOBUS_SUCCESS) { printf("# %s\n", globus_object_printable_to_string( globus_error_get(result))); exit(1); } globus_mutex_lock(&monitor->mutex); monitor->connected = GLOBUS_TRUE; globus_cond_signal(&monitor->cond); globus_mutex_unlock(&monitor->mutex); }
void * list_peek_head(list_t * List) { void * data = NULL; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); if (List == NULL) goto cleanup; globus_mutex_lock(&List->Lock); { if (List->Head != NULL) data = List->Head->Data; } globus_mutex_unlock(&List->Lock); cleanup: GlobusGFSHpssDebugExit(); return data; }
static void data_cb_write( void * user_arg, globus_ftp_client_handle_t * handle, globus_object_t * err, globus_byte_t * buffer, globus_size_t length, globus_off_t offset, globus_bool_t eof) { int curr_offset; if(err) { fprintf(stderr, "%s", globus_object_printable_to_string(err)); } else { if (!eof) { FILE* fd = (FILE*) user_arg; int rc; globus_mutex_lock(&lock); curr_offset = global_offset; rc = fread(buffer, 1, MAX_BUFFER_SIZE_W, fd); global_offset += rc; globus_mutex_unlock(&lock); if (ferror(fd)) { printf("Read error in function data_cb_write; errno = %d\n", errno); return; } globus_ftp_client_register_write(handle, buffer, rc, curr_offset, feof(fd) != 0, data_cb_write, (void*) fd); } else { globus_libc_free(buffer); } } return; }
static void gridftp_record_eof(gridftp_t * GridFTP, globus_bool_t Eof) { globus_bool_t call_callback = GLOBUS_FALSE; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); if (Eof == GLOBUS_TRUE) { globus_mutex_lock(&GridFTP->Lock); { if (GridFTP->Eof == GLOBUS_FALSE) { /* Record it. */ GridFTP->Eof = GLOBUS_TRUE; /* Call the callback. */ if (GridFTP->EofCallbackCalled == GLOBUS_FALSE) call_callback = GLOBUS_TRUE; /* Indicate that we will call the eof callback. */ GridFTP->EofCallbackCalled = GLOBUS_TRUE; /* On error we should wake people. */ globus_cond_broadcast(&GridFTP->Cond); } } globus_mutex_unlock(&GridFTP->Lock); } /* Inform the caller. */ if (call_callback == GLOBUS_TRUE) GridFTP->EofCallbackFunc(GridFTP->EofCallbackArg, GLOBUS_SUCCESS); GlobusGFSHpssDebugExit(); }
static void accept_callback( globus_xio_server_t server, globus_xio_handle_t server_handle, globus_result_t result, void * user_arg) { globus_l_timeout_info_t * info = user_arg; globus_mutex_lock(&lock); if (result != GLOBUS_SUCCESS) { if (info->timeout_state == info->state && info->expect_timeout && result_is_timeout(result)) { /* hit expected result */ info->expect_timeout = GLOBUS_FALSE; result = GLOBUS_SUCCESS; } else { fprintf(stderr, "Unexpected accept failure\n"); } info->state = GLOBUS_XIO_OPERATION_TYPE_FINISHED; } else { info->state = GLOBUS_XIO_OPERATION_TYPE_OPEN; } info->handle = server_handle; info->result = result; globus_mutex_unlock(&lock); state_machine(info); }
static void data_cb( globus_xio_handle_t handle, globus_result_t result, globus_byte_t * buffer, globus_size_t len, globus_size_t nbytes, globus_xio_data_descriptor_t data_desc, void * user_arg) { globus_result_t res; globus_mutex_lock(&globus_l_mutex); { res = globus_xio_close( handle, NULL); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); globus_l_closed = GLOBUS_TRUE; globus_cond_signal(&globus_l_cond); } globus_mutex_unlock(&globus_l_mutex); }
static void gram_state_callback( void * arg, char * job_contact, int state, int errorcode) { monitor_t * monitor; monitor = arg; globus_mutex_lock(&monitor->mutex); monitor->state = state; monitor->errorcode = errorcode; if(state == GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE || state == GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED) { monitor->done_count++; } globus_cond_signal(&monitor->cond); globus_mutex_unlock(&monitor->mutex); }
void gridftp_flush(gridftp_t * GridFTP) { GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); if (GridFTP == NULL) goto cleanup; globus_mutex_lock(&GridFTP->Lock); { /* * On STOR, we were the ones that kicked out EOF so we * have nothing to do. On RETR, we need to send all * ready buffers. */ /* Set Eof so (for RETR) so that we will get signaled. */ GridFTP->Eof = GLOBUS_TRUE; while (buffer_get_ready_buffer_count(GridFTP->BufferHandle, GridFTP->PrivateBufferID) > 0) { globus_cond_wait(&GridFTP->Cond, &GridFTP->Lock); } /* Wait for all ops to complete. */ while (GridFTP->OpCount != 0) { globus_cond_wait(&GridFTP->Cond, &GridFTP->Lock); } } globus_mutex_unlock(&GridFTP->Lock); cleanup: GlobusGFSHpssDebugExit(); }
static void close_cb( globus_xio_handle_t handle, globus_result_t result, void * user_arg) { char * timeout_type; timeout_type = (char *) user_arg; if(strcmp(timeout_type, "C") == 0) { if(!result_is_cancel(result)) { failed_exit("Close was not canceled."); } } globus_mutex_lock(&globus_l_mutex); { globus_l_closed = GLOBUS_TRUE; globus_cond_signal(&globus_l_cond); } globus_mutex_unlock(&globus_l_mutex); }
static globus_bool_t globus_l_gfs_event_cb( globus_gfs_embed_handle_t handle, globus_result_t result, globus_gfs_embed_event_t event, void * user_arg) { globus_mutex_lock(&globus_l_gfs_mutex); { switch(event) { case GLOBUS_GFS_EMBED_EVENT_STOPPED: globus_libc_printf("Embedded server stopped.\n"); globus_l_gfs_server_active = GLOBUS_FALSE; globus_cond_signal(&globus_l_gfs_cond); globus_gridftp_server_embed_destroy(handle); break; case GLOBUS_GFS_EMBED_EVENT_CONNECTION_CLOSED: globus_libc_printf("Connection closed.\n"); break; case GLOBUS_GFS_EMBED_EVENT_CONNECTION_OPENED: globus_libc_printf("Connection established.\n"); break; default: break; } } globus_mutex_unlock(&globus_l_gfs_mutex); return GLOBUS_TRUE; }
void quit_callback( void * callback_arg, globus_ftp_control_handle_t * handle, globus_object_t * error, globus_ftp_control_response_t * ftp_response) { if (ftp_response->code == 221) { verbose_printf(2, "%s\n", ftp_response->response_buffer); globus_mutex_lock(&end_mutex); { end_done = GLOBUS_TRUE; globus_cond_signal(&end_cond); } globus_mutex_unlock(&end_mutex); } else { verbose_printf(1,"Error : %s\n", ftp_response->response_buffer); exit(1); } }
void * list_remove_head(list_t * List) { void * data = NULL; entry_t * entry = NULL; GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); if (List == NULL) goto cleanup; globus_mutex_lock(&List->Lock); { if (List->Head != NULL) { /* Save the entry. */ entry = List->Head; /* Unlink it. */ List->Head = List->Head->Next; if (List->Head != NULL) List->Head->Prev = NULL; if (List->Head == NULL) List->Tail = NULL; /* Save the data. */ data = entry->Data; /* Release the entry */ globus_free(entry); } } globus_mutex_unlock(&List->Lock); cleanup: GlobusGFSHpssDebugExit(); return data; }
void globus_module_setenv( const char * name, const char * value) { int rc; /* * First, check to see if the environment mutex has been initialized */ if(globus_l_environ_mutex_initialized == GLOBUS_FALSE) { if(globus_i_module_initialized == GLOBUS_TRUE) { rc = globus_mutex_init(&globus_l_environ_hashtable_mutex, (globus_mutexattr_t *) GLOBUS_NULL); globus_assert (rc == 0); globus_l_environ_mutex_initialized = GLOBUS_TRUE; } } /* * then, check to see if the environment hash table has been initialized */ if((globus_l_environ_initialized == GLOBUS_FALSE)) { if(globus_i_module_initialized==GLOBUS_TRUE) { globus_mutex_lock(&globus_l_environ_hashtable_mutex); } globus_hashtable_init(&globus_l_environ_table, GLOBUS_L_ENVIRON_TABLE_SIZE, globus_hashtable_string_hash, globus_hashtable_string_keyeq); globus_l_environ_initialized = GLOBUS_TRUE; if(globus_i_module_initialized == GLOBUS_TRUE) { globus_mutex_unlock(&globus_l_environ_hashtable_mutex); } } /* * Then actually put the name and value into the hash table */ if(globus_i_module_initialized == GLOBUS_TRUE) { globus_mutex_lock(&globus_l_environ_hashtable_mutex); } globus_hashtable_remove( &globus_l_environ_table, (void *) name); globus_hashtable_insert( &globus_l_environ_table, (void *) name, (void *) value); if(globus_i_module_initialized == GLOBUS_TRUE) { globus_mutex_unlock(&globus_l_environ_hashtable_mutex); } }
int space_main( int argc, char ** argv) { int rc; globus_xio_stack_t stack; globus_xio_handle_t handle; globus_result_t res; globus_xio_attr_t attr; globus_condattr_t condattr; globus_l_closed = GLOBUS_FALSE; globus_l_close_called = GLOBUS_FALSE; rc = globus_module_activate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); res = globus_xio_attr_init(&attr); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); res = globus_xio_stack_init(&stack, NULL); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); parse_parameters(argc, argv, stack, attr); globus_callback_space_init(&globus_l_space, NULL); globus_condattr_init(&condattr); globus_condattr_setspace(&condattr, globus_l_space); globus_mutex_init(&globus_l_mutex, NULL); globus_cond_init(&globus_l_cond, &condattr); res = globus_xio_handle_create(&handle, stack); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); res = globus_xio_attr_cntl(attr, NULL, GLOBUS_XIO_ATTR_SET_SPACE, globus_l_space); res = globus_xio_register_open( handle, "whatever", attr, open_cb, argv[argc-1]); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); globus_mutex_lock(&globus_l_mutex); { while(!globus_l_closed) { globus_cond_wait(&globus_l_cond, &globus_l_mutex); } } globus_mutex_unlock(&globus_l_mutex); globus_xio_attr_destroy(attr); globus_xio_stack_destroy(stack); test_common_end(); globus_callback_space_destroy(globus_l_space); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == 0); fprintf(stdout, "Success.\n"); return 0; }
/** * @brief Init Sec Context * @ingroup globus_gsi_gssapi */ OM_uint32 GSS_CALLCONV gss_init_sec_context( OM_uint32 * minor_status, const gss_cred_id_t initiator_cred_handle, gss_ctx_id_t * context_handle_P, const gss_name_t target_name, const gss_OID mech_type, OM_uint32 req_flags, OM_uint32 time_req, const gss_channel_bindings_t input_chan_bindings, const gss_buffer_t input_token, gss_OID * actual_mech_type, gss_buffer_t output_token, OM_uint32 * ret_flags, OM_uint32 * time_rec) { gss_ctx_id_desc * context = NULL; OM_uint32 major_status = GSS_S_COMPLETE; OM_uint32 local_minor_status; OM_uint32 local_major_status; globus_result_t local_result; int rc; char cbuf[1]; globus_gsi_cert_utils_cert_type_t cert_type; GLOBUS_I_GSI_GSSAPI_DEBUG_ENTER; *minor_status = (OM_uint32) GLOBUS_SUCCESS; output_token->length = 0; context = *context_handle_P; /* module activation if not already done by calling * globus_module_activate */ globus_thread_once( &once_control, globus_l_gsi_gssapi_activate_once); globus_mutex_lock(&globus_i_gssapi_activate_mutex); if (!globus_i_gssapi_active) { globus_module_activate(GLOBUS_GSI_GSSAPI_MODULE); } globus_mutex_unlock(&globus_i_gssapi_activate_mutex); if(req_flags & GSS_C_ANON_FLAG && req_flags & GSS_C_DELEG_FLAG) { major_status = GSS_S_FAILURE; GLOBUS_GSI_GSSAPI_ERROR_RESULT( minor_status, GLOBUS_GSI_GSSAPI_ERROR_BAD_ARGUMENT, (_GGSL("Can't initialize a context to be both anonymous and " "provide delegation"))); goto error_exit; } if(req_flags & GSS_C_GLOBUS_SSL_COMPATIBLE && req_flags & GSS_C_DELEG_FLAG) { major_status = GSS_S_FAILURE; GLOBUS_GSI_GSSAPI_ERROR_RESULT( minor_status, GLOBUS_GSI_GSSAPI_ERROR_BAD_ARGUMENT, (_GGSL("Can't initialize a context to both use SSL compatible " "context establishment and provide delegation"))); goto error_exit; } if(req_flags & GSS_C_DELEG_FLAG && target_name == GSS_C_NO_NAME) { major_status = GSS_S_FAILURE; GLOBUS_GSI_GSSAPI_ERROR_RESULT( minor_status, GLOBUS_GSI_GSSAPI_ERROR_BAD_ARGUMENT, (_GGSL("Need a target name for authorization prior " "to doing delegation"))); goto error_exit; } if ((context == (gss_ctx_id_t) GSS_C_NO_CONTEXT) || !(context->ctx_flags & GSS_I_CTX_INITIALIZED)) { GLOBUS_I_GSI_GSSAPI_DEBUG_FPRINTF( 2, (globus_i_gsi_gssapi_debug_fstream, "Creating context w/ %s.\n", (initiator_cred_handle == GSS_C_NO_CREDENTIAL) ? "GSS_C_NO_CREDENTIAL" : "Credentials provided")); major_status = globus_i_gsi_gss_create_and_fill_context(&local_minor_status, &context, initiator_cred_handle, GSS_C_INITIATE, req_flags); if (GSS_ERROR(major_status)) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_minor_status, GLOBUS_GSI_GSSAPI_ERROR_WITH_GSS_CONTEXT); goto error_exit; } *context_handle_P = context; if (actual_mech_type != NULL) { *actual_mech_type = (gss_OID) gss_mech_globus_gssapi_openssl; } if (ret_flags != NULL) { *ret_flags = 0 ; } } else { /* first time there is no input token, but after that * there will always be one */ major_status = globus_i_gsi_gss_put_token(&local_minor_status, context, NULL, input_token); if (GSS_ERROR(major_status)) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_minor_status, GLOBUS_GSI_GSSAPI_ERROR_TOKEN_FAIL); goto error_exit; } } switch (context->gss_state) { case(GSS_CON_ST_HANDSHAKE): /* do the handshake work */ major_status = globus_i_gsi_gss_handshake(&local_minor_status, context); if (major_status == GSS_S_CONTINUE_NEEDED) { break; } if(GSS_ERROR(major_status)) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_minor_status, GLOBUS_GSI_GSSAPI_ERROR_HANDSHAKE); context->gss_state = GSS_CON_ST_DONE; break; } /* make sure we are talking to the correct server */ major_status = globus_i_gsi_gss_retrieve_peer(&local_minor_status, context, GSS_C_INITIATE); if (GSS_ERROR(major_status)) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_minor_status, GLOBUS_GSI_GSSAPI_ERROR_WITH_GSS_CONTEXT); context->gss_state = GSS_CON_ST_DONE; break; } local_result = globus_gsi_callback_get_cert_type( context->callback_data, &cert_type); if(local_result != GLOBUS_SUCCESS) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_minor_status, GLOBUS_GSI_GSSAPI_ERROR_WITH_CALLBACK_DATA); major_status = GSS_S_FAILURE; goto error_exit; } /* * Need to check if the server is using a limited proxy. * And if that is acceptable here. * Caller tells us if it is not acceptable to * use a limited proxy. */ if ((context->req_flags & GSS_C_GLOBUS_DONT_ACCEPT_LIMITED_PROXY_FLAG) && GLOBUS_GSI_CERT_UTILS_IS_LIMITED_PROXY(cert_type)) { major_status = GSS_S_UNAUTHORIZED; GLOBUS_GSI_GSSAPI_ERROR_RESULT( minor_status, GLOBUS_GSI_GSSAPI_ERROR_PROXY_VIOLATION, (_GGSL("Function set to not accept limited proxies"))); context->gss_state = GSS_CON_ST_DONE; break; } /* this is the mutual authentication test */ if (target_name != NULL) { major_status = gss_compare_name(&local_minor_status, context->peer_cred_handle->globusid, target_name, &rc); if (GSS_ERROR(major_status)) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_minor_status, GLOBUS_GSI_GSSAPI_ERROR_BAD_NAME); context->gss_state = GSS_CON_ST_DONE; break; } else if(rc == GSS_NAMES_NOT_EQUAL) { char * expected_name; char * actual_name; if(g_OID_equal(((gss_name_desc*) target_name)->name_oid, GSS_C_NT_HOSTBASED_SERVICE)) { GLOBUS_GSI_GSSAPI_ERROR_RESULT( minor_status, GLOBUS_GSI_GSSAPI_ERROR_AUTHZ_DENIED, (_GGSL("The expected name for the remote host (%s%s%s) does not match the authenticated " "name of the remote host (%s%s%s). This happens when the name in the host certificate does not match the information obtained from DNS and is often a DNS configuration problem."), target_name->service_name ? target_name->service_name : "", target_name->service_name ? "@" : "", target_name->host_name ? target_name->host_name : "unknown", context->peer_cred_handle->globusid->service_name ? context->peer_cred_handle->globusid->service_name : "", context->peer_cred_handle->globusid->service_name ? "@" : "", context->peer_cred_handle->globusid->host_name ? context->peer_cred_handle->globusid->host_name : "unknown")); } else { expected_name = ((gss_name_desc*) target_name)->x509n_oneline; actual_name = ((gss_name_desc*) context->peer_cred_handle->globusid)->x509n_oneline; GLOBUS_GSI_GSSAPI_ERROR_RESULT( minor_status, GLOBUS_GSI_GSSAPI_ERROR_AUTHZ_DENIED, (_GGSL("The name of the remote entity (%s), and the expected " "name for the remote entity (%s) do not match"), actual_name, expected_name)); } major_status = GSS_S_UNAUTHORIZED; context->gss_state = GSS_CON_ST_DONE; break; } } context->ret_flags |= GSS_C_MUTUAL_FLAG; context->ret_flags |= GSS_C_PROT_READY_FLAG; context->ret_flags |= GSS_C_INTEG_FLAG | GSS_C_REPLAY_FLAG | GSS_C_SEQUENCE_FLAG | GSS_C_ANON_FLAG | GSS_C_DELEG_FLAG; if (GLOBUS_GSI_CERT_UTILS_IS_LIMITED_PROXY(cert_type)) { context->ret_flags |= GSS_C_GLOBUS_RECEIVED_LIMITED_PROXY_FLAG; } # if LINK_WITH_INTERNAL_OPENSSL_API context->ret_flags |= GSS_C_TRANS_FLAG; # endif /* * IF we are talking to a real SSL server, * we don't want to do delegation, so we are done */ if (context->req_flags & GSS_C_GLOBUS_SSL_COMPATIBLE) { context->gss_state = GSS_CON_ST_DONE; break; } /* * If we have completed the handshake, but don't * have any more data to send, we can send the flag * now. i.e. fall through without break, * Otherwise, we will wait for the null byte * to get back in sync which we will ignore */ if (output_token->length != 0) { context->gss_state=GSS_CON_ST_FLAGS; break; } case(GSS_CON_ST_FLAGS): if (input_token->length > 0) { BIO_read(context->gss_sslbio, cbuf, 1); } /* send D if we want delegation, 0 otherwise */ if (context->req_flags & GSS_C_DELEG_FLAG) { BIO_write(context->gss_sslbio, "D", 1); context->gss_state = GSS_CON_ST_REQ; } else { BIO_write(context->gss_sslbio, "0", 1); context->gss_state = GSS_CON_ST_DONE; } break; case(GSS_CON_ST_REQ): local_result = globus_gsi_proxy_inquire_req( context->proxy_handle, context->gss_sslbio); if(local_result != GLOBUS_SUCCESS) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_result, GLOBUS_GSI_GSSAPI_ERROR_PROXY_NOT_RECEIVED); major_status = GSS_S_FAILURE; context->gss_state = GSS_CON_ST_DONE; goto error_exit; } local_result = globus_gsi_cred_get_cert_type( context->cred_handle->cred_handle, &cert_type); if(local_result != GLOBUS_SUCCESS) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_result, GLOBUS_GSI_GSSAPI_ERROR_WITH_GSI_CREDENTIAL); major_status = GSS_S_FAILURE; context->gss_state = GSS_CON_ST_DONE; goto error_exit; } local_result = globus_gsi_proxy_handle_set_type( context->proxy_handle, (context->req_flags & GSS_C_GLOBUS_DELEGATE_LIMITED_PROXY_FLAG) ? GLOBUS_GSI_CERT_UTILS_TYPE_LIMITED_PROXY : GLOBUS_GSI_CERT_UTILS_TYPE_IMPERSONATION_PROXY); if(local_result != GLOBUS_SUCCESS) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_result, GLOBUS_GSI_GSSAPI_ERROR_WITH_GSI_PROXY); major_status = GSS_S_FAILURE; context->gss_state = GSS_CON_ST_DONE; goto exit; } local_result = globus_gsi_proxy_sign_req( context->proxy_handle, context->cred_handle->cred_handle, context->gss_sslbio); if(local_result != GLOBUS_SUCCESS) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_result, GLOBUS_GSI_GSSAPI_ERROR_WITH_GSI_PROXY); major_status = GSS_S_FAILURE; context->gss_state = GSS_CON_ST_DONE; goto error_exit; } context->gss_state = GSS_CON_ST_DONE; break; case(GSS_CON_ST_CERT): ; case(GSS_CON_ST_DONE): ; } /* end of switch for gss_con_st */ local_major_status = globus_i_gsi_gss_get_token(&local_minor_status, context, NULL, output_token); if(GSS_ERROR(local_major_status)) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_minor_status, GLOBUS_GSI_GSSAPI_ERROR_TOKEN_FAIL); major_status = GSS_S_FAILURE; context->gss_state = GSS_CON_ST_DONE; goto error_exit; } /* some error occurred during switch */ if(GSS_ERROR(major_status)) { goto error_exit; } if (context->gss_state != GSS_CON_ST_DONE) { major_status |= GSS_S_CONTINUE_NEEDED; } else if(time_rec != NULL) { time_t lifetime; time_t current_time; major_status = globus_i_gsi_gss_get_context_goodtill( &local_minor_status, context, &lifetime); if(GSS_ERROR(major_status)) { GLOBUS_GSI_GSSAPI_ERROR_CHAIN_RESULT( minor_status, local_minor_status, GLOBUS_GSI_GSSAPI_ERROR_WITH_GSS_CONTEXT); goto exit; } current_time = time(NULL); if(current_time > lifetime) { *time_rec = 0; } else { *time_rec = (OM_uint32) (lifetime - current_time); } } if (ret_flags != NULL) { *ret_flags = context->ret_flags; } GLOBUS_I_GSI_GSSAPI_DEBUG_FPRINTF( 2, (globus_i_gsi_gssapi_debug_fstream, "init_sec_context:major_status:%08x" ":gss_state:%d req_flags=%08x:ret_flags=%08x\n", (unsigned int) major_status, context->gss_state, (unsigned int) req_flags, (unsigned int) context->ret_flags)); goto exit; error_exit: gss_delete_sec_context(&local_minor_status, (gss_ctx_id_t *) &context, output_token); *context_handle_P = (gss_ctx_id_t) context; exit: GLOBUS_I_GSI_GSSAPI_DEBUG_EXIT; return major_status; }
void ADIOI_GRIDFTP_Open(ADIO_File fd, int *error_code) { static char myname[]="ADIOI_GRIDFTP_Open"; int myrank, nprocs, keyfound; char hintval[MPI_MAX_INFO_VAL+1]; globus_ftp_client_handleattr_t hattr; globus_result_t result; MPI_Comm_size(fd->comm, &nprocs); MPI_Comm_rank(fd->comm, &myrank); /* activate Globus ftp client module -- can be called multiple times, so it's safest to call once per file/connection */ globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); fd->fd_sys = num_gridftp_handles; /* No shared file pointers for now */ fd->shared_fp_fname = NULL; *error_code = MPI_SUCCESS; /* Access modes here mean something very different here than they would on a "real" filesystem... As a result, the amode and hint processing here is intermingled and a little weird because many of them have to do with the connection rather than the file itself. The thing that sucks about this is that read and write ops will have to check themselves if the file is being accessed rdonly, rdwr, or wronly. */ result=globus_ftp_client_handleattr_init(&hattr); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_handleattr_init", myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } result = globus_ftp_client_operationattr_init(&(oattr[fd->fd_sys])); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_operationattr_init", myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* Always use connection caching unless told otherwise */ result=globus_ftp_client_handleattr_set_cache_all(&hattr,GLOBUS_TRUE); if ( result !=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_handleattr_set_cache_all",myname,result); /* Assume that it's safe to cache a file if it's read-only */ if ( (fd->access_mode&ADIO_RDONLY) && (result=globus_ftp_client_handleattr_add_cached_url(&hattr,fd->filename))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_handleattr_add_cached_url",myname,result); /* Since we're (almost by definition) doing things that FTP S (stream) control mode can't handle, default to E (extended block) control mode for gsiftp:// URLs. ftp:// URLs use standard stream control mode by default. This behavior can be overridden by the ftp_control_mode hint. */ /* if ( !strncmp(fd->filename,"gsiftp:",7) && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_EXTENDED_BLOCK))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strncmp(fd->filename,"ftp:",4) && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_STREAM))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); */ /* Set append mode if necessary */ if ( (fd->access_mode&ADIO_APPEND) && ((result=globus_ftp_client_operationattr_set_append(&(oattr[fd->fd_sys]),GLOBUS_TRUE))!=GLOBUS_SUCCESS) ) globus_err_handler("globus_ftp_client_operationattr_set_append",myname,result); /* Other hint and amode processing that would affect hattr and/or oattr[] (eg. parallelism, striping, etc.) goes here */ if ( fd->info!=MPI_INFO_NULL ) { ADIOI_Info_get(fd->info,"ftp_control_mode",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { if ( ( !strcmp(hintval,"extended") || !strcmp(hintval,"extended_block") ) && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_EXTENDED_BLOCK))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strcmp(hintval,"block") && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_BLOCK))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strcmp(hintval,"compressed") && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_COMPRESSED))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); else if ( !strcmp(hintval,"stream") && (result=globus_ftp_client_operationattr_set_mode(&(oattr[fd->fd_sys]),GLOBUS_FTP_CONTROL_MODE_STREAM))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_mode",myname,result); } ADIOI_Info_get(fd->info,"parallelism",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { int nftpthreads; if ( sscanf(hintval,"%d",&nftpthreads)==1 ) { globus_ftp_control_parallelism_t parallelism; parallelism.mode = GLOBUS_FTP_CONTROL_PARALLELISM_FIXED; parallelism.fixed.size = nftpthreads; if ( (result=globus_ftp_client_operationattr_set_parallelism(&(oattr[fd->fd_sys]), ¶llelism))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_parallelism",myname,result); } } ADIOI_Info_get(fd->info,"striped_ftp",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { /* if set to "true" or "enable", set up round-robin block layout */ if ( !strncmp("true",hintval,4) || !strncmp("TRUE",hintval,4) || !strncmp("enable",hintval,4) || !strncmp("ENABLE",hintval,4) ) { ADIOI_Info_get(fd->info,"striping_factor",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { int striping_factor; if ( sscanf(hintval,"%d",&striping_factor)==1 ) { globus_ftp_control_layout_t layout; layout.mode = GLOBUS_FTP_CONTROL_STRIPING_BLOCKED_ROUND_ROBIN; layout.round_robin.block_size = striping_factor; if ( (result=globus_ftp_client_operationattr_set_layout(&(oattr[fd->fd_sys]), &layout))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_layout", myname,result); } } } } ADIOI_Info_get(fd->info,"tcp_buffer",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { /* set tcp buffer size */ int buffer_size; if ( sscanf(hintval,"%d",&buffer_size)==1 ) { globus_ftp_control_tcpbuffer_t tcpbuf; tcpbuf.mode = GLOBUS_FTP_CONTROL_TCPBUFFER_FIXED; tcpbuf.fixed.size = buffer_size; if ( (result=globus_ftp_client_operationattr_set_tcp_buffer(&(oattr[fd->fd_sys]), &tcpbuf))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_tcp_buffer",myname,result); } } ADIOI_Info_get(fd->info,"transfer_type",MPI_MAX_INFO_VAL,hintval,&keyfound); if ( keyfound ) { globus_ftp_control_type_t filetype; /* set transfer type (i.e. ASCII or binary) */ if ( !strcmp("ascii",hintval) || !strcmp("ASCII",hintval) ) { filetype=GLOBUS_FTP_CONTROL_TYPE_ASCII; } else { filetype=GLOBUS_FTP_CONTROL_TYPE_IMAGE; } if ( (result=globus_ftp_client_operationattr_set_type(&(oattr[fd->fd_sys]),filetype))!=GLOBUS_SUCCESS ) globus_err_handler("globus_ftp_client_operationattr_set_type",myname,result); } } else FPRINTF(stderr,"no MPI_Info object associated with %s\n",fd->filename); /* Create the ftp handle */ result=globus_ftp_client_handle_init(&(gridftp_fh[fd->fd_sys]),&hattr); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_handle_init",myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* Check for existence of the file */ globus_mutex_init(&lock, GLOBUS_NULL); globus_cond_init(&cond, GLOBUS_NULL); file_exists=GLOBUS_FALSE; exists_done=GLOBUS_FALSE; if ( myrank==0 ) { if ( (result=globus_ftp_client_exists(&(gridftp_fh[fd->fd_sys]), fd->filename, &(oattr[fd->fd_sys]), exists_cb, GLOBUS_NULL))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_exists",myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } /* wait till the callback completes */ globus_mutex_lock(&lock); while ( exists_done!=GLOBUS_TRUE ) globus_cond_wait(&cond,&lock); globus_mutex_unlock(&lock); } MPI_Barrier(fd->comm); MPI_Bcast(&file_exists,1,MPI_INT,0,fd->comm); /* It turns out that this is handled by MPI_File_open() directly */ if ( (file_exists!=GLOBUS_TRUE) && (fd->access_mode&ADIO_CREATE) && !(fd->access_mode&ADIO_EXCL) && !(fd->access_mode&ADIO_RDONLY) ) { if ( myrank==0 ) { /* if the file doesn't exist, write a single NULL to it */ globus_byte_t touchbuf=(globus_byte_t)'\0'; touch_ctl_done=GLOBUS_FALSE; if ( (result=globus_ftp_client_put(&(gridftp_fh[fd->fd_sys]), fd->filename, &(oattr[fd->fd_sys]), GLOBUS_NULL, touch_ctl_cb, GLOBUS_NULL))!=GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_put",myname,result); fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } result=globus_ftp_client_register_write(&(gridftp_fh[fd->fd_sys]), (globus_byte_t *)&touchbuf, 0, (globus_off_t)0, GLOBUS_TRUE, touch_data_cb, GLOBUS_NULL); if ( result != GLOBUS_SUCCESS ) { globus_err_handler("globus_ftp_client_register_write",myname,result); *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", globus_object_printable_to_string(globus_error_get(result))); return; } globus_mutex_lock(&lock); while ( touch_ctl_done!=GLOBUS_TRUE ) globus_cond_wait(&cond,&lock); globus_mutex_unlock(&lock); } MPI_Barrier(fd->comm); } else if ( (fd->access_mode&ADIO_EXCL) && (file_exists==GLOBUS_TRUE) ) { fd->fd_sys = -1; *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", 0); return; } else if ( (fd->access_mode&ADIO_RDONLY) && (file_exists!=GLOBUS_TRUE) ) { if ( myrank==0 ) { FPRINTF(stderr,"WARNING: read-only file %s does not exist!\n",fd->filename); } } num_gridftp_handles++; }
int globus_args_scan( int * argc, char *** argv, int option_count, globus_args_option_descriptor_t * options, const char * name, const globus_version_t * version, const char * oneline_usage, const char * long_usage, globus_list_t ** options_found, char ** error_msg ) { static globus_mutex_t args_mutex; static globus_bool_t args_mutex_initialized = GLOBUS_FALSE; int rc; int my_argc; char * my_arg; int len; int i; char ** alias; char ** arglist; globus_fifo_t fifo; globus_bool_t done; globus_bool_t found; globus_libc_lock(); if (!args_mutex_initialized) { globus_mutex_init(&args_mutex, (globus_mutexattr_t *) GLOBUS_NULL); args_mutex_initialized = GLOBUS_TRUE; } globus_libc_unlock(); globus_mutex_lock(&args_mutex); rc = GLOBUS_SUCCESS; globus_fifo_init(&fifo); *options_found = GLOBUS_NULL; if (error_msg) *error_msg = GLOBUS_NULL; /* precheck : are the options correct? */ rc = globus_l_args_check_options(option_count, options, error_msg); done = (rc==GLOBUS_SUCCESS) ? GLOBUS_FALSE : GLOBUS_TRUE; my_argc=1; while (!done) { /* any more options? */ if (my_argc == *argc) { done=GLOBUS_TRUE; continue; } my_arg = (*argv)[my_argc]; len = strlen(my_arg); if (my_arg[0]!='-' || len<2) { /* unrecognized option */ done=GLOBUS_TRUE; continue; } /* '--*' is a special case : if '*' is non-null, it's an error. Otherwise, it signals end of parsing. */ if (!strncmp(my_arg,"--",2)) { if (len == 2) /* end of parsing */ { /* next argument is first "unrecognized" option */ my_argc++; } else { rc = GLOBUS_FAILURE; globus_l_args_create_error_msg( error_msg, my_argc, my_arg, _GCSL("double-dashed option syntax is not allowed"), oneline_usage ); } done = GLOBUS_TRUE; continue; } /* four specials : -help, -usage, -version, -versions */ if (!strcmp("-help",my_arg)) { globus_l_args_create_msg( error_msg , (char *) long_usage ); rc = GLOBUS_ARGS_HELP; done = GLOBUS_TRUE; continue; } if(!strcmp("-usage",my_arg)) { globus_l_args_create_msg( error_msg , (char *) oneline_usage ); rc = GLOBUS_ARGS_HELP; done = GLOBUS_TRUE; continue; } if (!strcmp("-version",my_arg)) { globus_version_print( name, version, stderr, GLOBUS_FALSE); rc = GLOBUS_ARGS_VERSION; done = GLOBUS_TRUE; continue; } if (!strcmp("-versions",my_arg)) { globus_version_print( name, version, stderr, GLOBUS_TRUE); globus_module_print_activated_versions(stderr, GLOBUS_TRUE); rc = GLOBUS_ARGS_VERSION; done = GLOBUS_TRUE; continue; } /* is it a known flag? */ found=GLOBUS_FALSE; for (i=0; !found && !rc && i<option_count; i++) { for (alias=options[i].names; !found && !rc && *alias; alias++) { if (!strcmp(my_arg, *alias)) { found = GLOBUS_TRUE; arglist = GLOBUS_NULL; if (options[i].arity > 0) { if (my_argc+options[i].arity >= *argc) { globus_l_args_create_error_msg( error_msg, my_argc, my_arg, _GCSL("not enough arguments"), oneline_usage ); rc = GLOBUS_FAILURE; continue; } rc = globus_l_args_validate( &options[i], my_argc, (*argv), &arglist, oneline_usage, error_msg ); } /* if */ if (rc==GLOBUS_SUCCESS) { /* option successfully detected: add it */ globus_l_args_add_instance( &fifo, &options[i], arglist ); my_argc += 1+options[i].arity; } } /* strcmp(my_arg,*alias)) */ } /* alias */ } /* i */ if (!found) { /* my_arg contains an unregistered option */ rc = GLOBUS_FAILURE; globus_l_args_create_error_msg( error_msg, my_argc, my_arg, _GCSL("unknown option"), oneline_usage ); } if (rc!=GLOBUS_SUCCESS) { done = GLOBUS_TRUE; continue; } } /* while (!done) */ if (rc==GLOBUS_SUCCESS) { /* if successful, return number of options found */ rc = globus_fifo_size(&fifo); *options_found = globus_fifo_convert_to_list( &fifo ); /* modify argc/argv */ if (my_argc>1) { for (i = my_argc; i < *argc; i++) (*argv)[i-my_argc+1] = (*argv)[i]; *argc -= my_argc - 1; } } globus_fifo_destroy(&fifo); globus_mutex_unlock(&args_mutex); return rc; }
/** * Periodic poll of file to act like tail -f * * @param user_arg * Log file parsing state */ static void globus_l_job_manager_poll_callback( void * user_arg) { int rc; globus_l_job_manager_logfile_state_t * state = user_arg; globus_bool_t eof_hit = GLOBUS_FALSE; globus_reltime_t delay; globus_result_t result; time_t poll_time = time(NULL); struct tm poll_tm, *tm_result; struct stat stat; char * today; SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_INFO, ("globus_l_job_manager_poll_callback()\n")); globus_mutex_lock(&globus_l_job_manager_mutex); if (shutdown_called) { SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_INFO, ("polling while deactivating")); globus_mutex_unlock(&globus_l_job_manager_mutex); goto error; } globus_mutex_unlock(&globus_l_job_manager_mutex); if (state->fp != NULL) { /* Parse data */ SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_TRACE, ("parsing events\n")); rc = globus_l_job_manager_parse_events(state); if (rc == SEG_JOB_MANAGER_ERROR_LOG_EOF) { eof_hit = GLOBUS_TRUE; } } if (eof_hit) { tm_result = globus_libc_gmtime_r(&poll_time, &poll_tm); if (tm_result == NULL) { SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_WARN, ("Couldn't convert to gmtime\n")); } else { today = globus_common_create_string( "%s/%4d%02d%02d", state->log_dir, tm_result->tm_year+1900, tm_result->tm_mon+1, tm_result->tm_mday); if (today && (strcmp(today, state->path) != 0)) { /* New day... if new file exists and the old one hasn't changed since our * last poll, mark it as old */ if (globus_l_next_file_exists(state)) { rc = fstat(fileno(state->fp), &stat); if (rc != -1) { if (ftello(state->fp) == stat.st_size) { state->old_log = GLOBUS_TRUE; } } } } if (today) { free(today); } } } /* If end of log, close this logfile and look for a new one. Also, if * the current day's log doesn't exist yet, check for it */ if ((eof_hit && state->old_log) || state->fp == NULL) { if (state->fp) { fclose(state->fp); state->fp = NULL; state->start_timestamp.tm_mday++; state->start_timestamp.tm_hour = 0; state->start_timestamp.tm_min = 0; state->start_timestamp.tm_sec = 0; globus_l_job_manager_normalize_date(&state->start_timestamp); } rc = globus_l_job_manager_find_logfile(state); if (rc == GLOBUS_SUCCESS) { /* Opening a new logfile, run w/out delay */ state->fp = fopen(state->path, "r"); if (state->fp == NULL) { goto error; } eof_hit = GLOBUS_FALSE; GlobusTimeReltimeSet(delay, 0, 0); } else if (rc == SEG_JOB_MANAGER_ERROR_LOG_NOT_PRESENT) { /* Current day's logfile not present, wait a bit longer for * it to show up */ GlobusTimeReltimeSet(delay, 30, 0); eof_hit = GLOBUS_TRUE; } else { goto error; } } else if(eof_hit) { /* eof on current logfile, wait for new data */ GlobusTimeReltimeSet(delay, 2, 0); } else { /* still data available in current file, hurry up! */ GlobusTimeReltimeSet(delay, 0, 0); } result = globus_callback_register_oneshot( &state->callback, &delay, globus_l_job_manager_poll_callback, state); if (result != GLOBUS_SUCCESS) { goto error; } SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_INFO, ("globus_l_job_manager_poll_callback() exited with/success\n")); return; error: globus_mutex_lock(&globus_l_job_manager_mutex); if (shutdown_called) { callback_count--; if (callback_count == 0) { globus_cond_signal(&globus_l_job_manager_cond); } } globus_mutex_unlock(&globus_l_job_manager_mutex); SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_WARN, ("globus_l_job_manager_poll_callback() exited with/error\n")); return; }
int main(int argc, char * argv[]) { globus_ftp_client_handle_t handle; globus_ftp_client_operationattr_t attr; globus_result_t result; globus_ftp_client_handleattr_t handle_attr; char * src = NULL; char * dst = NULL; struct tm modtime; extern char * optarg; extern int optind; int c; globus_module_activate(GLOBUS_FTP_CLIENT_MODULE); globus_ftp_client_handleattr_init(&handle_attr); globus_ftp_client_operationattr_init(&attr); globus_mutex_init(&lock, GLOBUS_NULL); globus_cond_init(&cond, GLOBUS_NULL); test_parse_args(argc, argv, &handle_attr, &attr, &src, &dst); optind = 1; while((c = getopt(argc, argv, "T:")) != -1) { switch(c) { case 'T': memset(&modtime, 0, sizeof(modtime)); if (sscanf(optarg, "%4d%2d%2d%2d%2d%2d", &modtime.tm_year, &modtime.tm_mon, &modtime.tm_mday, &modtime.tm_hour, &modtime.tm_min, &modtime.tm_sec) != 6) { printf("Invalid time format\n"); return GLOBUS_TRUE; } modtime.tm_year -= 1900; modtime.tm_mon -= 1; break; } } globus_ftp_client_operationattr_set_type(&attr, GLOBUS_FTP_CONTROL_TYPE_ASCII); globus_ftp_client_handleattr_set_cache_all(&handle_attr, GLOBUS_TRUE); globus_ftp_client_handle_init(&handle, &handle_attr); done = GLOBUS_FALSE; result = globus_ftp_client_utime(&handle, src, &modtime, &attr, done_cb, 0); if(result != GLOBUS_SUCCESS) { done = GLOBUS_TRUE; } globus_mutex_lock(&lock); while(!done) { globus_cond_wait(&cond, &lock); } globus_mutex_unlock(&lock); globus_ftp_client_handle_destroy(&handle); globus_module_deactivate_all(); if(test_abort_count && error) { return 0; } return error; }
int unlock() { return globus_mutex_unlock(&mutex_); }
static void read_cb( globus_xio_handle_t handle, globus_result_t result, globus_byte_t * buffer, globus_size_t len, globus_size_t nbytes, globus_xio_data_descriptor_t data_desc, void * user_arg) { test_info_t * info; globus_result_t res; if(!globus_xio_error_is_eof(result) && !globus_xio_error_is_canceled(result)) { test_res(GLOBUS_XIO_TEST_FAIL_FINISH_READ, result, __LINE__, __FILE__); } info = (test_info_t *) user_arg; globus_mutex_lock(&info->mutex); { if(len < nbytes) { failed_exit("read wait for has failed"); } else if(nbytes > len) { failed_exit("too many bytes were read."); } info->nread += nbytes; if(info->nread >= info->total_read_bytes && !info->read_done) { info->closed++; info->read_done = GLOBUS_TRUE; if(info->closed == 2 || info->write_count == 0) { res = globus_xio_register_close( handle, NULL, close_cb, user_arg); test_res(GLOBUS_XIO_TEST_FAIL_NONE, res, __LINE__, __FILE__); } } else if(!info->read_done) { res = globus_xio_register_read( handle, info->buffer, info->buffer_length, info->buffer_length, NULL, read_cb, user_arg); test_res(GLOBUS_XIO_TEST_FAIL_PASS_READ, res, __LINE__, __FILE__); } } globus_mutex_unlock(&info->mutex); }