Skip to content

Commit b64ce69

Browse files
committed
fix bash test on Windows by retrieving exit code from child process
fix bash test on Windows by retrieving exit code from child process
1 parent 990629f commit b64ce69

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sshd.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,9 @@ send_rexec_state(int fd)
817817

818818
sshbuf_free(keys);
819819
debug3_f("done");
820+
#ifndef WINDOWS
820821
exit(0);
822+
#endif /* !WINDOWS */
821823
}
822824

823825
/*
@@ -1964,6 +1966,7 @@ main(int ac, char **av)
19641966
#else
19651967
posix_spawn_file_actions_t actions;
19661968
posix_spawnattr_t attributes;
1969+
pid_t pid;
19671970
if (posix_spawn_file_actions_init(&actions) != 0 ||
19681971
(debug_flag && posix_spawn_file_actions_adddup2(&actions, newsock, STDIN_FILENO) != 0) ||
19691972
(debug_flag && posix_spawn_file_actions_adddup2(&actions, newsock, STDOUT_FILENO) != 0) ||
@@ -1973,7 +1976,6 @@ main(int ac, char **av)
19731976
posix_spawnattr_setpgroup(&attributes, 0) != 0)
19741977
error("posix_spawn initialization failed");
19751978
else {
1976-
pid_t pid;
19771979
if (posix_spawn(&pid, rexec_argv[0], &actions, &attributes, rexec_argv, NULL) != 0)
19781980
error("%s, posix_spawn failed", __func__);
19791981
posix_spawn_file_actions_destroy(&actions);
@@ -1983,7 +1985,13 @@ main(int ac, char **av)
19831985
send_rexec_state(config_s[0]);
19841986
close(config_s[0]);
19851987
close(newsock);
1986-
cleanup_exit(255);
1988+
// wait for child to exit to propagate exit code to terminal
1989+
int status;
1990+
if (waitpid(pid, &status, 0) == -1) {
1991+
error("waitpid failed");
1992+
cleanup_exit(255);
1993+
}
1994+
cleanup_exit(status);
19871995
#endif /* FORK_NOT_SUPPORTED */
19881996
}
19891997

0 commit comments

Comments
 (0)