Esempio n. 1
0
static int __config_init( void )
{
    OSH_ERROR status = OSH_ERR_NONE;
    char temp_buf[1024];
    static int global_test_rc = 0;

    sys_memset(&osh_config, 0, sizeof(osh_config));

    osh_config.active = 0;
    if (gethostname(osh_config.hostname, sizeof(osh_config.hostname)) != 0)
    {
        sys_strcpy(osh_config.hostname, "localhost");
    }
    osh_config.my_pe = INVALID_PE;
    osh_config.num_pe = INVALID_PE;
    osh_config.rc = &global_test_rc; /*NULL*/
    /* 
     * Seed the random-number generator with current time so that
     * the numbers will be different every time we run.
     */
    osh_config.timer = (unsigned int)time( NULL );
    srand( osh_config.timer );

    PE_LIST_SET(DEFAULT_PE, osh_config.exec_mode.log_pe_list);
    osh_config.exec_mode.out_level = LOG_INFO;
    osh_config.exec_mode.out_file = stdout;

    osh_config.exec_mode.log_level = LOG_NONE;
    osh_config.exec_mode.log_file = NULL;
    sys_snprintf_safe(temp_buf, sizeof(temp_buf), "%s_%s_%04d.log", MODULE_NAME, osh_config.hostname, getpid());
    osh_config.exec_mode.log_file_name = sys_strdup(temp_buf);

    return status;
}
Esempio n. 2
0
/**
 * sys_hostdate
 *
 * @brief
 *    Return a string with host date. Should be freed with sys_free().
 *
 * @retval Host date - on success
 * @retval NULL - on failure
 ***************************************************************************/
char *sys_hostdate(void)
{
	char tmp_buf[256];
	char* host_date = NULL;
	time_t t;
	struct tm *tmp;

	sys_memset(tmp_buf, 0, sizeof(tmp_buf));

	t = time(NULL);
	tmp = localtime(&t);
	sys_snprintf_safe( tmp_buf, sizeof(tmp_buf), "%02d.%02d.%04d %02d:%02d:%02d",
			tmp->tm_mday, tmp->tm_mon + 1, tmp->tm_year + 1900,
			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);

	host_date = sys_strdup(tmp_buf);

	return host_date;
}
Esempio n. 3
0
static void _ibprof_conf_mode(char *env)
{
	char *lower_env, *ptr;
	int i;

	i = sys_strlen(env);
	lower_env = sys_strdup(env);

	while (i--)
		lower_env[i] = tolower(env[i]); 

	ptr = sys_strstr(lower_env, "use_ibv");

	if (NULL != ptr) {
		sscanf(ptr, "use_ibv=%d", (int *) enviroment[IBPROF_MODE_IBV]);
	}

	ptr = sys_strstr(lower_env, "use_hcol");
	if (NULL != ptr) {
		sscanf(ptr, "use_hcol=%d", (int *) enviroment[IBPROF_MODE_HCOL]);
	}

	ptr = sys_strstr(lower_env, "use_mxm");
	if (NULL != ptr) {
		sscanf(ptr, "use_mxm=%d", (int *) enviroment[IBPROF_MODE_MXM]);
	}

	ptr = sys_strstr(lower_env, "use_pmix");
	if (NULL != ptr) {
		sscanf(ptr, "use_pmix=%d", (int *) enviroment[IBPROF_MODE_PMIX]);
	}

	ptr = sys_strstr(lower_env, "use_shmem");
	if (NULL != ptr) {
		sscanf(ptr, "use_shmem=%d", (int *) enviroment[IBPROF_MODE_SHMEM]);
	}

	sys_free(lower_env);
}
Esempio n. 4
0
uint8_t *getNetworkInterfaceName(uint32_t interface)
{
    struct ifaddrs *interfaces, *ints;
    uint8_t *name = NULL;
    uint32_t i=0;
    
    interfaces = getNetworkInterfaces();
    ints = interfaces;
    
    if(interfaces == NULL) return NULL;
    
    for(; i < interface; i++)
    {
        if(ints == NULL) break;
        ints = ints->ifa_next;
    }
    
    if(ints != NULL)
    {
        name = sys_strdup((uint8_t *)ints->ifa_name);
    }
    freeNetworkInterfaces(interfaces);
    return name;
}
Esempio n. 5
0
static int __parse_common_opt( const AOPT_OBJECT* opt_obj )
{
    OSH_ERROR status = OSH_ERR_NONE;

    if (opt_obj) 
    {
        if ( !status && aopt_check(opt_obj, 'o') ) 
        {
            const char* optarg = aopt_value(opt_obj, 'o');
            long value = -1;
            if (optarg) 
            {
                errno = 0;
                value = sys_strtol(optarg, NULL, 0);
                if ( !errno && (value >= LOG_NONE) ) 
                {
                    osh_config.exec_mode.out_level = (int)value;
                }
            }
            if ( value == -1 ) 
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }

        if ( !status && aopt_check(opt_obj, 'd') ) 
        {
            const char* optarg = aopt_value(opt_obj, 'd');
            long value = -1;
            if (optarg) 
            {
                errno = 0;
                value = sys_strtol(optarg, NULL, 0);
                if ( !errno && (value >= LOG_NONE) ) 
                {
                    osh_config.exec_mode.log_level = (int)value;
                }
            }
            if ( value == -1 ) 
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }

        if ( !status && aopt_check(opt_obj, 'l') ) 
        {
            const char * optarg = aopt_value(opt_obj, 'l');
            char* value = NULL;
            if (optarg) 
            {
                value = sys_strdup(optarg);
                if ( value )
                {
                    if (osh_config.exec_mode.log_file_name)
                    {
                        sys_free(osh_config.exec_mode.log_file_name);
                    }
                    osh_config.exec_mode.log_file_name = value;
                }
            }
            if ( !value )
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }

        if ( !status && aopt_check(opt_obj, 'p') ) 
        {
            const char* optarg = aopt_value(opt_obj, 'p');
            unsigned long long value = 0;
            if (optarg) 
            {
                if (!sys_strcmp(optarg, "all"))
                {
                    value = INVALID_PE;
                }
                else
                {
                    value = set_pe_list(optarg);
                }
                osh_config.exec_mode.log_pe_list = value;
            }
            if ( !value ) 
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }
    }

    return status;
}