2
* Copyright 2007, Intel Corporation
4
* This file is part of PowerTOP
6
* This program file is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
* You should have received a copy of the GNU General Public License
16
* along with this program in a file named COPYING; if not, write to the
17
* Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301 USA
22
* Arjan van de Ven <arjan@linux.intel.com>
30
#include <sys/types.h>
35
/* static arrays are not nice programming.. but they're easy */
36
#define MAXCONFIGLINES 10000
37
static char configlines[MAXCONFIGLINES][100];
38
static int configcount;
40
static void read_kernel_config(void)
43
char version[100], *c;
47
if (access("/proc/config.gz", R_OK) == 0) {
48
file = popen("zcat /proc/config.gz 2> /dev/null", "r");
49
while (file && !feof(file)) {
51
if (fgets(line, 100, file) == NULL)
53
if (configcount >= MAXCONFIGLINES)
55
strcpy(configlines[configcount++], line);
60
file = fopen("/proc/sys/kernel/osrelease", "r");
63
if (fgets(version, 100, file) == NULL) {
68
c = strchr(version, '\n');
71
sprintf(filename, "/boot/config-%s", version);
72
file = fopen(filename, "r");
74
sprintf(filename, "/lib/modules/%s/build/.config", version);
75
file = fopen(filename, "r");
81
if (fgets(line, 100, file) == NULL)
83
if (configcount >= MAXCONFIGLINES)
85
strcpy(configlines[configcount++], line);
91
* Suggest the user to turn on/off a kernel config option.
92
* "comment" gets displayed if it's not already set to the right value
94
void suggest_kernel_config(char *string, int onoff, char *comment, int weight)
101
read_kernel_config();
103
sprintf(searchon, "%s=", string);
104
sprintf(searchoff, "# %s is not set", string);
106
for (i = 0; i < configcount; i++) {
107
if (onoff && strstr(configlines[i], searchon))
109
if (onoff==0 && strstr(configlines[i], searchoff))
111
if (onoff==0 && strstr(configlines[i], searchon))
115
add_suggestion(comment, weight, 0, NULL, NULL);