sshd's -e doesn't work as expected

Julio M. Merino Vidal jmmv at
Thu Dec 27 07:15:19 EST 2007


I'm running a sshd server using the -e flag so that I can capture its
whole output and later send it to the user.  I'm also setting LogLevel
to DEBUG1 in the configuration file and I don't want to disturb syslogd.
But the problem is that it doesn't work as expected (or as I expect,
which I think should be the correct behavior).  The log file ends up
being empty because the call to daemon(0, 0) done by the server
effectively closes the stderr stream and all prints to it do not work.

I've fixed this issue with the attached patch.  Hope that it is OK and
can be committed.  If not, please tell me why.

Thank you,

Index: sshd.c
RCS file: /cvsroot/src/crypto/dist/ssh/sshd.c,v
retrieving revision 1.42
diff -u -p -r1.42 sshd.c
--- sshd.c	18 Dec 2007 02:35:33 -0000	1.42
+++ sshd.c	26 Dec 2007 20:12:22 -0000
@@ -1485,8 +1485,16 @@ main(int ac, char **av)
 	if (!(debug_flag || inetd_flag || no_daemon_flag)) {
 		int fd;
-		if (daemon(0, 0) < 0)
+		if (daemon(0, 1) < 0)
 			fatal("daemon() failed: %.200s", strerror(errno));
+		close(STDIN_FILENO);
+		close(STDOUT_FILENO);
+		if (!log_stderr) {
+			close(STDERR_FILENO);
+		}
 		/* Disconnect from the controlling tty. */
 		fd = open(_PATH_TTY, O_RDWR | O_NOCTTY);

Julio M. Merino Vidal <jmmv at>

More information about the openssh-unix-dev mailing list