def _do_open_terminal(self, term): ready = self.wait_for_data([self.sock], 0.1) if self.sock not in ready: # XXX TODO: wait for a keypress from some existing terminal # to trigger the appearance of the terminal. # Specify options via the environment. # This allows us to spawn the joiner with no arguments, # so it will work with the "-e" option of terminal programs. env = {} env["PIAS_OPT_JOIN"] = "1" env["PIAS_OPT_COMMAND"] = "replay" env["PIAS_OPT_DATAFILE"] = self.eventlog.datafile env["PIAS_OPT_TERMINAL"] = self.terminal forkexec([self.terminal, "-e", get_pias_script()], env) view_sock, _ = self.sock.accept() if self.live_replay: # this is cribbed from recorder._handle_open_terminal # TODO (JC): look into further refactoring common code into an util function # Fork a new shell behind a pty. _, proc_fd = forkexec_pty([self.replay_shell]) # often the terminal comes up before the pty has had a chance to send: ready = None while not ready: ready = self.wait_for_data([proc_fd], 0.1) else: proc_fd = None self.terminals[term] = (view_sock, proc_fd) self.proc_fds[proc_fd] = term
def _do_open_terminal(self, term): ready = self.wait_for_data([self.sock], 0.1) if self.sock not in ready: # XXX TODO: wait for a keypress from some existing terminal # to trigger the appearance of the terminal. # Specify options via the environment. # This allows us to spawn the joiner with no arguments, # so it will work with the "-e" option of terminal programs. env = {} env["PIAS_OPT_JOIN"] = "1" env["PIAS_OPT_COMMAND"] = "replay" env["PIAS_OPT_DATAFILE"] = self.eventlog.datafile env["PIAS_OPT_TERMINAL"] = self.terminal cmd = self.terminal or get_default_terminal() forkexec([cmd, "-e", get_pias_script()], env) view_sock, _ = self.sock.accept() if self.live_replay: # this is cribbed from recorder._handle_open_terminal # TODO (JC): look into further refactoring common code into an util function # Fork a new shell behind a pty. _, proc_fd = forkexec_pty([self.replay_shell]) # often the terminal comes up before the pty has had a chance to send: ready = None while not ready: ready = self.wait_for_data([proc_fd], 0.1) else: proc_fd = None self.terminals[term] = (view_sock, proc_fd) self.proc_fds[proc_fd] = term
def _handle_open_terminal(self, client_sock): # Read the program to start, in form "SIZE JSON-DATA\n" size = 0 c = client_sock.recv(1) while c != " ": size = (size * 10) + int(c) c = client_sock.recv(1) data = client_sock.recv(size) while len(data) < size + 1: more_data = client_sock.recv(size + 1 - len(data)) if not more_data: raise ValueError("client sent incomplete data") data += more_data shell = json.loads(data.strip()) # Fork the requested process behind a pty. if isinstance(shell, basestring): shell = [shell] proc_pid, proc_fd = forkexec_pty(*shell) # Assign a new id for the terminal term = uuid.uuid4().hex self.terminals[term] = client_sock, proc_fd, proc_pid self.view_fds[client_sock.fileno()] = term self.proc_fds[proc_fd] = term # Append it to the eventlog. self.eventlog.append({ "act": "OPEN", "term": term, })
def _handle_open_terminal(self, client_sock): # Fork a new shell behind a pty. env = {"TERM": "vt100"} proc_pid, proc_fd = forkexec_pty([self.shell], env=env) # Assign a new id for the terminal term = uuid.uuid4().hex self.terminals[term] = client_sock, proc_fd, proc_pid self.view_fds[client_sock.fileno()] = term self.proc_fds[proc_fd] = term # Append it to the eventlog. # XXX TODO: this assumes all terminals are the same size as mine. self.eventlog.write_event({ "act": "OPEN", "term": term, "size": get_terminal_size(1) })
def _handle_open_terminal(self, client_sock): # Fork a new shell behind a pty. proc_pid, proc_fd = forkexec_pty([self.shell]) # Assign a new id for the terminal. # As a special case, the first terminal created when appending to # an existing session will re-use the last-known terminal uuid. term = None if not self.terminals and self.eventlog.events: last_event = self.eventlog.events[-1] if last_event["act"] == "CLOSE": term = last_event.get("term") if term is None: term = uuid.uuid4().hex self.terminals[term] = client_sock, proc_fd, proc_pid self.view_fds[client_sock.fileno()] = term self.proc_fds[proc_fd] = term # Append it to the eventlog. # XXX TODO: this assumes all terminals are the same size as mine. self.eventlog.write_event({ "act": "OPEN", "term": term, "size": get_terminal_size(1) })