root/lm-sensors/tags/V2-10-2/lib/init.c

Revision 4208, 4.5 kB (checked in by khali, 2 years ago)

libsensors: Drop support for algorithm names.
I2C algorithms no longer have names in Linux 2.6, and anyway they are
implementation details user-space doesn't care about. No third party
application is known to have ever used this particular feature of
libsensors. "sensord" and "sensors" no longer do.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2     init.c - Part of libsensors, a Linux library for reading sensor data.
3     Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include "sensors.h"
23 #include "data.h"
24 #include "proc.h"
25 #include "error.h"
26 #include "access.h"
27 #include "conf.h"
28 #include "sysfs.h"
29 #include "scanner.h"
30
31 static void free_proc_chips_entry(sensors_proc_chips_entry entry);
32 static void free_chip_name(sensors_chip_name name);
33 static void free_bus(sensors_bus bus);
34 static void free_chip(sensors_chip chip);
35 static void free_label(sensors_label label);
36 static void free_set(sensors_set set);
37 static void free_compute(sensors_compute compute);
38 static void free_ignore(sensors_ignore ignore);
39 static void free_expr(sensors_expr *expr);
40
41 int sensors_init(FILE *input)
42 {
43   int res;
44   sensors_cleanup();
45   if (sensors_init_sysfs()) {
46     if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips()))
47       return res;
48   } else {
49     if ((res = sensors_read_proc_bus()) || (res = sensors_read_proc_chips()))
50       return res;
51   }
52   if ((res = sensors_scanner_init(input)))
53     return -SENSORS_ERR_PARSE;
54   if ((res = sensors_yyparse()))
55     return -SENSORS_ERR_PARSE;
56   if ((res = sensors_substitute_busses()));
57     return res;
58   return 0;
59 }
60
61 void sensors_cleanup(void)
62 {
63   int i;
64
65   sensors_scanner_exit();
66
67   for (i = 0; i < sensors_proc_chips_count; i++)
68     free_proc_chips_entry(sensors_proc_chips[i]);
69   free(sensors_proc_chips);
70   sensors_proc_chips = NULL;
71   sensors_proc_chips_count = sensors_proc_chips_max = 0;
72  
73   for (i = 0; i < sensors_config_busses_count; i++)
74     free_bus(sensors_config_busses[i]);
75   free(sensors_config_busses);
76   sensors_config_busses = NULL;
77   sensors_config_busses_count = sensors_config_busses_max = 0;
78
79   for (i = 0; i < sensors_config_chips_count; i++)
80     free_chip(sensors_config_chips[i]);
81   free(sensors_config_chips);
82   sensors_config_chips = NULL;
83   sensors_config_chips_count = sensors_config_chips_max = 0;
84
85   for (i = 0; i < sensors_proc_bus_count; i++)
86     free_bus(sensors_proc_bus[i]);
87   free(sensors_proc_bus);
88   sensors_proc_bus = NULL;
89   sensors_proc_bus_count = sensors_proc_bus_max = 0;
90 }
91
92 void free_proc_chips_entry(sensors_proc_chips_entry entry)
93 {
94     free_chip_name(entry.name);
95 }
96
97 void free_chip_name(sensors_chip_name name)
98 {
99   free(name.prefix);
100   free(name.busname);
101 }
102
103 void free_bus(sensors_bus bus)
104 {
105   free(bus.adapter);
106 }
107
108 void free_chip(sensors_chip chip)
109 {
110   int i;
111
112   for (i = 0; i < chip.chips.fits_count; i++)
113     free_chip_name(chip.chips.fits[i]);
114   free(chip.chips.fits);
115   chip.chips.fits_count = chip.chips.fits_max = 0;
116
117   for (i = 0; i < chip.labels_count; i++)
118     free_label(chip.labels[i]);
119   free(chip.labels);
120   chip.labels_count = chip.labels_max = 0;
121
122   for (i = 0; i < chip.sets_count; i++)
123     free_set(chip.sets[i]);
124   free(chip.sets);
125   chip.sets_count = chip.sets_max = 0;
126
127   for (i = 0; i < chip.computes_count; i++)
128     free_compute(chip.computes[i]);
129   free(chip.computes);
130   chip.computes_count = chip.computes_max = 0;
131
132   for (i = 0; i < chip.ignores_count; i++)
133     free_ignore(chip.ignores[i]);
134   free(chip.ignores);
135   chip.ignores_count = chip.ignores_max = 0;
136 }
137
138 void free_label(sensors_label label)
139 {
140   free(label.name);
141   free(label.value);
142 }
143
144 void free_set(sensors_set set)
145 {
146   free(set.name);
147   free_expr(set.value);
148 }
149
150 void free_compute(sensors_compute compute)
151 {
152   free(compute.name);
153   free_expr(compute.from_proc);
154   free_expr(compute.to_proc);
155 }
156
157 void free_ignore(sensors_ignore ignore)
158 {
159   free(ignore.name);
160 }
161
162 void free_expr(sensors_expr *expr)
163 {
164   if ((expr->kind) == sensors_kind_var)
165     free(expr->data.var);
166   else if ((expr->kind) == sensors_kind_sub) {
167     if (expr->data.subexpr.sub1)
168       free_expr(expr->data.subexpr.sub1);
169     if (expr->data.subexpr.sub2)
170       free_expr(expr->data.subexpr.sub2);
171   }
172   free(expr);
173 }
Note: See TracBrowser for help on using the browser.