This source file includes following definitions.
- sys_syslog
- printk
1
2
3
4
5
6
7 #include <stdarg.h>
8
9 #include <asm/segment.h>
10 #include <asm/system.h>
11
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/kernel.h>
15
16 static char buf[1024];
17
18 extern int vsprintf(char * buf, const char * fmt, va_list args);
19 extern void console_print(const char *);
20
21 static unsigned long log_page = 0;
22 static unsigned long log_start = 0;
23 unsigned long log_size = 0;
24 struct wait_queue * log_wait = NULL;
25
26 int sys_syslog(int type, char * buf, int len)
27 {
28 unsigned long i;
29 char c;
30
31 if (!suser())
32 return -EPERM;
33 switch (type) {
34 case 0:
35 i = log_page;
36 log_page = 0;
37 free_page(i);
38 wake_up_interruptible(&log_wait);
39 return 0;
40 case 1:
41 i = get_free_page(GFP_KERNEL);
42 if (log_page) {
43 free_page(i);
44 return 0;
45 } else if ((log_page = i) != 0) {
46 log_start = log_size = 0;
47 return 0;
48 }
49 return -ENOMEM;
50 case 2:
51 if (!buf || len < 0)
52 return -EINVAL;
53 if (!len)
54 return 0;
55 i = verify_area(VERIFY_WRITE, buf, len);
56 if (i)
57 return i;
58 while (!log_size) {
59 if (!log_page)
60 return -EIO;
61 if (current->signal & ~current->blocked)
62 return -ERESTARTSYS;
63 cli();
64 if (!log_size)
65 interruptible_sleep_on(&log_wait);
66 sti();
67 }
68 i = 0;
69 while (log_size && i < len) {
70 c = *((char *) log_page+log_start);
71 log_start++;
72 log_size--;
73 log_start &= 4095;
74 put_fs_byte(c,buf);
75 buf++;
76 i++;
77 }
78 return i;
79 }
80 return -EINVAL;
81 }
82
83
84 int printk(const char *fmt, ...)
85 {
86 va_list args;
87 int i,j;
88 char * p;
89
90 va_start(args, fmt);
91 i=vsprintf(buf,fmt,args);
92 va_end(args);
93 for (j = 0; j < i && log_page ; j++) {
94 p = (char *) log_page + (4095 & (log_start+log_size));
95 *p = buf[j];
96 if (log_size < 4096)
97 log_size++;
98 else
99 log_start++;
100 }
101 if (log_page)
102 wake_up_interruptible(&log_wait);
103 console_print(buf);
104 return i;
105 }