Skip to content

Commit 265e5b9

Browse files
committed
Merge pull request #1552 from kmroz/wip-hostname-len-cleanup-1
ompi/opal/orte/oshmem/test: max hostname length cleanup
2 parents 45f9a47 + 941f2c1 commit 265e5b9

Some content is hidden

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

45 files changed

+166
-167
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
@@ -66,7 +66,7 @@ int MPI_Get_processor_name(char *name, int *resultlen)
6666
Guard against gethostname() returning a *really long* hostname
6767
and not null-terminating the string. The Fortran API version
6868
will pad to the right if necessary. */
69-
gethostname(name, MPI_MAX_PROCESSOR_NAME - 1);
69+
gethostname(name, (MPI_MAX_PROCESSOR_NAME - 1));
7070
name[MPI_MAX_PROCESSOR_NAME - 1] = '\0';
7171
*resultlen = (int) strlen(name);
7272

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
@@ -120,7 +120,7 @@ int ompi_mpi_finalize(void)
120120
/* Note that if we're not initialized or already finalized, we
121121
cannot raise an MPI exception. The best that we can do is
122122
write something to stderr. */
123-
char hostname[MAXHOSTNAMELEN];
123+
char hostname[OPAL_MAXHOSTNAMELEN];
124124
pid_t pid = getpid();
125125
gethostname(hostname, sizeof(hostname));
126126

ompi/tools/mpisync/sync.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
7474
MPI_Comm comm = MPI_COMM_WORLD;
7575
int rank, commsize;
7676
double offs = 0, rtt = 0;
77-
char hname[1024];
77+
char hname[OPAL_MAXHOSTNAMELEN];
7878

7979
MPI_Comm_rank(comm, &rank);
8080
MPI_Comm_size(comm, &commsize);
@@ -98,7 +98,7 @@ int main(int argc, char **argv)
9898
exit(1);
9999
}
100100

101-
if( gethostname(hname, 1024) ){
101+
if( gethostname(hname, sizeof(hname)) ){
102102
perror("Cannot get hostname. Abort");
103103
MPI_Abort(MPI_COMM_WORLD, 1);
104104
}
@@ -129,13 +129,13 @@ int main(int argc, char **argv)
129129
fprintf(stderr, "Fail to allocate memory. Abort\n");
130130
MPI_Abort(MPI_COMM_WORLD, 1);
131131
}
132-
char *hnames = malloc(1024*commsize);
132+
char *hnames = malloc(OPAL_MAXHOSTNAMELEN * commsize);
133133
if( hnames == NULL ){
134134
fprintf(stderr, "Fail to allocate memory. Abort\n");
135135
MPI_Abort(MPI_COMM_WORLD, 1);
136136
}
137137

138-
MPI_Gather(hname,1024,MPI_CHAR,hnames,1024,MPI_CHAR, 0, MPI_COMM_WORLD);
138+
MPI_Gather(hname,sizeof(hname),MPI_CHAR,hnames,sizeof(hname),MPI_CHAR, 0, MPI_COMM_WORLD);
139139
MPI_Gather(send,2,MPI_DOUBLE,measure,2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
140140
char tmpname[128];
141141
FILE *fp = fopen(filename,"w");
@@ -144,15 +144,15 @@ int main(int argc, char **argv)
144144
MPI_Abort(MPI_COMM_WORLD, 1);
145145
}
146146
double (*m)[2] = (void*)measure;
147-
char (*h)[1024] = (void*)hnames;
147+
char (*h)[OPAL_MAXHOSTNAMELEN] = (void*)hnames;
148148
int i;
149149
fprintf(fp, "# Used algorithm: %s\n", (alg ? "binary tree" : "linear"));
150150
for(i=0; i<commsize;i++){
151151
fprintf(fp, "%s %lf %lf\n", h[i], m[i][0], m[i][1]);
152152
}
153153
fclose(fp);
154154
} else {
155-
MPI_Gather(hname,1024, MPI_CHAR, NULL, 1024, MPI_CHAR, 0, MPI_COMM_WORLD);
155+
MPI_Gather(hname, sizeof(hname), MPI_CHAR, NULL, sizeof(hname), MPI_CHAR, 0, MPI_COMM_WORLD);
156156
MPI_Gather(send,2, MPI_DOUBLE, NULL, 2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
157157
}
158158

opal/include/opal_config_bottom.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ typedef OPAL_PTRDIFF_TYPE ptrdiff_t;
285285
#define OPAL_PATH_SEP "/"
286286
#define OPAL_ENV_SEP ':'
287287

288+
#if defined(MAXHOSTNAMELEN)
289+
#define OPAL_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1)
290+
#elif defined(HOST_NAME_MAX)
291+
#define OPAL_MAXHOSTNAMELEN (HOST_NAME_MAX + 1)
292+
#else
293+
/* SUSv2 guarantees that "Host names are limited to 255 bytes". */
294+
#define OPAL_MAXHOSTNAMELEN (255 + 1)
295+
#endif
288296

289297
/*
290298
* Do we want memory debugging?
@@ -489,14 +497,9 @@ static inline uint16_t ntohs(uint16_t netvar) { return netvar; }
489497
#ifdef HAVE_HOSTLIB_H
490498
/* gethostname() */
491499
#include <hostLib.h>
492-
493-
#ifndef MAXHOSTNAMELEN
494-
#define MAXHOSTNAMELEN 64
495500
#endif
496501
#endif
497502

498-
#endif
499-
500503
/* If we're in C++, then just undefine restrict and then define it to
501504
nothing. "restrict" is not part of the C++ language, and we don't
502505
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)