Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/planix-v0/sys/src/cmd/aux/clog.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/* clog - log console */
2
#include <u.h>
3
#include <libc.h>
4
#include <bio.h>
5
 
6
char *argv0;
7
 
8
int
9
openlog(char *name)
10
{
11
	int fd;
12
 
13
	fd = open(name, OWRITE);
14
	if(fd < 0)
15
		fd = create(name, OWRITE, DMAPPEND|0666);
16
	if(fd < 0){
17
		fprint(2, "%s: can't open %s: %r\n", argv0, name);
18
		return -1;
19
	}
20
	seek(fd, 0, 2);
21
	return fd;
22
}
23
 
24
void
25
main(int argc, char **argv)
26
{
27
	Biobuf in;
28
	int fd;
29
	char *p, *t;
30
	char buf[Bsize];
31
 
32
	argv0 = argv[0];
33
	if(argc < 3){
34
		fprint(2, "usage: %s console logfile \n", argv0);
35
		exits("usage");
36
	}
37
 
38
	fd = open(argv[1], OREAD);
39
	if(fd < 0){
40
		fprint(2, "%s: can't open %s: %r\n", argv0, argv[1]);
41
		exits("open");
42
	}
43
	Binit(&in, fd, OREAD);
44
 
45
	fd = openlog(argv[2]);
46
 
47
	for(;;){
48
		if(p = Brdline(&in, '\n')){
49
			p[Blinelen(&in)-1] = 0;
50
			t = ctime(time(0));
51
			t[19] = 0;
52
			while(fprint(fd, "%s: %s\n", t, p) < 0) {
53
				close(fd);
54
				sleep(500);
55
				fd = openlog(argv[2]);
56
			}
57
		} else if(Blinelen(&in) == 0)	/* true eof or error */
58
			break;
59
		/* discard partial buffer? perhaps due to very long line */
60
		else if (Bread(&in, buf, sizeof buf) < 0)
61
			break;
62
	}
63
	exits(0);
64
}