S_ISSOCK fails in openssh >= 5.1
Damien Miller
djm at mindrot.org
Wed Feb 24 09:46:09 EST 2010
On Mon, 22 Feb 2010, petesea at bigfoot.com wrote:
> Starting with openssh 5.1 the following code fails (when executed on a remote
> host)... prior to 5.0 this worked, ie S_ISSOCK says STDIN is a socket.
>
> struct stat s;
> fstat(STDIN_FILENO, &s);
> if (S_ISSOCK(s.st_mode))
> // STDIN is a socket
> else
> // STDIN is not a socket
>
> Soo... if I have a command on a remote host that includes the above code and I
> ssh to the remote host and execute the command, S_ISSOCK will fail if the ssh
> server is >= 5.1.
>
> Is this change on purpose or a bug?
Yes, it is on purpose to better support independant signalling of input/output
closure. The channel between a shell/program and sshd is an implementation
detail and is not part of any promised interface, so it is unwise to
depend upon it.
If you want to detect if your program is running under sshd, then you might
want to try testing for the presence of a SSH_CLIENT environment variable.
-d
More information about the openssh-unix-dev
mailing list