Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit c6caf6b

Browse files
authored
Merge pull request #1124 from kmroz/hostname-len-cleanup
ompi/opal/orte/oshmem/test: max hostname length cleanup
2 parents 27d186d + 44ee3cc commit c6caf6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+163
-165
lines changed

ompi/info/info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ opal_pointer_array_t ompi_info_f_to_c_table = {{0}};
9595
*/
9696
int ompi_info_init(void)
9797
{
98-
char val[MPI_MAX_INFO_VAL];
98+
char val[OPAL_MAXHOSTNAMELEN];
9999
char *cptr;
100100

101101
/* initialize table */
@@ -134,7 +134,7 @@ int ompi_info_init(void)
134134
}
135135

136136
/* local host name */
137-
gethostname(val, MPI_MAX_INFO_VAL);
137+
gethostname(val, sizeof(val));
138138
ompi_info_set(&ompi_mpi_info_env.info, "host", val);
139139

140140
/* architecture name */

ompi/mca/pml/v/pml_v_output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
int pml_v_output_open(char *output, int verbosity) {
2323
opal_output_stream_t lds;
24-
char hostname[32] = "NA";
24+
char hostname[OPAL_MAXHOSTNAMELEN] = "NA";
2525

2626
OBJ_CONSTRUCT(&lds, opal_output_stream_t);
2727
if(!output) {
@@ -40,7 +40,7 @@ int pml_v_output_open(char *output, int verbosity) {
4040
lds.lds_file_suffix = output;
4141
}
4242
lds.lds_is_debugging = true;
43-
gethostname(hostname, 32);
43+
gethostname(hostname, sizeof(hostname));
4444
asprintf(&lds.lds_prefix, "[%s:%05d] pml_v: ", hostname, getpid());
4545
lds.lds_verbose_level = verbosity;
4646
mca_pml_v.output = opal_output_open(&lds);

ompi/mpi/c/get_processor_name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int MPI_Get_processor_name(char *name, int *resultlen)
6464
Guard against gethostname() returning a *really long* hostname
6565
and not null-terminating the string. The Fortran API version
6666
will pad to the right if necessary. */
67-
gethostname(name, MPI_MAX_PROCESSOR_NAME - 1);
67+
gethostname(name, (MPI_MAX_PROCESSOR_NAME - 1));
6868
name[MPI_MAX_PROCESSOR_NAME - 1] = '\0';
6969
*resultlen = (int) strlen(name);
7070

ompi/runtime/ompi_mpi_abort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int
119119
ompi_mpi_abort(struct ompi_communicator_t* comm,
120120
int errcode)
121121
{
122-
char *msg, *host, hostname[MAXHOSTNAMELEN];
122+
char *msg, *host, hostname[OPAL_MAXHOSTNAMELEN];
123123
pid_t pid = 0;
124124

125125
/* Protection for recursive invocation */

ompi/runtime/ompi_mpi_finalize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int ompi_mpi_finalize(void)
114114
/* Note that if we're not initialized or already finalized, we
115115
cannot raise an MPI exception. The best that we can do is
116116
write something to stderr. */
117-
char hostname[MAXHOSTNAMELEN];
117+
char hostname[OPAL_MAXHOSTNAMELEN];
118118
pid_t pid = getpid();
119119
gethostname(hostname, sizeof(hostname));
120120

ompi/tools/mpisync/sync.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
6969
MPI_Comm comm = MPI_COMM_WORLD;
7070
int rank, commsize;
7171
double offs = 0, rtt = 0;
72-
char hname[1024];
72+
char hname[OPAL_MAXHOSTNAMELEN];
7373

7474
MPI_Comm_rank(comm, &rank);
7575
MPI_Comm_size(comm, &commsize);
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
9393
exit(1);
9494
}
9595

96-
if( gethostname(hname, 1024) ){
96+
if( gethostname(hname, sizeof(hname)) ){
9797
perror("Cannot get hostname. Abort");
9898
MPI_Abort(MPI_COMM_WORLD, 1);
9999
}
@@ -114,13 +114,13 @@ int main(int argc, char **argv)
114114
fprintf(stderr, "Fail to allocate memory. Abort\n");
115115
MPI_Abort(MPI_COMM_WORLD, 1);
116116
}
117-
char *hnames = malloc(1024*commsize);
117+
char *hnames = malloc(OPAL_MAXHOSTNAMELEN * commsize);
118118
if( hnames == NULL ){
119119
fprintf(stderr, "Fail to allocate memory. Abort\n");
120120
MPI_Abort(MPI_COMM_WORLD, 1);
121121
}
122122

123-
MPI_Gather(hname,1024,MPI_CHAR,hnames,1024,MPI_CHAR, 0, MPI_COMM_WORLD);
123+
MPI_Gather(hname,sizeof(hname),MPI_CHAR,hnames,sizeof(hname),MPI_CHAR, 0, MPI_COMM_WORLD);
124124
MPI_Gather(send,2,MPI_DOUBLE,measure,2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
125125
char tmpname[128];
126126
FILE *fp = fopen(filename,"w");
@@ -129,14 +129,14 @@ int main(int argc, char **argv)
129129
MPI_Abort(MPI_COMM_WORLD, 1);
130130
}
131131
double (*m)[2] = (void*)measure;
132-
char (*h)[1024] = (void*)hnames;
132+
char (*h)[OPAL_MAXHOSTNAMELEN] = (void*)hnames;
133133
int i;
134134
for(i=0; i<commsize;i++){
135135
fprintf(fp, "%s %lf %lf\n", h[i], m[i][0], m[i][1]);
136136
}
137137
fclose(fp);
138138
} else {
139-
MPI_Gather(hname,1024, MPI_CHAR, NULL, 1024, MPI_CHAR, 0, MPI_COMM_WORLD);
139+
MPI_Gather(hname, sizeof(hname), MPI_CHAR, NULL, sizeof(hname), MPI_CHAR, 0, MPI_COMM_WORLD);
140140
MPI_Gather(send,2, MPI_DOUBLE, NULL, 2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
141141
}
142142

opal/include/opal_config_bottom.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ typedef unsigned char bool;
339339
#define OPAL_PATH_SEP "/"
340340
#define OPAL_ENV_SEP ':'
341341

342+
#if defined(MAXHOSTNAMELEN)
343+
#define OPAL_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1)
344+
#elif defined(HOST_NAME_MAX)
345+
#define OPAL_MAXHOSTNAMELEN (HOST_NAME_MAX + 1)
346+
#else
347+
/* SUSv2 guarantees that "Host names are limited to 255 bytes". */
348+
#define OPAL_MAXHOSTNAMELEN (255 + 1)
349+
#endif
342350

343351
/*
344352
* Do we want memory debugging?
@@ -540,14 +548,9 @@ static inline uint16_t ntohs(uint16_t netvar) { return netvar; }
540548
#ifdef HAVE_HOSTLIB_H
541549
/* gethostname() */
542550
#include <hostLib.h>
543-
544-
#ifndef MAXHOSTNAMELEN
545-
#define MAXHOSTNAMELEN 64
546551
#endif
547552
#endif
548553

549-
#endif
550-
551554
/* If we're in C++, then just undefine restrict and then define it to
552555
nothing. "restrict" is not part of the C++ language, and we don't
553556
have a corresponding AC_CXX_RESTRICT to figure out what the C++

opal/mca/base/mca_base_component_find.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static int component_find_check (mca_base_framework_t *framework, char **request
330330
}
331331

332332
if (!found) {
333-
char h[MAXHOSTNAMELEN];
333+
char h[OPAL_MAXHOSTNAMELEN];
334334
gethostname(h, sizeof(h));
335335
opal_show_help("help-mca-base.txt",
336336
"find-available:not-valid", true,

opal/mca/base/mca_base_open.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int mca_base_open(void)
6666
{
6767
char *value;
6868
opal_output_stream_t lds;
69-
char hostname[64];
69+
char hostname[OPAL_MAXHOSTNAMELEN];
7070
int var_id;
7171

7272
if (mca_base_opened++) {
@@ -137,7 +137,7 @@ int mca_base_open(void)
137137
} else {
138138
set_defaults(&lds);
139139
}
140-
gethostname(hostname, 64);
140+
gethostname(hostname, sizeof(hostname));
141141
asprintf(&lds.lds_prefix, "[%s:%05d] ", hostname, getpid());
142142
opal_output_reopen(0, &lds);
143143
opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, 0, "mca: base: opening components");

opal/mca/event/libevent2022/libevent/evdns.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
* Version: 0.1b
4949
*/
5050

51+
#include "opal_config.h"
52+
5153
#include <sys/types.h>
5254
#include "event2/event-config.h"
5355

@@ -121,10 +123,6 @@
121123
#define EVDNS_LOG_WARN 1
122124
#define EVDNS_LOG_MSG 2
123125

124-
#ifndef HOST_NAME_MAX
125-
#define HOST_NAME_MAX 255
126-
#endif
127-
128126
#include <stdio.h>
129127

130128
#undef MIN
@@ -3108,7 +3106,7 @@ evdns_search_ndots_set(const int ndots) {
31083106

31093107
static void
31103108
search_set_from_hostname(struct evdns_base *base) {
3111-
char hostname[HOST_NAME_MAX + 1], *domainname;
3109+
char hostname[OPAL_MAXHOSTNAMELEN], *domainname;
31123110

31133111
ASSERT_LOCKED(base);
31143112
search_postfix_clear(base);

0 commit comments

Comments
 (0)