This source file includes following definitions.
- sys_syslog
- printk
- register_console
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <stdarg.h>
15
16 #include <asm/segment.h>
17 #include <asm/system.h>
18
19 #include <linux/errno.h>
20 #include <linux/sched.h>
21 #include <linux/kernel.h>
22
23 static char buf[1024];
24
25 extern int vsprintf(char * buf, const char * fmt, va_list args);
26 extern void console_print(const char *);
27
28 static void (*console_print_proc)(const char *) = 0;
29 static char log_buf[4096];
30 static unsigned long log_start = 0;
31 static unsigned long logged_chars = 0;
32 unsigned long log_size = 0;
33 int log_to_console = 1;
34 struct wait_queue * log_wait = NULL;
35
36
37
38
39
40
41
42
43
44
45
46
47
48 int sys_syslog(int type, char * buf, int len)
49 {
50 unsigned long i, j, count;
51 int do_clear = 0;
52 char c;
53
54 if ((type != 3) && !suser())
55 return -EPERM;
56 switch (type) {
57 case 0:
58 return 0;
59 case 1:
60 return 0;
61 case 2:
62 if (!buf || len < 0)
63 return -EINVAL;
64 if (!len)
65 return 0;
66 verify_area(VERIFY_WRITE,buf,len);
67 while (!log_size) {
68 if (current->signal & ~current->blocked)
69 return -ERESTARTSYS;
70 cli();
71 if (!log_size)
72 interruptible_sleep_on(&log_wait);
73 sti();
74 }
75 i = 0;
76 while (log_size && i < len) {
77 c = *((char *) log_buf+log_start);
78 log_start++;
79 log_size--;
80 log_start &= 4095;
81 put_fs_byte(c,buf);
82 buf++;
83 i++;
84 }
85 return i;
86 case 4:
87 do_clear = 1;
88 case 3:
89 if (!buf || len < 0)
90 return -EINVAL;
91 if (!len)
92 return 0;
93 verify_area(VERIFY_WRITE,buf,len);
94 count = len;
95 if (count > 4096)
96 count = 4096;
97 if (count > logged_chars)
98 count = logged_chars;
99 j = log_start + log_size - count;
100 for (i = 0; i < count; i++) {
101 c = *((char *) log_buf + (j++ & 4095));
102 put_fs_byte(c, buf++);
103 }
104 if (do_clear)
105 logged_chars = 0;
106 return i;
107 case 5:
108 logged_chars = 0;
109 return 0;
110 case 6:
111 log_to_console = 0;
112 return 0;
113 case 7:
114 log_to_console = 1;
115 return 0;
116 }
117 return -EINVAL;
118 }
119
120
121 int printk(const char *fmt, ...)
122 {
123 va_list args;
124 int i,j;
125
126 va_start(args, fmt);
127 i=vsprintf(buf,fmt,args);
128 va_end(args);
129 for (j = 0; j < i ; j++) {
130 log_buf[(log_start+log_size) & 4095] = buf[j];
131 if (log_size < 4096)
132 log_size++;
133 else
134 log_start++;
135 logged_chars++;
136 }
137 wake_up_interruptible(&log_wait);
138 if (log_to_console && console_print_proc)
139 (*console_print_proc)(buf);
140 return i;
141 }
142
143
144
145
146
147
148
149 void register_console(void (*proc)(const char *))
150 {
151 int i,j;
152 int p = log_start;
153 char buf[16];
154
155 console_print_proc = proc;
156
157 for (i=0,j=0; i < log_size; i++) {
158 buf[j++] = log_buf[p];
159 p++; p &= 4095;
160 if (j < sizeof(buf)-1)
161 continue;
162 buf[j] = 0;
163 (*proc)(buf);
164 j = 0;
165 }
166 buf[j] = 0;
167 (*proc)(buf);
168 }