root/lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/lib.c @ 4987

Revision 4987, 2.4 KB (checked in by khali, 7 years ago)

"sensord" no longer needs a default configuration file name. If no
file name is provided on the command line, use the libsensors default.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * sensord
3 *
4 * A daemon that periodically logs sensor information to syslog.
5 *
6 * Copyright (c) 1999-2002 Merlin Hughes <merlin@merlin.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <syslog.h>
27#include <time.h>
28#include <unistd.h>
29#include <sys/stat.h>
30
31#include "sensord.h"
32#include "lib/error.h"
33
34static int
35loadConfig
36(const char *cfgPath, int reload) {
37  struct stat stats;
38  FILE *cfg = NULL;
39  int ret = 0;
40
41  if (cfgPath && !strcmp (cfgPath, "-")) {
42    if (!reload) {
43      if ((ret = sensors_init (stdin))) {
44        sensorLog (LOG_ERR, "Error loading sensors configuration file <stdin>: %s",
45                   sensors_strerror (ret));
46        ret = 12;
47      }
48    }
49  } else if (cfgPath && stat (cfgPath, &stats) < 0) {
50    sensorLog (LOG_ERR, "Error stating sensors configuration file: %s", cfgPath);
51    ret = 10;
52  } else {
53    if (reload) {
54      sensorLog (LOG_INFO, "configuration reloading");
55      sensors_cleanup ();
56    }
57    if (cfgPath && !(cfg = fopen (cfgPath, "r"))) {
58      sensorLog (LOG_ERR, "Error opening sensors configuration file: %s", cfgPath);
59      ret = 11;
60    } else if ((ret = sensors_init (cfg))) {
61      sensorLog (LOG_ERR, "Error loading sensors configuration file %s: %s",
62                 cfgPath ? cfgPath : "(default)", sensors_strerror (ret));
63      ret = 11;
64    }
65    if (cfg)
66      fclose (cfg);
67  }
68
69  return ret;
70}
71
72int
73loadLib
74(const char *cfgPath) {
75  int ret;
76  ret = loadConfig (cfgPath, 0);
77  if (!ret)
78    ret = initKnownChips ();
79  return ret;
80}
81
82int
83reloadLib
84(const char *cfgPath) {
85  int ret;
86  freeKnownChips ();
87  ret = loadConfig (cfgPath, 1);
88  if (!ret)
89    ret = initKnownChips ();
90  return ret;
91}
92
93int
94unloadLib
95(void) {
96  freeKnownChips ();
97  sensors_cleanup ();
98  return 0; 
99}
Note: See TracBrowser for help on using the browser.