From ca87aacaf2ac2ceaf68e39b5a08be4ed9fe3893b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 10 Feb 2014 18:28:45 -0500 Subject: [PATCH] Support console exit and dedicated console mode Have confetty assume that a plain nodename is a requset for console. If a console session is started from interactive mode, return to interactive mode on ctrl-e, c, . rather than exiting. --- bin/confetty | 22 +++++++++++++++++++--- confluent/sockapi.py | 6 ++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/bin/confetty b/bin/confetty index 2198622c..a9565432 100755 --- a/bin/confetty +++ b/bin/confetty @@ -36,6 +36,7 @@ import sys import termios import tty +consoleonly = False target = "/" path = os.path.dirname(os.path.realpath(__file__)) path = os.path.realpath(os.path.join(path, '..')) @@ -83,6 +84,7 @@ def send_request(operation, path, server): def do_command(command, server): global target + global currconsole global currchildren if command == "": # result of ctrl-d command = "exit\n" @@ -112,6 +114,7 @@ def do_command(command, server): print item["href"] if argv[0] == 'start': targpath = fullpath_target(argv[1]) + currconsole = targpath tlvdata.send_tlvdata(server, {'operation': 'start', 'path': targpath}) status = tlvdata.recv_tlvdata(server) if 'error' in status: @@ -151,10 +154,18 @@ def startconsole(): inconsole = True def exit(code=0): + global consoleonly + global inconsole + global currconsole termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, oldtcattr) - server.shutdown(socket.SHUT_RDWR) - server.close() - sys.exit(code) + if consoleonly: + server.shutdown(socket.SHUT_RDWR) + server.close() + sys.exit(code) + else: + tlvdata.send_tlvdata(server, {'operation': 'stop', 'path': currconsole}) + inconsole = False + prompt() def conserver_command(fh, command): while not command: @@ -249,6 +260,7 @@ doexit = False inconsole = False pendingcommand = "" if len(args) == 1: # a node name, go straight to trying to console + consoleonly = True do_command("start /node/%s/console/session" % args[0], server) else: prompt() @@ -256,6 +268,10 @@ while not doexit: rdylist, _, _ = select.select((sys.stdin, server), (), (), 60) for fh in rdylist: if fh == server: + # this only should get called in the + # case of a console session + # each command should slurp up all relevant + # recv_tlvdata potential #fh.read() try: data = tlvdata.recv_tlvdata(fh) diff --git a/confluent/sockapi.py b/confluent/sockapi.py index 47cdb4ec..500082a1 100644 --- a/confluent/sockapi.py +++ b/confluent/sockapi.py @@ -105,6 +105,12 @@ def process_request(connection, request, cfm, authdata): ccons.startsending() while consession is not None: data = tlvdata.recv_tlvdata(connection) + if type(data) == dict: + if data['operation'] == 'stop': + consession.destroy() + return + else: + raise Exception("TODO") if not data: consession.destroy() return