2004-05-20 17:54:14 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-08-23 07:32:36 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. 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>
|
2007-04-01 20:16:54 +04:00
|
|
|
#endif /* HAVE_UNISTD_H */
|
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>
|
2007-04-01 20:16:54 +04:00
|
|
|
#endif /* HAVE_PWD_H */
|
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-08-13 00:46:25 +04:00
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
2005-07-04 03:31:27 +04:00
|
|
|
#include "opal/util/output.h"
|
2005-07-04 06:16:57 +04:00
|
|
|
#include "opal/util/printf.h"
|
2005-08-13 00:46:25 +04:00
|
|
|
#include "opal/mca/base/mca_base_param.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "orte/orte_constants.h"
|
2005-06-01 23:30:05 +04:00
|
|
|
|
2004-09-14 18:21:04 +04:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "orte/util/sys_info.h"
|
2004-05-20 17:54:14 +04:00
|
|
|
|
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,
|
|
|
|
/* .user = */ 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;
|
2004-05-26 06:23:01 +04:00
|
|
|
|
2005-12-12 23:04:00 +03:00
|
|
|
#ifndef __WINDOWS__
|
2006-08-23 07:32:36 +04:00
|
|
|
int uid;
|
2004-10-22 20:06:05 +04:00
|
|
|
struct passwd *pwdent;
|
|
|
|
#else
|
2006-08-23 07:32:36 +04:00
|
|
|
#define INFO_BUF_SIZE 256
|
2004-10-22 20:06:05 +04:00
|
|
|
TCHAR info_buf[INFO_BUF_SIZE];
|
|
|
|
DWORD info_buf_length = INFO_BUF_SIZE;
|
|
|
|
#endif
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (orte_system_info.init) {
|
2006-08-23 07:32:36 +04: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-07-14 08:11:59 +04:00
|
|
|
if (NULL != orte_system_info.sysname) {
|
2005-03-14 23:57:21 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
/* get the name of the user */
|
2005-12-12 23:04:00 +03:00
|
|
|
#ifndef __WINDOWS__
|
2005-03-29 23:13:28 +04:00
|
|
|
uid = getuid();
|
2005-07-14 08:11:59 +04:00
|
|
|
#ifdef HAVE_GETPWUID
|
|
|
|
pwdent = getpwuid(uid);
|
|
|
|
#else
|
|
|
|
pwdent = NULL;
|
|
|
|
#endif
|
|
|
|
if (NULL != pwdent) {
|
2005-07-02 18:41:58 +04:00
|
|
|
orte_system_info.user = strdup(pwdent->pw_name);
|
2004-10-22 20:06:05 +04:00
|
|
|
} else {
|
2005-07-02 18:41:58 +04:00
|
|
|
if (0 > asprintf(&(orte_system_info.user), "%d", uid)) {
|
2005-03-29 23:13:28 +04:00
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
2005-07-02 18:41:58 +04:00
|
|
|
}
|
2004-10-22 20:06:05 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (!GetUserName(info_buf, &info_buf_length)) {
|
2005-07-02 18:41:58 +04:00
|
|
|
orte_system_info.user = strdup("unknown");
|
2004-05-26 06:23:01 +04:00
|
|
|
} else {
|
2005-07-02 18:41:58 +04: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.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.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
|
|
|
}
|