@@ -114,16 +114,32 @@ OPAL_DECLSPEC void opal_warn_fork(void);
114
114
*/
115
115
OPAL_DECLSPEC int opal_register_params (void );
116
116
117
+ /**
118
+ * Internal function. Should not be called directly (should only be
119
+ * invoked internally by opal_init() and opal_gethostname()).
120
+ */
121
+ OPAL_DECLSPEC int opal_init_gethostname (void );
122
+
117
123
/**
118
124
* Wrapper to return the hostname value that is in
119
- opal_process_info.nodename, as opposed to calling gethostname()
120
- directly, which is not guaranteed to be null-terminated and
121
- varies in its behavior depending on implementation. The
122
- opal_process_info.nodename value is first populated in
123
- opal/runtime/opal_init.c
124
- */
125
- static inline const char * opal_gethostname ( void ) {
126
- assert ( NULL != opal_process_info .nodename );
125
+ * opal_process_info.nodename, as opposed to calling gethostname()
126
+ * directly, which is not guaranteed to be null-terminated and varies
127
+ * in its behavior depending on implementation. The
128
+ * opal_process_info.nodename value is first populated in
129
+ * opal/runtime/opal_init.c.
130
+ *
131
+ * NOTE: In some cases (usually: developer debugging), it is possible
132
+ * that this function is invoked (e.g., via opal_output()) before
133
+ * opal_init() has been invoked, and therefore
134
+ * opal_process_info.nodename is still NULL. In those cases, just
135
+ * call opal_init_gethostname() directly to fill in
136
+ * opal_process_info.nodename.
137
+ */
138
+ static inline const char * opal_gethostname (void )
139
+ {
140
+ if (NULL == opal_process_info .nodename ) {
141
+ opal_init_gethostname ();
142
+ }
127
143
return opal_process_info .nodename ;
128
144
}
129
145
0 commit comments