1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*
* Copyright 2009, Intel Corporation
*
* This file is part of PowerTOP
*
* This program file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file named COPYING; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authors:
* Arjan van de Ven <arjan@linux.intel.com>
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/klog.h>
int klogctl(int type, char *bufp, int len);
#include "powertop.h"
/* static arrays are not nice programming.. but they're easy */
static char *dmesg_content;
static void read_dmesg(void)
{
int size;
if (dmesg_content)
return;
size = klogctl(10, NULL, 0);
if (size <= 0)
return;
dmesg_content = calloc(size + 1, 1);
klogctl(3, dmesg_content, size);
}
void suggest_on_dmesg(char *string, char *comment, int weight)
{
read_dmesg();
if (strstr(dmesg_content, string))
add_suggestion(comment, weight, 0, NULL, NULL);
}
|