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

Commit f320b94

Browse files
committed
orte: fixup hostname max length usage
Also removes orte specific max hostname value. Signed-off-by: Karol Mroz <[email protected]> (cherry picked from commit 5c11bdb) Conflicts: orte/orted/orted_main.c orte/test/system/ulfm.c
1 parent 5e02b6d commit f320b94

File tree

15 files changed

+53
-33
lines changed

15 files changed

+53
-33
lines changed

orte/mca/oob/alps/oob_alps_component.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,14 @@ static int component_send(orte_rml_send_t *msg)
188188
static char* component_get_addr(void)
189189
{
190190
int len;
191-
char hn[MAXHOSTNAMELEN], *cptr;
191+
char hn[OPAL_MAXHOSTNAMELEN], *cptr;
192192

193193
/*
194194
* TODO: for aries want to plug in GNI addr here instead to
195195
* eventually be able to support connect/accept using aprun.
196196
*/
197197

198-
len = gethostname(hn, MAXHOSTNAMELEN - 1);
199-
hn[len]='\0';
198+
len = gethostname(hn, sizeof(hn));
200199

201200
asprintf(&cptr, "gni://%s:%d", hn, getpid());
202201

orte/orted/orted_main.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ int orte_daemon(int argc, char *argv[])
235235
char *rml_uri;
236236
int i;
237237
opal_buffer_t *buffer;
238-
char hostname[100];
238+
239+
char hostname[OPAL_MAXHOSTNAMELEN];
239240
char *coprocessors;
240241
uint8_t tflag;
241242

@@ -301,7 +302,7 @@ int orte_daemon(int argc, char *argv[])
301302
* away just in case we have a problem along the way
302303
*/
303304
if (orted_globals.debug) {
304-
gethostname(hostname, 100);
305+
gethostname(hostname, sizeof(hostname));
305306
fprintf(stderr, "Daemon was launched on %s - beginning to initialize\n", hostname);
306307
}
307308

@@ -721,12 +722,12 @@ int orte_daemon(int argc, char *argv[])
721722
if (orte_retain_aliases) {
722723
char **aliases=NULL;
723724
uint8_t naliases, ni;
724-
char hostname[ORTE_MAX_HOSTNAME_SIZE];
725+
char hostname[OPAL_MAXHOSTNAMELEN];
725726

726727
/* if we stripped the prefix or removed the fqdn,
727728
* include full hostname as an alias
728729
*/
729-
gethostname(hostname, ORTE_MAX_HOSTNAME_SIZE);
730+
gethostname(hostname, sizeof(hostname));
730731
if (strlen(orte_process_info.nodename) < strlen(hostname)) {
731732
opal_argv_append_nosize(&aliases, hostname);
732733
}

orte/test/mpi/concurrent_spawn.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#define _GNU_SOURCE
2+
#include "orte_config.h"
3+
24
#include <stdio.h>
35
#include <sys/types.h>
46
#include <unistd.h>
@@ -13,7 +15,7 @@ int main(int argc, char* argv[])
1315
int msg;
1416
MPI_Comm parent, children[NUM_CHILDREN];
1517
int rank, size, i;
16-
char hostname[512];
18+
char hostname[OPAL_MAXHOSTNAMELEN];
1719
pid_t pid;
1820
char *child_argv[2] = { "", NULL };
1921

@@ -54,7 +56,7 @@ int main(int argc, char* argv[])
5456
}
5557
/* Otherwise, we're the child */
5658
else {
57-
gethostname(hostname, 512);
59+
gethostname(hostname, sizeof(hostname));
5860
if (argc == 1) {
5961
printf("ERROR: child did not receive exepcted argv!\n");
6062
i = -1;

orte/test/mpi/delayed_abort.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
* The most basic of MPI applications
66
*/
77

8+
#include "orte_config.h"
9+
810
#include <stdio.h>
911
#include <unistd.h>
1012
#include "mpi.h"
1113

1214
int main(int argc, char* argv[])
1315
{
1416
int rank, size;
15-
char hostname[512];
17+
char hostname[OPAL_MAXHOSTNAMELEN];
1618

1719
MPI_Init(&argc, &argv);
1820
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
1921
MPI_Comm_size(MPI_COMM_WORLD, &size);
2022

21-
gethostname(hostname, 512);
23+
gethostname(hostname, sizeof(hostname));
2224
printf("%s: I am %d of %d. pid=%d\n", hostname, rank, size, getpid());
2325

2426
if (rank%3 == 0) {

orte/test/mpi/hello_nodename.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77

88
#define _GNU_SOURCE
9+
10+
#include "orte_config.h"
11+
912
#include <stdio.h>
1013
#include <unistd.h>
1114
#include <stdlib.h>
@@ -15,7 +18,7 @@
1518
int main(int argc, char* argv[])
1619
{
1720
int rank, size;
18-
char hostname[512];
21+
char hostname[OPAL_MAXHOSTNAMELEN];
1922
void *appnum;
2023
void *univ_size;
2124
char *appstr, *unistr;
@@ -40,7 +43,7 @@ int main(int argc, char* argv[])
4043
asprintf(&unistr, "%d", *(int*)univ_size);
4144
}
4245

43-
gethostname(hostname, 512);
46+
gethostname(hostname, sizeof(hostname));
4447
printf("Hello, World, I am %d of %d on host %s from app number %s universe size %s universe envar %s\n",
4548
rank, size, hostname, appstr, unistr, (NULL == envar) ? "NULL" : envar);
4649

orte/test/mpi/info_spawn.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "orte_config.h"
2+
13
#include <stdio.h>
24
#include <sys/types.h>
35
#include <unistd.h>
@@ -11,7 +13,7 @@ int main(int argc, char* argv[])
1113
int msg, rc, i;
1214
MPI_Comm parent, child;
1315
int rank, size;
14-
char hostname[512];
16+
char hostname[OPAL_MAXHOSTNAMELEN];
1517
pid_t pid;
1618
MPI_Info info;
1719
char *keyval, *tmp;
@@ -63,7 +65,7 @@ int main(int argc, char* argv[])
6365
else {
6466
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
6567
MPI_Comm_size(MPI_COMM_WORLD, &size);
66-
gethostname(hostname, 512);
68+
gethostname(hostname, sizeof(hostname));
6769
pid = getpid();
6870
printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid);
6971
if (0 == rank) {

orte/test/mpi/simple_spawn.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "orte_config.h"
2+
13
#include <stdio.h>
24
#include <sys/types.h>
35
#include <unistd.h>
@@ -9,7 +11,7 @@ int main(int argc, char* argv[])
911
int msg, rc;
1012
MPI_Comm parent, child;
1113
int rank, size;
12-
char hostname[512];
14+
char hostname[OPAL_MAXHOSTNAMELEN];
1315
pid_t pid;
1416

1517
pid = getpid();
@@ -41,7 +43,7 @@ int main(int argc, char* argv[])
4143
else {
4244
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
4345
MPI_Comm_size(MPI_COMM_WORLD, &size);
44-
gethostname(hostname, 512);
46+
gethostname(hostname, sizeof(hostname));
4547
pid = getpid();
4648
printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid);
4749
if (0 == rank) {

orte/test/mpi/singleton_client_server.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "orte_config.h"
12

23
#include <stdio.h>
34
#include <stdlib.h>
@@ -44,7 +45,7 @@
4445

4546
int main(int argc, char *argv[])
4647
{
47-
char hostname[255] ;
48+
char hostname[OPAL_MAXHOSTNAMELEN] ;
4849
char buff[255] ;
4950

5051
int role ;
@@ -80,7 +81,7 @@ int main(int argc, char *argv[])
8081

8182
/* get the node name */
8283
{
83-
int retval = gethostname(hostname, 255) ;
84+
int retval = gethostname(hostname, sizeof(hostname));
8485
if(retval == -1)
8586
{
8687
fprintf(stderr, "gethostname failed: %s\n", strerror(errno)) ;

orte/test/mpi/spawn_multiple.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "orte_config.h"
2+
13
#include <stdio.h>
24
#include <sys/types.h>
35
#include <unistd.h>
@@ -9,7 +11,7 @@ int main(int argc, char* argv[])
911
int msg;
1012
MPI_Comm parent, child;
1113
int rank, size;
12-
char hostname[512];
14+
char hostname[OPAL_MAXHOSTNAMELEN];
1315
pid_t pid;
1416
int i;
1517
char *cmds[2];
@@ -48,7 +50,7 @@ int main(int argc, char* argv[])
4850
else {
4951
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
5052
MPI_Comm_size(MPI_COMM_WORLD, &size);
51-
gethostname(hostname, 512);
53+
gethostname(hostname, sizeof(hostname));
5254
pid = getpid();
5355
printf("Hello from the child %d of %d on host %s pid %ld: argv[1] = %s\n", rank, size, hostname, (long)pid, argv[1]);
5456
MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE);

orte/test/mpi/spawn_tree.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "orte_config.h"
2+
13
#include <stdio.h>
24
#include <stdlib.h>
35
#include <string.h>
@@ -9,7 +11,7 @@ int main(int argc, char ** argv){
911

1012
int i;
1113
int rank, size, child_rank;
12-
char nomehost[20];
14+
char nomehost[OPAL_MAXHOSTNAMELEN];
1315
MPI_Comm parent, intercomm1, intercomm2;
1416
int erro;
1517
int level, curr_level;
@@ -60,7 +62,7 @@ int main(int argc, char ** argv){
6062

6163
}
6264

63-
gethostname(nomehost, 20);
65+
gethostname(nomehost, sizeof(nomehost));
6466
printf("(%d) in %s\n", rank, nomehost);
6567

6668
MPI_Finalize();

0 commit comments

Comments
 (0)