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.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-05-20 17:54:14 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2004-10-20 05:03:09 +04:00
|
|
|
#include "ompi_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
|
|
|
|
2004-05-26 23:00:47 +04:00
|
|
|
#include "include/constants.h"
|
2004-09-14 18:21:04 +04:00
|
|
|
#include "util/output.h"
|
|
|
|
|
2004-05-20 17:54:14 +04:00
|
|
|
#include "util/sys_info.h"
|
|
|
|
|
2004-05-26 23:11:55 +04:00
|
|
|
ompi_sys_info_t ompi_system_info = {
|
2004-06-29 08:50:40 +04:00
|
|
|
/* .init = */ false,
|
|
|
|
/* .sysname = */ NULL,
|
|
|
|
/* .nodename = */ NULL,
|
|
|
|
/* .release = */ NULL,
|
|
|
|
/* .version = */ NULL,
|
|
|
|
/* .machine = */ NULL,
|
|
|
|
/* .path_sep = */ NULL,
|
|
|
|
/* .user = */ NULL,
|
|
|
|
/* .enviro = */ NULL,
|
|
|
|
/* .suffix = */ NULL};
|
2004-05-26 06:23:01 +04:00
|
|
|
|
2004-06-17 07:26:28 +04:00
|
|
|
int ompi_sys_info(void)
|
2004-05-20 17:54:14 +04:00
|
|
|
{
|
2004-05-21 01:28:59 +04:00
|
|
|
struct utsname sys_info;
|
2004-10-22 20:06:05 +04:00
|
|
|
char *path_name;
|
2004-05-26 06:23:01 +04:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifndef WIN32
|
|
|
|
struct passwd *pwdent;
|
|
|
|
char sep[2];
|
|
|
|
#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
|
|
|
|
|
|
|
|
if (ompi_system_info.init) {
|
2004-06-17 07:26:28 +04:00
|
|
|
return OMPI_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 */
|
|
|
|
if (NULL != ompi_system_info.sysname) {
|
|
|
|
free(ompi_system_info.sysname);
|
|
|
|
ompi_system_info.sysname = NULL;
|
|
|
|
}
|
|
|
|
if (NULL != ompi_system_info.nodename) {
|
|
|
|
free(ompi_system_info.nodename);
|
|
|
|
ompi_system_info.nodename = NULL;
|
|
|
|
}
|
|
|
|
if (NULL != ompi_system_info.release) {
|
|
|
|
free(ompi_system_info.release);
|
|
|
|
ompi_system_info.release = NULL;
|
|
|
|
}
|
|
|
|
if (NULL != ompi_system_info.version) {
|
|
|
|
free(ompi_system_info.version);
|
|
|
|
ompi_system_info.version = NULL;
|
|
|
|
}
|
|
|
|
if (NULL != ompi_system_info.machine) {
|
|
|
|
free(ompi_system_info.machine);
|
|
|
|
ompi_system_info.machine = NULL;
|
|
|
|
}
|
2004-06-17 07:26:28 +04:00
|
|
|
return OMPI_ERROR;
|
2004-05-26 06:23:01 +04:00
|
|
|
} else {
|
|
|
|
ompi_system_info.sysname = strdup(sys_info.sysname);
|
|
|
|
ompi_system_info.nodename = strdup(sys_info.nodename);
|
|
|
|
ompi_system_info.release = strdup(sys_info.release);
|
|
|
|
ompi_system_info.version = strdup(sys_info.version);
|
|
|
|
ompi_system_info.machine = strdup(sys_info.machine);
|
2004-05-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifndef WIN32
|
2004-05-26 06:23:01 +04:00
|
|
|
if (NULL != (path_name = getcwd(NULL, 0))) {
|
|
|
|
if (strlen(path_name) > 1) {
|
|
|
|
sep[0] = path_name[strlen(path_name)-strlen(basename(path_name))-1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sep[0] = path_name[0];
|
|
|
|
}
|
|
|
|
sep[1] = '\0';
|
|
|
|
ompi_system_info.path_sep = strdup(sep);
|
2004-05-21 01:28:59 +04:00
|
|
|
}
|
2004-10-22 20:06:05 +04:00
|
|
|
#else
|
|
|
|
/* we can hardcode windows path seperator to be "\" */
|
|
|
|
ompi_system_info.path_sep = strdup(sep);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-05-26 06:23:01 +04:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
|
|
|
|
/* get the name of the user */
|
|
|
|
#ifndef WIN32
|
|
|
|
if ((pwdent = getpwuid(getuid())) != 0) {
|
|
|
|
ompi_system_info.user = strdup(pwdent->pw_name);
|
|
|
|
} else {
|
|
|
|
ompi_system_info.user = strdup("unknown");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (!GetUserName(info_buf, &info_buf_length)) {
|
|
|
|
ompi_system_info.user = strdup("unknown");
|
2004-05-26 06:23:01 +04:00
|
|
|
} else {
|
2004-10-22 20:06:05 +04:00
|
|
|
ompi_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 */
|
2004-05-26 06:23:01 +04:00
|
|
|
ompi_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
|
|
|
|
|
|
|
return(OMPI_SUCCESS);
|
2004-05-20 17:54:14 +04:00
|
|
|
}
|