|Perl Monk, Perl Meditation|
' Inappropriate ioctl for device ' on read from SSH over open2() handleby jblank (Initiate)
|on Jan 28, 2008 at 21:44 UTC||Need Help??|
jblank has asked for the
wisdom of the Perl Monks concerning the following question:
Hello o monks of Perl knowledge:
I am having an odd problem with reading from SSH via the reader handle provided by open2(). (As you know, open2() opens two handles: One to read and one to write, permitting bidirectional communication.)
As part of an application I am working on, I need the ability to execute a small script with 'sudo' on a remote host via ssh. Sudo, in turn, requires a pseudo-tty. Thus, I must add the '-t -t' flags to SSH to force it to allocate a pseudo-tty. Without these flags, I do not get my mysterious warning/error; however, my script breaks, since sudo cannot run!
The warning/error in question is 'tcgetattr: Inappropriate ioctl for device'. I get this error after I open2() a pipe through an openssh session and attempt to read from it. The read succeeds... but on the first read, I get that error/warning (I'm not quite sure which it would be considered, an error or a warning).
I do not have this problem with open(), nor with open3()-- and since open3() does everything that open2() does, I have migrated my script to open3(). However, I am seeking explanations here. Have I found a bug? Is ssh trying to do something to stderr that open2() cannot handle?
Code snippet below. Set $TESTHOST to the IP of a host that you can SSH to without passwords (via authorized_hosts) and watch the error-y fun! (For some reason, on my machine, I only see the error when I am logged in as a normal user, not as root. Go figure.)