mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-27 12:30:43 +00:00
sensord: This patch does some refactoring of the loadConfig()
function. * Simplifying the conditions makes code flow clearer and eliminates long lines (> 80 chars). * Removed useless stat() call. * Return -1 in error case, instead of several positive values (never defined). git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5722 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
b5375e4344
commit
f5aaeec448
2 files changed
+39
-37
No files matched your search
+37
-35
@@ -21,6 +21,7 @@
|
||||
* MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -34,46 +35,47 @@
|
||||
|
||||
static int loadConfig(const char *cfgPath, int reload)
|
||||
{
|
||||
struct stat stats;
|
||||
FILE *cfg = NULL;
|
||||
int ret = 0;
|
||||
int ret;
|
||||
FILE *fp;
|
||||
|
||||
if (cfgPath && !strcmp(cfgPath, "-")) {
|
||||
if (!reload) {
|
||||
if ((ret = sensors_init(stdin))) {
|
||||
sensorLog(LOG_ERR,
|
||||
"Error loading sensors configuration file <stdin>: %s",
|
||||
sensors_strerror(ret));
|
||||
ret = 12;
|
||||
}
|
||||
}
|
||||
} else if (cfgPath && stat(cfgPath, &stats) < 0) {
|
||||
sensorLog(LOG_ERR,
|
||||
"Error stating sensors configuration file: %s",
|
||||
cfgPath);
|
||||
ret = 10;
|
||||
} else {
|
||||
if (reload) {
|
||||
/* Load default configuration. */
|
||||
if (!cfgPath) {
|
||||
if (reload) {
|
||||
sensorLog(LOG_INFO, "configuration reloading");
|
||||
sensors_cleanup();
|
||||
}
|
||||
if (cfgPath && !(cfg = fopen(cfgPath, "r"))) {
|
||||
sensorLog(LOG_ERR,
|
||||
"Error opening sensors configuration file: %s",
|
||||
cfgPath);
|
||||
ret = 11;
|
||||
} else if ((ret = sensors_init(cfg))) {
|
||||
sensorLog(LOG_ERR,
|
||||
"Error loading sensors configuration file %s: %s",
|
||||
cfgPath ? cfgPath : "(default)",
|
||||
sensors_strerror(ret));
|
||||
ret = 11;
|
||||
}
|
||||
if (cfg)
|
||||
fclose(cfg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
ret = sensors_init(NULL);
|
||||
if (ret) {
|
||||
sensorLog(LOG_ERR, "Error loading default"
|
||||
" configuration file: %s",
|
||||
sensors_strerror(ret));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
fp = fopen(cfgPath, "r");
|
||||
if (!fp) {
|
||||
sensorLog(LOG_ERR, "Error opening config file %s: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (reload) {
|
||||
sensorLog(LOG_INFO, "configuration reloading");
|
||||
sensors_cleanup();
|
||||
}
|
||||
ret = sensors_init(fp);
|
||||
if (ret) {
|
||||
sensorLog(LOG_ERR, "Error loading sensors configuration file"
|
||||
" %s: %s", cfgPath, sensors_strerror(ret));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int loadLib(const char *cfgPath)
|
||||
|
||||
@@ -93,8 +93,8 @@ static int sensord(void)
|
||||
if (reload) {
|
||||
ret = reloadLib(sensord_args.cfgFile);
|
||||
if (ret)
|
||||
sensorLog(LOG_NOTICE,
|
||||
"config reload error (%d)", ret);
|
||||
sensorLog(LOG_NOTICE, "configuration reload"
|
||||
" error");
|
||||
reload = 0;
|
||||
}
|
||||
if (sensord_args.scanTime && (scanValue <= 0)) {
|
||||
|
||||
Reference in new issue
Block a user