Skip to content

Commit ce03c06

Browse files
committed
shell: correct HOSTNAME env var if set in job environment
Problem: If the HOSTNAME variable is set in the job environment, it is almost certainly incorrect. This can cause confusing behavior for job tasks that make use of this variable. If HOSTNAME is set in the job environment, correct it by using the current hostname. Fixes #5258
1 parent 98eb2c1 commit ce03c06

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/shell/task.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* . FLUX_JOB_NNODES
2323
* . FLUX_JOB_ID
2424
* . FLUX_URI (if not running standalone)
25+
* . correct HOSTNAME if set in job environment
2526
*
2627
* Current working directory
2728
* Ignore - shell should already be in it.
@@ -154,6 +155,17 @@ struct shell_task *shell_task_create (flux_shell_t *shell,
154155
getenv ("FLUX_KVS_NAMESPACE")) < 0)
155156
goto error;
156157
}
158+
159+
/* If HOSTNAME is set in job environment it is almost certain to be
160+
* incorrect. Overwrite with the correct hostname.
161+
*/
162+
if (flux_cmd_getenv (task->cmd, "HOSTNAME")
163+
&& flux_cmd_setenvf (task->cmd,
164+
1,
165+
"HOSTNAME",
166+
"%s",
167+
shell->hostname) < 0)
168+
goto error;
157169
return task;
158170
error:
159171
shell_task_destroy (task);

0 commit comments

Comments
 (0)