On my linux box, when using screen I can open, read and write to a pseudo terminal with screen. After closing it (C-a k y) I can't connect to it again, without restarting socat, which provides the pseudo terminal.
Just after starting socat things look like this:
/home/kidmose $ fuser /dev/pts/9
/dev/pts/9: 20960
/home/kidmose $ lsof /dev/pts/9
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
socat 20960 kidmose 5u CHR 136,9 0t0 12 /dev/pts/9
and I can write and read as expected:
/home/kidmose $ echo "uname -a" > /dev/pts/9 && cat /dev/pts/9
uname -a
Linux egki-laptop-linuxmint 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Starting screen also works once (I can write and read the expected output):
/home/kidmose $ screen /dev/pts/9
uname -a # My input
Linux egki-laptop-linuxmint 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux # Response
(C-a k y) # I kill the window and screen terminates ([screen is terminating])
Now I can no longer connect with screen nor simply write. Screen immediately exits with [screen is terminating] and I get the following error when trying to write:
/home/kidmose $ echo "uname -a" > /dev/pts/9 && cat /dev/pts/9
bash: /dev/pts/9: Device or resource busy
Some info:
/home/kidmose $ fuser /dev/pts/9
/dev/pts/9: 20960
/home/kidmose $ lsof /dev/pts/9
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
socat 20960 kidmose 5u CHR 136,9te 0t0 12 /dev/pts/9
/home/kidmose $
Any ideas on why it is 'busy' / unavailable?
I've noticed the 'te' appears in the lsof output. Any explanation for that?
My final goal is to have like a virtual terminal on a remote device. Due to NAT etc. I need the remote device to call in to the server, where the the virtual terminal will be.
Edit: As lemonsqueeze put it in his comment:
[A: sh -> socat] --> [B: socat -> pty -> screen]
Machine A TCP Machine B
Answer
Suggestion: In this situation I'd go with a Reverse SSH connection:
Instead of your machine doing an ssh, the server machine does an ssh and through port forwarding makes sure that you can ssh back to server machine.
But it's certainly not as fun as building it yourself with socat. I'd still recommend getting to the bottom of this pty issue, it's a good way to learn.
No comments:
Post a Comment