2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) and
3 * geoffrey hing <ghing@net.ohio-state.edu>
4 * Licensed under the GPL
15 #include "kern_util.h"
18 #define TTY_LOG_DIR "./"
20 /* Set early in boot and then unchanged */
21 static char *tty_log_dir
= TTY_LOG_DIR
;
22 static int tty_log_fd
= -1;
24 #define TTY_LOG_OPEN 1
25 #define TTY_LOG_CLOSE 2
26 #define TTY_LOG_WRITE 3
27 #define TTY_LOG_EXEC 4
41 int open_tty_log(void *tty
, void *current_tty
)
44 struct tty_log_buf data
;
45 char buf
[strlen(tty_log_dir
) + sizeof("01234567890-01234567\0")];
48 gettimeofday(&tv
, NULL
);
50 data
= ((struct tty_log_buf
) { .what
= TTY_LOG_OPEN
,
51 .tty
= (unsigned long) tty
,
52 .len
= sizeof(current_tty
),
55 .usec
= tv
.tv_usec
} );
56 write(tty_log_fd
, &data
, sizeof(data
));
57 write(tty_log_fd
, ¤t_tty
, data
.len
);
61 sprintf(buf
, "%s/%0u-%0u", tty_log_dir
, (unsigned int) tv
.tv_sec
,
62 (unsigned int) tv
.tv_usec
);
64 fd
= os_open_file(buf
, of_append(of_create(of_rdwr(OPENFLAGS()))),
67 printk("open_tty_log : couldn't open '%s', errno = %d\n",
73 void close_tty_log(int fd
, void *tty
)
75 struct tty_log_buf data
;
79 gettimeofday(&tv
, NULL
);
80 data
= ((struct tty_log_buf
) { .what
= TTY_LOG_CLOSE
,
81 .tty
= (unsigned long) tty
,
85 .usec
= tv
.tv_usec
} );
86 write(tty_log_fd
, &data
, sizeof(data
));
92 static int log_chunk(int fd
, const char *buf
, int len
)
94 int total
= 0, try, missed
, n
;
98 try = (len
> sizeof(chunk
)) ? sizeof(chunk
) : len
;
99 missed
= copy_from_user_proc(chunk
, (char *) buf
, try);
101 n
= write(fd
, chunk
, try);
118 int write_tty_log(int fd
, const char *buf
, int len
, void *tty
, int is_read
)
121 struct tty_log_buf data
;
124 if(fd
== tty_log_fd
){
125 gettimeofday(&tv
, NULL
);
126 direction
= is_read
? TTY_READ
: TTY_WRITE
;
127 data
= ((struct tty_log_buf
) { .what
= TTY_LOG_WRITE
,
128 .tty
= (unsigned long) tty
,
130 .direction
= direction
,
132 .usec
= tv
.tv_usec
} );
133 write(tty_log_fd
, &data
, sizeof(data
));
136 return log_chunk(fd
, buf
, len
);
139 void log_exec(char **argv
, void *tty
)
142 struct tty_log_buf data
;
146 if(tty_log_fd
== -1) return;
148 gettimeofday(&tv
, NULL
);
151 for(ptr
= argv
; ; ptr
++){
152 if(copy_from_user_proc(&arg
, ptr
, sizeof(arg
)))
154 if(arg
== NULL
) break;
155 len
+= strlen_user_proc(arg
);
158 data
= ((struct tty_log_buf
) { .what
= TTY_LOG_EXEC
,
159 .tty
= (unsigned long) tty
,
163 .usec
= tv
.tv_usec
} );
164 write(tty_log_fd
, &data
, sizeof(data
));
166 for(ptr
= argv
; ; ptr
++){
167 if(copy_from_user_proc(&arg
, ptr
, sizeof(arg
)))
169 if(arg
== NULL
) break;
170 log_chunk(tty_log_fd
, arg
, strlen_user_proc(arg
));
174 extern void register_tty_logger(int (*opener
)(void *, void *),
175 int (*writer
)(int, const char *, int,
177 void (*closer
)(int, void *));
179 static int register_logger(void)
181 register_tty_logger(open_tty_log
, write_tty_log
, close_tty_log
);
185 __uml_initcall(register_logger
);
187 static int __init
set_tty_log_dir(char *name
, int *add
)
193 __uml_setup("tty_log_dir=", set_tty_log_dir
,
194 "tty_log_dir=<directory>\n"
195 " This is used to specify the directory where the logs of all pty\n"
196 " data from this UML machine will be written.\n\n"
199 static int __init
set_tty_log_fd(char *name
, int *add
)
203 tty_log_fd
= strtoul(name
, &end
, 0);
204 if((*end
!= '\0') || (end
== name
)){
205 printf("set_tty_log_fd - strtoul failed on '%s'\n", name
);
213 __uml_setup("tty_log_fd=", set_tty_log_fd
,
215 " This is used to specify a preconfigured file descriptor to which all\n"
216 " tty data will be written. Preconfigure the descriptor with something\n"
217 " like '10>tty_log tty_log_fd=10'.\n\n"