sshd's -e doesn't work as expected
Julio M. Merino Vidal
jmmv at NetBSD.org
Thu Dec 27 07:15:19 EST 2007
Hello,
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);
+ open(_PATH_DEVNULL, O_RDONLY);
+ close(STDOUT_FILENO);
+ open(_PATH_DEVNULL, O_WRONLY);
+ if (!log_stderr) {
+ close(STDERR_FILENO);
+ open(_PATH_DEVNULL, O_WRONLY);
+ }
/* Disconnect from the controlling tty. */
fd = open(_PATH_TTY, O_RDWR | O_NOCTTY);
--
Julio M. Merino Vidal <jmmv at NetBSD.org>
More information about the openssh-unix-dev
mailing list