mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-31 14:25:39 +00:00
New sensors option: --bus-list. This option lists i2c buses that are
used by sensor chips on the running system, in a format suitable for sensors.conf. This is a replacement for the old, broken grab_busses.sh script. Benefits of having this directly in sensors: * It lists only the i2c buses that are relevant to sensors. * sensors is installed by default, while most people didn't have access to grab_busses.sh. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4781 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
@@ -59,6 +59,7 @@ static void print_long_help(void)
|
||||
" -s, --set Execute `set' statements (root only)\n"
|
||||
" -f, --fahrenheit Show temperatures in degrees fahrenheit\n"
|
||||
" -A, --no-adapter Do not show adapter for each chip\n"
|
||||
" --bus-list Generate bus statements for sensors.conf\n"
|
||||
" -u Raw output (debugging only)\n"
|
||||
" -v, --version Display the program version\n"
|
||||
"\n"
|
||||
@@ -207,9 +208,35 @@ static int do_the_real_work(const sensors_chip_name *match, int *error)
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/* List the buses in a format suitable for sensors.conf. We only list
|
||||
bus types for which bus statements are actually useful and supported.
|
||||
Known bug: i2c buses with number >= 32 or 64 could be listed several
|
||||
times. Very unlikely to ever happen, though. */
|
||||
static void print_bus_list(void)
|
||||
{
|
||||
const sensors_chip_name *chip;
|
||||
int chip_nr;
|
||||
unsigned long seen_i2c = 0;
|
||||
|
||||
chip_nr = 0;
|
||||
while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
|
||||
switch (chip->bus.type) {
|
||||
case SENSORS_BUS_TYPE_I2C:
|
||||
if (chip->bus.nr < (int)sizeof(unsigned long) * 8) {
|
||||
if (seen_i2c & (1 << chip->bus.nr))
|
||||
break;
|
||||
seen_i2c |= 1 << chip->bus.nr;
|
||||
}
|
||||
printf("bus \"i2c-%d\" \"%s\"\n", chip->bus.nr,
|
||||
sensors_get_adapter_name(&chip->bus));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int c, res, i, error;
|
||||
int c, res, i, error, do_bus_list;
|
||||
const char *config_file_name = DEFAULT_CONFIG_FILE;
|
||||
|
||||
struct option long_opts[] = {
|
||||
@@ -219,6 +246,7 @@ int main(int argc, char *argv[])
|
||||
{ "fahrenheit", no_argument, NULL, 'f' },
|
||||
{ "no-adapter", no_argument, NULL, 'A' },
|
||||
{ "config-file", required_argument, NULL, 'c' },
|
||||
{ "bus-list", no_argument, NULL, 'B' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -226,6 +254,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
do_raw = 0;
|
||||
do_sets = 0;
|
||||
do_bus_list = 0;
|
||||
hide_adapter = 0;
|
||||
while (1) {
|
||||
c = getopt_long(argc, argv, "hsvfAc:u", long_opts, NULL);
|
||||
@@ -257,6 +286,9 @@ int main(int argc, char *argv[])
|
||||
case 'u':
|
||||
do_raw = 1;
|
||||
break;
|
||||
case 'B':
|
||||
do_bus_list = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"Internal error while parsing options!\n");
|
||||
@@ -271,7 +303,9 @@ int main(int argc, char *argv[])
|
||||
/* build the degrees string */
|
||||
set_degstr();
|
||||
|
||||
if (optind == argc) { /* No chip name on command line */
|
||||
if (do_bus_list) {
|
||||
print_bus_list();
|
||||
} else if (optind == argc) { /* No chip name on command line */
|
||||
if (!do_the_real_work(NULL, &error)) {
|
||||
fprintf(stderr,
|
||||
"No sensors found!\n"
|
||||
|
@@ -22,7 +22,7 @@
|
||||
.\" Formatted or processed versions of this manual, if unaccompanied by
|
||||
.\" the source, must acknowledge the copyright and authors of this work.
|
||||
.\"
|
||||
.TH sensors 1 "August 2007" "lm-sensors 3" "Linux User's Manual"
|
||||
.TH sensors 1 "September 2007" "lm-sensors 3" "Linux User's Manual"
|
||||
.SH NAME
|
||||
sensors \- print sensors information
|
||||
.SH SYNOPSIS
|
||||
@@ -33,10 +33,10 @@ sensors \- print sensors information
|
||||
.B ]
|
||||
.br
|
||||
.B sensors -s [
|
||||
.I options
|
||||
.B ] [
|
||||
.I chips
|
||||
.B ]
|
||||
.br
|
||||
.B sensors --bus-list
|
||||
|
||||
.SH DESCRIPTION
|
||||
.B sensors
|
||||
@@ -44,6 +44,9 @@ is used to show the current readings of all sensor chips.
|
||||
.br
|
||||
.B sensors -s
|
||||
is used to set all limits as specified in the configuration file.
|
||||
.br
|
||||
.B sensors --bus-list
|
||||
is used to generate bus statements suitable for the configuration file.
|
||||
|
||||
.SH OPTIONS
|
||||
.IP "-c config-file"
|
||||
@@ -64,6 +67,12 @@ Raw output. This mode is only meant for debugging.
|
||||
Print the program version and exit.
|
||||
.IP -f
|
||||
Print the temperatures in degrees Fahrenheit instead of Celsius.
|
||||
.IP --bus-list
|
||||
Generate bus statements suitable for using in sensors.conf. Such bus statements
|
||||
are only needed if you have several chips sharing the same address on different
|
||||
buses of the same type. As bus numbers are usually not guaranteed to be stable
|
||||
over reboots, these statements let you refer to each bus by its name rather
|
||||
than numbers.
|
||||
.SH FILES
|
||||
.I /etc/sensors.conf
|
||||
.RS
|
||||
|
Reference in New Issue
Block a user