11 #include "blacklist.h"
15 #include "../libcheckers/checkers.h"
18 * helper function to draw a list of callout binaries found in the config file
21 push_callout(char * callout)
28 * purge command line arguments
32 while (*p != ' ' && *p != '\0')
36 conf->binvec = vector_alloc();
43 * if this callout is already stored in binvec, don't store it twice
45 vector_foreach_slot (conf->binvec, bin, i)
46 if (memcmp(bin, callout, p - callout) == 0)
52 bin = MALLOC((p - callout) + 1);
57 strncpy(bin, callout, p - callout);
59 if (!vector_alloc_slot(conf->binvec))
62 vector_set_slot(conf->binvec, bin);
68 find_hwe (vector hwtable, char * vendor, char * product)
73 vector_foreach_slot (hwtable, hwe, i) {
74 if (strcmp_chomp(hwe->vendor, vendor) == 0 &&
75 (hwe->product[0] == '*' ||
76 strcmp_chomp(hwe->product, product) == 0))
82 extern struct mpentry *
83 find_mpe (char * wwid)
91 vector_foreach_slot (conf->mptable, mpe, i)
92 if (mpe->wwid && strcmp(mpe->wwid, wwid) == 0)
99 get_mpe_wwid (char * alias)
102 struct mpentry * mpe;
107 vector_foreach_slot (conf->mptable, mpe, i)
108 if (mpe->alias && strcmp(mpe->alias, alias) == 0)
115 free_hwe (struct hwentry * hwe)
139 FREE(hwe->hwhandler);
145 free_hwtable (vector hwtable)
148 struct hwentry * hwe;
153 vector_foreach_slot (hwtable, hwe, i)
156 vector_free(hwtable);
160 free_mpe (struct mpentry * mpe)
181 free_mptable (vector mptable)
184 struct mpentry * mpe;
189 vector_foreach_slot (mptable, mpe, i)
192 vector_free(mptable);
195 static struct hwentry *
198 return (struct hwentry *)MALLOC(sizeof(struct hwentry));
202 set_param_str(char * str)
215 dst = (char *)MALLOC(len + 1);
225 store_hwe (vector hwtable, char * vendor, char * product, int pgp,
228 struct hwentry * hwe;
235 hwe->vendor = set_param_str(vendor);
240 hwe->product = set_param_str(product);
249 hwe->getuid = set_param_str(getuid);
250 push_callout(getuid);
252 hwe->getuid = set_default(DEFAULT_GETUID);
253 push_callout(DEFAULT_GETUID);
259 if (!vector_alloc_slot(hwtable))
262 vector_set_slot(hwtable, hwe);
270 store_hwe_ext (vector hwtable, char * vendor, char * product, int pgp,
271 char * getuid, char * getprio, char * hwhandler,
272 char * features, char * checker)
274 struct hwentry * hwe;
281 hwe->vendor = set_param_str(vendor);
286 hwe->product = set_param_str(product);
295 hwe->getuid = set_param_str(getuid);
296 push_callout(getuid);
298 hwe->getuid = set_default(DEFAULT_GETUID);
299 push_callout(DEFAULT_GETUID);
306 hwe->getprio = set_param_str(getprio);
307 push_callout(getprio);
312 hwe->hwhandler = set_param_str(hwhandler);
314 hwe->hwhandler = set_default(DEFAULT_HWHANDLER);
320 hwe->features = set_param_str(features);
322 hwe->features = set_default(DEFAULT_FEATURES);
328 hwe->checker_index = get_checker_id(checker);
330 hwe->checker_index = get_checker_id(DEFAULT_CHECKER);
332 if (!vector_alloc_slot(hwtable))
335 vector_set_slot(hwtable, hwe);
345 return (struct config *)MALLOC(sizeof(struct config));
349 free_config (struct config * conf)
358 FREE(conf->multipath);
361 FREE(conf->udev_dir);
363 if (conf->default_selector)
364 FREE(conf->default_selector);
366 if (conf->default_getuid)
367 FREE(conf->default_getuid);
369 if (conf->default_getprio)
370 FREE(conf->default_getprio);
372 if (conf->default_features)
373 FREE(conf->default_features);
375 if (conf->default_hwhandler)
376 FREE(conf->default_hwhandler);
378 free_blacklist(conf->blist);
379 free_mptable(conf->mptable);
380 free_hwtable(conf->hwtable);
381 free_strvec(conf->binvec);
387 load_config (char * file)
389 conf = alloc_config();
398 conf->dev_type = DEV_NONE;
402 * read the config file
404 if (filepresent(file)) {
405 if (init_data(file, init_keywords)) {
406 condlog(0, "error parsing config file");
412 * fill the voids left in the config file
414 if (conf->hwtable == NULL) {
415 conf->hwtable = vector_alloc();
420 if (setup_default_hwtable(conf->hwtable))
423 if (conf->blist == NULL) {
424 conf->blist = vector_alloc();
429 if (setup_default_blist(conf->blist))
432 if (conf->mptable == NULL) {
433 conf->mptable = vector_alloc();
438 if (conf->default_selector == NULL)
439 conf->default_selector = set_default(DEFAULT_SELECTOR);
441 if (conf->udev_dir == NULL)
442 conf->udev_dir = set_default(DEFAULT_UDEVDIR);
444 if (conf->default_getuid == NULL)
445 conf->default_getuid = set_default(DEFAULT_GETUID);
447 if (conf->default_features == NULL)
448 conf->default_features = set_default(DEFAULT_FEATURES);
450 if (conf->default_hwhandler == NULL)
451 conf->default_hwhandler = set_default(DEFAULT_HWHANDLER);
453 if (!conf->default_selector || !conf->udev_dir ||
454 !conf->default_getuid || !conf->default_features ||
455 !conf->default_hwhandler)