]>
git.ipfire.org Git - people/ummeegge/ipfire-2.x.git/blob - src/hwinfo/src/hd/klog.c
10 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
16 static int str_ok(str_list_t
*sl
);
17 static int str_list_cmp(str_list_t
*sl1
, str_list_t
*sl2
);
21 * Check if a string starts with '<[0-9]>'.
23 int str_ok(str_list_t
*sl
)
25 return sl
->str
[0] == '<' && sl
->str
[2] == '>' && sl
->str
[1] >= '0' && sl
->str
[1] <= '9';
29 * Check if sl1 is idential to sl2; sl1 may be shorter as sl2.
31 * Returns 0/1 if they are equal/not equal. If sl1 is NULL, 0 is returned.
33 int str_list_cmp(str_list_t
*sl1
, str_list_t
*sl2
)
35 for(; sl1
; sl1
= sl1
->next
, sl2
= sl2
->next
) {
36 if(!sl2
|| strcmp(sl1
->str
, sl2
->str
)) return 1;
43 * Read kernel log info. Combine with /var/log/boot.msg.
45 void read_klog(hd_data_t
*hd_data
)
47 char buf
[0x2000 + 1], *s
;
49 str_list_t
*sl
, *sl1
, *sl2
, *sl_last
, **ssl
, *sl_next
;
52 hd_data
->klog
= free_str_list(hd_data
->klog
);
54 sl1
= read_file(KLOG_BOOT
, 0, 0);
58 * remove non-canonical lines (not starting with <[0-9]>) at the start and
62 /* note: the implementations assumes that at least *one* line is ok */
63 for(sl_last
= NULL
, sl
= sl1
; sl
; sl
= (sl_last
= sl
)->next
) {
74 for(sl_last
= NULL
, sl
= sl1
; sl
; sl
= (sl_last
= sl
)->next
) {
84 n
= klogctl(3, buf
, sizeof buf
- 1);
90 if(n
> (int) sizeof buf
- 1) n
= sizeof buf
- 1;
92 for(i
= j
= 0; i
< n
; i
++) {
96 memcpy(s
, buf
+ j
, len
);
97 add_str_list(&sl2
, s
);
103 /* the 1st line may be incomplete */
104 if(sl2
&& !str_ok(sl2
)) {
121 /* now, try to join sl1 & sl2 */
122 for(sl_last
= NULL
, sl
= sl1
; sl
; sl
= (sl_last
= sl
)->next
) {
123 if(!str_list_cmp(sl
, sl2
)) {
126 sl_last
->next
= NULL
;
133 /* append sl2 to sl1 */
134 for(ssl
= &sl1
; *ssl
; ssl
= &(*ssl
)->next
);
142 * Add some klog data to the global log.
144 void dump_klog(hd_data_t
*hd_data
)
148 ADD2LOG("----- kernel log -----\n");
149 for(sl
= hd_data
->klog
; sl
; sl
= sl
->next
) {
150 ADD2LOG(" %s", sl
->str
);
152 ADD2LOG("----- kernel log end -----\n");