What does the phrase "early close of stdout" mean?
February 20, 2007 11:35 AM   Subscribe

In the context of OpenSSH, what does the phrase "early close of stdout/stderr" mean?

I am looking at the regress tests in OpenSSH portable, and one phrase I keep seeing over and over is "...with early close of stdout/err". These tests will have something that looks like:

ssh -1 -n somehost
exec sh -c \'"sleep 2 ; exec > /dev/null 2>&1 ; sleep 3 ; exit 9"\'

I understand I'm calling ssh, and expecting it to run the exec command on the destination machine, somehost.

I understand the sh -c means only execute a single command, in this case everything between the quotes, though I'm not clear why it's an escaped single quotes surrounding native double-quotes. Unless that has something to do with the early close, I don't care too much.

I understand the exec > /dev/null 2> &1 means a No-op with stdout and stderr redirected to null.

I don't understand how the two sleeps fit in to create the "early close" condition, or what that really means in this context. Can anyone clarify?
posted by nomisxid to Technology (1 answer total)
 
exec replaces the currently running program with another program. So the first exec sh -c ... will replace whatever shell is normally running with sh (just to ensure that you get a predictable shell).

The second ... exec > /dev/null 2>&1 ... as you said is used to redirect stdout to /dev/null, and then to clone stderr onto stdout. After this, it sleeps for the 3 seconds. ssh should notice that the stdout/stderr that it had originally opened is now closed (because the shell would have closed the original stdout/stderr when they were redirected by the exec).

The quoting is just because passing strings through the current shell (where the ssh command is run) onto the second shell (where the first exec is run) and then into the sh program is a nasty thing. Shell quoting is scary.
posted by zengargoyle at 12:49 PM on February 20, 2007


« Older Graphic novel in which protagonist wanders through...   |   I ate the 'Grilled Pork Chops and Vietnamese... Newer »
This thread is closed to new comments.