2004-06-16 23:51:51 +00:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
#include <bio.h>
|
|
|
|
|
|
|
|
char *argv0;
|
|
|
|
|
|
|
|
int
|
|
|
|
openlog(char *name)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open(name, OWRITE);
|
|
|
|
if(fd < 0)
|
|
|
|
fd = create(name, OWRITE, DMAPPEND|0666);
|
|
|
|
if(fd < 0){
|
|
|
|
fprint(2, "%s: can't open %s: %r\n", argv0, name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
seek(fd, 0, 2);
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
Biobuf in;
|
|
|
|
int fd;
|
|
|
|
char *p, *t;
|
|
|
|
char buf[8192];
|
|
|
|
|
|
|
|
argv0 = argv[0];
|
2005-01-21 20:23:06 +00:00
|
|
|
if(argc != 3){
|
2004-06-16 23:51:51 +00:00
|
|
|
fprint(2, "usage: %s console logfile \n", argv0);
|
|
|
|
exits("usage");
|
|
|
|
}
|
|
|
|
|
2005-01-04 21:25:17 +00:00
|
|
|
if(strcmp(argv[1], "-") == 0)
|
|
|
|
fd = 1;
|
|
|
|
else
|
|
|
|
fd = open(argv[1], OREAD);
|
2004-06-16 23:51:51 +00:00
|
|
|
if(fd < 0){
|
|
|
|
fprint(2, "%s: can't open %s: %r\n", argv0, argv[1]);
|
|
|
|
exits("open");
|
|
|
|
}
|
|
|
|
Binit(&in, fd, OREAD);
|
|
|
|
|
|
|
|
fd = openlog(argv[2]);
|
|
|
|
|
|
|
|
for(;;){
|
|
|
|
if(p = Brdline(&in, '\n')){
|
|
|
|
p[Blinelen(&in)-1] = 0;
|
|
|
|
t = ctime(time(0));
|
|
|
|
t[19] = 0;
|
|
|
|
if(fprint(fd, "%s: %s\n", t, p) < 0){
|
|
|
|
close(fd);
|
|
|
|
fd = openlog(argv[2]);
|
|
|
|
fprint(fd, "%s: %s\n", t, p);
|
|
|
|
}
|
|
|
|
} else if(Blinelen(&in) == 0) // true eof
|
|
|
|
break;
|
|
|
|
else {
|
|
|
|
Bread(&in, buf, sizeof buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exits(0);
|
|
|
|
}
|