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
@@ -70,9 +71,11 @@ static void sn_des(seq_node_t *p)
7071{
7172 if (NULL != p -> hostname ) {
7273 free (p -> hostname );
74+ p -> hostname = NULL ;
7375 }
7476 if (NULL != p -> cpuset ) {
7577 free (p -> cpuset );
78+ p -> cpuset = NULL ;
7679 }
7780}
7881OBJ_CLASS_INSTANCE (seq_node_t ,
@@ -101,7 +104,7 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
101104 opal_list_t node_list , * seq_list , sq_list ;
102105 orte_proc_t * proc ;
103106 mca_base_component_t * c = & mca_rmaps_seq_component .base_version ;
104- char * hosts , * sep , * eptr ;
107+ char * hosts = NULL , * sep , * eptr ;
105108 FILE * fp ;
106109 opal_hwloc_resource_type_t rtype ;
107110
@@ -156,7 +159,7 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
156159 /* if there is a default hostfile, go and get its ordered list of nodes */
157160 OBJ_CONSTRUCT (& default_seq_list , opal_list_t );
158161 if (NULL != orte_default_hostfile ) {
159- char * hstname ;
162+ char * hstname = NULL ;
160163 /* open the file */
161164 fp = fopen (orte_default_hostfile , "r" );
162165 if (NULL == fp ) {
@@ -170,6 +173,11 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
170173 /* blank line - ignore */
171174 continue ;
172175 }
176+ if ( '#' == hstname [0 ] ) {
177+ free (hstname );
178+ /* Comment line - ignore */
179+ continue ;
180+ }
173181 sq = OBJ_NEW (seq_node_t );
174182 if (NULL != (sep = strchr (hstname , ' ' ))) {
175183 * sep = '\0' ;
@@ -182,6 +190,21 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
182190 * (eptr + 1 ) = 0 ;
183191 sq -> cpuset = strdup (sep );
184192 }
193+
194+ // Strip off the FQDN if present
195+ if ( !orte_keep_fqdn_hostnames ) {
196+ char * ptr ;
197+ struct in_addr buf ;
198+
199+ /* if the nodename is an IP address, do not mess with it! */
200+ if (0 == inet_pton (AF_INET , hstname , & buf ) &&
201+ 0 == inet_pton (AF_INET6 , hstname , & buf )) {
202+ if (NULL != (ptr = strchr (hstname , '.' ))) {
203+ * ptr = '\0' ;
204+ }
205+ }
206+ }
207+
185208 sq -> hostname = hstname ;
186209 opal_list_append (& default_seq_list , & sq -> super );
187210 }
@@ -255,6 +278,16 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
255278 goto error ;
256279 }
257280 while (NULL != (hstname = orte_getline (fp ))) {
281+ if (0 == strlen (hstname )) {
282+ free (hstname );
283+ /* blank line - ignore */
284+ continue ;
285+ }
286+ if ( '#' == hstname [0 ] ) {
287+ free (hstname );
288+ /* Comment line - ignore */
289+ continue ;
290+ }
258291 sq = OBJ_NEW (seq_node_t );
259292 if (NULL != (sep = strchr (hstname , ' ' ))) {
260293 * sep = '\0' ;
@@ -267,6 +300,20 @@ static int orte_rmaps_seq_map(orte_job_t *jdata)
267300 * (eptr + 1 ) = 0 ;
268301 sq -> cpuset = strdup (sep );
269302 }
303+
304+ // Strip off the FQDN if present
305+ if ( !orte_keep_fqdn_hostnames ) {
306+ char * ptr ;
307+ struct in_addr buf ;
308+ /* if the nodename is an IP address, do not mess with it! */
309+ if (0 == inet_pton (AF_INET , hstname , & buf ) &&
310+ 0 == inet_pton (AF_INET6 , hstname , & buf )) {
311+ if (NULL != (ptr = strchr (hstname , '.' ))) {
312+ (* ptr ) = '\0' ;
313+ }
314+ }
315+ }
316+
270317 sq -> hostname = hstname ;
271318 opal_list_append (& sq_list , & sq -> super );
272319 }
0 commit comments