mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-29 12:50:43 +00:00
Include the configuration file name when reporting parse errors.
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5649 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
6a7286464d
commit
0efe346b80
9 files changed
+65
-19
No files matched your search
@@ -12,7 +12,8 @@ SVN-HEAD
|
||||
Report configuration file read errors
|
||||
Exit the configuration file parser sooner
|
||||
Free bus statements from the configuration file sooner
|
||||
Read extra configuration files from /etc/sensors.d
|
||||
Read extra configuration files from /etc/sensors.d (#2174)
|
||||
Report the configuration file name on parse errors
|
||||
lm_sensors.init: Support new format of /etc/sysconfig/lm_sensors (#2246)
|
||||
Drop support for kernels 2.4 and earlier
|
||||
lm_sensors.init.suse: Delete (actual SuSE script is much different)
|
||||
|
||||
@@ -24,6 +24,10 @@ given new feature.
|
||||
enum sensors_subfeature_type SENSORS_SUBFEATURE_CURR_BEEP
|
||||
* Added error value for excessive recursion depth
|
||||
#define SENSORS_ERR_RECURSION 11
|
||||
* Added parse error reporting function including the configuration file
|
||||
name
|
||||
extern void (*sensors_parse_error_wfn) (const char *err,
|
||||
const char *filename, int lineno);
|
||||
|
||||
0x401 lm-sensors 3.0.2 to 3.0.3
|
||||
* Added bus type "virtual":
|
||||
|
||||
+7
-4
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
access.c - Part of libsensors, a Linux library for reading sensor data.
|
||||
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
||||
Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
|
||||
Copyright (C) 2007-2009 Jean Delvare <khali@linux-fr.org>
|
||||
|
||||
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
|
||||
@@ -511,7 +511,8 @@ static int sensors_do_this_chip_sets(const sensors_chip_name *name)
|
||||
subfeature = sensors_lookup_subfeature_name(chip_features,
|
||||
chip->sets[i].name);
|
||||
if (!subfeature) {
|
||||
sensors_parse_error("Unknown feature name",
|
||||
sensors_parse_error_wfn("Unknown feature name",
|
||||
chip->sets[i].line.filename,
|
||||
chip->sets[i].line.lineno);
|
||||
err = -SENSORS_ERR_NO_ENTRY;
|
||||
continue;
|
||||
@@ -521,14 +522,16 @@ static int sensors_do_this_chip_sets(const sensors_chip_name *name)
|
||||
chip->sets[i].value, 0,
|
||||
0, &value);
|
||||
if (res) {
|
||||
sensors_parse_error("Error parsing expression",
|
||||
sensors_parse_error_wfn("Error parsing expression",
|
||||
chip->sets[i].line.filename,
|
||||
chip->sets[i].line.lineno);
|
||||
err = res;
|
||||
continue;
|
||||
}
|
||||
if ((res = sensors_set_value(name, subfeature->number,
|
||||
value))) {
|
||||
sensors_parse_error("Failed to set value",
|
||||
sensors_parse_error_wfn("Failed to set value",
|
||||
chip->sets[i].line.filename,
|
||||
chip->sets[i].line.lineno);
|
||||
err = res;
|
||||
continue;
|
||||
|
||||
+2
-2
@@ -332,10 +332,10 @@ chip_name: NAME
|
||||
void sensors_yyerror(const char *err)
|
||||
{
|
||||
if (sensors_lex_error[0]) {
|
||||
sensors_parse_error(sensors_lex_error,sensors_yylineno);
|
||||
sensors_parse_error_wfn(sensors_lex_error, sensors_yyfilename, sensors_yylineno);
|
||||
sensors_lex_error[0] = '\0';
|
||||
} else
|
||||
sensors_parse_error(err,sensors_yylineno);
|
||||
sensors_parse_error_wfn(err, sensors_yyfilename, sensors_yylineno);
|
||||
}
|
||||
|
||||
sensors_expr *malloc_expr(void)
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
/* This is defined in conf-lex.l */
|
||||
int sensors_yylex(void);
|
||||
extern char sensors_lex_error[];
|
||||
extern const char *sensors_yyfilename;
|
||||
extern int sensors_yylineno;
|
||||
extern FILE *sensors_yyin;
|
||||
|
||||
|
||||
+8
-3
@@ -202,7 +202,8 @@ int sensors_parse_bus_id(const char *name, sensors_bus_id *bus)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensors_substitute_chip(sensors_chip_name *name, int lineno)
|
||||
static int sensors_substitute_chip(sensors_chip_name *name,
|
||||
const char *filename, int lineno)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < sensors_config_busses_count; i++)
|
||||
@@ -211,7 +212,8 @@ static int sensors_substitute_chip(sensors_chip_name *name, int lineno)
|
||||
break;
|
||||
|
||||
if (i == sensors_config_busses_count) {
|
||||
sensors_parse_error("Undeclared bus id referenced", lineno);
|
||||
sensors_parse_error_wfn("Undeclared bus id referenced",
|
||||
filename, lineno);
|
||||
name->bus.nr = SENSORS_BUS_NR_IGNORE;
|
||||
return -SENSORS_ERR_BUS_NAME;
|
||||
}
|
||||
@@ -238,10 +240,12 @@ int sensors_substitute_busses(void)
|
||||
{
|
||||
int err, i, j, lineno;
|
||||
sensors_chip_name_list *chips;
|
||||
const char *filename;
|
||||
int res = 0;
|
||||
|
||||
for (i = sensors_config_chips_subst;
|
||||
i < sensors_config_chips_count; i++) {
|
||||
filename = sensors_config_chips[i].line.filename;
|
||||
lineno = sensors_config_chips[i].line.lineno;
|
||||
chips = &sensors_config_chips[i].chips;
|
||||
for (j = 0; j < chips->fits_count; j++) {
|
||||
@@ -250,7 +254,8 @@ int sensors_substitute_busses(void)
|
||||
if (chips->fits[j].bus.nr == SENSORS_BUS_NR_ANY)
|
||||
continue;
|
||||
|
||||
err = sensors_substitute_chip(&chips->fits[j], lineno);
|
||||
err = sensors_substitute_chip(&chips->fits[j],
|
||||
filename, lineno);
|
||||
if (err)
|
||||
res = err;
|
||||
}
|
||||
|
||||
+22
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
error.c - Part of libsensors, a Linux library for reading sensor data.
|
||||
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
||||
Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
|
||||
Copyright (C) 2007-2009 Jean Delvare <khali@linux-fr.org>
|
||||
|
||||
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
|
||||
@@ -25,10 +25,14 @@
|
||||
#include "general.h"
|
||||
|
||||
static void sensors_default_parse_error(const char *err, int lineno);
|
||||
static void sensors_default_parse_error_wfn(const char *err,
|
||||
const char *filename, int lineno);
|
||||
static void sensors_default_fatal_error(const char *proc, const char *err);
|
||||
|
||||
void (*sensors_parse_error) (const char *err, int lineno) =
|
||||
sensors_default_parse_error;
|
||||
void (*sensors_parse_error_wfn) (const char *err, const char *filename,
|
||||
int lineno) = sensors_default_parse_error_wfn;
|
||||
void (*sensors_fatal_error) (const char *proc, const char *err) =
|
||||
sensors_default_fatal_error;
|
||||
|
||||
@@ -64,6 +68,23 @@ void sensors_default_parse_error(const char *err, int lineno)
|
||||
fprintf(stderr, "Error: %s\n", err);
|
||||
}
|
||||
|
||||
void sensors_default_parse_error_wfn(const char *err,
|
||||
const char *filename, int lineno)
|
||||
{
|
||||
/* If application provided a custom parse error reporting function
|
||||
but not the variant with the filename, fall back to the original
|
||||
variant without the filename, for backwards compatibility. */
|
||||
if (sensors_parse_error != sensors_default_parse_error ||
|
||||
!filename)
|
||||
return sensors_parse_error(err, lineno);
|
||||
|
||||
if (lineno)
|
||||
fprintf(stderr, "Error: File %s, line %d: %s\n", filename,
|
||||
lineno, err);
|
||||
else
|
||||
fprintf(stderr, "Error: File %s: %s\n", filename, err);
|
||||
}
|
||||
|
||||
void sensors_default_fatal_error(const char *proc, const char *err)
|
||||
{
|
||||
fprintf(stderr, "Fatal error in `%s': %s\n", proc, err);
|
||||
|
||||
+16
-5
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
error.h - Part of libsensors, a Linux library for reading sensor data.
|
||||
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
||||
Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
|
||||
Copyright (C) 2007-2009 Jean Delvare <khali@linux-fr.org>
|
||||
|
||||
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
|
||||
@@ -44,11 +44,22 @@ extern "C" {
|
||||
You may not modify the result! */
|
||||
const char *sensors_strerror(int errnum);
|
||||
|
||||
/* This function is called when a parse error is detected. Give it a new
|
||||
value, and your own function is called instead of the default (which
|
||||
prints to stderr). This function may terminate the program, but it
|
||||
usually outputs an error and returns. */
|
||||
/* These functions are called when a parse error is detected. Give them new
|
||||
values, and your own functions are called instead of the default (which
|
||||
print to stderr). These functions may terminate the program, but they
|
||||
usually output an error and return. The first function is the original
|
||||
one, the second one was added later when support for multiple
|
||||
configuration files was added.
|
||||
The library code now only calls the second function. However, for
|
||||
backwards compatibility, if an application provides a custom handling
|
||||
function for the first function but not the second, then all parse
|
||||
errors will be reported using the first function (that is, the filename
|
||||
is never reported.)
|
||||
Note that filename can be NULL (if filename isn't known) and lineno
|
||||
can be 0 (if the error occurs before the actual parsing starts.) */
|
||||
extern void (*sensors_parse_error) (const char *err, int lineno);
|
||||
extern void (*sensors_parse_error_wfn) (const char *err,
|
||||
const char *filename, int lineno);
|
||||
|
||||
/* This function is called when an immediately fatal error (like no
|
||||
memory left) is detected. Give it a new value, and your own function
|
||||
|
||||
+3
-3
@@ -125,7 +125,7 @@ static int add_config_from_dir(const char *dir)
|
||||
|
||||
count = scandir(dir, &namelist, config_file_filter, alphasort);
|
||||
if (count < 0) {
|
||||
sensors_parse_error(strerror(errno), 0);
|
||||
sensors_parse_error_wfn(strerror(errno), NULL, 0);
|
||||
return -SENSORS_ERR_PARSE;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ static int add_config_from_dir(const char *dir)
|
||||
fclose(input);
|
||||
} else {
|
||||
res = -SENSORS_ERR_PARSE;
|
||||
sensors_parse_error(strerror(errno), 0);
|
||||
sensors_parse_error_wfn(strerror(errno), path, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ int sensors_init(FILE *input)
|
||||
goto exit_cleanup;
|
||||
|
||||
} else if (errno != ENOENT) {
|
||||
sensors_parse_error(strerror(errno), 0);
|
||||
sensors_parse_error_wfn(strerror(errno), name, 0);
|
||||
res = -SENSORS_ERR_PARSE;
|
||||
goto exit_cleanup;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user