[patch] Re: -n vs batch_mode vs batch_flag
Tom Holroyd
tomh at po.crl.go.jp
Mon Apr 9 11:58:59 EST 2001
On Sun, 8 Apr 2001, Markus Friedl wrote:
> i did not invent '-n' but the manpage reads:
>
> -n Redirects stdin from /dev/null (actually, prevents reading from
> stdin). This must be used when ssh is run in the background. A
> common trick is to use this to run X11 programs on a remote ma-
> chine. For example, ssh -n shadows.cs.hut.fi emacs & will start
> an emacs on shadows.cs.hut.fi, and the X11 connection will be au-
> tomatically forwarded over an encrypted channel. The ssh program
> will be put in the background. (This does not work if ssh needs
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> to ask for a password or passphrase; see also the -f option.)
> ^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^
Yes, I read that. Notice how ssh doesn't do what that says.
> > % ssh -n localhost &
> > [1] 5220
> > % tomh at localhost's password:
> > [1] + Suspended (tty input) ssh -n localhost
According to the man page, -n should _prevent_ reading from stdin, but it
doesn't. There is a mechanism for this (batch mode) but it isn't used. I
was suggesting that -n set options.batch_mode (the stuff I said about
batch_flag was all wrong; if -n sets options.batch_mode it works).
Here's a patch. With this, you can put
ssh -n host command &
in a background script (or a menu item) and it will die gracefully if a
passwordless method (such as pubkey) isn't available. If you say -f then
it's an error to use batch mode.
--- ssh.c.old Mon Apr 9 10:44:52 2001
+++ ssh.c Mon Apr 9 10:53:35 2001
@@ -335,6 +335,7 @@
break;
case 'n':
stdin_null_flag = 1;
+ options.batch_mode = 1;
break;
case 'f':
fork_after_authentication_flag = 1;
@@ -533,6 +534,8 @@
/* Cannot fork to background if no command. */
if (fork_after_authentication_flag && buffer_len(&command) == 0 && !no_shell_flag)
fatal("Cannot fork into background without a command to execute.");
+ if (fork_after_authentication_flag)
+ options.batch_mode = 0;
/* Allocate a tty by default if no command specified. */
if (buffer_len(&command) == 0)
Dr. Tom
More information about the openssh-unix-dev
mailing list