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

Commit ddb60c6

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]> (cherry picked from commit e1c64e6) Conflicts: opal/mca/pmix/pmix112/pmix/examples/dynamic.c
1 parent 82f7a76 commit ddb60c6

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

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/pmix112/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];
48+
char hostname[PMIX_MAXHOSTNAMELEN];
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

5555
/* init us */
5656
if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc))) {

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

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

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

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

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

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

130130
if (initialized) {
@@ -249,7 +249,7 @@ bool pmix_output_switch(int output_id, bool enable)
249249
void pmix_output_reopen_all(void)
250250
{
251251
char *str;
252-
char hostname[32];
252+
char hostname[PMIX_MAXHOSTNAMELEN];
253253

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

opal/mca/pmix/pmix112/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/pmix112/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)