mirror of
https://github.com/AuxXxilium/eudev.git
synced 2025-02-25 21:29:54 +07:00
device: only expose devices with SYSTEMD_EXPOSE=1, ignore all others
This commit is contained in:
parent
09477267f6
commit
09e80b16f2
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
ACTION!="add|change", GOTO="systemd_end"
|
ACTION!="add|change", GOTO="systemd_end"
|
||||||
|
|
||||||
KERNEL=="tty[0-9]|tty1[0-2]", GOTO="systemd_end"
|
KERNEL=="tty[0-9]|tty1[0-2]", ENV{SYSTEMD_EXPOSE}="1"
|
||||||
|
KERNEL=="ttyS*", ENV{SYSTEMD_EXPOSE}="1"
|
||||||
KERNEL=="tty[0-9]*", ENV{SYSTEMD_EXPOSE}="0"
|
SUBSYSTEM=="block", ENV{SYSTEMD_EXPOSE}="1"
|
||||||
|
|
||||||
LABEL="systemd_end"
|
LABEL="systemd_end"
|
||||||
|
52
device.c
52
device.c
@ -153,28 +153,6 @@ static int device_find_escape_name(Manager *m, const char *dn, Unit **_u) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool devnode_is_api(const char *node) {
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
static const char * const table[] = {
|
|
||||||
"/dev/null",
|
|
||||||
"/dev/zero",
|
|
||||||
"/dev/urandom",
|
|
||||||
"/dev/random",
|
|
||||||
"/dev/port",
|
|
||||||
"/dev/oldmem",
|
|
||||||
"/dev/full",
|
|
||||||
"/dev/kmsg",
|
|
||||||
"/dev/mem"
|
|
||||||
};
|
|
||||||
|
|
||||||
for (i = 0; i < ELEMENTSOF(table); i++)
|
|
||||||
if (streq(table[i], node))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int device_process_new_device(Manager *m, struct udev_device *dev, bool update_state) {
|
static int device_process_new_device(Manager *m, struct udev_device *dev, bool update_state) {
|
||||||
const char *dn, *names, *wants, *sysfs, *expose, *model;
|
const char *dn, *names, *wants, *sysfs, *expose, *model;
|
||||||
Unit *u = NULL;
|
Unit *u = NULL;
|
||||||
@ -183,35 +161,29 @@ static int device_process_new_device(Manager *m, struct udev_device *dev, bool u
|
|||||||
size_t l;
|
size_t l;
|
||||||
bool delete;
|
bool delete;
|
||||||
struct udev_list_entry *item = NULL, *first = NULL;
|
struct udev_list_entry *item = NULL, *first = NULL;
|
||||||
|
int b;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
|
|
||||||
if (!(sysfs = udev_device_get_syspath(dev)))
|
if (!(sysfs = udev_device_get_syspath(dev)))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
if (!(expose = udev_device_get_property_value(dev, "SYSTEMD_EXPOSE")))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ((b = parse_boolean(expose)) < 0) {
|
||||||
|
log_error("Failed to parse SYSTEMD_EXPOSE udev property for device %s: %s", sysfs, expose);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!b)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Check whether this entry is even relevant for us. */
|
/* Check whether this entry is even relevant for us. */
|
||||||
dn = udev_device_get_devnode(dev);
|
dn = udev_device_get_devnode(dev);
|
||||||
expose = udev_device_get_property_value(dev, "SYSTEMD_EXPOSE");
|
|
||||||
names = udev_device_get_property_value(dev, "SYSTEMD_NAMES");
|
names = udev_device_get_property_value(dev, "SYSTEMD_NAMES");
|
||||||
wants = udev_device_get_property_value(dev, "SYSTEMD_WANTS");
|
wants = udev_device_get_property_value(dev, "SYSTEMD_WANTS");
|
||||||
|
|
||||||
if (expose) {
|
|
||||||
int b;
|
|
||||||
|
|
||||||
if ((b = parse_boolean(expose)) < 0) {
|
|
||||||
log_error("Failed to parse SYSTEMD_EXPOSE udev property for device %s: %s", sysfs, expose);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!b)
|
|
||||||
return 0;
|
|
||||||
} else
|
|
||||||
if ((!dn || devnode_is_api(dn)) && !names && !wants)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* Ok, seems kinda interesting. Now, let's see if this one
|
|
||||||
* already exists. */
|
|
||||||
|
|
||||||
if ((r = device_find_escape_name(m, sysfs, &u)) < 0)
|
if ((r = device_find_escape_name(m, sysfs, &u)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user