ia64/xen-unstable

view tools/misc/xencons @ 2020:4fc62e2234f4

bitkeeper revision 1.1108.33.23 (410d0a8aWM5n48Ku4nUKCSOzCx9B2A)

sync with 2.4 block backend driver:
always print error messages
author cl349@freefall.cl.cam.ac.uk
date Sun Aug 01 15:21:46 2004 +0000 (2004-08-01)
parents a823ac69d295
children d200c22469e2 777ddc539761 7a1b61b77a0b 8724fc0ba838 86e3ae8351cd 708bd9c8362b
line source
1 #!/usr/bin/env python
3 ##############################################
4 # Console client for Xen guest OSes
5 # Copyright (c) 2004, K A Fraser
6 ##############################################
8 import errno, os, signal, socket, struct, sys
10 from termios import *
11 # Indexes into termios.tcgetattr() list.
12 IFLAG = 0
13 OFLAG = 1
14 CFLAG = 2
15 LFLAG = 3
16 ISPEED = 4
17 OSPEED = 5
18 CC = 6
20 def __child_death(signum, frame):
21 global stop
22 stop = True
24 def __recv_from_sock(sock):
25 global stop
26 stop = False
27 while not stop:
28 try:
29 data = sock.recv(1024)
30 os.write(1, data)
31 except socket.error, error:
32 if error[0] != errno.EINTR:
33 raise
34 os.wait()
36 def __send_to_sock(sock):
37 while 1:
38 data = os.read(0,1024)
39 if ord(data[0]) == ord(']')-64:
40 break
41 try:
42 sock.send(data)
43 except socket.error, error:
44 if error[0] == errno.EPIPE:
45 sys.exit(0)
46 if error[0] != errno.EINTR:
47 raise
48 sys.exit(0)
50 def connect(host,port):
51 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
52 sock.connect((host,port))
54 oattrs = tcgetattr(0)
55 nattrs = tcgetattr(0)
56 nattrs[IFLAG] = nattrs[IFLAG] & ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON)
57 nattrs[OFLAG] = nattrs[OFLAG] & ~(OPOST)
58 nattrs[CFLAG] = nattrs[CFLAG] & ~(CSIZE | PARENB)
59 nattrs[CFLAG] = nattrs[CFLAG] | CS8
60 nattrs[LFLAG] = nattrs[LFLAG] & ~(ECHO | ICANON | IEXTEN | ISIG)
61 nattrs[CC][VMIN] = 1
62 nattrs[CC][VTIME] = 0
64 if os.fork():
65 signal.signal(signal.SIGCHLD, __child_death)
66 print "************ REMOTE CONSOLE: CTRL-] TO QUIT ********"
67 tcsetattr(0, TCSAFLUSH, nattrs)
68 try:
69 __recv_from_sock(sock)
70 finally:
71 tcsetattr(0, TCSAFLUSH, oattrs)
72 print
73 print "************ REMOTE CONSOLE EXITED *****************"
74 else:
75 signal.signal(signal.SIGPIPE, signal.SIG_IGN)
76 __send_to_sock(sock)
78 if __name__ == '__main__':
79 if len(sys.argv) != 3:
80 print sys.argv[0] + " <host> <port>"
81 sys.exit(1)
82 connect(str(sys.argv[1]),int(sys.argv[2]))