Only allow user input after successfully entering the container

feature/node-rewrite
Sven Slootweg 12 years ago
parent a3d18f2ea1
commit e2e7bd646f

@ -12,6 +12,8 @@ endpoint = "http://cvm.local/api.local.php"
def posix_shell(chan, ctid): def posix_shell(chan, ctid):
oldtty = termios.tcgetattr(sys.stdin) oldtty = termios.tcgetattr(sys.stdin)
enable_input = False
try: try:
tty.setraw(sys.stdin.fileno()) tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno())
@ -24,17 +26,26 @@ def posix_shell(chan, ctid):
if chan in r: if chan in r:
try: try:
buff = chan.recv(1024) buff = chan.recv(1024)
if len(buff) == 0: if len(buff) == 0:
print '\r\nYou have been logged out of your container. Goodbye!\r\n', print '\r\nYou have been logged out of your container. Goodbye!\r\n',
break break
if "entered into" in buff:
# Successfully entered into the container, we can enable user input now.
enable_input = True
sys.stdout.write(buff) sys.stdout.write(buff)
sys.stdout.flush() sys.stdout.flush()
except socket.timeout: except socket.timeout:
pass pass
if sys.stdin in r: if sys.stdin in r:
if enable_input == True:
buff = sys.stdin.read(1) buff = sys.stdin.read(1)
if len(buff) == 0: if len(buff) == 0:
break break
chan.send(buff) chan.send(buff)
finally: finally:

Loading…
Cancel
Save