1515 * Copyright (c) 2014-2016 Intel, Inc. All rights reserved.
1616 * Copyright (c) 2015 Research Organization for Information Science
1717 * and Technology (RIST). All rights reserved.
18+ * Copyright (c) 2016 IBM Corporation. All rights reserved.
1819 * $COPYRIGHT$
1920 *
2021 * Additional copyrights may follow
3435#include <ctype.h>
3536
3637#include "opal/util/if.h"
38+ #include "opal/util/net.h"
3739#include "opal/mca/hwloc/hwloc.h"
3840
3941#include "orte/util/show_help.h"
@@ -70,9 +72,11 @@ static void sn_des(seq_node_t *p)
7072{
7173 if (NULL != p -> hostname ) {
7274 free (p -> hostname );
75+ p -> hostname = NULL ;
7376 }
7477 if (NULL != p -> cpuset ) {
7578 free (p -> cpuset );
79+ p -> cpuset = NULL ;
7680 }
7781}
7882OBJ_CLASS_INSTANCE (seq_node_t ,
@@ -101,7 +105,7 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
101105 opal_list_t node_list , * seq_list , sq_list ;
102106 orte_proc_t * proc ;
103107 mca_base_component_t * c = & mca_rmaps_seq_component .base_version ;
104- char * hosts , * sep , * eptr ;
108+ char * hosts = NULL , * sep , * eptr ;
105109 FILE * fp ;
106110 opal_hwloc_resource_type_t rtype ;
107111
@@ -156,7 +160,7 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
156160 /* if there is a default hostfile, go and get its ordered list of nodes */
157161 OBJ_CONSTRUCT (& default_seq_list , opal_list_t );
158162 if (NULL != orte_default_hostfile ) {
159- char * hstname ;
163+ char * hstname = NULL ;
160164 /* open the file */
161165 fp = fopen (orte_default_hostfile , "r" );
162166 if (NULL == fp ) {
@@ -170,6 +174,11 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
170174 /* blank line - ignore */
171175 continue ;
172176 }
177+ if ( '#' == hstname [0 ] ) {
178+ free (hstname );
179+ /* Comment line - ignore */
180+ continue ;
181+ }
173182 sq = OBJ_NEW (seq_node_t );
174183 if (NULL != (sep = strchr (hstname , ' ' ))) {
175184 * sep = '\0' ;
@@ -182,6 +191,15 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
182191 * (eptr + 1 ) = 0 ;
183192 sq -> cpuset = strdup (sep );
184193 }
194+
195+ // Strip off the FQDN if present, ignore IP addresses
196+ if ( !orte_keep_fqdn_hostnames && !opal_net_isaddr (hstname ) ) {
197+ char * ptr ;
198+ if (NULL != (ptr = strchr (hstname , '.' ))) {
199+ * ptr = '\0' ;
200+ }
201+ }
202+
185203 sq -> hostname = hstname ;
186204 opal_list_append (& default_seq_list , & sq -> super );
187205 }
@@ -255,6 +273,16 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
255273 goto error ;
256274 }
257275 while (NULL != (hstname = orte_getline (fp ))) {
276+ if (0 == strlen (hstname )) {
277+ free (hstname );
278+ /* blank line - ignore */
279+ continue ;
280+ }
281+ if ( '#' == hstname [0 ] ) {
282+ free (hstname );
283+ /* Comment line - ignore */
284+ continue ;
285+ }
258286 sq = OBJ_NEW (seq_node_t );
259287 if (NULL != (sep = strchr (hstname , ' ' ))) {
260288 * sep = '\0' ;
@@ -267,6 +295,15 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
267295 * (eptr + 1 ) = 0 ;
268296 sq -> cpuset = strdup (sep );
269297 }
298+
299+ // Strip off the FQDN if present, ignore IP addresses
300+ if ( !orte_keep_fqdn_hostnames && !opal_net_isaddr (hstname ) ) {
301+ char * ptr ;
302+ if (NULL != (ptr = strchr (hstname , '.' ))) {
303+ (* ptr ) = '\0' ;
304+ }
305+ }
306+
270307 sq -> hostname = hstname ;
271308 opal_list_append (& sq_list , & sq -> super );
272309 }
0 commit comments