1# Copyright (c) 2009 Upi Tamminen <desaster@gmail.com>
2# See the COPYRIGHT file for more information
3
4# Should be compatible with user mode linux
5
6import struct, sys
7
8OP_OPEN, OP_CLOSE, OP_WRITE, OP_EXEC = 1, 2, 3, 4
9TYPE_INPUT, TYPE_OUTPUT, TYPE_INTERACT = 1, 2, 3
10
11def ttylog_write(logfile, len, direction, stamp, data = None):
12    f = file(logfile, 'ab')
13    sec, usec = int(stamp), int(1000000 * (stamp - int(stamp)))
14    f.write(struct.pack('<iLiiLL', 3, 0, len, direction, sec, usec))
15    f.write(data)
16    f.close()
17
18def ttylog_open(logfile, stamp):
19    f = file(logfile, 'ab')
20    sec, usec = int(stamp), int(1000000 * (stamp - int(stamp)))
21    f.write(struct.pack('<iLiiLL', 1, 0, 0, 0, sec, usec))
22    f.close()
23
24def ttylog_close(logfile, stamp):
25    f = file(logfile, 'ab')
26    sec, usec = int(stamp), int(1000000 * (stamp - int(stamp)))
27    f.write(struct.pack('<iLiiLL', 2, 0, 0, 0, sec, usec))
28    f.close()
29
30# vim: set sw=4 et:
31