File tree Expand file tree Collapse file tree 4 files changed +28
-4
lines changed
Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -1668,7 +1668,7 @@ int main (int argc, char *argv[])
16681668 while (taskid != IDSET_INVALID_ID ) {
16691669 struct shell_task * task ;
16701670
1671- if (!(task = shell_task_create (shell . info , i , taskid )))
1671+ if (!(task = shell_task_create (& shell , i , taskid )))
16721672 shell_die (1 , "shell_task_create index=%d" , i );
16731673
16741674 task -> pre_exec_cb = shell_task_exec ;
Original file line number Diff line number Diff line change 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.
@@ -91,10 +92,11 @@ struct shell_task *shell_task_new (void)
9192 return NULL ;
9293}
9394
94- struct shell_task * shell_task_create (struct shell_info * info ,
95+ struct shell_task * shell_task_create (flux_shell_t * shell ,
9596 int index ,
9697 int taskid )
9798{
99+ struct shell_info * info = shell -> info ;
98100 struct shell_task * task ;
99101 const char * key ;
100102 json_t * entry ;
@@ -153,6 +155,17 @@ struct shell_task *shell_task_create (struct shell_info *info,
153155 getenv ("FLUX_KVS_NAMESPACE" )) < 0 )
154156 goto error ;
155157 }
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 ;
156169 return task ;
157170error :
158171 shell_task_destroy (task );
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ struct shell_task {
5454
5555void shell_task_destroy (struct shell_task * task );
5656
57- struct shell_task * shell_task_create (struct shell_info * info ,
57+ struct shell_task * shell_task_create (flux_shell_t * shell ,
5858 int index ,
5959 int taskid );
6060
Original file line number Diff line number Diff line change @@ -340,7 +340,18 @@ test_expect_success 'job-shell: fails if FLUX_EXEC_PROTOCOL_FD incorrect' '
340340 -n2 -N2 hostname 2>protocol_fd_invalid.err &&
341341 grep FLUX_EXEC_PROTOCOL_FD protocol_fd_invalid.err
342342'
343-
343+ test_expect_success ' job-shell: corrects HOSTNAME environment variable' '
344+ HOSTNAME=incorrect \
345+ flux run -n1 printenv HOSTNAME >hostname.out &&
346+ test_debug "cat hostname.out" &&
347+ test "$(hostname)" = "$(cat hostname.out)"
348+ '
349+ test_expect_success ' job-shell: leaves HOSTNAME unset if not set' '
350+ ( unset HOSTNAME &&
351+ test_expect_code 1 flux run -n1 printenv HOSTNAME >hostname.out2
352+ ) &&
353+ test_must_be_empty hostname.out2
354+ '
344355# Note: in below tests, os.exit(True) returns with nonzero exit code,
345356# so the sense of the tests is reversed so the tasks exit with zero exit
346357# code for success.
You can’t perform that action at this time.
0 commit comments