static int register_test_with_interfaces(const char *transport, const char *client_ip, const char *server_ip, int connection_family) { int ret=0; belle_sip_listener_callbacks_t client_callbacks; belle_sip_listener_callbacks_t server_callbacks; endpoint_t* client,*server; memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); client_callbacks.process_response_event=client_process_response_event; client_callbacks.process_auth_requested=client_process_auth_requested; server_callbacks.process_request_event=server_process_request_event; client = create_endpoint(client_ip,3452,transport,&client_callbacks); client->connection_family=connection_family; client->register_count=1; server = create_endpoint(server_ip,6788,transport,&server_callbacks); server->expire_in_contact=client->expire_in_contact=0; server->auth=none; if (client->lp==NULL || server->lp==NULL){ belle_sip_warning("Cannot check ipv6 because host has no ipv6 support."); ret=-1; }else register_base(client,server); destroy_endpoint(client); destroy_endpoint(server); return ret; }
static int unpriv_test_custom_ep(const char *buspath) { int ret, ep_fd1, ep_fd2; char *ep1, *ep2, *tmp1, *tmp2; tmp1 = strdup(buspath); tmp2 = strdup(buspath); ASSERT_RETURN(tmp1 && tmp2); ret = asprintf(&ep1, "%s/%u-%s", dirname(tmp1), getuid(), "apps1"); ASSERT_RETURN(ret >= 0); ret = asprintf(&ep2, "%s/%u-%s", dirname(tmp2), getuid(), "apps2"); ASSERT_RETURN(ret >= 0); free(tmp1); free(tmp2); /* endpoint only accessible to current uid */ ep_fd1 = create_endpoint(buspath, getuid(), "apps1", 0); ASSERT_RETURN(ep_fd1 >= 0); /* endpoint world accessible */ ep_fd2 = create_endpoint(buspath, getuid(), "apps2", KDBUS_MAKE_ACCESS_WORLD); ASSERT_RETURN(ep_fd2 >= 0); ret = RUN_UNPRIVILEGED(UNPRIV_UID, UNPRIV_UID, ({ int ep_fd; struct kdbus_conn *ep_conn; /* * Make sure that we are not able to create custom * endpoints */ ep_fd = create_endpoint(buspath, getuid(), "unpriv_costum_ep", 0); ASSERT_EXIT(ep_fd == -EPERM); /* * Endpoint "apps1" only accessible to same users, * that own the endpoint. Access denied by VFS */ ep_conn = kdbus_hello(ep1, 0, NULL, 0); ASSERT_EXIT(!ep_conn && errno == EACCES); /* Endpoint "apps2" world accessible */ ep_conn = kdbus_hello(ep2, 0, NULL, 0); ASSERT_EXIT(ep_conn); kdbus_conn_free(ep_conn); _exit(EXIT_SUCCESS); }),
static void ipv4_and_ipv6_dns_server(void) { struct addrinfo *ai; int timeout; endpoint_t *client; const char *nameservers[]={ "8.8.8.8", "2a01:e00::2", NULL }; if (!belle_sip_tester_ipv6_available()){ belle_sip_warning("Test skipped, IPv6 connectivity not available."); return; } client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); set_custom_resolv_conf(client->stack,nameservers); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); ai = belle_sip_ip_address_to_addrinfo(AF_INET, IPV4_SIP_IP, SIP_PORT); if (ai) { CU_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr); belle_sip_freeaddrinfo(ai); } } destroy_endpoint(client); }
void acceptors_list<Connection>::add_acceptor(const std::string &address) { acceptors.emplace_back(new acceptor_type(get_acceptor_service())); auto &acceptor = acceptors.back(); try { endpoint_type endpoint = create_endpoint(*acceptor, address); acceptor->open(endpoint.protocol()); acceptor->set_option(boost::asio::socket_base::reuse_address(true)); acceptor->bind(endpoint); acceptor->listen(data.backlog_size); BH_LOG(data.logger, SWARM_LOG_INFO, "Started to listen address: %s, backlog: %d", address, data.backlog_size); local_endpoints.emplace_back(boost::lexical_cast<std::string>(endpoint)); protocols.push_back(endpoint.protocol()); complete_socket_creation(endpoint); } catch (boost::system::system_error &error) { std::cerr << "Can not bind socket \"" << address << "\": " << error.what() << std::endl; std::cerr.flush(); acceptors.pop_back(); if (local_endpoints.size() > acceptors.size()) local_endpoints.pop_back(); if (protocols.size() > acceptors.size()) protocols.pop_back(); throw; } start_acceptor(acceptors.size() - 1); }
static void dns_fallback(void) { struct addrinfo *ai; int timeout; endpoint_t *client = create_endpoint(); const char *nameservers[]={ "94.23.19.176", /*linphone.org ; this is not a name server, it will not respond*/ "8.8.8.8", /* public nameserver, should work*/ NULL }; CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); set_custom_resolv_conf(client->stack,nameservers); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); ai = belle_sip_ip_address_to_addrinfo(AF_INET, IPV4_SIP_IP, SIP_PORT); if (ai) { CU_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr); belle_sip_freeaddrinfo(ai); } } destroy_endpoint(client); }
/* Successful IPv6 AAAA query */ static void ipv6_aaaa_query(void) { struct addrinfo *ai; int timeout; endpoint_t *client; if (!belle_sip_tester_ipv6_available()){ belle_sip_warning("Test skipped, IPv6 connectivity not available."); return; } client = create_endpoint(); if (!BC_ASSERT_PTR_NOT_NULL(client)) return; timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV6_SIP_DOMAIN, SIP_PORT, AF_INET6, a_resolve_done, client); BC_ASSERT_PTR_NOT_NULL(client->resolver_ctx); BC_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); BC_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct addrinfo *next; struct sockaddr_in6 *sock_in6 = (struct sockaddr_in6 *)client->ai_list->ai_addr; int ntohsi = ntohs(sock_in6->sin6_port); BC_ASSERT_EQUAL(ntohsi, SIP_PORT, int, "%d"); /*the IPv6 address shall return first, and must be a real ipv6 address*/ BC_ASSERT_EQUAL(client->ai_list->ai_family,AF_INET6,int,"%d"); BC_ASSERT_FALSE(IN6_IS_ADDR_V4MAPPED(&sock_in6->sin6_addr)); ai = bctbx_ip_address_to_addrinfo(AF_INET6, SOCK_STREAM, IPV6_SIP_IP, SIP_PORT); BC_ASSERT_PTR_NOT_NULL(ai); if (ai) { struct in6_addr *ipv6_address = &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr; int i; for (i = 0; i < 8; i++) { BC_ASSERT_EQUAL(sock_in6->sin6_addr.s6_addr[i], ipv6_address->s6_addr[i], int, "%d"); } bctbx_freeaddrinfo(ai); } next=client->ai_list->ai_next; BC_ASSERT_PTR_NOT_NULL(next); if (next){ int ntohsi = ntohs(sock_in6->sin6_port); sock_in6 = (struct sockaddr_in6 *)next->ai_addr; BC_ASSERT_EQUAL(next->ai_family,AF_INET6,int,"%d"); BC_ASSERT_TRUE(IN6_IS_ADDR_V4MAPPED(&sock_in6->sin6_addr)); BC_ASSERT_EQUAL(ntohsi, SIP_PORT, int, "%d"); ai = bctbx_ip_address_to_addrinfo(AF_INET6, SOCK_STREAM, IPV6_SIP_IPV4, SIP_PORT); BC_ASSERT_PTR_NOT_NULL(ai); if (ai) { struct in6_addr *ipv6_address = &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr; int i; for (i = 0; i < 8; i++) { BC_ASSERT_EQUAL(sock_in6->sin6_addr.s6_addr[i], ipv6_address->s6_addr[i], int, "%d"); } bctbx_freeaddrinfo(ai); } } } destroy_endpoint(client); }
/************************************************************************* * * FUNCTION * * mcapi_create_endpoint * * DESCRIPTION * * API routine to create an endpoint on the local node. If the port * ID field is set to MCAPI_PORT_ANY, an endpoint will be created using * the next available port in the system. * * INPUTS * * port_id The port ID of the endpoint, or MCAPI_PORT_ANY * to create an endpoint with the next available * port ID. * *mcapi_status A pointer to memory that will be filled in * with the status of the call. * * OUTPUTS * * The newly created endpoint. * *************************************************************************/ mcapi_endpoint_t mcapi_create_endpoint(mcapi_port_t port_id, mcapi_status_t *mcapi_status) { mcapi_endpoint_t endpoint = 0; MCAPI_GLOBAL_DATA *node_data; MCAPI_NODE *node_ptr = MCAPI_NULL; int node_idx; /* Ensure mcapi_status is valid. */ if (mcapi_status) { /* Ensure the port ID is only 16-bits in length. */ if ( (port_id == (unsigned int)MCAPI_PORT_ANY) || (port_id <= 65535) ) { //#if defined(__ALI_LINUX__) /* Get the lock. */ mcapi_lock_node_data(); //#endif /* Get a pointer to the global node list. */ node_data = mcapi_get_node_data(); /* Get a pointer to the local node. */ node_idx = mcapi_find_node(MCAPI_Node_ID, node_data); /* If the node has been initialized. */ if (node_idx != -1) { /* Get a pointer to the node structure. */ node_ptr = &node_data->mcapi_node_list[node_idx]; /* Create the endpoint. */ endpoint = create_endpoint(node_ptr, port_id, mcapi_status); } /* The node has not been initialized. */ else { *mcapi_status = MCAPI_ERR_NODE_NOTINIT; } //#if defined(__ALI_LINUX__) /* Release the lock. */ mcapi_unlock_node_data(); //#endif } /* Ports can be only 16-bits in length. */ else { *mcapi_status = MCAPI_ERR_PORT_INVALID; } } return (endpoint); }
/* IPv4 A query send failure */ static void ipv4_a_query_send_failure(void) { endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); belle_sip_stack_set_resolver_send_error(client->stack, -1); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_EQUAL(client->resolver_ctx, NULL); belle_sip_stack_set_resolver_send_error(client->stack, 0); destroy_endpoint(client); }
int main(int argc, char * argv[]) { pid_t our_pid = getpid(); char * endp_name = create_endp_name(); char * endp_path = create_endp_path(endp_name); int endp = create_endpoint(endp_path); if (endp >= 0) { struct request * r = create_request(READ, ROOT_STATUS, endp_name); int ret = send_message(endp, "early-boot-arbit", 16, r, sizeof(*r)); if (ret > 0) { unsigned char data[4096]; ret = read(endp, data, 4096); if (ret < 0) { fprintf(stderr, "boot-wrapper %d: read for reply failed: %s\n", our_pid, strerror(errno)); } } else { fprintf(stderr, "boot-wrapper %d: send_message failed\n", our_pid); } close(endp); unlink(endp_path); free(endp_name); free(endp_path); if (ret > 0) { execv(argv[1], &argv[2]); exit(1); } exit(2); } if (endp < 0) { fprintf(stderr, "endp is %d\n", endp); if (endp == -1) exit(13); else if (endp == -2) exit(14); else if (endp == -3) exit(15); else if (endp == -4) exit(16); else exit(17); } }
/* IPv4 A query timeout */ static void ipv4_a_query_timeout(void) { endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); belle_sip_stack_set_dns_timeout(client->stack, 0); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, "toto.com", SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, 2000)); CU_ASSERT_PTR_EQUAL(client->ai_list, NULL); CU_ASSERT_EQUAL(client->resolve_ko,1); destroy_endpoint(client); }
/* Successful IPv4 A query with no result */ static void ipv4_a_query_no_result(void) { int timeout; endpoint_t *client = create_endpoint(); if (!BC_ASSERT_PTR_NOT_NULL(client)) return; timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_BAD_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); BC_ASSERT_PTR_NOT_NULL(client->resolver_ctx); BC_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); BC_ASSERT_PTR_EQUAL(client->ai_list, NULL); destroy_endpoint(client); }
/* Successful SRV + A or AAAA queries */ static void srv_a_query(void) { int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve(client->stack, "udp", SRV_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); destroy_endpoint(client); }
/* Successful SRV query */ static void srv_query(void) { int timeout; endpoint_t *client = create_endpoint(); if (!BC_ASSERT_PTR_NOT_NULL(client)) return; timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_srv(client->stack, "udp", SRV_DOMAIN, srv_resolve_done, client); BC_ASSERT_PTR_NOT_NULL(client->resolver_ctx); BC_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); BC_ASSERT_PTR_NOT_NULL(client->srv_list); BC_ASSERT_NOT_EQUAL(belle_sip_list_size(client->srv_list), 0,int,"%d"); if (client->srv_list && (belle_sip_list_size(client->srv_list) > 0)) { belle_sip_dns_srv_t *result_srv = belle_sip_list_nth_data(client->srv_list, 0); BC_ASSERT_EQUAL(belle_sip_dns_srv_get_port(result_srv), SIP_PORT, int, "%d"); }
static void local_full_query(void) { int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve(client->stack, "tcp", "localhost", SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_PTR_NOT_NULL(client->resolver_ctx); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); } destroy_endpoint(client); }
/* Successful IPv4 A query with multiple results */ static void ipv4_a_query_multiple_results(void) { int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_MULTIRES_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { CU_ASSERT_PTR_NOT_NULL(client->ai_list->ai_next); } destroy_endpoint(client); }
static void ipv4_a_query_with_v4mapped_results(void) { int timeout; endpoint_t *client; if (!belle_sip_tester_ipv6_available()){ belle_sip_warning("Test skipped, IPv6 connectivity not available."); return; } client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_DOMAIN, SIP_PORT, AF_INET6, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_NULL(client->ai_list); destroy_endpoint(client); }
/* No query needed because already resolved */ static void no_query_needed(void) { struct addrinfo *ai; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); client->resolver_ctx = belle_sip_stack_resolve(client->stack, "udp", IPV4_SIP_IP, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(client->resolve_done); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); ai = belle_sip_ip_address_to_addrinfo(AF_INET, IPV4_SIP_IP, SIP_PORT); if (ai) { CU_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr); belle_sip_freeaddrinfo(ai); } } destroy_endpoint(client); }
static void local_query(void) { int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, "localhost", SIP_PORT, AF_INET, a_resolve_done, client); // A DNS query is needed on Windows platform #ifdef WIN32 CU_ASSERT_PTR_NOT_EQUAL(client->resolver_ctx, NULL); #else CU_ASSERT_PTR_EQUAL(client->resolver_ctx, NULL); #endif CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); } destroy_endpoint(client); }
/* Successful SRV query with no result + A query */ static void srv_a_query_no_srv_result(void) { struct addrinfo *ai; int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve(client->stack, "udp", IPV4_SIP_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); ai = belle_sip_ip_address_to_addrinfo(AF_INET, IPV4_SIP_IP, SIP_PORT); if (ai) { CU_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr); belle_sip_freeaddrinfo(ai); } } destroy_endpoint(client); }
/*This tests the recursion of dns.c*/ static void ipv4_cname_a_query(void) { struct addrinfo *ai; int timeout; endpoint_t *client = create_endpoint(); if (!BC_ASSERT_PTR_NOT_NULL(client)) return; timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_CNAME, SIP_PORT, AF_INET, a_resolve_done, client); BC_ASSERT_PTR_NOT_NULL(client->resolver_ctx); BC_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); BC_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; int ntohsi = (int)ntohs(sock_in->sin_port); BC_ASSERT_EQUAL(ntohsi, SIP_PORT, int, "%d"); ai = bctbx_ip_address_to_addrinfo(AF_INET, SOCK_STREAM, IPV4_CNAME_IP, SIP_PORT); if (ai) { BC_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr, int, "%d"); bctbx_freeaddrinfo(ai); } } destroy_endpoint(client); }
int mca_btl_portals4_add_procs(struct mca_btl_base_module_t* btl_base, size_t nprocs, struct opal_proc_t **procs, struct mca_btl_base_endpoint_t** btl_peer_data, opal_bitmap_t* reachable) { struct mca_btl_portals4_module_t* portals4_btl = (struct mca_btl_portals4_module_t*) btl_base; int ret; size_t i; opal_output_verbose(50, opal_btl_base_framework.framework_output, "mca_btl_portals4_add_procs: Adding %d procs (%d) for NI %d", (int) nprocs, (int) portals4_btl->portals_num_procs, portals4_btl->interface_num); /* * The PML handed us a list of procs that need Portals4 * peer info. Complete those procs here. */ for (i = 0 ; i < nprocs ; ++i) { struct opal_proc_t *curr_proc = procs[i]; /* portals doesn't support heterogeneous yet... */ if (opal_proc_local_get()->proc_arch != curr_proc->proc_arch) { opal_output_verbose(1, opal_btl_base_framework.framework_output, "Portals 4 BTL does not support heterogeneous operations."); opal_output_verbose(1, opal_btl_base_framework.framework_output, "Proc %s architecture %x, mine %x.", OPAL_NAME_PRINT(curr_proc->proc_name), curr_proc->proc_arch, opal_proc_local_get()->proc_arch); return OPAL_ERR_NOT_SUPPORTED; } ret = create_endpoint(portals4_btl->interface_num, curr_proc, &btl_peer_data[i]); OPAL_THREAD_ADD_FETCH32(&portals4_btl->portals_num_procs, 1); /* and here we can reach */ opal_bitmap_set_bit(reachable, i); OPAL_OUTPUT_VERBOSE((90, opal_btl_base_framework.framework_output, "add_procs: rank=%lx nid=%x pid=%x for NI %d", i, btl_peer_data[i]->ptl_proc.phys.nid, btl_peer_data[i]->ptl_proc.phys.pid, portals4_btl->interface_num)); } if (mca_btl_portals4_component.need_init && portals4_btl->portals_num_procs > 0) { if (mca_btl_portals4_component.use_logical) { ret = create_maptable(portals4_btl, nprocs, procs, btl_peer_data); if (OPAL_SUCCESS != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, "%s:%d: mca_btl_portals4_add_procs::create_maptable() failed: %d\n", __FILE__, __LINE__, ret); return ret; } } ret = btl_portals4_init_interface(); if (OPAL_SUCCESS != ret) { opal_output_verbose(1, opal_btl_base_framework.framework_output, "%s:%d: portals4 interface initialization failed: %d", __FILE__, __LINE__, ret); return ret; } mca_btl_portals4_component.need_init = 0; } return OPAL_SUCCESS; }
int launch_control_proc(struct passwd * pwd, char * socket_path, struct sockaddr_un * u, socklen_t * l, pid_t * p) { int endp = -1; pid_t child_pid = fork(); *p = child_pid; if (child_pid) { if (pwd) { fprintf(stderr, "dropping privs\n"); setuid(pwd->pw_uid); setgid(pwd->pw_gid); } endp = create_endpoint(socket_path); if (endp < 0) return -1; struct sockaddr_un ctl_sock; memset(&ctl_sock, 0, sizeof(ctl_sock)); socklen_t ctl_socklen = sizeof(ctl_sock); size_t len = 4096; unsigned char data[4096]; alarm(1); int ret = recvfrom(endp, data, len, 0, (struct sockaddr *)&ctl_sock, &ctl_socklen); if (ret < 0) { if (EINTR == errno) { if (SIGALRM == signum) { fprintf(stderr, "test_procman: recvfrom timed out\n"); } else if (SIGCHLD == signum) { int status; pid_t p = wait(&status); if (WIFEXITED(status)) fprintf(stderr, "child %d exited with %d\n", p, WEXITSTATUS(status)); else if (WIFSIGNALED(status)) fprintf(stderr, "child %d terminated with signal %d\n", p, WTERMSIG(status)); } } else { fprintf(stderr, "launch_control_proc: recvfrom failed: %s\n", strerror(errno)); sleep(3); } } else { if (ctl_checkin(data, ret)) { if (-1 == sendto(endp, SERVCTL_ACK, 16, 0, (struct sockaddr *)&ctl_sock, ctl_socklen)) fprintf(stderr, "sendto failed: %s\n", strerror(errno)); else fprintf(stderr, "test_procman: sent ack\n"); unsigned char ack_ack[1024]; size_t acklen = 1024; if (-1 == recvfrom(endp, ack_ack, acklen, 0, (struct sockaddr *)&ctl_sock, &ctl_socklen)) { fprintf(stderr, "test_procman: failed to recieve ack ack: %s\n", strerror(errno)); if (EINTR == errno) { fprintf(stderr, "singum %d, %s\n", signum, strsignal(signum)); } } else { fprintf(stderr, "test_procman: recieved ack ack\n"); if (len) { *l = ctl_socklen; if (u) { memcpy(u, &ctl_sock, ctl_socklen); } } } } } } else { char * argv[3]; argv[0] = "servctl"; if (pwd) { argv[1] = pwd->pw_name; argv[2] = 0; } else argv[1] = 0; if (-1 == execv("/lib/process-manager/servctld", argv)) fprintf(stderr, "execv failed: %s\n", strerror(errno)); _exit(4); } return endp; }
static endpoint_t* create_udp_endpoint(int port,belle_sip_listener_callbacks_t* listener_callbacks) { endpoint_t *endpoint=create_endpoint("0.0.0.0",port,"udp",listener_callbacks); CU_ASSERT_PTR_NOT_NULL_FATAL(endpoint->lp); return endpoint; }