Skip to content

Commit e1c64e6

Browse files
committed
opal: standardize on max hostname length
Define OPAL_MAXHOSTNAMELEN to be either: (MAXHOSTNAMELEN + 1) or (limits.h:HOST_NAME_MAX + 1) or (255 + 1) For pmix code, define above using PMIX_MAXHOSTNAMELEN. Fixup opal layer to use the new max. Signed-off-by: Karol Mroz <[email protected]>
1 parent fdd1ff7 commit e1c64e6

File tree

21 files changed

+94
-116
lines changed

21 files changed

+94
-116
lines changed

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);

opal/mca/hwloc/base/hwloc_base_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ int opal_hwloc_base_report_bind_failure(const char *file,
399399

400400
if (!already_reported &&
401401
OPAL_HWLOC_BASE_MBFA_SILENT != opal_hwloc_base_mbfa) {
402-
char hostname[64];
402+
char hostname[OPAL_MAXHOSTNAMELEN];
403403
gethostname(hostname, sizeof(hostname));
404404

405405
opal_show_help("help-opal-hwloc-base.txt", "mbind failure", true,

opal/mca/pmix/pmix114/pmix/examples/dynamic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ int main(int argc, char **argv)
4545
uint32_t nprocs;
4646
char nsp2[PMIX_MAX_NSLEN+1];
4747
pmix_app_t *app;
48-
char hostname[1024], dir[1024];
48+
char hostname[PMIX_MAXHOSTNAMELEN], dir[1024];
4949
pmix_proc_t *peers;
5050
size_t npeers, ntmp=0;
5151
char *nodelist;
5252

53-
gethostname(hostname, 1024);
53+
gethostname(hostname, sizeof(hostname));
5454
getcwd(dir, 1024);
5555

5656
/* init us */

opal/mca/pmix/pmix114/pmix/include/pmix/autogen/pmix_config_bottom.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ typedef PMIX_PTRDIFF_TYPE ptrdiff_t;
258258
#define PMIX_PATH_MAX 256
259259
#endif
260260

261+
#if defined(MAXHOSTNAMELEN)
262+
#define PMIX_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1)
263+
#elif defined(HOST_NAME_MAX)
264+
#define PMIX_MAXHOSTNAMELEN (HOST_NAME_MAX + 1)
265+
#else
266+
/* SUSv2 guarantees that "Host names are limited to 255 bytes". */
267+
#define PMIX_MAXHOSTNAMELEN (255 + 1)
268+
#endif
269+
261270
/*
262271
* Set the compile-time path-separator on this system and variable separator
263272
*/
@@ -387,12 +396,7 @@ typedef PMIX_PTRDIFF_TYPE ptrdiff_t;
387396
#ifdef HAVE_HOSTLIB_H
388397
/* gethostname() */
389398
#include <hostLib.h>
390-
391-
#ifndef MAXHOSTNAMELEN
392-
#define MAXHOSTNAMELEN 64
393-
#endif
394399
#endif
395-
396400
#endif
397401

398402
/* If we're in C++, then just undefine restrict and then define it to

opal/mca/pmix/pmix114/pmix/src/util/output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ PMIX_CLASS_INSTANCE(pmix_output_stream_t, pmix_object_t, construct, NULL);
125125
bool pmix_output_init(void)
126126
{
127127
int i;
128-
char hostname[32];
128+
char hostname[PMIX_MAXHOSTNAMELEN];
129129
char *str;
130130

131131
if (initialized) {
@@ -250,7 +250,7 @@ bool pmix_output_switch(int output_id, bool enable)
250250
void pmix_output_reopen_all(void)
251251
{
252252
char *str;
253-
char hostname[32];
253+
char hostname[PMIX_MAXHOSTNAMELEN];
254254

255255
str = getenv("PMIX_OUTPUT_STDERR_FD");
256256
if (NULL != str) {

opal/mca/pmix/pmix114/pmix/test/simple/simpdyn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ int main(int argc, char **argv)
4949
uint32_t nprocs;
5050
char nsp2[PMIX_MAX_NSLEN+1];
5151
pmix_app_t *app;
52-
char hostname[1024];
52+
char hostname[PMIX_MAXHOSTNAMELEN];
5353
pmix_proc_t *peers;
5454
size_t npeers, ntmp=0;
5555
char *nodelist;
5656

57-
gethostname(hostname, 1024);
57+
gethostname(hostname, sizeof(hostname));
5858

5959
/* init us */
6060
if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc))) {

opal/mca/pmix/pmix114/pmix/test/simple/simptest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ static void set_namespace(int nprocs, char *ranks, char *nspace,
316316
pmix_op_cbfunc_t cbfunc, myxfer_t *x)
317317
{
318318
char *regex, *ppn;
319-
char hostname[1024];
319+
char hostname[PMIX_MAXHOSTNAMELEN];
320320

321-
gethostname(hostname, 1024);
321+
gethostname(hostname, sizeof(hostname));
322322
x->ninfo = 6;
323323

324324
PMIX_INFO_CREATE(x->info, x->ninfo);

0 commit comments

Comments
 (0)