mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-23 20:35:42 +02:00
module/removables: add 'ignore' configuration option
This is a list of devnames (e.g. /dev/sr0). Devices listed here will be ignored.
This commit is contained in:
parent
b0e9c02876
commit
5d17f1eb57
1 changed files with 40 additions and 2 deletions
|
@ -56,6 +56,7 @@ struct private {
|
|||
int left_spacing;
|
||||
int right_spacing;
|
||||
|
||||
tll(char *) ignore;
|
||||
tll(struct block_device) devices;
|
||||
};
|
||||
|
||||
|
@ -90,6 +91,7 @@ destroy(struct module *mod)
|
|||
tll_foreach(m->devices, it)
|
||||
free_device(&it->item);
|
||||
tll_free(m->devices);
|
||||
tll_free_and_free(m->ignore, free);
|
||||
|
||||
free(m);
|
||||
module_default_destroy(mod);
|
||||
|
@ -301,6 +303,16 @@ add_device(struct module *mod, struct udev_device *dev)
|
|||
if (!removable && !sd)
|
||||
return NULL;
|
||||
|
||||
const char *devname = udev_device_get_property_value(dev, "DEVNAME");
|
||||
if (devname != NULL) {
|
||||
tll_foreach(m->ignore, it) {
|
||||
if (strcmp(it->item, devname) == 0) {
|
||||
LOG_DBG("ignoring %s because it is on the ignore list", devname);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *_size = udev_device_get_sysattr_value(dev, "size");
|
||||
uint64_t size = 0;
|
||||
if (_size != NULL)
|
||||
|
@ -557,13 +569,17 @@ run(struct module *mod)
|
|||
}
|
||||
|
||||
static struct module *
|
||||
removables_new(struct particle *label, int left_spacing, int right_spacing)
|
||||
removables_new(struct particle *label, int left_spacing, int right_spacing,
|
||||
size_t ignore_count, const char *ignore[static ignore_count])
|
||||
{
|
||||
struct private *priv = calloc(1, sizeof(*priv));
|
||||
priv->label = label;
|
||||
priv->left_spacing = left_spacing;
|
||||
priv->right_spacing = right_spacing;
|
||||
|
||||
for (size_t i = 0; i < ignore_count; i++)
|
||||
tll_push_back(priv->ignore, strdup(ignore[i]));
|
||||
|
||||
struct module *mod = module_common_new();
|
||||
mod->private = priv;
|
||||
mod->run = &run;
|
||||
|
@ -579,13 +595,34 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited)
|
|||
const struct yml_node *spacing = yml_get_value(node, "spacing");
|
||||
const struct yml_node *left_spacing = yml_get_value(node, "left-spacing");
|
||||
const struct yml_node *right_spacing = yml_get_value(node, "right-spacing");
|
||||
const struct yml_node *ignore_list = yml_get_value(node, "ignore");
|
||||
|
||||
int left = spacing != NULL ? yml_value_as_int(spacing) :
|
||||
left_spacing != NULL ? yml_value_as_int(left_spacing) : 0;
|
||||
int right = spacing != NULL ? yml_value_as_int(spacing) :
|
||||
right_spacing != NULL ? yml_value_as_int(right_spacing) : 0;
|
||||
|
||||
return removables_new(conf_to_particle(content, inherited), left, right);
|
||||
size_t ignore_count = ignore_list != NULL ? yml_list_length(ignore_list) : 0;
|
||||
const char *ignore[ignore_count];
|
||||
|
||||
if (ignore_list != NULL) {
|
||||
size_t i = 0;
|
||||
for (struct yml_list_iter iter = yml_list_iter(ignore_list);
|
||||
iter.node != NULL;
|
||||
yml_list_next(&iter), i++)
|
||||
{
|
||||
ignore[i] = yml_value_as_string(iter.node);
|
||||
}
|
||||
}
|
||||
|
||||
return removables_new(
|
||||
conf_to_particle(content, inherited), left, right, ignore_count, ignore);
|
||||
}
|
||||
|
||||
static bool
|
||||
verify_ignore(keychain_t *chain, const struct yml_node *node)
|
||||
{
|
||||
return conf_verify_list(chain, node, &conf_verify_string);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -595,6 +632,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
|
|||
{"spacing", false, &conf_verify_int},
|
||||
{"left-spacing", false, &conf_verify_int},
|
||||
{"right-spacing", false, &conf_verify_int},
|
||||
{"ignore", false, &verify_ignore},
|
||||
MODULE_COMMON_ATTRS,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue