1
1
openmpi/ompi/mca/pml/v/pml_v_output.c
Charles Shereda cbc6feaab2 Created opal_gethostname() as safer gethostname substitute.
The opal_gethostname() function provides a more robust mechanism
to retrieve the hostname than gethostname(), which can return
results that are not null-terminated, and which can vary in its
behavior from system to system.

opal_gethostname() just returns the value in opal_process_info.nodename;
this is populated in opal_init_gethostname() inside opal_init.c.

-Changed all gethostname calls in opal subtree to opal_gethostname
-Changed all gethostname calls in orte subtree to opal_gethostname
-Changed all gethostname calls in ompi subdir to opal_gethostname
-Changed all gethostname calls in oshmem subdir to opal_gethostname
-Changed opal_if.c in test subdir to use opal_gethostname
-Changed opal_init.c to include opal_init_gethostname. This function
 returns an int and directly sets opal_process_info.nodename per
 jsquyres' modifications.

Relates to open-mpi#6801

Signed-off-by: Charles Shereda <cpshereda@lanl.gov>
2020-01-13 08:52:17 -08:00

62 строки
1.6 KiB
C

/*
* Copyright (c) 2004-2007 The Trustees of the University of Tennessee.
* 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
*
* $HEADER$
*/
#include "ompi_config.h"
#include "opal/runtime/opal.h"
#include "opal/util/output.h"
#include "opal/util/printf.h"
#include "pml_v_output.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include <string.h>
int ompi_pml_v_output_open(char *output, int verbosity) {
opal_output_stream_t lds;
const char *hostname;
OBJ_CONSTRUCT(&lds, opal_output_stream_t);
if(!output) {
mca_pml_v.output = 0;
}
else {
if(!strcmp(output, "stdout")) {
lds.lds_want_stdout = true;
}
else if(!strcmp(output, "stderr")) {
lds.lds_want_stderr = true;
}
else
{
lds.lds_want_file = true;
lds.lds_file_suffix = output;
}
lds.lds_is_debugging = true;
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);
free(lds.lds_prefix);
}
return mca_pml_v.output;
}
void ompi_pml_v_output_close(void) {
opal_output_close(mca_pml_v.output);
mca_pml_v.output = -1;
}