1998-12-19 00:10:48 +00:00
|
|
|
/*
|
|
|
|
error.c - Part of libsensors, a Linux library for reading sensor data.
|
1999-02-08 22:50:29 +00:00
|
|
|
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
2014-03-20 10:23:35 +00:00
|
|
|
Copyright (C) 2007-2010 Jean Delvare <jdelvare@suse.de>
|
1998-12-19 00:10:48 +00:00
|
|
|
|
2010-07-01 11:56:42 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1998-12-19 00:10:48 +00:00
|
|
|
|
2010-07-01 11:56:42 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
1998-12-19 00:10:48 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-07-01 11:56:42 +00:00
|
|
|
GNU Lesser General Public License for more details.
|
1998-12-19 00:10:48 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2008-03-26 13:37:12 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301 USA.
|
1998-12-19 00:10:48 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-29 12:39:10 +00:00
|
|
|
#include <stdlib.h>
|
1998-12-19 00:10:48 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "error.h"
|
2007-07-03 16:03:22 +00:00
|
|
|
#include "general.h"
|
1998-12-19 00:10:48 +00:00
|
|
|
|
|
|
|
static void sensors_default_parse_error(const char *err, int lineno);
|
2009-02-15 17:26:57 +00:00
|
|
|
static void sensors_default_parse_error_wfn(const char *err,
|
|
|
|
const char *filename, int lineno);
|
2007-08-31 14:42:20 +00:00
|
|
|
static void sensors_default_fatal_error(const char *proc, const char *err);
|
1998-12-19 00:10:48 +00:00
|
|
|
|
2007-08-31 14:42:20 +00:00
|
|
|
void (*sensors_parse_error) (const char *err, int lineno) =
|
|
|
|
sensors_default_parse_error;
|
2009-02-15 17:26:57 +00:00
|
|
|
void (*sensors_parse_error_wfn) (const char *err, const char *filename,
|
|
|
|
int lineno) = sensors_default_parse_error_wfn;
|
2007-08-31 14:42:20 +00:00
|
|
|
void (*sensors_fatal_error) (const char *proc, const char *err) =
|
|
|
|
sensors_default_fatal_error;
|
1998-12-19 00:10:48 +00:00
|
|
|
|
2007-08-31 14:42:20 +00:00
|
|
|
static const char *errorlist[] = {
|
2009-01-29 12:24:08 +00:00
|
|
|
/* Invalid error code */ "Unknown error",
|
2007-08-31 14:42:20 +00:00
|
|
|
/* SENSORS_ERR_WILDCARDS */ "Wildcard found in chip name",
|
2007-09-23 12:07:53 +00:00
|
|
|
/* SENSORS_ERR_NO_ENTRY */ "No such subfeature known",
|
2007-09-24 16:34:56 +00:00
|
|
|
/* SENSORS_ERR_ACCESS_R */ "Can't read",
|
2007-09-23 13:53:11 +00:00
|
|
|
/* SENSORS_ERR_KERNEL */ "Kernel interface error",
|
2007-08-31 14:42:20 +00:00
|
|
|
/* SENSORS_ERR_DIV_ZERO */ "Divide by zero",
|
|
|
|
/* SENSORS_ERR_CHIP_NAME */ "Can't parse chip name",
|
|
|
|
/* SENSORS_ERR_BUS_NAME */ "Can't parse bus name",
|
|
|
|
/* SENSORS_ERR_PARSE */ "General parse error",
|
|
|
|
/* SENSORS_ERR_ACCESS_W */ "Can't write",
|
2007-09-29 18:48:20 +00:00
|
|
|
/* SENSORS_ERR_IO */ "I/O error",
|
2009-01-11 12:19:32 +00:00
|
|
|
/* SENSORS_ERR_RECURSION */ "Evaluation recurses too deep",
|
2007-08-31 14:42:20 +00:00
|
|
|
};
|
1998-12-19 00:10:48 +00:00
|
|
|
|
1998-12-20 21:57:39 +00:00
|
|
|
const char *sensors_strerror(int errnum)
|
1998-12-19 00:10:48 +00:00
|
|
|
{
|
2007-08-31 14:42:20 +00:00
|
|
|
if (errnum < 0)
|
|
|
|
errnum = -errnum;
|
|
|
|
if (errnum >= ARRAY_SIZE(errorlist))
|
|
|
|
errnum = 0;
|
|
|
|
return errorlist[errnum];
|
|
|
|
}
|
1998-12-19 00:10:48 +00:00
|
|
|
|
|
|
|
void sensors_default_parse_error(const char *err, int lineno)
|
|
|
|
{
|
2009-02-10 20:50:16 +00:00
|
|
|
if (lineno)
|
|
|
|
fprintf(stderr, "Error: Line %d: %s\n", lineno, err);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Error: %s\n", err);
|
1998-12-19 00:10:48 +00:00
|
|
|
}
|
|
|
|
|
2009-02-15 17:26:57 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1998-12-19 00:10:48 +00:00
|
|
|
void sensors_default_fatal_error(const char *proc, const char *err)
|
|
|
|
{
|
2007-08-31 14:42:20 +00:00
|
|
|
fprintf(stderr, "Fatal error in `%s': %s\n", proc, err);
|
|
|
|
exit(1);
|
1998-12-19 00:10:48 +00:00
|
|
|
}
|