1998-12-21 16:49:11 +00:00
|
|
|
/*
|
|
|
|
main.c - Part of sensors, a user-space program for hardware monitoring
|
1999-02-08 22:50:29 +00:00
|
|
|
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
1998-12-21 16:49:11 +00:00
|
|
|
|
|
|
|
This program 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; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "lib/sensors.h"
|
|
|
|
#include "lib/error.h"
|
1998-12-22 17:41:43 +00:00
|
|
|
#include "chips.h"
|
2001-01-31 03:51:06 +00:00
|
|
|
#include "version.h"
|
1998-12-21 16:49:11 +00:00
|
|
|
|
|
|
|
#define PROGRAM "sensors"
|
2001-01-31 03:51:06 +00:00
|
|
|
#define VERSION LM_VERSION
|
1998-12-21 16:49:11 +00:00
|
|
|
#define DEFAULT_CONFIG_FILE_NAME "sensors.conf"
|
|
|
|
|
|
|
|
static char *config_file_name;
|
|
|
|
FILE *config_file;
|
|
|
|
static const char *config_file_path[] =
|
2002-07-23 01:50:18 +00:00
|
|
|
{ "/etc", "/usr/local/etc", "/usr/lib/sensors", "/usr/local/lib/sensors",
|
|
|
|
"/usr/lib", "/usr/local/lib", ".", 0 };
|
1998-12-21 16:49:11 +00:00
|
|
|
|
|
|
|
extern int main(int argc, char *arv[]);
|
|
|
|
static void print_short_help(void);
|
|
|
|
static void print_long_help(void);
|
|
|
|
static void print_version(void);
|
|
|
|
static void open_config_file(void);
|
|
|
|
static int open_this_config_file(char *filename);
|
1998-12-29 20:33:34 +00:00
|
|
|
static void do_a_print(sensors_chip_name name);
|
|
|
|
static void do_a_set(sensors_chip_name name);
|
2000-12-14 01:20:52 +00:00
|
|
|
static int do_the_real_work(void);
|
1998-12-29 20:33:34 +00:00
|
|
|
static const char *sprintf_chip_name(sensors_chip_name name);
|
|
|
|
|
|
|
|
#define CHIPS_MAX 20
|
|
|
|
sensors_chip_name chips[CHIPS_MAX];
|
|
|
|
int chips_count=0;
|
2002-06-22 03:32:55 +00:00
|
|
|
int do_sets, do_unknown, fahrenheit, hide_adapter;
|
1998-12-21 16:49:11 +00:00
|
|
|
|
|
|
|
void print_short_help(void)
|
|
|
|
{
|
|
|
|
printf("Try `%s -h' for more information\n",PROGRAM);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_long_help(void)
|
|
|
|
{
|
1998-12-29 20:33:34 +00:00
|
|
|
printf("Usage: %s [OPTION]... [CHIP]...\n",PROGRAM);
|
1998-12-21 16:49:11 +00:00
|
|
|
printf(" -c, --config-file Specify a config file\n");
|
|
|
|
printf(" -h, --help Display this help text\n");
|
1998-12-29 19:48:43 +00:00
|
|
|
printf(" -s, --set Execute `set' statements too (root only)\n");
|
2002-06-22 03:32:55 +00:00
|
|
|
printf(" -f, --fahrenheit Show temperatures in degrees fahrenheit\n");
|
|
|
|
printf(" -A, --no-adapter Do not show adapter and algorithm for each chip\n");
|
2000-07-19 21:22:05 +00:00
|
|
|
printf(" -u, --unknown Treat chips as unknown ones (testing only)\n");
|
1998-12-21 16:49:11 +00:00
|
|
|
printf(" -v, --version Display the program version\n");
|
|
|
|
printf("\n");
|
2001-04-04 23:22:40 +00:00
|
|
|
printf("By default, a list of directories is examined for config file `sensors.conf'.\n");
|
|
|
|
printf("Use `-' after `-c' to read the config file from stdin.\n");
|
|
|
|
printf("If no chips are specified, all chip info will be printed.\n");
|
|
|
|
printf("Example chip names:\n");
|
|
|
|
printf("\tlm78-i2c-0-2d\t*-i2c-0-2d\n");
|
|
|
|
printf("\tlm78-i2c-0-*\t*-i2c-0-*\n");
|
|
|
|
printf("\tlm78-i2c-*-2d\t*-i2c-*-2d\n");
|
|
|
|
printf("\tlm78-i2c-*-*\t*-i2c-*-*\n");
|
|
|
|
printf("\tlm78-isa-0290\t*-isa-0290\n");
|
|
|
|
printf("\tlm78-isa-*\t*-isa-*\n");
|
|
|
|
printf("\tlm78-*\n");
|
1998-12-21 16:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_version(void)
|
|
|
|
{
|
|
|
|
printf("%s version %s\n", PROGRAM, VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This examines global var config_file, and leaves the name there too.
|
|
|
|
It also opens config_file. */
|
|
|
|
void open_config_file(void)
|
|
|
|
{
|
|
|
|
#define MAX_FILENAME_LEN 1024
|
|
|
|
char *filename;
|
|
|
|
char buffer[MAX_FILENAME_LEN];
|
|
|
|
int res,i;
|
|
|
|
|
|
|
|
if (config_file_name && !strcmp(config_file_name,"-")) {
|
|
|
|
config_file = stdin;
|
|
|
|
return;
|
|
|
|
} else if (config_file_name && index(config_file_name,'/')) {
|
|
|
|
if ((res = open_this_config_file(config_file_name))) {
|
|
|
|
fprintf(stderr,"Could not locate or open config file\n");
|
|
|
|
fprintf(stderr,"%s: %s\n",config_file_name,strerror(res));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (config_file_name)
|
|
|
|
filename = config_file_name;
|
|
|
|
else
|
|
|
|
filename = strdup(DEFAULT_CONFIG_FILE_NAME);
|
|
|
|
for (i = 0; config_file_path[i]; i++) {
|
|
|
|
if ((snprintf(buffer,MAX_FILENAME_LEN,
|
|
|
|
"%s/%s",config_file_path[i],filename)) < 1) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"open_config_file: ridiculous long config file name!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!open_this_config_file(buffer)) {
|
|
|
|
free(config_file_name);
|
|
|
|
config_file_name = strdup(buffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr,"Could not locate or open config file!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int open_this_config_file(char *filename)
|
|
|
|
{
|
|
|
|
config_file = fopen(filename,"r");
|
|
|
|
if (! config_file)
|
|
|
|
return -errno;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
1998-12-29 20:33:34 +00:00
|
|
|
int c,res,i;
|
1998-12-22 02:06:51 +00:00
|
|
|
|
1998-12-21 16:49:11 +00:00
|
|
|
struct option long_opts[] = {
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
1998-12-29 19:48:43 +00:00
|
|
|
{ "set", no_argument, NULL, 's' },
|
1998-12-21 16:49:11 +00:00
|
|
|
{ "version", no_argument, NULL, 'v'},
|
2000-11-13 18:31:48 +00:00
|
|
|
{ "fahrenheit", no_argument, NULL, 'f' },
|
2002-06-22 03:32:55 +00:00
|
|
|
{ "no-adapter", no_argument, NULL, 'A' },
|
1999-03-22 00:40:40 +00:00
|
|
|
{ "config-file", required_argument, NULL, 'c' },
|
2002-06-22 03:32:55 +00:00
|
|
|
{ "unknown", no_argument, NULL, 'u' },
|
1999-03-22 00:40:40 +00:00
|
|
|
{ 0,0,0,0 }
|
1998-12-21 16:49:11 +00:00
|
|
|
};
|
|
|
|
|
2000-07-14 19:03:02 +00:00
|
|
|
do_unknown = 0;
|
1998-12-29 19:48:43 +00:00
|
|
|
do_sets = 0;
|
2002-06-22 03:32:55 +00:00
|
|
|
hide_adapter = 0;
|
1998-12-21 16:49:11 +00:00
|
|
|
while (1) {
|
2002-08-07 11:55:35 +00:00
|
|
|
c = getopt_long(argc,argv,"hsvfAc:u",long_opts,NULL);
|
1998-12-21 16:49:11 +00:00
|
|
|
if (c == EOF)
|
|
|
|
break;
|
|
|
|
switch(c) {
|
|
|
|
case ':':
|
|
|
|
case '?':
|
|
|
|
print_short_help();
|
|
|
|
exit(1);
|
|
|
|
case 'h':
|
|
|
|
print_long_help();
|
|
|
|
exit(0);
|
|
|
|
case 'v':
|
|
|
|
print_version();
|
|
|
|
exit(0);
|
|
|
|
case 'c':
|
|
|
|
config_file_name = strdup(optarg);
|
|
|
|
break;
|
1998-12-29 19:48:43 +00:00
|
|
|
case 's':
|
|
|
|
do_sets = 1;
|
|
|
|
break;
|
2000-11-13 18:31:48 +00:00
|
|
|
case 'f':
|
|
|
|
fahrenheit = 1;
|
|
|
|
break;
|
2002-06-22 03:32:55 +00:00
|
|
|
case 'A':
|
|
|
|
hide_adapter = 1;
|
|
|
|
break;
|
2000-07-14 19:03:02 +00:00
|
|
|
case 'u':
|
|
|
|
do_unknown = 1;
|
|
|
|
break;
|
1998-12-21 16:49:11 +00:00
|
|
|
default:
|
|
|
|
fprintf(stderr,"Internal error while parsing options!\n");
|
1998-12-29 20:33:34 +00:00
|
|
|
exit(1);
|
1998-12-21 16:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-29 20:33:34 +00:00
|
|
|
|
|
|
|
if (optind == argc) {
|
|
|
|
chips[0].prefix = SENSORS_CHIP_NAME_PREFIX_ANY;
|
|
|
|
chips[0].bus = SENSORS_CHIP_NAME_BUS_ANY;
|
|
|
|
chips[0].addr = SENSORS_CHIP_NAME_ADDR_ANY;
|
|
|
|
chips_count = 1;
|
|
|
|
} else
|
|
|
|
for(i = optind; i < argc; i++)
|
|
|
|
if ((res = sensors_parse_chip_name(argv[i],chips+chips_count))) {
|
|
|
|
fprintf(stderr,"Parse error in chip name `%s'\n",argv[i]);
|
2001-03-25 18:28:15 +00:00
|
|
|
print_short_help();
|
1998-12-29 20:33:34 +00:00
|
|
|
exit(1);
|
|
|
|
} else if (++chips_count == CHIPS_MAX) {
|
|
|
|
fprintf(stderr,"Too many chips on command line!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-21 16:49:11 +00:00
|
|
|
open_config_file();
|
|
|
|
|
1998-12-21 22:41:59 +00:00
|
|
|
if ((res = sensors_init(config_file))) {
|
2001-06-08 23:57:26 +00:00
|
|
|
fprintf(stderr,"%s\n",sensors_strerror(res));
|
|
|
|
if (res == -SENSORS_ERR_PROC)
|
1998-12-21 16:49:11 +00:00
|
|
|
fprintf(stderr,
|
2001-06-08 23:57:26 +00:00
|
|
|
"/proc/sys/dev/sensors/chips or /proc/bus/i2c unreadable;\n"
|
|
|
|
"Make sure you have done 'modprobe i2c-proc'!\n");
|
1998-12-21 16:49:11 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1998-12-22 02:06:51 +00:00
|
|
|
|
2000-12-14 01:20:52 +00:00
|
|
|
if(do_the_real_work()) {
|
|
|
|
exit(0);
|
|
|
|
} else {
|
|
|
|
if(chips[0].prefix == SENSORS_CHIP_NAME_PREFIX_ANY)
|
|
|
|
fprintf(stderr,"No sensors found!\n");
|
|
|
|
else
|
|
|
|
fprintf(stderr,"Specified sensor(s) not found!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
1998-12-21 16:49:11 +00:00
|
|
|
}
|
1998-12-24 18:40:58 +00:00
|
|
|
|
2000-12-14 01:20:52 +00:00
|
|
|
/* returns number of chips found */
|
|
|
|
int do_the_real_work(void)
|
1998-12-29 20:33:34 +00:00
|
|
|
{
|
|
|
|
const sensors_chip_name *chip;
|
|
|
|
int chip_nr,i;
|
2000-12-14 01:20:52 +00:00
|
|
|
int cnt = 0;
|
1998-12-29 20:33:34 +00:00
|
|
|
|
|
|
|
for (chip_nr = 0; (chip = sensors_get_detected_chips(&chip_nr));)
|
|
|
|
for(i = 0; i < chips_count; i++)
|
|
|
|
if (sensors_match_chip(*chip,chips[i])) {
|
|
|
|
if(do_sets)
|
|
|
|
do_a_set(*chip);
|
|
|
|
else
|
|
|
|
do_a_print(*chip);
|
|
|
|
i = chips_count;
|
2000-12-14 01:20:52 +00:00
|
|
|
cnt++;
|
1998-12-29 20:33:34 +00:00
|
|
|
}
|
2000-12-14 01:20:52 +00:00
|
|
|
return(cnt);
|
1998-12-29 20:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void do_a_set(sensors_chip_name name)
|
|
|
|
{
|
|
|
|
int res;
|
2001-06-08 23:57:26 +00:00
|
|
|
if ((res = sensors_do_chip_sets(name))) {
|
|
|
|
if (res == -SENSORS_ERR_PROC) {
|
|
|
|
fprintf(stderr,"%s: %s for writing;\n",sprintf_chip_name(name),
|
|
|
|
sensors_strerror(res));
|
|
|
|
fprintf(stderr,"Run as root?\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"%s: %s\n",sprintf_chip_name(name),
|
|
|
|
sensors_strerror(res));
|
|
|
|
}
|
|
|
|
}
|
1998-12-29 20:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *sprintf_chip_name(sensors_chip_name name)
|
|
|
|
{
|
|
|
|
#define BUF_SIZE 200
|
|
|
|
static char buf[BUF_SIZE];
|
1998-12-24 18:40:58 +00:00
|
|
|
|
1998-12-29 20:33:34 +00:00
|
|
|
if (name.bus == SENSORS_CHIP_NAME_BUS_ISA)
|
|
|
|
snprintf(buf,BUF_SIZE,"%s-isa-%04x",name.prefix,name.addr);
|
|
|
|
else
|
|
|
|
snprintf(buf,BUF_SIZE,"%s-i2c-%d-%02x",name.prefix,name.bus,name.addr);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_a_print(sensors_chip_name name)
|
|
|
|
{
|
|
|
|
const char *algo,*adap;
|
|
|
|
|
|
|
|
printf("%s\n",sprintf_chip_name(name));
|
|
|
|
adap = sensors_get_adapter_name(name.bus);
|
2002-06-22 03:32:55 +00:00
|
|
|
if (adap && !hide_adapter)
|
1998-12-29 20:33:34 +00:00
|
|
|
printf("Adapter: %s\n",adap);
|
|
|
|
algo = sensors_get_algorithm_name(name.bus);
|
2002-06-22 03:32:55 +00:00
|
|
|
if (algo && !hide_adapter)
|
1998-12-29 20:33:34 +00:00
|
|
|
printf("Algorithm: %s\n",algo);
|
|
|
|
if (!algo || !adap)
|
|
|
|
printf(" ERROR: Can't get adapter or algorithm?!?\n");
|
2000-07-14 19:03:02 +00:00
|
|
|
if (do_unknown)
|
|
|
|
print_unknown_chip(&name);
|
2000-11-26 23:07:17 +00:00
|
|
|
else if (!strcmp(name.prefix,"ds1621"))
|
|
|
|
print_ds1621(&name);
|
2000-07-14 19:03:02 +00:00
|
|
|
else if (!strcmp(name.prefix,"lm75"))
|
1998-12-29 20:33:34 +00:00
|
|
|
print_lm75(&name);
|
1999-05-01 15:03:14 +00:00
|
|
|
else if (!strcmp(name.prefix,"adm1021") || !strcmp(name.prefix,"max1617") ||
|
1999-10-30 23:31:39 +00:00
|
|
|
!strcmp(name.prefix,"max1617a") || !strcmp(name.prefix, "thmc10") ||
|
2002-01-09 01:19:23 +00:00
|
|
|
!strcmp(name.prefix,"lm84") || !strcmp(name.prefix, "gl523") ||
|
2002-09-18 19:17:30 +00:00
|
|
|
!strcmp(name.prefix, "adm1023") || !strcmp(name.prefix, "mc1066"))
|
1999-05-01 15:03:14 +00:00
|
|
|
print_adm1021(&name);
|
1999-08-22 17:52:38 +00:00
|
|
|
else if (!strcmp(name.prefix,"adm9240") ||
|
|
|
|
!strcmp(name.prefix,"ds1780") ||
|
|
|
|
!strcmp(name.prefix,"lm81"))
|
1999-05-01 15:28:49 +00:00
|
|
|
print_adm9240(&name);
|
1998-12-29 20:33:34 +00:00
|
|
|
else if (!strcmp(name.prefix,"lm78") || !strcmp(name.prefix,"lm78-j") ||
|
1999-11-18 23:42:12 +00:00
|
|
|
!strcmp(name.prefix,"lm79"))
|
1998-12-29 20:33:34 +00:00
|
|
|
print_lm78(&name);
|
2000-10-18 00:34:07 +00:00
|
|
|
else if (!strcmp(name.prefix,"mtp008"))
|
|
|
|
print_mtp008(&name);
|
1999-05-01 15:36:27 +00:00
|
|
|
else if (!strcmp(name.prefix,"sis5595"))
|
|
|
|
print_sis5595(&name);
|
2000-03-04 16:14:08 +00:00
|
|
|
else if (!strcmp(name.prefix,"via686a"))
|
|
|
|
print_via686a(&name);
|
1999-05-01 15:36:27 +00:00
|
|
|
else if (!strcmp(name.prefix,"lm80"))
|
|
|
|
print_lm80(&name);
|
2000-12-16 17:07:24 +00:00
|
|
|
else if (!strcmp(name.prefix,"lm87"))
|
|
|
|
print_lm87(&name);
|
1999-07-21 10:14:59 +00:00
|
|
|
else if (!strcmp(name.prefix,"gl518sm"))
|
1998-12-29 20:33:34 +00:00
|
|
|
print_gl518(&name);
|
2000-05-11 02:04:30 +00:00
|
|
|
else if (!strcmp(name.prefix,"adm1025"))
|
|
|
|
print_adm1025(&name);
|
2001-05-15 03:18:18 +00:00
|
|
|
else if (!strcmp(name.prefix,"adm1024"))
|
|
|
|
print_adm1024(&name);
|
1999-03-11 03:19:54 +00:00
|
|
|
else if ((!strcmp(name.prefix,"w83781d")) ||
|
|
|
|
(!strcmp(name.prefix,"w83782d")) ||
|
1999-08-15 21:34:21 +00:00
|
|
|
(!strcmp(name.prefix,"w83783s")) ||
|
1999-10-30 21:26:21 +00:00
|
|
|
(!strcmp(name.prefix,"w83627hf")) ||
|
2001-11-21 01:01:17 +00:00
|
|
|
(!strcmp(name.prefix,"w83697hf")) ||
|
1999-10-30 21:26:21 +00:00
|
|
|
(!strcmp(name.prefix,"as99127f")))
|
1998-12-29 20:33:34 +00:00
|
|
|
print_w83781d(&name);
|
2001-05-15 02:40:36 +00:00
|
|
|
else if (!strncmp(name.prefix,"maxilife-", 9))
|
1999-03-19 21:11:33 +00:00
|
|
|
print_maxilife(&name);
|
2002-11-09 20:46:07 +00:00
|
|
|
else if (!strcmp(name.prefix,"it87"))
|
2001-06-08 23:57:26 +00:00
|
|
|
print_it87(&name);
|
2000-01-30 01:20:51 +00:00
|
|
|
else if (!strcmp(name.prefix,"ddcmon"))
|
|
|
|
print_ddcmon(&name);
|
|
|
|
else if (!strcmp(name.prefix,"eeprom"))
|
|
|
|
print_eeprom(&name);
|
2001-09-18 15:20:15 +00:00
|
|
|
else if (!strcmp(name.prefix,"fscpos"))
|
|
|
|
print_fscpos(&name);
|
2001-11-08 17:06:30 +00:00
|
|
|
else if (!strcmp(name.prefix,"fscscy"))
|
|
|
|
print_fscscy(&name);
|
2001-11-19 20:29:27 +00:00
|
|
|
else if (!strcmp(name.prefix,"pcf8591"))
|
|
|
|
print_pcf8591(&name);
|
2002-06-30 20:28:08 +00:00
|
|
|
else if (!strcmp(name.prefix,"vt1211"))
|
|
|
|
print_vt1211(&name);
|
2002-07-07 16:41:23 +00:00
|
|
|
else if (!strcmp(name.prefix,"smsc47m1"))
|
|
|
|
print_smsc47m1(&name);
|
2002-07-10 11:57:13 +00:00
|
|
|
else if (!strcmp(name.prefix,"lm92"))
|
|
|
|
print_lm92(&name);
|
2002-08-23 21:32:08 +00:00
|
|
|
else if (!strcmp(name.prefix,"vt8231"))
|
|
|
|
print_vt8231(&name);
|
1998-12-29 20:33:34 +00:00
|
|
|
else
|
|
|
|
print_unknown_chip(&name);
|
|
|
|
printf("\n");
|
|
|
|
}
|