Пример #1
0
opal_hwloc_print_buffers_t *opal_hwloc_get_print_buffer(void)
{
    opal_hwloc_print_buffers_t *ptr;
    int ret, i;
    
    if (!fns_init) {
        /* setup the print_args function */
        if (OPAL_SUCCESS != (ret = opal_tsd_key_create(&print_tsd_key, buffer_cleanup))) {
            return NULL;
        }
        fns_init = true;
    }
    
    ret = opal_tsd_getspecific(print_tsd_key, (void**)&ptr);
    if (OPAL_SUCCESS != ret) return NULL;
    
    if (NULL == ptr) {
        ptr = (opal_hwloc_print_buffers_t*)malloc(sizeof(opal_hwloc_print_buffers_t));
        for (i=0; i < OPAL_HWLOC_PRINT_NUM_BUFS; i++) {
            ptr->buffers[i] = (char *) malloc((OPAL_HWLOC_PRINT_MAX_SIZE+1) * sizeof(char));
        }
        ptr->cntr = 0;
        ret = opal_tsd_setspecific(print_tsd_key, (void*)ptr);
    }
    
    return (opal_hwloc_print_buffers_t*) ptr;
}
Пример #2
0
int
opal_net_init(void)
{
    char **args, *arg;
    uint32_t a, b, c, d, bits, addr;
    int i, count, found_bad = 0;

    args = opal_argv_split( opal_net_private_ipv4, ';' );
    if( NULL != args ) {
        count = opal_argv_count(args);
        private_ipv4 = (private_ipv4_t*)malloc( (count + 1) * sizeof(private_ipv4_t));
        if( NULL == private_ipv4 ) {
            opal_output(0, "Unable to allocate memory for the private addresses array" );
            opal_argv_free(args);
            goto do_local_init;
        }
        for( i = 0; i < count; i++ ) {
            arg = args[i];

            (void)sscanf( arg, "%u.%u.%u.%u/%u", &a, &b, &c, &d, &bits );

            if( (a > 255) || (b > 255) || (c > 255) ||
                (d > 255) || (bits > 32) ) {
                if (0 == found_bad) {
                    opal_show_help("help-opal-util.txt",
                                   "malformed net_private_ipv4",
                                   true, args[i]);
                    found_bad = 1;
                }
                continue;
            }
            addr = (a << 24) | (b << 16) | (c << 8) | d;
            private_ipv4[i].addr = htonl(addr);
            private_ipv4[i].netmask_bits = bits;
        }
        private_ipv4[i].addr         = 0;
        private_ipv4[i].netmask_bits = 0;
        opal_argv_free(args);
    }

 do_local_init:
#if OPAL_ENABLE_IPV6
    return opal_tsd_key_create(&hostname_tsd_key, hostname_cleanup);
#else
    return OPAL_SUCCESS;
#endif
}