2004-05-20 17:54:14 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-05-20 17:54:14 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2005-03-14 23:57:21 +03:00
|
|
|
#include "orte_config.h"
|
2004-05-21 01:28:59 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-05-21 01:28:59 +04:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBGEN_H
|
2004-05-21 01:28:59 +04:00
|
|
|
#include <libgen.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-05-26 06:23:01 +04:00
|
|
|
#include <stdlib.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_PWD_H
|
2004-05-26 06:23:01 +04:00
|
|
|
#include <pwd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-05-26 06:23:01 +04:00
|
|
|
#include <sys/stat.h>
|
2004-05-20 17:54:14 +04:00
|
|
|
|
2004-06-17 07:26:28 +04:00
|
|
|
|
2005-03-19 02:40:08 +03:00
|
|
|
#include "include/orte_constants.h"
|
2005-03-29 23:13:28 +04:00
|
|
|
#include "mca/errmgr/errmgr.h"
|
2004-09-14 18:21:04 +04:00
|
|
|
#include "util/output.h"
|
2005-03-29 23:13:28 +04:00
|
|
|
#include "util/printf.h"
|
2005-06-01 23:30:05 +04:00
|
|
|
#include "mca/base/mca_base_param.h"
|
|
|
|
|
2004-09-14 18:21:04 +04:00
|
|
|
|
2004-05-20 17:54:14 +04:00
|
|
|
#include "util/sys_info.h"
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_sys_info_t orte_system_info = {
|
2004-06-29 08:50:40 +04:00
|
|
|
/* .init = */ false,
|
|
|
|
/* .sysname = */ NULL,
|
2005-03-14 23:57:21 +03:00
|
|
|
/* .nodename = */ NULL,
|
2004-06-29 08:50:40 +04:00
|
|
|
/* .release = */ NULL,
|
|
|
|
/* .version = */ NULL,
|
|
|
|
/* .machine = */ NULL,
|
|
|
|
/* .path_sep = */ NULL,
|
|
|
|
/* .user = */ NULL,
|
|
|
|
/* .enviro = */ NULL,
|
|
|
|
/* .suffix = */ NULL};
|
2004-05-26 06:23:01 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
int orte_sys_info(void)
|
2004-05-20 17:54:14 +04:00
|
|
|
{
|
2004-05-21 01:28:59 +04:00
|
|
|
struct utsname sys_info;
|
2005-03-29 23:13:28 +04:00
|
|
|
int uid;
|
2004-05-26 06:23:01 +04:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifndef WIN32
|
|
|
|
struct passwd *pwdent;
|
2005-03-22 03:31:17 +03:00
|
|
|
char *sep = "/";
|
2004-10-22 20:06:05 +04:00
|
|
|
#else
|
|
|
|
#define INFO_BUF_SIZE 32768
|
|
|
|
TCHAR info_buf[INFO_BUF_SIZE];
|
|
|
|
DWORD info_buf_length = INFO_BUF_SIZE;
|
2004-11-02 16:14:34 +03:00
|
|
|
char *sep = "\\";
|
2004-10-22 20:06:05 +04:00
|
|
|
#endif
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_system_info.init) {
|
2005-03-19 02:40:08 +03:00
|
|
|
return ORTE_SUCCESS;
|
2004-05-21 01:28:59 +04:00
|
|
|
}
|
2004-05-26 06:23:01 +04:00
|
|
|
|
|
|
|
if (0 > uname(&sys_info)) { /* have an error - set utsname values to indicate */
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL != orte_system_info.sysname) {
|
|
|
|
free(orte_system_info.sysname);
|
|
|
|
orte_system_info.sysname = NULL;
|
2004-05-26 06:23:01 +04:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL != orte_system_info.nodename) {
|
|
|
|
free(orte_system_info.nodename);
|
|
|
|
orte_system_info.nodename = NULL;
|
2004-05-26 06:23:01 +04:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL != orte_system_info.release) {
|
|
|
|
free(orte_system_info.release);
|
|
|
|
orte_system_info.release = NULL;
|
2004-05-26 06:23:01 +04:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL != orte_system_info.version) {
|
|
|
|
free(orte_system_info.version);
|
|
|
|
orte_system_info.version = NULL;
|
2004-05-26 06:23:01 +04:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
if (NULL != orte_system_info.machine) {
|
|
|
|
free(orte_system_info.machine);
|
|
|
|
orte_system_info.machine = NULL;
|
2004-05-26 06:23:01 +04:00
|
|
|
}
|
2005-03-19 02:40:08 +03:00
|
|
|
return ORTE_ERROR;
|
2004-05-26 06:23:01 +04:00
|
|
|
} else {
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_system_info.sysname = strdup(sys_info.sysname);
|
2005-05-13 01:44:23 +04:00
|
|
|
if (NULL == orte_system_info.nodename) {
|
2005-06-01 23:30:05 +04:00
|
|
|
/* make sure we weren't given a nodename by environment */
|
|
|
|
int id = mca_base_param_register_string("orte", "base", "nodename",
|
|
|
|
NULL, sys_info.nodename);
|
|
|
|
mca_base_param_lookup_string(id, &(orte_system_info.nodename));
|
2005-03-18 06:43:59 +03:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_system_info.release = strdup(sys_info.release);
|
|
|
|
orte_system_info.version = strdup(sys_info.version);
|
|
|
|
orte_system_info.machine = strdup(sys_info.machine);
|
2004-05-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_system_info.path_sep = strdup(sep);
|
2004-05-26 06:23:01 +04:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
/* get the name of the user */
|
|
|
|
#ifndef WIN32
|
2005-03-29 23:13:28 +04:00
|
|
|
uid = getuid();
|
|
|
|
if ((pwdent = getpwuid(uid)) != 0) {
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_system_info.user = strdup(pwdent->pw_name);
|
2004-10-22 20:06:05 +04:00
|
|
|
} else {
|
2005-03-29 23:13:28 +04:00
|
|
|
if (0 > asprintf(&(orte_system_info.user), "%d", uid)) {
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2004-10-22 20:06:05 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (!GetUserName(info_buf, &info_buf_length)) {
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_system_info.user = strdup("unknown");
|
2004-05-26 06:23:01 +04:00
|
|
|
} else {
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_system_info.user = strdup(info_buf);
|
2004-05-21 01:28:59 +04:00
|
|
|
}
|
2004-10-22 20:06:05 +04:00
|
|
|
#endif
|
2004-05-21 01:28:59 +04:00
|
|
|
|
2004-06-29 08:50:40 +04:00
|
|
|
/* set the init flag */
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_system_info.init = true; /* only indicates that we have been through here once - still have to test for NULL values */
|
2004-06-17 07:26:28 +04:00
|
|
|
|
2005-03-19 02:40:08 +03:00
|
|
|
return(ORTE_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int orte_sys_info_finalize(void)
|
|
|
|
{
|
2005-05-22 07:11:33 +04:00
|
|
|
if (NULL != orte_system_info.sysname) {
|
2005-03-19 02:40:08 +03:00
|
|
|
free(orte_system_info.sysname);
|
2005-05-22 07:11:33 +04:00
|
|
|
orte_system_info.sysname = NULL;
|
|
|
|
}
|
2005-03-19 02:40:08 +03:00
|
|
|
|
2005-05-22 07:11:33 +04:00
|
|
|
if (NULL != orte_system_info.nodename) {
|
2005-03-19 02:40:08 +03:00
|
|
|
free(orte_system_info.nodename);
|
2005-05-22 07:11:33 +04:00
|
|
|
orte_system_info.nodename = NULL;
|
|
|
|
}
|
2005-03-19 02:40:08 +03:00
|
|
|
|
2005-05-22 07:11:33 +04:00
|
|
|
if (NULL != orte_system_info.release) {
|
2005-03-19 02:40:08 +03:00
|
|
|
free(orte_system_info.release);
|
2005-05-22 07:11:33 +04:00
|
|
|
orte_system_info.release = NULL;
|
|
|
|
}
|
2005-03-19 02:40:08 +03:00
|
|
|
|
2005-05-22 07:11:33 +04:00
|
|
|
if (NULL != orte_system_info.version) {
|
2005-03-19 02:40:08 +03:00
|
|
|
free(orte_system_info.version);
|
2005-05-22 07:11:33 +04:00
|
|
|
orte_system_info.version = NULL;
|
|
|
|
}
|
2005-03-19 02:40:08 +03:00
|
|
|
|
2005-05-22 07:11:33 +04:00
|
|
|
if (NULL != orte_system_info.machine) {
|
2005-03-19 02:40:08 +03:00
|
|
|
free(orte_system_info.machine);
|
2005-05-22 07:11:33 +04:00
|
|
|
orte_system_info.machine = NULL;
|
|
|
|
}
|
2005-03-19 02:40:08 +03:00
|
|
|
|
2005-05-22 07:11:33 +04:00
|
|
|
if (NULL != orte_system_info.path_sep) {
|
2005-03-19 02:40:08 +03:00
|
|
|
free(orte_system_info.path_sep);
|
2005-05-22 07:11:33 +04:00
|
|
|
orte_system_info.path_sep = NULL;
|
|
|
|
}
|
2005-03-19 02:40:08 +03:00
|
|
|
|
2005-05-22 07:11:33 +04:00
|
|
|
if (NULL != orte_system_info.user) {
|
2005-03-19 02:40:08 +03:00
|
|
|
free(orte_system_info.user);
|
2005-05-22 07:11:33 +04:00
|
|
|
orte_system_info.user = NULL;
|
|
|
|
}
|
2005-03-19 02:40:08 +03:00
|
|
|
|
2005-05-22 07:11:33 +04:00
|
|
|
if (NULL != orte_system_info.enviro) {
|
2005-03-19 02:40:08 +03:00
|
|
|
free(orte_system_info.enviro);
|
2005-05-22 07:11:33 +04:00
|
|
|
orte_system_info.enviro = NULL;
|
|
|
|
}
|
2005-03-19 02:40:08 +03:00
|
|
|
|
2005-05-22 07:11:33 +04:00
|
|
|
if (NULL != orte_system_info.suffix) {
|
2005-03-19 02:40:08 +03:00
|
|
|
free(orte_system_info.suffix);
|
2005-05-22 07:11:33 +04:00
|
|
|
orte_system_info.suffix = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
orte_system_info.init = false;
|
|
|
|
|
2005-03-19 02:40:08 +03:00
|
|
|
return ORTE_SUCCESS;
|
2004-05-20 17:54:14 +04:00
|
|
|
}
|