debuggers.hg

annotate tools/misc/xencons @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 0a4b76b6b5a0
children
rev   line source
kaf24@1243 1 #!/usr/bin/env python
kaf24@1243 2
kaf24@1243 3 ##############################################
kaf24@1243 4 # Console client for Xen guest OSes
kaf24@1243 5 # Copyright (c) 2004, K A Fraser
kaf24@1243 6 ##############################################
kaf24@1243 7
kaf24@1243 8 import errno, os, signal, socket, struct, sys
kaf24@1243 9
kaf24@1243 10 from termios import *
kaf24@1243 11 # Indexes into termios.tcgetattr() list.
kaf24@1243 12 IFLAG = 0
kaf24@1243 13 OFLAG = 1
kaf24@1243 14 CFLAG = 2
kaf24@1243 15 LFLAG = 3
kaf24@1243 16 ISPEED = 4
kaf24@1243 17 OSPEED = 5
kaf24@1243 18 CC = 6
kaf24@1243 19
kaf24@1243 20 def __child_death(signum, frame):
kaf24@1243 21 global stop
kaf24@1243 22 stop = True
kaf24@1243 23
kaf24@1243 24 def __recv_from_sock(sock):
kaf24@1243 25 global stop
kaf24@1243 26 stop = False
kaf24@1243 27 while not stop:
kaf24@1243 28 try:
kaf24@1246 29 data = sock.recv(1024)
kaf24@3320 30 except socket.error, error:
kaf24@3320 31 if error[0] != errno.EINTR:
kaf24@3320 32 raise
kaf24@3358 33 else:
kaf24@3358 34 try:
kaf24@3358 35 os.write(1, data)
kaf24@3358 36 except os.error, error:
kaf24@3358 37 if error[0] != errno.EINTR:
kaf24@3358 38 raise
kaf24@1243 39 os.wait()
kaf24@1243 40
kaf24@1243 41 def __send_to_sock(sock):
kaf24@1243 42 while 1:
kaf24@1243 43 try:
kaf24@3320 44 data = os.read(0,1024)
kaf24@3320 45 except os.error, error:
kaf24@1243 46 if error[0] != errno.EINTR:
kaf24@1243 47 raise
kaf24@3320 48 else:
kaf24@3320 49 if ord(data[0]) == ord(']')-64:
kaf24@3320 50 break
kaf24@3320 51 try:
kaf24@3320 52 sock.send(data)
kaf24@3320 53 except socket.error, error:
kaf24@3320 54 if error[0] == errno.EPIPE:
kaf24@3320 55 sys.exit(0)
kaf24@3320 56 if error[0] != errno.EINTR:
kaf24@3320 57 raise
kaf24@1243 58 sys.exit(0)
kaf24@1243 59
kaf24@1243 60 def connect(host,port):
kaf24@1243 61 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
kaf24@1243 62 sock.connect((host,port))
kaf24@1243 63
kaf24@1243 64 oattrs = tcgetattr(0)
kaf24@1243 65 nattrs = tcgetattr(0)
kaf24@1243 66 nattrs[IFLAG] = nattrs[IFLAG] & ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON)
kaf24@1243 67 nattrs[OFLAG] = nattrs[OFLAG] & ~(OPOST)
kaf24@1243 68 nattrs[CFLAG] = nattrs[CFLAG] & ~(CSIZE | PARENB)
kaf24@1243 69 nattrs[CFLAG] = nattrs[CFLAG] | CS8
kaf24@1243 70 nattrs[LFLAG] = nattrs[LFLAG] & ~(ECHO | ICANON | IEXTEN | ISIG)
kaf24@1243 71 nattrs[CC][VMIN] = 1
kaf24@1243 72 nattrs[CC][VTIME] = 0
kaf24@1243 73
kaf24@1243 74 if os.fork():
kaf24@1243 75 signal.signal(signal.SIGCHLD, __child_death)
kaf24@1243 76 print "************ REMOTE CONSOLE: CTRL-] TO QUIT ********"
kaf24@1243 77 tcsetattr(0, TCSAFLUSH, nattrs)
kaf24@1243 78 try:
kaf24@1243 79 __recv_from_sock(sock)
kaf24@1243 80 finally:
kaf24@1243 81 tcsetattr(0, TCSAFLUSH, oattrs)
kaf24@1243 82 print
kaf24@1243 83 print "************ REMOTE CONSOLE EXITED *****************"
kaf24@1243 84 else:
kaf24@1243 85 signal.signal(signal.SIGPIPE, signal.SIG_IGN)
kaf24@1243 86 __send_to_sock(sock)
kaf24@1243 87
kaf24@1243 88 if __name__ == '__main__':
kaf24@1243 89 if len(sys.argv) != 3:
kaf24@1243 90 print sys.argv[0] + " <host> <port>"
kaf24@1243 91 sys.exit(1)
kaf24@1243 92 connect(str(sys.argv[1]),int(sys.argv[2]))