@@ -67,6 +67,8 @@ pmix_server_globals_t pmix_server_globals = {{{0}}};
6767// local variables
6868static char * security_mode = NULL ;
6969static pid_t mypid ;
70+ static char * mytmpdir = NULL ;
71+ static char * systmpdir = NULL ;
7072
7173// local functions for connection support
7274static void server_message_handler (struct pmix_peer_t * pr , pmix_usock_hdr_t * hdr ,
@@ -181,7 +183,9 @@ static pmix_status_t initialize_server_base(pmix_server_module_t *module)
181183 security_mode = strdup (pmix_sec .name );
182184
183185 /* find the temp dir */
184- if (NULL == (tdir = getenv ("PMIX_SERVER_TMPDIR" ))) {
186+ if (NULL != mytmpdir ) {
187+ tdir = mytmpdir ;
188+ } else if (NULL == (tdir = getenv ("PMIX_SERVER_TMPDIR" ))) {
185189 if (NULL == (tdir = getenv ("TMPDIR" ))) {
186190 if (NULL == (tdir = getenv ("TEMP" ))) {
187191 if (NULL == (tdir = getenv ("TMP" ))) {
@@ -233,6 +237,7 @@ PMIX_EXPORT pmix_status_t PMIx_server_init(pmix_server_module_t *module,
233237 char * pmix_pid , * tdir ;
234238 char * * protected = NULL ;
235239 bool protect ;
240+ bool tool_support = false;
236241
237242 ++ pmix_globals .init_cntr ;
238243 if (1 < pmix_globals .init_cntr ) {
@@ -289,40 +294,51 @@ PMIX_EXPORT pmix_status_t PMIx_server_init(pmix_server_module_t *module,
289294 lt -> mode = info [n ].value .data .uint32 ;
290295 }
291296 } else if (0 == strcmp (info [n ].key , PMIX_SERVER_TOOL_SUPPORT )) {
292- pmix_listener_t * tl = PMIX_NEW (pmix_listener_t );
293- tl -> address .sun_family = AF_UNIX ;
294- tl -> protocol = PMIX_PROTOCOL_TOOL ;
295- /* Get up to 30 chars of hostname.*/
296- gethostname (myhostname , myhostnamelen );
297- /* ensure it is NULL terminated */
298- myhostname [myhostnamelen - 1 ] = '\0' ;
299- /* need to put this in the global tmpdir as opposed to
300- * where the server tmpdir might be */
301- if (NULL == (tdir = getenv ("TMPDIR" ))) {
302- if (NULL == (tdir = getenv ("TEMP" ))) {
303- if (NULL == (tdir = getenv ("TMP" ))) {
304- tdir = "/tmp" ;
305- }
306- }
307- }
308- if (0 > asprintf (& pmix_pid , "%s/pmix.%s.tool.%d" , tdir , myhostname , mypid )) {
309- return PMIX_ERR_NOMEM ;
310- }
311- if ((strlen (pmix_pid ) + 1 ) > sizeof (tl -> address .sun_path )- 1 ) {
312- free (pmix_pid );
313- return PMIX_ERR_INVALID_LENGTH ;
297+ /* defer processing to ensure we pickup any tmpdir
298+ * directives before setting location */
299+ tool_support = true;
300+ } else if (0 == strcmp (info [n ].key , PMIX_SERVER_TMPDIR )) {
301+ mytmpdir = strdup (info [n ].value .data .string );
302+ } else if (0 == strcmp (info [n ].key , PMIX_SYSTEM_TMPDIR )) {
303+ systmpdir = strdup (info [n ].value .data .string );
304+ }
305+ }
306+ }
307+ if (tool_support ) {
308+ pmix_listener_t * tl = PMIX_NEW (pmix_listener_t );
309+ tl -> address .sun_family = AF_UNIX ;
310+ tl -> protocol = PMIX_PROTOCOL_TOOL ;
311+ /* Get up to 30 chars of hostname.*/
312+ gethostname (myhostname , myhostnamelen );
313+ /* ensure it is NULL terminated */
314+ myhostname [myhostnamelen - 1 ] = '\0' ;
315+ /* need to put this in the global tmpdir as opposed to
316+ * where the server tmpdir might be */
317+ if (NULL != systmpdir ) {
318+ tdir = systmpdir ;
319+ } else if (NULL == (tdir = getenv ("TMPDIR" ))) {
320+ if (NULL == (tdir = getenv ("TEMP" ))) {
321+ if (NULL == (tdir = getenv ("TMP" ))) {
322+ tdir = "/tmp" ;
314323 }
315- snprintf (tl -> address .sun_path , sizeof (tl -> address .sun_path ) - 1 , "%s" , pmix_pid );
316- free (pmix_pid );
317- /* we don't provide a URI for this listener as we don't pass
318- * the TOOL connection URI to a child process */
319- pmix_server_globals .tool_connections_allowed = true;
320- pmix_list_append (& pmix_server_globals .listeners , & tl -> super );
321- /* push this onto our protected list of keys not
322- * to be passed to the clients */
323- pmix_argv_append_nosize (& protected , PMIX_SERVER_TOOL_SUPPORT );
324324 }
325325 }
326+ if (0 > asprintf (& pmix_pid , "%s/pmix.%s.tool.%d" , tdir , myhostname , mypid )) {
327+ return PMIX_ERR_NOMEM ;
328+ }
329+ if ((strlen (pmix_pid ) + 1 ) > sizeof (tl -> address .sun_path )- 1 ) {
330+ free (pmix_pid );
331+ return PMIX_ERR_INVALID_LENGTH ;
332+ }
333+ snprintf (tl -> address .sun_path , sizeof (tl -> address .sun_path ) - 1 , "%s" , pmix_pid );
334+ free (pmix_pid );
335+ /* we don't provide a URI for this listener as we don't pass
336+ * the TOOL connection URI to a child process */
337+ pmix_server_globals .tool_connections_allowed = true;
338+ pmix_list_append (& pmix_server_globals .listeners , & tl -> super );
339+ /* push this onto our protected list of keys not
340+ * to be passed to the clients */
341+ pmix_argv_append_nosize (& protected , PMIX_SERVER_TOOL_SUPPORT );
326342 }
327343
328344 /* setup the wildcard recv for inbound messages from clients */
@@ -408,6 +424,14 @@ static void cleanup_server_state(void)
408424 free (security_mode );
409425 }
410426
427+ if (NULL != mytmpdir ) {
428+ free (mytmpdir );
429+ }
430+
431+ if (NULL != systmpdir ) {
432+ free (systmpdir );
433+ }
434+
411435 pmix_bfrop_close ();
412436 pmix_sec_finalize ();
413437 pmix_globals_finalize ();
0 commit comments