1
1

orte: fixup hostname max length usage

Also removes orte specific max hostname value.

Signed-off-by: Karol Mroz <mroz.karol@gmail.com>
Этот коммит содержится в:
Karol Mroz 2016-04-16 02:47:42 +02:00
родитель 3322347da9
Коммит 5c11bdb251
16 изменённых файлов: 56 добавлений и 35 удалений

Просмотреть файл

@ -194,15 +194,14 @@ static int component_send(orte_rml_send_t *msg)
static char* component_get_addr(void) static char* component_get_addr(void)
{ {
int len; int len;
char hn[MAXHOSTNAMELEN], *cptr; char hn[OPAL_MAXHOSTNAMELEN], *cptr;
/* /*
* TODO: for aries want to plug in GNI addr here instead to * TODO: for aries want to plug in GNI addr here instead to
* eventually be able to support connect/accept using aprun. * eventually be able to support connect/accept using aprun.
*/ */
len = gethostname(hn, MAXHOSTNAMELEN - 1); len = gethostname(hn, sizeof(hn));
hn[len]='\0';
asprintf(&cptr, "gni://%s:%d", hn, getpid()); asprintf(&cptr, "gni://%s:%d", hn, getpid());

Просмотреть файл

@ -230,7 +230,7 @@ int orte_daemon(int argc, char *argv[])
char *rml_uri; char *rml_uri;
int i; int i;
opal_buffer_t *buffer; opal_buffer_t *buffer;
char hostname[100]; char hostname[OPAL_MAXHOSTNAMELEN];
#if OPAL_ENABLE_FT_CR == 1 #if OPAL_ENABLE_FT_CR == 1
char *tmp_env_var = NULL; char *tmp_env_var = NULL;
#endif #endif
@ -297,7 +297,7 @@ int orte_daemon(int argc, char *argv[])
* away just in case we have a problem along the way * away just in case we have a problem along the way
*/ */
if (orted_globals.debug) { if (orted_globals.debug) {
gethostname(hostname, 100); gethostname(hostname, sizeof(hostname));
fprintf(stderr, "Daemon was launched on %s - beginning to initialize\n", hostname); fprintf(stderr, "Daemon was launched on %s - beginning to initialize\n", hostname);
} }
@ -725,12 +725,12 @@ int orte_daemon(int argc, char *argv[])
if (orte_retain_aliases) { if (orte_retain_aliases) {
char **aliases=NULL; char **aliases=NULL;
uint8_t naliases, ni; uint8_t naliases, ni;
char hostname[ORTE_MAX_HOSTNAME_SIZE]; char hostname[OPAL_MAXHOSTNAMELEN];
/* if we stripped the prefix or removed the fqdn, /* if we stripped the prefix or removed the fqdn,
* include full hostname as an alias * include full hostname as an alias
*/ */
gethostname(hostname, ORTE_MAX_HOSTNAME_SIZE); gethostname(hostname, sizeof(hostname));
if (strlen(orte_process_info.nodename) < strlen(hostname)) { if (strlen(orte_process_info.nodename) < strlen(hostname)) {
opal_argv_append_nosize(&aliases, hostname); opal_argv_append_nosize(&aliases, hostname);
} }

Просмотреть файл

@ -1,4 +1,6 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@ -13,7 +15,7 @@ int main(int argc, char* argv[])
int msg; int msg;
MPI_Comm parent, children[NUM_CHILDREN]; MPI_Comm parent, children[NUM_CHILDREN];
int rank, size, i; int rank, size, i;
char hostname[512]; char hostname[OPAL_MAXHOSTNAMELEN];
pid_t pid; pid_t pid;
char *child_argv[2] = { "", NULL }; char *child_argv[2] = { "", NULL };
@ -54,7 +56,7 @@ int main(int argc, char* argv[])
} }
/* Otherwise, we're the child */ /* Otherwise, we're the child */
else { else {
gethostname(hostname, 512); gethostname(hostname, sizeof(hostname));
if (argc == 1) { if (argc == 1) {
printf("ERROR: child did not receive exepcted argv!\n"); printf("ERROR: child did not receive exepcted argv!\n");
i = -1; i = -1;

Просмотреть файл

@ -5,6 +5,8 @@
* The most basic of MPI applications * The most basic of MPI applications
*/ */
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "mpi.h" #include "mpi.h"
@ -12,13 +14,13 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int rank, size; int rank, size;
char hostname[512]; char hostname[OPAL_MAXHOSTNAMELEN];
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_size(MPI_COMM_WORLD, &size);
gethostname(hostname, 512); gethostname(hostname, sizeof(hostname));
printf("%s: I am %d of %d. pid=%d\n", hostname, rank, size, getpid()); printf("%s: I am %d of %d. pid=%d\n", hostname, rank, size, getpid());
if (rank%3 == 0) { if (rank%3 == 0) {

Просмотреть файл

@ -6,6 +6,9 @@
*/ */
#define _GNU_SOURCE #define _GNU_SOURCE
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
@ -15,7 +18,7 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int rank, size; int rank, size;
char hostname[512]; char hostname[OPAL_MAXHOSTNAMELEN];
void *appnum; void *appnum;
void *univ_size; void *univ_size;
char *appstr, *unistr; char *appstr, *unistr;
@ -40,7 +43,7 @@ int main(int argc, char* argv[])
asprintf(&unistr, "%d", *(int*)univ_size); asprintf(&unistr, "%d", *(int*)univ_size);
} }
gethostname(hostname, 512); gethostname(hostname, sizeof(hostname));
printf("Hello, World, I am %d of %d on host %s from app number %s universe size %s universe envar %s\n", printf("Hello, World, I am %d of %d on host %s from app number %s universe size %s universe envar %s\n",
rank, size, hostname, appstr, unistr, (NULL == envar) ? "NULL" : envar); rank, size, hostname, appstr, unistr, (NULL == envar) ? "NULL" : envar);

Просмотреть файл

@ -1,3 +1,5 @@
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@ -11,7 +13,7 @@ int main(int argc, char* argv[])
int msg, rc, i; int msg, rc, i;
MPI_Comm parent, child; MPI_Comm parent, child;
int rank, size; int rank, size;
char hostname[512]; char hostname[OPAL_MAXHOSTNAMELEN];
pid_t pid; pid_t pid;
MPI_Info info; MPI_Info info;
char *keyval, *tmp; char *keyval, *tmp;
@ -63,7 +65,7 @@ int main(int argc, char* argv[])
else { else {
MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_size(MPI_COMM_WORLD, &size);
gethostname(hostname, 512); gethostname(hostname, sizeof(hostname));
pid = getpid(); pid = getpid();
printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid); printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid);
if (0 == rank) { if (0 == rank) {

Просмотреть файл

@ -1,3 +1,5 @@
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@ -9,7 +11,7 @@ int main(int argc, char* argv[])
int msg, rc; int msg, rc;
MPI_Comm parent, child; MPI_Comm parent, child;
int rank, size; int rank, size;
char hostname[512]; char hostname[OPAL_MAXHOSTNAMELEN];
pid_t pid; pid_t pid;
pid = getpid(); pid = getpid();
@ -41,7 +43,7 @@ int main(int argc, char* argv[])
else { else {
MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_size(MPI_COMM_WORLD, &size);
gethostname(hostname, 512); gethostname(hostname, sizeof(hostname));
pid = getpid(); pid = getpid();
printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid); printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid);
if (0 == rank) { if (0 == rank) {

Просмотреть файл

@ -1,3 +1,4 @@
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -44,7 +45,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char hostname[255] ; char hostname[OPAL_MAXHOSTNAMELEN] ;
char buff[255] ; char buff[255] ;
int role ; int role ;
@ -80,7 +81,7 @@ int main(int argc, char *argv[])
/* get the node name */ /* get the node name */
{ {
int retval = gethostname(hostname, 255) ; int retval = gethostname(hostname, sizeof(hostname));
if(retval == -1) if(retval == -1)
{ {
fprintf(stderr, "gethostname failed: %s\n", strerror(errno)) ; fprintf(stderr, "gethostname failed: %s\n", strerror(errno)) ;

Просмотреть файл

@ -1,3 +1,5 @@
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@ -9,7 +11,7 @@ int main(int argc, char* argv[])
int msg; int msg;
MPI_Comm parent, child; MPI_Comm parent, child;
int rank, size; int rank, size;
char hostname[512]; char hostname[OPAL_MAXHOSTNAMELEN];
pid_t pid; pid_t pid;
int i; int i;
char *cmds[2]; char *cmds[2];
@ -48,7 +50,7 @@ int main(int argc, char* argv[])
else { else {
MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_size(MPI_COMM_WORLD, &size);
gethostname(hostname, 512); gethostname(hostname, sizeof(hostname));
pid = getpid(); pid = getpid();
printf("Hello from the child %d of %d on host %s pid %ld: argv[1] = %s\n", rank, size, hostname, (long)pid, argv[1]); printf("Hello from the child %d of %d on host %s pid %ld: argv[1] = %s\n", rank, size, hostname, (long)pid, argv[1]);
MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE); MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE);

Просмотреть файл

@ -1,3 +1,5 @@
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -9,7 +11,7 @@ int main(int argc, char ** argv){
int i; int i;
int rank, size, child_rank; int rank, size, child_rank;
char nomehost[20]; char nomehost[OPAL_MAXHOSTNAMELEN];
MPI_Comm parent, intercomm1, intercomm2; MPI_Comm parent, intercomm1, intercomm2;
int erro; int erro;
int level, curr_level; int level, curr_level;
@ -60,7 +62,7 @@ int main(int argc, char ** argv){
} }
gethostname(nomehost, 20); gethostname(nomehost, sizeof(nomehost));
printf("(%d) in %s\n", rank, nomehost); printf("(%d) in %s\n", rank, nomehost);
MPI_Finalize(); MPI_Finalize();

Просмотреть файл

@ -6,6 +6,8 @@
* abnormal program termination * abnormal program termination
*/ */
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
@ -21,14 +23,14 @@ int main(int argc, char* argv[])
int i, rc; int i, rc;
double pi; double pi;
pid_t pid; pid_t pid;
char hostname[500]; char hostname[OPAL_MAXHOSTNAMELEN];
if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) { if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc); fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc);
return rc; return rc;
} }
pid = getpid(); pid = getpid();
gethostname(hostname, 500); gethostname(hostname, sizeof(hostname));
if (1 < argc) { if (1 < argc) {
rc = strtol(argv[1], NULL, 10); rc = strtol(argv[1], NULL, 10);

Просмотреть файл

@ -6,6 +6,8 @@
* abnormal program termination * abnormal program termination
*/ */
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
@ -21,14 +23,14 @@ int main(int argc, char* argv[])
int i, rc; int i, rc;
double pi; double pi;
pid_t pid; pid_t pid;
char hostname[500]; char hostname[OPAL_MAXHOSTNAMELEN];
if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) { if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc); fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc);
return rc; return rc;
} }
pid = getpid(); pid = getpid();
gethostname(hostname, 500); gethostname(hostname, sizeof(hostname));
printf("orte_abort: Name %s Host: %s Pid %ld\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), printf("orte_abort: Name %s Host: %s Pid %ld\n", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
hostname, (long)pid); hostname, (long)pid);

Просмотреть файл

@ -5,6 +5,8 @@
* The most basic of MPI applications * The most basic of MPI applications
*/ */
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
@ -20,7 +22,7 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int rc, i, restart=-1; int rc, i, restart=-1;
char hostname[512], *rstrt; char hostname[OPAL_MAXHOSTNAMELEN], *rstrt;
pid_t pid; pid_t pid;
if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) { if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
@ -32,7 +34,7 @@ int main(int argc, char* argv[])
restart = strtol(rstrt, NULL, 10); restart = strtol(rstrt, NULL, 10);
} }
gethostname(hostname, 512); gethostname(hostname, sizeof(hostname));
pid = getpid(); pid = getpid();
printf("orte_nodename: Node %s Name %s Pid %ld Restarts: %d\n", printf("orte_nodename: Node %s Name %s Pid %ld Restarts: %d\n",

Просмотреть файл

@ -1,6 +1,8 @@
/* -*- C -*- /* -*- C -*-
*/ */
#include "orte_config.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
@ -19,14 +21,14 @@ int main(int argc, char* argv[])
int i, rc; int i, rc;
double pi; double pi;
pid_t pid; pid_t pid;
char hostname[500]; char hostname[OPAL_MAXHOSTNAMELEN];
if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) { if (0 > (rc = orte_init(&argc, &argv, ORTE_PROC_NON_MPI))) {
fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc); fprintf(stderr, "orte_abort: couldn't init orte - error code %d\n", rc);
return rc; return rc;
} }
pid = getpid(); pid = getpid();
gethostname(hostname, 500); gethostname(hostname, sizeof(hostname));
if (1 < argc) { if (1 < argc) {
rc = strtol(argv[1], NULL, 10); rc = strtol(argv[1], NULL, 10);

Просмотреть файл

@ -99,7 +99,7 @@ int orte_proc_info(void)
int idx, i; int idx, i;
char *ptr; char *ptr;
char hostname[ORTE_MAX_HOSTNAME_SIZE]; char hostname[OPAL_MAXHOSTNAMELEN];
char **prefixes; char **prefixes;
bool match; bool match;
struct in_addr buf; struct in_addr buf;
@ -168,7 +168,7 @@ int orte_proc_info(void)
orte_process_info.pid = getpid(); orte_process_info.pid = getpid();
/* get the nodename */ /* get the nodename */
gethostname(hostname, ORTE_MAX_HOSTNAME_SIZE); gethostname(hostname, sizeof(hostname));
/* add this to our list of aliases */ /* add this to our list of aliases */
opal_argv_append_nosize(&orte_process_info.aliases, hostname); opal_argv_append_nosize(&orte_process_info.aliases, hostname);

Просмотреть файл

@ -45,8 +45,6 @@
BEGIN_C_DECLS BEGIN_C_DECLS
#define ORTE_MAX_HOSTNAME_SIZE 512
typedef uint32_t orte_proc_type_t; typedef uint32_t orte_proc_type_t;
#define ORTE_PROC_TYPE_NONE 0x0000 #define ORTE_PROC_TYPE_NONE 0x0000
#define ORTE_PROC_SINGLETON 0x0001 #define ORTE_PROC_SINGLETON 0x0001