1
1

Merge pull request #7200 from cpshereda/master-opal_gethostname-change

Fix unsafe use of gethostname()
Этот коммит содержится в:
Jeff Squyres 2020-01-13 16:07:43 -05:00 коммит произвёл GitHub
родитель 887400c878 cbc6feaab2
Коммит 25931ea8bf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
40 изменённых файлов: 385 добавлений и 153 удалений

Просмотреть файл

@ -17,6 +17,8 @@
* Copyright (c) 2015-2018 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -40,6 +42,7 @@
#endif
#include <assert.h>
#include "opal/runtime/opal.h"
#include "opal/util/argv.h"
#include "opal/util/opal_getcwd.h"
#include "opal/util/output.h"
@ -82,7 +85,7 @@ opal_pointer_array_t ompi_info_f_to_c_table = {{0}};
*/
int ompi_mpiinfo_init(void)
{
char val[OPAL_MAXHOSTNAMELEN];
const char *val;
char *cptr;
/* initialize table */
@ -121,7 +124,7 @@ int ompi_mpiinfo_init(void)
}
/* local host name */
gethostname(val, sizeof(val));
val = opal_gethostname();
opal_info_set(&ompi_mpi_info_env.info.super, "host", val);
/* architecture name */

Просмотреть файл

@ -10,6 +10,7 @@
* Copyright (c) 2017-2018 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -26,6 +27,7 @@
#include <opal/class/opal_hash_table.h>
#include <opal/util/output.h>
#include "opal/util/printf.h"
#include "opal/runtime/opal.h"
#include <math.h>
#if SIZEOF_LONG_LONG == SIZEOF_SIZE_T
@ -213,11 +215,11 @@ int mca_common_monitoring_init( void )
if( !mca_common_monitoring_enabled ) return OMPI_ERROR;
if( 1 < opal_atomic_add_fetch_32(&mca_common_monitoring_hold, 1) ) return OMPI_SUCCESS; /* Already initialized */
char hostname[OPAL_MAXHOSTNAMELEN] = "NA";
const char *hostname;
/* Initialize constant */
log10_2 = log10(2.);
/* Open the opal_output stream */
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
opal_asprintf(&mca_common_monitoring_output_stream_obj.lds_prefix,
"[%s:%06d] monitoring: ", hostname, getpid());
mca_common_monitoring_output_stream_id =

Просмотреть файл

@ -3,6 +3,8 @@
* All rights reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -12,6 +14,7 @@
#include "ompi_config.h"
#include "opal/runtime/opal.h"
#include "opal/util/output.h"
#include "opal/util/printf.h"
@ -24,7 +27,7 @@
int ompi_pml_v_output_open(char *output, int verbosity) {
opal_output_stream_t lds;
char hostname[OPAL_MAXHOSTNAMELEN] = "NA";
const char *hostname;
OBJ_CONSTRUCT(&lds, opal_output_stream_t);
if(!output) {
@ -43,7 +46,7 @@ int ompi_pml_v_output_open(char *output, int verbosity) {
lds.lds_file_suffix = output;
}
lds.lds_is_debugging = true;
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
opal_asprintf(&lds.lds_prefix, "[%s:%05d] pml_v: ", hostname, getpid());
lds.lds_verbose_level = verbosity;
mca_pml_v.output = opal_output_open(&lds);

Просмотреть файл

@ -19,6 +19,8 @@
* Copyright (c) 2015 Mellanox Technologies, Inc.
* All rights reserved.
* Copyright (c) 2017 FUJITSU LIMITED. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -42,6 +44,7 @@
#endif
#include <errno.h>
#include "opal/runtime/opal.h"
#include "opal/mca/backtrace/backtrace.h"
#include "opal/util/error.h"
#include "opal/runtime/opal_params.h"
@ -121,7 +124,7 @@ int
ompi_mpi_abort(struct ompi_communicator_t* comm,
int errcode)
{
char *host, hostname[OPAL_MAXHOSTNAMELEN];
const char *host;
pid_t pid = 0;
/* Protection for recursive invocation */
@ -131,12 +134,11 @@ ompi_mpi_abort(struct ompi_communicator_t* comm,
have_been_invoked = true;
/* If MPI is initialized, we know we have a runtime nodename, so
use that. Otherwise, call gethostname. */
use that. Otherwise, call opal_gethostname. */
if (ompi_rte_initialized) {
host = ompi_process_info.nodename;
} else {
gethostname(hostname, sizeof(hostname));
host = hostname;
host = opal_gethostname();
}
pid = getpid();

Просмотреть файл

@ -21,6 +21,8 @@
* and Technology (RIST). All rights reserved.
*
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -119,9 +121,9 @@ int ompi_mpi_finalize(void)
/* Note that if we're not initialized or already finalized, we
cannot raise an MPI exception. The best that we can do is
write something to stderr. */
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
pid_t pid = getpid();
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
if (state < OMPI_MPI_STATE_INIT_COMPLETED) {
opal_show_help("help-mpi-runtime.txt",

Просмотреть файл

@ -1,6 +1,8 @@
/*
* Copyright (C) 2014 Artem Polyakov <artpol84@gmail.com>
* Copyright (c) 2014-2017 Intel, Inc. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -9,6 +11,7 @@
*/
#include "opal_config.h"
#include "opal/runtime/opal.h"
#include <stdio.h>
#include <mpi.h>
@ -77,7 +80,8 @@ int main(int argc, char **argv)
int rank, commsize;
double offs = 0, rtt = 0;
char hname[OPAL_MAXHOSTNAMELEN];
const char *local_hname;
MPI_Comm_rank(comm, &rank);
MPI_Comm_size(comm, &commsize);
@ -99,11 +103,20 @@ int main(int argc, char **argv)
MPI_Finalize();
exit(1);
}
/* All error checking for getting the hostname is done with the initial
populating of opal_process_info.nodename inside opal/runtime/opal_init.c */
local_hname = opal_gethostname();
if( gethostname(hname, sizeof(hname)) ){
perror("Cannot get hostname. Abort");
MPI_Abort(MPI_COMM_WORLD, 1);
}
/* Truncate hostname if it is longer than OPAL_MAXHOSTNAMELEN,
since we are only reading that length with the MPI_Gather.
If full and complete hostnames are necessary in all cases,
this could be implemented with MPI_Gatherv rather than
MPI_Gather, instead of using the longer but more
accurate OPAL_LOCAL_MAXHOSTNAMELEN value, because for very
large task counts there is a risk of running out of memory
if OPAL_LOCAL_MAXHOSTNAMELEN is used. */
strncpy(hname, local_hname, OPAL_MAXHOSTNAMELEN - 1);
hname[OPAL_MAXHOSTNAMELEN - 1] = '\0';
int rc = hpctimer_initialize("gettimeofday");

Просмотреть файл

@ -301,6 +301,12 @@
#define OPAL_MAXHOSTNAMELEN (255 + 1)
#endif
#define OPAL_LOCAL_MAXHOSTNAMELEN 4096
#if (OPAL_MAXHOSTNAMELEN > OPAL_LOCAL_MAXHOSTNAMELEN)
#define OPAL_LOCAL_MAXHOSTNAMELEN OPAL_MAXHOSTNAMELEN
#endif
/*
* Do we want memory debugging?
*

Просмотреть файл

@ -16,6 +16,8 @@
* and Technology (RIST). All rights reserved.
* Copyright (c) 2014-2015 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -45,6 +47,7 @@
#include <netdb.h>
#endif
#include "opal/runtime/opal.h"
#include "opal/mca/installdirs/installdirs.h"
#include "opal/util/opal_environ.h"
#include "opal/util/output.h"
@ -330,8 +333,8 @@ static int component_find_check (mca_base_framework_t *framework, char **request
}
if (!found) {
char h[OPAL_MAXHOSTNAMELEN];
gethostname(h, sizeof(h));
const char *h;
h = opal_gethostname();
opal_show_help("help-mca-base.txt",
"find-available:not-valid", true,
h, framework->framework_name, requested_component_names[i]);

Просмотреть файл

@ -15,7 +15,7 @@
* reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
* Copyright (c) 2018 Triad National Security, LLC. All rights
* Copyright (c) 2018-2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
@ -73,7 +73,7 @@ int mca_base_open(void)
{
char *value;
opal_output_stream_t lds;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
int var_id;
if (mca_base_opened++) {
@ -159,7 +159,7 @@ int mca_base_open(void)
} else {
set_defaults(&lds);
}
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
opal_asprintf(&lds.lds_prefix, "[%s:%05d] ", hostname, getpid());
opal_output_reopen(0, &lds);
opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, 0, "mca: base: opening components");

Просмотреть файл

@ -3,6 +3,8 @@
* Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights
* reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -45,6 +47,7 @@
#include <ifaddrs.h>
#endif
#include "opal/runtime/opal.h"
#include "opal/constants.h"
#include "opal/util/if.h"
#include "opal/util/output.h"
@ -127,8 +130,8 @@ static int if_linux_ipv6_open(void)
opal_if_t *intf;
if (!hexdecode(addrhex, a6.s6_addr, sizeof a6.s6_addr)) {
char hostname[OPAL_MAXHOSTNAMELEN];
gethostname(hostname, sizeof(hostname));
const char *hostname;
hostname = opal_gethostname();
opal_show_help("help-opal-if-linux-ipv6.txt",
"fail to parse if_inet6", true,
hostname, ifname, addrhex);

Просмотреть файл

@ -11,6 +11,8 @@
* All rights reserved.
* Copyright (c) 2007-2011 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
*
* $COPYRIGHT$
*
@ -30,6 +32,7 @@
#include <sys/time.h>
#endif
#include "opal/runtime/opal.h"
#include "opal/mca/pstat/pstat.h"
#include "opal/mca/pstat/base/base.h"
#include "opal/util/string_copy.h"
@ -66,7 +69,7 @@ static int query(pid_t pid,
opal_node_stats_t *nstats)
{
double dtime;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
if (NULL != stats) {
/* record the time of this sample */
@ -84,7 +87,7 @@ static int query(pid_t pid,
}
if (NULL != stats) {
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
opal_string_copy(stats->node, hostname, OPAL_PSTAT_MAX_STRING_LEN);
stats->pid = pid;

Просмотреть файл

@ -15,6 +15,8 @@
* Copyright (c) 2010-2014 Los Alamos National Security, LLC.
* All rights reserved.
* Copyright (c) 2016 University of Houston. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
*
* $COPYRIGHT$
*
@ -47,6 +49,7 @@
#include <sys/stat.h>
#endif /* HAVE_SYS_STAT_H */
#include "opal/runtime/opal.h"
#include "opal_stdint.h"
#include "opal/constants.h"
#include "opal/util/alfg.h"
@ -366,8 +369,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
* a network filesystem, the user may see a shared memory performance hit.
*/
if (opal_shmem_mmap_nfs_warning && opal_path_nfs(real_file_name, NULL)) {
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "mmap on nfs", 1, hn,
real_file_name);
}
@ -382,8 +385,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
goto out;
}
if (!space_available) {
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
rc = OPAL_ERR_OUT_OF_RESOURCE;
opal_show_help("help-opal-shmem-mmap.txt", "target full", 1,
real_file_name, hn, (unsigned long)real_size,
@ -393,8 +396,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
/* enough space is available, so create the segment */
if (-1 == (ds_buf->seg_id = open(real_file_name, O_CREAT | O_RDWR, 0600))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn,
"open(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -403,8 +406,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
/* size backing file - note the use of real_size here */
if (0 != ftruncate(ds_buf->seg_id, real_size)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn,
"ftruncate(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -415,8 +418,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
PROT_READ | PROT_WRITE, MAP_SHARED,
ds_buf->seg_id, 0))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn,
"mmap(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -462,8 +465,8 @@ out:
if (-1 != ds_buf->seg_id) {
if (0 != close(ds_buf->seg_id)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn,
"close(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -495,8 +498,8 @@ segment_attach(opal_shmem_ds_t *ds_buf)
if (my_pid != ds_buf->seg_cpid) {
if (-1 == (ds_buf->seg_id = open(ds_buf->seg_name, O_RDWR))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn,
"open(2)", "", strerror(err), err);
return NULL;
@ -506,8 +509,8 @@ segment_attach(opal_shmem_ds_t *ds_buf)
PROT_READ | PROT_WRITE, MAP_SHARED,
ds_buf->seg_id, 0))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn,
"mmap(2)", "", strerror(err), err);
/* mmap failed, so close the file and return NULL - no error check
@ -522,8 +525,8 @@ segment_attach(opal_shmem_ds_t *ds_buf)
*/
if (0 != close(ds_buf->seg_id)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1,
hn, "close(2)", "", strerror(err), err);
}
@ -562,8 +565,8 @@ segment_detach(opal_shmem_ds_t *ds_buf)
if (0 != munmap((void *)ds_buf->seg_base_addr, ds_buf->seg_size)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn,
"munmap(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -590,8 +593,8 @@ segment_unlink(opal_shmem_ds_t *ds_buf)
if (-1 == unlink(ds_buf->seg_name)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn,
"unlink(2)", ds_buf->seg_name, strerror(err), err);
return OPAL_ERROR;

Просмотреть файл

@ -15,6 +15,8 @@
* All rights reserved.
* Copyright (c) 2011 NVIDIA Corporation. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
*
* $COPYRIGHT$
*
@ -49,6 +51,7 @@
#include <netdb.h>
#endif /* HAVE_NETDB_H */
#include "opal/runtime/opal.h"
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "opal/mca/shmem/base/base.h"
@ -88,8 +91,8 @@ shmem_posix_shm_open(char *posix_file_name_buff, size_t size)
* of here. we can't be selected :-(.
*/
else {
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_output_verbose(10, opal_shmem_base_framework.framework_output,
"shmem_posix_shm_open: disqualifying posix because "
"shm_open(2) failed with error: %s (errno %d)\n",

Просмотреть файл

@ -15,6 +15,8 @@
* All rights reserved.
* Copyright (c) 2011 NVIDIA Corporation. All rights reserved.
* Copyright (c) 2016 Intel, Inc. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -43,6 +45,7 @@
#include <netdb.h>
#endif /* HAVE_NETDB_H */
#include "opal/runtime/opal.h"
#include "opal/constants.h"
#include "opal/util/show_help.h"
#include "opal/util/output.h"
@ -178,8 +181,8 @@ posix_runtime_query(mca_base_module_t **module,
/* free up allocated resources before we return */
if (0 != shm_unlink(tmp_buff)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1,
hn, "shm_unlink(2)", "", strerror(err), err);
/* something strange happened, so consider this a run-time test

Просмотреть файл

@ -14,6 +14,8 @@
* Copyright (c) 2010-2012 Los Alamos National Security, LLC.
* All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -47,6 +49,7 @@
#include <netdb.h>
#endif /* HAVE_NETDB_H */
#include "opal/runtime/opal.h"
#include "opal/constants.h"
#include "opal_stdint.h"
#include "opal/util/output.h"
@ -203,8 +206,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
/* size backing file - note the use of real_size here */
else if (0 != ftruncate(ds_buf->seg_id, real_size)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn,
"ftruncate(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -214,8 +217,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
PROT_READ | PROT_WRITE, MAP_SHARED,
ds_buf->seg_id, 0))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn,
"mmap(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -265,8 +268,8 @@ out:
if (-1 != ds_buf->seg_id) {
if (0 != close(ds_buf->seg_id)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1, hn,
"close(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -304,8 +307,8 @@ segment_attach(opal_shmem_ds_t *ds_buf)
if (my_pid != ds_buf->seg_cpid) {
if (-1 == (ds_buf->seg_id = shm_open(ds_buf->seg_name, O_RDWR, 0600))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn,
"open(2)", "", strerror(err), err);
return NULL;
@ -315,8 +318,8 @@ segment_attach(opal_shmem_ds_t *ds_buf)
PROT_READ | PROT_WRITE, MAP_SHARED,
ds_buf->seg_id, 0))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn,
"mmap(2)", "", strerror(err), err);
/* mmap failed, so shm_unlink and return NULL - no error check here
@ -332,8 +335,8 @@ segment_attach(opal_shmem_ds_t *ds_buf)
*/
if (0 != close(ds_buf->seg_id)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-mmap.txt", "sys call fail", 1,
hn, "close(2)", "", strerror(err), err);
}
@ -373,8 +376,8 @@ segment_detach(opal_shmem_ds_t *ds_buf)
if (0 != munmap((void*)ds_buf->seg_base_addr, ds_buf->seg_size)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn,
"munmap(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -401,8 +404,8 @@ segment_unlink(opal_shmem_ds_t *ds_buf)
if (-1 == shm_unlink(ds_buf->seg_name)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-posix.txt", "sys call fail", 1, hn,
"shm_unlink(2)", ds_buf->seg_name, strerror(err), err);
return OPAL_ERROR;

Просмотреть файл

@ -13,6 +13,8 @@
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2010-2012 Los Alamos National Security, LLC.
* All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
*
* $COPYRIGHT$
*
@ -50,6 +52,7 @@
#include <netdb.h>
#endif /* HAVE_NETDB_H */
#include "opal/runtime/opal.h"
#include "opal/constants.h"
#include "opal_stdint.h"
#include "opal/util/output.h"
@ -195,8 +198,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
if (-1 == (ds_buf->seg_id = shmget(IPC_PRIVATE, real_size,
IPC_CREAT | IPC_EXCL | S_IRWXU))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn,
"shmget(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -205,8 +208,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
/* attach to the sement */
else if ((void *)-1 == (seg_hdrp = shmat(ds_buf->seg_id, NULL, 0))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn,
"shmat(2)", "", strerror(err), err);
shmctl(ds_buf->seg_id, IPC_RMID, NULL);
@ -219,8 +222,8 @@ segment_create(opal_shmem_ds_t *ds_buf,
*/
else if (0 != shmctl(ds_buf->seg_id, IPC_RMID, NULL)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn,
"shmctl(2)", "", strerror(err), err);
rc = OPAL_ERROR;
@ -291,8 +294,8 @@ segment_attach(opal_shmem_ds_t *ds_buf)
if ((void *)-1 == (ds_buf->seg_base_addr = shmat(ds_buf->seg_id, NULL,
0))) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn,
"shmat(2)", "", strerror(err), err);
shmctl(ds_buf->seg_id, IPC_RMID, NULL);
@ -333,8 +336,8 @@ segment_detach(opal_shmem_ds_t *ds_buf)
if (0 != shmdt((char*)ds_buf->seg_base_addr)) {
int err = errno;
char hn[OPAL_MAXHOSTNAMELEN];
gethostname(hn, sizeof(hn));
const char *hn;
hn = opal_gethostname();
opal_show_help("help-opal-shmem-sysv.txt", "sys call fail", 1, hn,
"shmdt(2)", "", strerror(err), err);
rc = OPAL_ERROR;

Просмотреть файл

@ -30,6 +30,9 @@
#include "opal_config.h"
#include "opal/types.h"
#include "opal/class/opal_list.h"
#include "opal/util/proc.h"
#include <assert.h>
BEGIN_C_DECLS
@ -111,6 +114,19 @@ OPAL_DECLSPEC void opal_warn_fork(void);
*/
OPAL_DECLSPEC int opal_register_params(void);
/**
* Wrapper to return the hostname value that is in
opal_process_info.nodename, as opposed to calling gethostname()
directly, which is not guaranteed to be null-terminated and
varies in its behavior depending on implementation. The
opal_process_info.nodename value is first populated in
opal/runtime/opal_init.c
*/
static inline const char *opal_gethostname( void ) {
assert( NULL != opal_process_info.nodename );
return opal_process_info.nodename;
}
/* finalize cleanup */
/**
* @brief Cleanup domain

Просмотреть файл

@ -37,7 +37,7 @@
#include <unistd.h>
#endif
#include "opal_config.h"
#include "opal/include/opal_config.h"
#include "opal/util/malloc.h"
#include "opal/util/arch.h"
@ -95,6 +95,108 @@ int opal_util_initialized = 0;
int opal_cache_line_size = 128;
bool opal_warn_on_fork = true;
/* If there is a preprocessor macro that redefined the call to
* gethostname, we undefine that here */
#ifdef gethostname
#undef gethostname
#endif
#define NUM_TRIES_FOR_NULL_HOSTNAME 8
/*
* This gethostname wrapper does not return the full-length hostname in
* those rare cases where it is too long for the buffer. It does, however,
* guarantee a null-terminated hostname is returned, even if it's
* truncated. It also tries again in the case where gethostname returns an
* error because the buffer is initially too short.
*/
static int opal_init_gethostname(void)
{
size_t count, length = OPAL_LOCAL_MAXHOSTNAMELEN;
int ret_val, num_tries = 0;
char *buf = calloc( 1, length );
if( NULL == buf ) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
while( num_tries < NUM_TRIES_FOR_NULL_HOSTNAME) {
++num_tries;
/*
* Offer all but the last byte of the buffer to gethostname.
*/
ret_val = gethostname( buf, length - 1 );
/*
* Terminate the buffer in the last position.
*/
buf[length - 1] = '\0';
if( 0 == ret_val ) {
count = strlen( buf );
/* The result was not truncated */
if( count > 0 && count < length - 1 ) {
/*
* If we got a good result, save it. This value may
* be longer than what callers to opal_gethostname()
* are expecting, so that should be checked by the
* caller.
*/
opal_process_info.nodename = buf;
return OPAL_SUCCESS;
}
/*
* "Good" cases:
*
* 0 == count: The buffer is empty. In some gethostname
* implementations, this can be because the
* buffer was too small.
* (length-1) == count: The result *may* be truncated.
*
* If it's one of these cases, we'll fall through to
* increase the length of the buffer and try again.
*
* If it's not one of these good cases, it's an error:
* return.
*/
else if( !(0 == count || count == length - 1) ) {
free(buf);
return OPAL_ERR_IN_ERRNO;
}
}
/*
* "Good" cases:
*
* errno == EINVAL or ENAMETOOLONG: hostname was truncated and
* there was an error. Perhaps there is something
* in the buffer and perhaps not.
*
* If it's one of these cases, we'll fall through to
* increase the length of the buffer and try again.
*
* If it's not one of these good cases, it's an error: return.
*/
else if( !(EINVAL == errno || ENAMETOOLONG == errno) ) {
free(buf);
return OPAL_ERR_IN_ERRNO;
}
/*
* If we get here, it means we want to double the length of
* the buffer and try again.
*/
length *= 2;
buf = realloc( buf, length );
if( NULL == buf ) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
} /* end while */
/* If we got here, it means that we tried too many times and are
* giving up. */
free(buf);
return OPAL_ERR_NOT_FOUND;
}
static int
opal_err2str(int errnum, const char **errmsg)
{
@ -367,7 +469,6 @@ opal_init_util(int* pargc, char*** pargv)
{
int ret;
char *error = NULL;
char hostname[OPAL_MAXHOSTNAMELEN];
OPAL_TIMING_ENV_INIT(otmng);
if( ++opal_util_initialized != 1 ) {
@ -390,8 +491,12 @@ opal_init_util(int* pargc, char*** pargv)
* that we don't bother with fqdn and prefix issues here - we let
* the RTE later replace this with a modified name if the user
* requests it */
gethostname(hostname, sizeof(hostname));
opal_process_info.nodename = strdup(hostname);
ret = opal_init_gethostname();
if (OPAL_SUCCESS != ret) {
fprintf(stderr, "opal_init_gethostname() failed -- process will likely abort (%s:%d, returned %d instead of OPAL_SUCCESS)\n",
__FILE__, __LINE__, ret);
return ret;
}
/* initialize the memory allocator */
opal_malloc_init();

Просмотреть файл

@ -20,6 +20,8 @@
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
* Copyright (c) 2018 Triad National Security, LLC. All rights
* reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -44,6 +46,7 @@
#include <sys/param.h>
#endif
#include "opal/runtime/opal.h"
#include "opal/util/opal_environ.h"
#include "opal/util/output.h"
#include "opal/util/string_copy.h"
@ -137,7 +140,7 @@ OBJ_CLASS_INSTANCE(opal_output_stream_t, opal_object_t, construct, destruct);
bool opal_output_init(void)
{
int i;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
char *str;
if (initialized) {
@ -193,7 +196,7 @@ bool opal_output_init(void)
verbose.lds_want_stderr = true;
}
}
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
opal_asprintf(&verbose.lds_prefix, "[%s:%05d] ", hostname, getpid());
for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) {
@ -274,7 +277,7 @@ bool opal_output_switch(int output_id, bool enable)
void opal_output_reopen_all(void)
{
char *str;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
str = getenv("OPAL_OUTPUT_STDERR_FD");
if (NULL != str) {
@ -283,7 +286,7 @@ void opal_output_reopen_all(void)
default_stderr_fd = -1;
}
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
if( NULL != verbose.lds_prefix ) {
free(verbose.lds_prefix);
verbose.lds_prefix = NULL;

Просмотреть файл

@ -13,6 +13,8 @@
* Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* Copyright (c) 2017 FUJITSU LIMITED. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -43,6 +45,7 @@
#include <string.h>
#include <signal.h>
#include "opal/runtime/opal.h"
#include "opal/util/stacktrace.h"
#include "opal/mca/backtrace/backtrace.h"
#include "opal/constants.h"
@ -63,6 +66,7 @@ int opal_stacktrace_output_fileno = -1;
static char *opal_stacktrace_output_filename_base = NULL;
static size_t opal_stacktrace_output_filename_max_len = 0;
static char stacktrace_hostname[OPAL_MAXHOSTNAMELEN];
static const char *stacktrace_hostname_full;
static char *unable_to_print_msg = "Unable to print stack trace!\n";
/*
@ -534,7 +538,9 @@ int opal_util_register_stackhandlers (void)
int i;
bool complain, showed_help = false;
gethostname(stacktrace_hostname, sizeof(stacktrace_hostname));
stacktrace_hostname_full = opal_gethostname();
strncpy(stacktrace_hostname, stacktrace_hostname_full, OPAL_MAXHOSTNAMELEN - 1);
stacktrace_hostname[OPAL_MAXHOSTNAMELEN - 1] = '\0';
/* to keep these somewhat readable, only print the machine name */
for (i = 0 ; i < (int)strlen(stacktrace_hostname) ; ++i) {
if (stacktrace_hostname[i] == '.') {

Просмотреть файл

@ -16,6 +16,8 @@
* Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
* Copyright (c) 2013-2018 Intel, Inc. All rights reserved.
* Copyright (c) 2014 NVIDIA Corporation. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -50,6 +52,7 @@
#endif
#include <ctype.h>
#include "opal/runtime/opal.h"
#include "opal/util/show_help.h"
#include "opal/util/error.h"
#include "opal/util/output.h"
@ -193,14 +196,15 @@ static int component_send(orte_rml_send_t *msg)
static char* component_get_addr(void)
{
char hn[OPAL_MAXHOSTNAMELEN], *cptr;
const char *hn;
char *cptr;
/*
* TODO: for aries want to plug in GNI addr here instead to
* eventually be able to support connect/accept using aprun.
*/
gethostname(hn, sizeof(hn));
hn = opal_gethostname();
opal_asprintf(&cptr, "gni://%s:%d", hn, getpid());

Просмотреть файл

@ -19,6 +19,8 @@
* Copyright (c) 2013-2019 Intel, Inc. All rights reserved.
* Copyright (c) 2015-2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -49,7 +51,6 @@
#include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */
#include "opal/mca/event/event.h"
#include "opal/mca/base/base.h"
#include "opal/util/output.h"
@ -236,7 +237,7 @@ int orte_daemon(int argc, char *argv[])
opal_cmd_line_t *cmd_line = NULL;
int i;
opal_buffer_t *buffer;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
#if OPAL_ENABLE_FT_CR == 1
char *tmp_env_var = NULL;
#endif
@ -304,7 +305,7 @@ int orte_daemon(int argc, char *argv[])
* away just in case we have a problem along the way
*/
if (orted_globals.debug) {
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
fprintf(stderr, "Daemon was launched on %s - beginning to initialize\n", hostname);
}
@ -866,12 +867,12 @@ int orte_daemon(int argc, char *argv[])
if (orte_retain_aliases) {
char **aliases=NULL;
uint8_t naliases, ni;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
/* if we stripped the prefix or removed the fqdn,
* include full hostname as an alias
*/
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
if (strlen(orte_process_info.nodename) < strlen(hostname)) {
opal_argv_append_nosize(&aliases, hostname);
}

Просмотреть файл

@ -4,6 +4,8 @@
#include <unistd.h>
#include <sys/param.h>
#include "opal/runtime/opal.h"
#include <mpi.h>
int main(int argc, char* argv[])
@ -11,7 +13,7 @@ int main(int argc, char* argv[])
int msg, rc;
MPI_Comm parent, child;
int rank, size;
char hostname[MAXHOSTNAMELEN];
const char *hostname;
pid_t pid;
char *env_rank,*env_nspace;
MPI_Info info;
@ -19,7 +21,7 @@ int main(int argc, char* argv[])
env_rank = getenv("PMIX_RANK");
env_nspace = getenv("PMIX_NAMESPACE");
pid = getpid();
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
printf("[%s:%s pid %ld] starting up on node %s!\n", env_nspace, env_rank, (long)pid, hostname);

Просмотреть файл

@ -11,6 +11,7 @@
#include <unistd.h>
#include <sched.h>
#include "opal/mca/hwloc/base/base.h"
#include "opal/runtime/opal.h"
#include "mpi.h"
#include "orte/util/proc_info.h"
@ -23,13 +24,13 @@ int main(int argc, char* argv[])
cpu_set_t *mask;
int nrcpus, c;
size_t csize;
char hostname[1024];
const char *hostname;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
gethostname(hostname, 1024);
hostname = opal_gethostname();
if (OPAL_SUCCESS == opal_hwloc_base_get_topology()) {
cpus = hwloc_bitmap_alloc();

Просмотреть файл

@ -1,6 +1,8 @@
#define _GNU_SOURCE
#include "orte_config.h"
#include "opal/runtime/opal.h"
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
@ -15,7 +17,7 @@ int main(int argc, char* argv[])
int msg;
MPI_Comm parent, children[NUM_CHILDREN];
int rank, size, i;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
pid_t pid;
char *child_argv[2] = { "", NULL };
@ -56,7 +58,7 @@ int main(int argc, char* argv[])
}
/* Otherwise, we're the child */
else {
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
if (argc == 1) {
printf("ERROR: child did not receive exepcted argv!\n");
i = -1;

Просмотреть файл

@ -7,6 +7,8 @@
#include "orte_config.h"
#include "opal/runtime/opal.h"
#include <stdio.h>
#include <unistd.h>
#include "mpi.h"
@ -14,13 +16,13 @@
int main(int argc, char* argv[])
{
int rank, size;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
printf("%s: I am %d of %d. pid=%d\n", hostname, rank, size, getpid());
if (rank%3 == 0) {

Просмотреть файл

@ -9,6 +9,8 @@
#include "orte_config.h"
#include "opal/runtime/opal.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@ -18,7 +20,7 @@
int main(int argc, char* argv[])
{
int rank, size;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
void *appnum;
void *univ_size;
char *appstr, *unistr;
@ -43,7 +45,7 @@ int main(int argc, char* argv[])
opal_asprintf(&unistr, "%d", *(int*)univ_size);
}
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
printf("Hello, World, I am %d of %d on host %s from app number %s universe size %s universe envar %s\n",
rank, size, hostname, appstr, unistr, (NULL == envar) ? "NULL" : envar);

Просмотреть файл

@ -1,5 +1,7 @@
#include "orte_config.h"
#include "opal/runtime/opal.h"
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
@ -13,7 +15,7 @@ int main(int argc, char* argv[])
int msg, rc, i;
MPI_Comm parent, child;
int rank, size;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
pid_t pid;
MPI_Info info;
char *keyval, *tmp;
@ -65,7 +67,7 @@ int main(int argc, char* argv[])
else {
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
pid = getpid();
printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid);
if (0 == rank) {

Просмотреть файл

@ -4,6 +4,8 @@
#include <unistd.h>
#include <sys/param.h>
#include "opal/runtime/opal.h"
#include <mpi.h>
int main(int argc, char* argv[])
@ -11,14 +13,14 @@ int main(int argc, char* argv[])
int msg, rc;
MPI_Comm parent, child;
int rank, size;
char hostname[MAXHOSTNAMELEN];
const char *hostname;
pid_t pid;
char *env_rank,*env_nspace;
env_rank = getenv("PMIX_RANK");
env_nspace = getenv("PMIX_NAMESPACE");
pid = getpid();
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
printf("[%s:%s pid %ld] starting up on node %s!\n", env_nspace, env_rank, (long)pid, hostname);

Просмотреть файл

@ -1,5 +1,7 @@
#include "orte_config.h"
#include "opal/runtime/opal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -45,12 +47,13 @@
int main(int argc, char *argv[])
{
char hostname[OPAL_MAXHOSTNAMELEN] ;
const char *hostname ;
char buff[255] ;
int role ;
int num_clients ;
int size, rank ;
int temp_errno ;
FILE *fp ;
char server_port_name[MPI_MAX_PORT_NAME] ;
@ -80,14 +83,9 @@ int main(int argc, char *argv[])
CHK(MPI_Init(&argc, &argv)) ;
/* get the node name */
{
int retval = gethostname(hostname, sizeof(hostname));
if(retval == -1)
{
fprintf(stderr, "gethostname failed: %s\n", strerror(errno)) ;
exit(1) ;
}
}
/* The opal_gethostname() function is just a wrapper that returns a global
variable value that is set earlier, so we don't check for errors here */
hostname = opal_gethostname();
/* server */
if(role == 1)

Просмотреть файл

@ -1,5 +1,7 @@
#include "orte_config.h"
#include "opal/runtime/opal.h"
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
@ -11,7 +13,7 @@ int main(int argc, char* argv[])
int msg;
MPI_Comm parent, child;
int rank, size;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
pid_t pid;
int i;
char *cmds[2];
@ -50,7 +52,7 @@ int main(int argc, char* argv[])
else {
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
pid = getpid();
printf("Hello from the child %d of %d on host %s pid %ld: argv[1] = %s\n", rank, size, hostname, (long)pid, argv[1]);
MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE);

Просмотреть файл

@ -1,5 +1,7 @@
#include "orte_config.h"
#include "opal/runtime/opal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -11,7 +13,7 @@ int main(int argc, char ** argv){
int i;
int rank, size, child_rank;
char nomehost[OPAL_MAXHOSTNAMELEN];
const char *nomehost;
MPI_Comm parent, intercomm1, intercomm2;
int erro;
int level, curr_level;
@ -62,7 +64,7 @@ int main(int argc, char ** argv){
}
gethostname(nomehost, sizeof(nomehost));
nomehost = opal_gethostname();
printf("(%d) in %s\n", rank, nomehost);
MPI_Finalize();

Просмотреть файл

@ -11,6 +11,8 @@
#include <stdio.h>
#include <unistd.h>
#include "opal/runtime/opal.h"
#include "orte/runtime/runtime.h"
#include "orte/util/proc_info.h"
#include "orte/util/name_fns.h"
@ -23,14 +25,14 @@ int main(int argc, char* argv[])
int i, rc;
double pi;
pid_t pid;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc);
return rc;
}
pid = getpid();
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
if (1 < argc) {
rc = strtol(argv[1], NULL, 10);

Просмотреть файл

@ -11,6 +11,8 @@
#include <stdio.h>
#include <unistd.h>
#include "opal/runtime/opal.h"
#include "orte/runtime/runtime.h"
#include "orte/util/proc_info.h"
#include "orte/util/name_fns.h"
@ -23,14 +25,14 @@ int main(int argc, char* argv[])
int i, rc;
double pi;
pid_t pid;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc);
return rc;
}
pid = getpid();
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
printf("orte_abort: Name %s Host: %s Pid %ld\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
hostname, (long)pid);

Просмотреть файл

@ -12,6 +12,7 @@
#include "opal/class/opal_list.h"
#include "opal/util/opal_environ.h"
#include "opal/runtime/opal.h"
#include "orte/util/proc_info.h"
#include "orte/util/name_fns.h"
@ -22,7 +23,8 @@
int main(int argc, char* argv[])
{
int rc, i, restart=-1;
char hostname[OPAL_MAXHOSTNAMELEN], *rstrt;
const char *hostname;
char *rstrt;
pid_t pid;
if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
@ -34,7 +36,7 @@ int main(int argc, char* argv[])
restart = strtol(rstrt, NULL, 10);
}
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
pid = getpid();
printf("orte_nodename: Node %s Name %s Pid %ld Restarts: %d\n",

Просмотреть файл

@ -9,6 +9,7 @@
#include <stdio.h>
#include <unistd.h>
#include "opal/runtime/opal.h"
#include "opal/mca/pmix/pmix.h"
#include "orte/runtime/runtime.h"
#include "orte/util/proc_info.h"
@ -50,13 +51,20 @@ int main(int argc, char* argv[])
int rc;
opal_value_t *kv;
opal_list_t info;
const char *local_hostname;
if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc);
return rc;
}
pid = getpid();
gethostname(hostname, sizeof(hostname));
/* Because hostname variable is static, we need to copy it from another variable that gets the
return of opal_gethostname. Truncate it if it is longer than OPAL_MAXHOSTNAMELEN.
*/
local_hostname = opal_gethostname();
strncpy(hostname, local_hostname, OPAL_MAXHOSTNAMELEN - 1);
local_hostname[OPAL_MAXHOSTNAMELEN - 1] = '\0';
printf("orte_notify: Name %s Host: %s Pid %ld\n",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),

Просмотреть файл

@ -3,11 +3,13 @@
#include "orte_config.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include "opal/runtime/opal.h"
#include "opal/mca/pmix/pmix.h"
#include "orte/runtime/runtime.h"
#include "orte/util/proc_info.h"
@ -21,14 +23,14 @@ int main(int argc, char* argv[])
int i, rc;
double pi;
pid_t pid;
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc);
return rc;
}
pid = getpid();
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
if (1 < argc) {
rc = strtol(argv[1], NULL, 10);

Просмотреть файл

@ -14,6 +14,8 @@
* All rights reserved.
* Copyright (c) 2014-2017 Intel, Inc. All rights reserved.
* Copyright (c) 2016 IBM Corporation. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -42,6 +44,7 @@
#include "opal/util/net.h"
#include "opal/util/output.h"
#include "opal/util/proc.h"
#include "opal/runtime/opal.h"
#include "orte/util/attr.h"
@ -96,7 +99,7 @@ int orte_proc_info(void)
int idx, i;
char *ptr;
char hostname[OPAL_MAXHOSTNAMELEN];
char *local_hostname = NULL;
char **prefixes;
bool match;
@ -164,17 +167,21 @@ int orte_proc_info(void)
/* get the process id */
orte_process_info.pid = getpid();
/* get the nodename */
gethostname(hostname, sizeof(hostname));
/* get the nodename (retrieves from a global variable) */
/* copy into a local version so that we can manipulate it */
local_hostname = strdup(opal_gethostname());
if (NULL == local_hostname) {
return OPAL_ERR_BUFFER;
}
/* add this to our list of aliases */
opal_argv_append_nosize(&orte_process_info.aliases, hostname);
opal_argv_append_nosize(&orte_process_info.aliases, local_hostname);
// Strip off the FQDN if present, ignore IP addresses
if( !orte_keep_fqdn_hostnames && !opal_net_isaddr(hostname) ) {
if (NULL != (ptr = strchr(hostname, '.'))) {
if( !orte_keep_fqdn_hostnames && !opal_net_isaddr(local_hostname) ) {
if (NULL != (ptr = strchr(local_hostname, '.'))) {
*ptr = '\0';
/* add this to our list of aliases */
opal_argv_append_nosize(&orte_process_info.aliases, hostname);
opal_argv_append_nosize(&orte_process_info.aliases, local_hostname);
}
}
@ -192,18 +199,18 @@ int orte_proc_info(void)
prefixes = opal_argv_split(orte_strip_prefix, ',');
match = false;
for (i=0; NULL != prefixes[i]; i++) {
if (0 == strncmp(hostname, prefixes[i], strlen(prefixes[i]))) {
if (0 == strncmp(local_hostname, prefixes[i], strlen(prefixes[i]))) {
/* remove the prefix and leading zeroes */
idx = strlen(prefixes[i]);
while (idx < (int)strlen(hostname) &&
(hostname[idx] <= '0' || '9' < hostname[idx])) {
while (idx < (int)strlen(local_hostname) &&
(local_hostname[idx] <= '0' || '9' < local_hostname[idx])) {
idx++;
}
if ((int)strlen(hostname) <= idx) {
if ((int)strlen(local_hostname) <= idx) {
/* there were no non-zero numbers in the name */
orte_process_info.nodename = strdup(&hostname[strlen(prefixes[i])]);
orte_process_info.nodename = strdup(&local_hostname[strlen(prefixes[i])]);
} else {
orte_process_info.nodename = strdup(&hostname[idx]);
orte_process_info.nodename = strdup(&local_hostname[idx]);
}
/* add this to our list of aliases */
opal_argv_append_nosize(&orte_process_info.aliases, orte_process_info.nodename);
@ -213,11 +220,11 @@ int orte_proc_info(void)
}
/* if we didn't find a match, then just use the hostname as-is */
if (!match) {
orte_process_info.nodename = strdup(hostname);
orte_process_info.nodename = strdup(local_hostname);
}
opal_argv_free(prefixes);
} else {
orte_process_info.nodename = strdup(hostname);
orte_process_info.nodename = strdup(local_hostname);
}
/* add "localhost" to our list of aliases */
@ -263,7 +270,7 @@ int orte_proc_info(void)
MCA_BASE_VAR_SCOPE_CONSTANT,
&orte_ess_node_rank);
orte_process_info.my_node_rank = (orte_node_rank_t) orte_ess_node_rank;
free(local_hostname);
return ORTE_SUCCESS;
}

Просмотреть файл

@ -4,6 +4,8 @@
* Copyright (c) 2017 FUJITSU LIMITED. All rights reserved.
* Copyright (c) 2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -28,6 +30,7 @@
#include "opal/mca/backtrace/backtrace.h"
#include "opal/util/error.h"
#include "opal/runtime/opal.h"
#include "opal/runtime/opal_params.h"
#include "opal/util/show_help.h"
@ -40,7 +43,7 @@ static bool have_been_invoked = false;
int oshmem_shmem_abort(int errcode)
{
char *host, hostname[OPAL_MAXHOSTNAMELEN];
const char *host;
pid_t pid = 0;
/* Protection for recursive invocation */
@ -50,15 +53,14 @@ int oshmem_shmem_abort(int errcode)
have_been_invoked = true;
/* If ORTE is initialized, use its nodename. Otherwise, call
gethostname. */
opal_gethostname. */
/* If MPI is initialized, we know we have a runtime nodename, so
use that. Otherwise, call gethostname. */
use that. Otherwise, call opal_gethostname. */
if (ompi_rte_initialized) {
host = ompi_process_info.nodename;
} else {
gethostname(hostname, sizeof(hostname));
host = hostname;
host = opal_gethostname();
}
pid = getpid();

Просмотреть файл

@ -9,6 +9,8 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -59,7 +61,7 @@ test_ifaddrtoname(char *addr)
int
main(int argc, char *argv[])
{
char hostname[OPAL_MAXHOSTNAMELEN];
const char *hostname;
opal_init(&argc, &argv);
test_init("opal_if");
@ -117,7 +119,7 @@ main(int argc, char *argv[])
}
/* local host name */
gethostname(hostname, sizeof(hostname));
hostname = opal_gethostname();
if (test_ifaddrtoname(hostname)) {
test_success();
} else {