@@ -817,7 +817,9 @@ send_rexec_state(int fd)
817
817
818
818
sshbuf_free (keys );
819
819
debug3_f ("done" );
820
+ #ifndef WINDOWS
820
821
exit (0 );
822
+ #endif /* !WINDOWS */
821
823
}
822
824
823
825
/*
@@ -1964,6 +1966,7 @@ main(int ac, char **av)
1964
1966
#else
1965
1967
posix_spawn_file_actions_t actions ;
1966
1968
posix_spawnattr_t attributes ;
1969
+ pid_t pid ;
1967
1970
if (posix_spawn_file_actions_init (& actions ) != 0 ||
1968
1971
(debug_flag && posix_spawn_file_actions_adddup2 (& actions , newsock , STDIN_FILENO ) != 0 ) ||
1969
1972
(debug_flag && posix_spawn_file_actions_adddup2 (& actions , newsock , STDOUT_FILENO ) != 0 ) ||
@@ -1973,7 +1976,6 @@ main(int ac, char **av)
1973
1976
posix_spawnattr_setpgroup (& attributes , 0 ) != 0 )
1974
1977
error ("posix_spawn initialization failed" );
1975
1978
else {
1976
- pid_t pid ;
1977
1979
if (posix_spawn (& pid , rexec_argv [0 ], & actions , & attributes , rexec_argv , NULL ) != 0 )
1978
1980
error ("%s, posix_spawn failed" , __func__ );
1979
1981
posix_spawn_file_actions_destroy (& actions );
@@ -1983,7 +1985,13 @@ main(int ac, char **av)
1983
1985
send_rexec_state (config_s [0 ]);
1984
1986
close (config_s [0 ]);
1985
1987
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
+ perror ("waitpid failed" );
1992
+ exit (1 );
1993
+ }
1994
+ cleanup_exit (status );
1987
1995
#endif /* FORK_NOT_SUPPORTED */
1988
1996
}
1989
1997
0 commit comments