../lib/device/dev-cache.h
../lib/device/device.h
../lib/display/display.h
+../lib/filters/filter-composite.h
../lib/filters/filter-persistent.h
../lib/filters/filter-regex.h
../lib/filters/filter.h
static struct config_node *_section(struct parser *p);
static struct config_value *_value(struct parser *p);
static struct config_value *_type(struct parser *p);
-static void _parse_error(struct parser *p, const char *file, int line,
- const char *mess);
static int _match_aux(struct parser *p, int t);
static struct config_value *_create_value(struct parser *p);
static struct config_node *_create_node(struct parser *p);
#define match(t) do {\
if (!_match_aux(p, (t))) {\
- _parse_error(p, __FILE__, __LINE__, "unexpected token"); \
+ log_error("Parse error at line %d: unexpected token", p->line); \
return 0;\
} \
} while(0);
break;
default:
- _parse_error(p, __FILE__, __LINE__, "expected a value");
+ log_error("Parse error at line %d: expected a value", p->line);
return 0;
}
return v;
}
-static void _parse_error(struct parser *p, const char *file, int line,
- const char *mess)
-{
- plog(_LOG_ERR, file, line, "parse error at %d: %s", p->line, mess);
-}
-
static int _match_aux(struct parser *p, int t)
{
if (p->t != t)
int dev_cache_add_dir(const char *path)
{
struct dir_list *dl;
+ struct stat st;
+
+ if (stat(path, &st)) {
+ log_error("Ignoring %s: %s", path, strerror(errno));
+ /* But don't fail */
+ return 1;
+ }
+
+ if (!S_ISDIR(st.st_mode)) {
+ log_error("Ignoring %s: Not a directory", path);
+ return 1;
+ }
if (!(dl = _alloc(sizeof(*dl) + strlen(path) + 1)))
return 0;
}
if (!(cn = find_config_node(cf->root, "/valid_devices", '/'))) {
- log_info("couldn't find 'valid_devices' array in '%s'",
+ log_info("Couldn't find 'valid_devices' array in '%s'",
pf->file);
goto out;
}
*/
for (cv = cn->v; cv; cv = cv->next) {
if (cv->type != CFG_STRING) {
- log_info("valid_devices array contains a value "
+ log_info("Valid_devices array contains a value "
"which is not a string ... ignoring");
continue;
}
if (!hash_insert(pf->devices, cv->v.str, PF_UNCHECKED))
- log_info("couldn't add '%s' to filter ... ignoring",
+ log_info("Couldn't add '%s' to filter ... ignoring",
cv->v.str);
}
r = 1;
struct hash_node *n;
FILE *fp = fopen(pf->file, "w");
+ log_very_verbose("Dumping persistent device cache to %s", pf->file);
+
if (!fp) {
log_info("Couldn't open '%s' for to hold valid devices.",
pf->file);
if (fd >= 0)
r = 1;
+ else
+ log_debug("Unable to open %s: %s", path, strerror(errno));
close(fd);
return r;
static int *scan_proc_dev(void);
-static int passes_config_device_filter(struct dev_filter *f, struct device *dev)
+static int passes_lvm_type_device_filter(struct dev_filter *f, struct device *dev)
{
- /* FIXME Check against config file scan/reject entries */
-
/* Is this a recognised device type? */
if (!(((int *) f->private)[MAJOR(dev->dev)]))
return 0;
return 1;
}
-struct dev_filter *config_filter_create()
+struct dev_filter *lvm_type_filter_create()
{
struct dev_filter *f;
return NULL;
}
- f->passes_filter = passes_config_device_filter;
+ f->passes_filter = passes_lvm_type_device_filter;
if (!(f->private = scan_proc_dev()))
return NULL;
return f;
}
-void config_filter_destroy(struct dev_filter *f)
+void lvm_type_filter_destroy(struct dev_filter *f)
{
dbg_free(f->private);
dbg_free(f);
#ifndef _LVM_FILTER_H
#define _LVM_FILTER_H
-struct dev_filter *config_filter_create();
+struct dev_filter *lvm_type_filter_create();
-void config_filter_destroy(struct dev_filter *f);
+void lvm_type_filter_destroy(struct dev_filter *f);
#endif
struct pool *p = dbg_malloc(sizeof(*p));
if (!p) {
- log_err("couldn't create pool");
+ log_error("Couldn't create memory pool");
return 0;
}
memset(p, 0, sizeof(*p));
}
if (!c)
- log_warn("pool_free asked to free a pointer "
+ log_debug("pool_free asked to free a pointer "
"that wasn't in the pool, doing nothing");
else
p->chunk = c;
if (log_file) {
/* set up the logging */
if (!(_log = fopen(log_file, "w")))
- log_error("couldn't open log file %s\n", log_file);
+ log_error("Couldn't open log file %s", log_file);
else
init_log(_log);
}
init_debug(_debug_level);
}
+static int dev_cache_setup(void)
+{
+ struct config_node *cn;
+ struct config_value *cv;
+
+ if (!dev_cache_init()) {
+ stack;
+ return 0;
+ }
+
+ if (!(cn = find_config_node(_cf->root, "devices/scan", '/'))) {
+ if (!dev_cache_add_dir("/dev")) {
+ log_error("Failed to add /dev to internal "
+ "device cache");
+ return 0;
+ }
+ }
+
+ for (cv = cn->v; cv; cv = cv->next) {
+ if (cv->type != CFG_STRING) {
+ log_error("Invalid string in config file: "
+ "devices/scan");
+ return 0;
+ }
+
+ if (!dev_cache_add_dir(cv->v.str)) {
+ log_error("Failed to add %s to internal device cache",
+ cv->v.str);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+static struct dev_filter *filter_setup(void)
+{
+ struct config_node *cn;
+ struct dev_filter *f1, *f2, *f3, *f4;
+
+ if (!(f1 = lvm_type_filter_create()))
+ return 0;
+
+ if (!(cn = find_config_node(_cf->root, "devices/filter", '/'))) {
+ log_debug("devices/filter not found in config file");
+ return f1;
+ }
+
+ if (!(f2 = regex_filter_create(cn->v))) {
+ log_error("Failed to create regex device filter");
+ return f1;
+ }
+
+ if (!(f4 = composite_filter_create(2, f1, f2))) {
+ log_error("Failed to create composite device filter");
+ return f1;
+ }
+
+ return f4;
+}
+
static int init(void)
{
int ret = 0;
if (stat(e, &info) != -1) {
/* we've found a config file */
if (!read_config(_cf, e)) {
- stack;
+ log_error("Failed to load config file %s", e);
goto out;
}
__init_log(_cf);
}
- if (!dev_cache_init()) {
- stack;
- goto out;
- }
- if (!dev_cache_add_dir("/dev")) {
- log_error("Failed to add %s to internal device cache", prefix);
+ if (!dev_cache_setup()) {
goto out;
}
- if (!(_filter = config_filter_create())) {
- /* Add scan & rejects from _cf->root */
+ if (!(_filter = filter_setup())) {
+ log_error("Failed to set up internal device filters");
goto out;
}
static void fin(void)
{
ios->destroy(ios);
- config_filter_destroy(_filter);
+ lvm_type_filter_destroy(_filter);
dev_cache_exit();
destroy_config_file(_cf);
__fin_commands();
#include "display.h"
#include "errors.h"
#include "filter.h"
+#include "filter-composite.h"
+#include "filter-regex.h"
#include "format1.h"
#include "toollib.h"
#include "activate.h"