1 .TH READ_CONFIG 3 "02 Mar 1999"
4 register_config_handler, register_premib_handler
5 unregister_config_handler, register_mib_handlers, read_configs,
6 read_premib_configs, config_perror, config_pwarn - read_config functions
8 .B #include <read_config.h>
10 .B struct config_line *
12 .B " register_config_handler(char *filePrefix, char *token,"
14 .B " void (*parser)(char *, char *) handler, "
16 .B " void (*releaser) (void) freefunc,"
18 .B " char *usageLine)"
20 .B struct config_line *
22 .B " register_premib_handler(char *filePrefix, char *token,"
24 .B " void (*parser)(char *, char *) handler, "
26 .B " void (*releaser) (void) freefunc,"
28 .B " char *usageLine)"
30 .B struct config_line *
32 .B " snmpd_register_config_handler(char *token,"
34 .B " void (*parser)(char *, char *) handler, "
36 .B " void (*releaser) (void) freefunc,"
38 .B " char *usageLine)"
40 .B "void unregister_config_handler(char *filePrefix, "
44 .B "void read_config_print_usage(char *lead)"
46 .B "void read_configs(void)"
48 .B "void read_premib_configs(void)"
51 The functions are a fairly extensible system of parsing various
52 configuration files at the run time of an application. The
53 configuration file flow is broken into the following phases:
56 registration of handlers.
58 reading of the configuration files for pre-mib parsing requirements.
60 reading of the textual mib files.
62 reading of the configuration files for configuration directives.
64 optionally re-reading of the configuration files at a future date.
67 The idea is that the calling application is able to register
71 specified in certain types of
75 function can then be called to look for all the files that it has
76 registrations for, find the first word on each line, and pass the
77 remainder to the appropriately registered handler.
80 Handler functions should be of the following type:
83 void handler(char *token, char *line);
86 The function will be called with two arguments, the first being the
87 token that triggered the call to this function (which would be one of
88 the tokens that the function had been registered for), and the second
89 being the remainder of the configuration file line beyond the white
90 space following the token.
91 .SH Resource Freeing Handlers
93 If the read_config configuration system is called a second time to
94 re-read the configuration files, the optional second handler
96 will be called, if registered as non-NULL, to free any resources and
97 reset its notions to defaults before the config handlers are called
98 again. It is not called with any arguments.
99 .SH Registering A Handler
100 .IP register_config_handler()
101 The handler above could then be registered for the configuration file
105 and the help string (discussed later)
107 using the following call to the
108 .B register_config_handler()
113 register_config_handler("snmp", "genericToken", handler, NULL, "ARG1 ARG2");
117 This would register the
119 function so that it will get called every time the first word in the
121 configuration file(s) matches "genericToken" (see
124 .IP register_premib_handler()
126 .B register_premib_handler()
127 function works identically to the
128 .B register_config_handler()
129 function but is intended for config file tokens that need to be read
130 in before the textual mibs are read in, probably because they will be
131 used to configure the mib parser. It is rarely the case that anything
132 but the snmp library itself should need to use this function.
133 .IP snmpd_register_config_handler()
134 This function performs exactly the same job as the
135 .B register_config_handler()
136 function, but doesn't require the file type argument (which is filled
137 in by the snmpd agent). It is intended that mib modules written for
138 the agent use this function instead of the
139 .B register_config_handler()
140 function directly to allow the agent to have more control over which
141 files the mib modules will read (which should be the
144 .IP unregister_config_handler()
145 Removes the registered configuration handler for the
154 token passed to the register_config_handler(), and similar calls, is
155 used to display help information when the
156 .B read_config_print_usage()
157 function is called. This function is used by all of the applications
160 flag is passed to the command line. It prints a summary of all of the
161 configuration file lines, and the associated files, that the
162 configuration system understands. The usageLine parameter should be a
163 list of arguments expected after the token, and not a lengthy
164 description (which should go into a manual page instead). The
166 prefix will be prepended to each line that the function prints to
167 stderr, where it displays its output.
171 function should be called before the
172 .B read_config_print_usage()
173 function is called, so that the library can register its configuration
174 file directives as well for the
175 .B read_config_print_usage()
177 .SH Reading Configuration Files
181 function call should be called after registrations to appropriately
182 register parser configuration tokens, parse the configuration file
183 tokens registered with
184 .B register_premib_handler(),
185 read in the textual mib files using
187 and finally parse the configuration file tokens registered with
188 .B register_config_handler().
192 function is used, none of the following functions need to be called by
195 .IP register_mib_handlers()
196 The snmp library's routine to register it's configuration file
198 .IP read_premib_configs()
199 The routine that parses the configuration files for tokens registered
200 to be dealt with before the textual mibs are read in. See
204 Reads all the configuration files it can find in the
206 environment variable (or its default value) for tokens and
207 appropriately calls the handlers registered to it, or prints a
208 "Unknown token" warning message. It looks for any file that it has
209 previously received a registration request for.
210 .SH Configuration Files Read
212 The configuration files read are found by using the colon separated
214 environment variable (or its default value, which will be
215 /usr/share/snmp, followed by /usr/lib/snmp, followed by $HOME/.snmp) and
216 reading in the files found that match both the prefix registered and
221 The idea behind the two different suffixes is that the first file can
222 be rdisted across a large number of machines and the second file can
223 be used to configure local settings for one particular machine. They
224 do not need to be present, and will only be read if found.
225 .SH Error Handling Functions
231 both take an error string as an argument and print it to stderr along
232 with the file and line number that caused the error. A call to the
233 second function will also force read_configs() to eventually return
234 with an error code indicating to it's calling function that it should
235 abort the operation of the application.
236 .SH "ENVIRONMENT VARIABLES"
239 A colon separated list of directories to search for configuration
241 Default: /usr/share/snmp:/usr/lib/snmp:$HOME/.snmp
243 mib_api(3), snmp_api(3)