2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) and
3 * geoffrey hing <ghing@net.ohio-state.edu>
4 * Licensed under the GPL
17 #define TTY_LOG_DIR "./"
19 /* Set early in boot and then unchanged */
20 static char *tty_log_dir
= TTY_LOG_DIR
;
21 static int tty_log_fd
= -1;
23 #define TTY_LOG_OPEN 1
24 #define TTY_LOG_CLOSE 2
25 #define TTY_LOG_WRITE 3
26 #define TTY_LOG_EXEC 4
40 int open_tty_log(void *tty
, void *current_tty
)
43 struct tty_log_buf data
;
44 char buf
[strlen(tty_log_dir
) + sizeof("01234567890-01234567\0")];
47 gettimeofday(&tv
, NULL
);
49 data
= ((struct tty_log_buf
) { .what
= TTY_LOG_OPEN
,
50 .tty
= (unsigned long) tty
,
51 .len
= sizeof(current_tty
),
54 .usec
= tv
.tv_usec
} );
55 write(tty_log_fd
, &data
, sizeof(data
));
56 write(tty_log_fd
, ¤t_tty
, data
.len
);
60 sprintf(buf
, "%s/%0u-%0u", tty_log_dir
, (unsigned int) tv
.tv_sec
,
61 (unsigned int) tv
.tv_usec
);
63 fd
= os_open_file(buf
, of_append(of_create(of_rdwr(OPENFLAGS()))),
66 printk("open_tty_log : couldn't open '%s', errno = %d\n",
72 void close_tty_log(int fd
, void *tty
)
74 struct tty_log_buf data
;
78 gettimeofday(&tv
, NULL
);
79 data
= ((struct tty_log_buf
) { .what
= TTY_LOG_CLOSE
,
80 .tty
= (unsigned long) tty
,
84 .usec
= tv
.tv_usec
} );
85 write(tty_log_fd
, &data
, sizeof(data
));
91 static int log_chunk(int fd
, const char *buf
, int len
)
93 int total
= 0, try, missed
, n
;
97 try = (len
> sizeof(chunk
)) ? sizeof(chunk
) : len
;
98 missed
= copy_from_user_proc(chunk
, (char *) buf
, try);
100 n
= write(fd
, chunk
, try);
117 int write_tty_log(int fd
, const char *buf
, int len
, void *tty
, int is_read
)
120 struct tty_log_buf data
;
123 if(fd
== tty_log_fd
){
124 gettimeofday(&tv
, NULL
);
125 direction
= is_read
? TTY_READ
: TTY_WRITE
;
126 data
= ((struct tty_log_buf
) { .what
= TTY_LOG_WRITE
,
127 .tty
= (unsigned long) tty
,
129 .direction
= direction
,
131 .usec
= tv
.tv_usec
} );
132 write(tty_log_fd
, &data
, sizeof(data
));
135 return log_chunk(fd
, buf
, len
);
138 void log_exec(char **argv
, void *tty
)
141 struct tty_log_buf data
;
145 if(tty_log_fd
== -1) return;
147 gettimeofday(&tv
, NULL
);
150 for(ptr
= argv
; ; ptr
++){
151 if(copy_from_user_proc(&arg
, ptr
, sizeof(arg
)))
153 if(arg
== NULL
) break;
154 len
+= strlen_user_proc(arg
);
157 data
= ((struct tty_log_buf
) { .what
= TTY_LOG_EXEC
,
158 .tty
= (unsigned long) tty
,
162 .usec
= tv
.tv_usec
} );
163 write(tty_log_fd
, &data
, sizeof(data
));
165 for(ptr
= argv
; ; ptr
++){
166 if(copy_from_user_proc(&arg
, ptr
, sizeof(arg
)))
168 if(arg
== NULL
) break;
169 log_chunk(tty_log_fd
, arg
, strlen_user_proc(arg
));
173 extern void register_tty_logger(int (*opener
)(void *, void *),
174 int (*writer
)(int, const char *, int,
176 void (*closer
)(int, void *));
178 static int register_logger(void)
180 register_tty_logger(open_tty_log
, write_tty_log
, close_tty_log
);
184 __uml_initcall(register_logger
);
186 static int __init
set_tty_log_dir(char *name
, int *add
)
192 __uml_setup("tty_log_dir=", set_tty_log_dir
,
193 "tty_log_dir=<directory>\n"
194 " This is used to specify the directory where the logs of all pty\n"
195 " data from this UML machine will be written.\n\n"
198 static int __init
set_tty_log_fd(char *name
, int *add
)
202 tty_log_fd
= strtoul(name
, &end
, 0);
203 if((*end
!= '\0') || (end
== name
)){
204 printf("set_tty_log_fd - strtoul failed on '%s'\n", name
);
212 __uml_setup("tty_log_fd=", set_tty_log_fd
,
214 " This is used to specify a preconfigured file descriptor to which all\n"
215 " tty data will be written. Preconfigure the descriptor with something\n"
216 " like '10>tty_log tty_log_fd=10'.\n\n"