static int manager_udev_fn(sd_event_source *source, int fd, uint32_t mask, void *data) { _cleanup_udev_device_ struct udev_device *d = NULL; struct manager *m = data; const char *action, *ifname; unsigned int ifindex; struct link *l; d = udev_monitor_receive_device(m->udev_mon); if (!d) return 0; ifindex = ifindex_from_udev_device(d); if (!ifindex) return 0; l = manager_find_link(m, ifindex); action = udev_device_get_action(d); if (action && !strcmp(action, "remove")) { if (l) link_free(l); } else if (l) { ifname = udev_device_get_property_value(d, "INTERFACE"); if (action && !strcmp(action, "move")) { if (ifname) link_renamed(l, ifname); } #ifdef RELY_UDEV if (udev_device_has_tag(d, "miracle") && !lazy_managed) link_set_managed(l, true); else link_set_managed(l, false); #else if ((!interface_name || !strcmp(interface_name, ifname)) && !lazy_managed) { link_set_managed(l, true); } else { log_debug("ignored device: %s", ifname); } #endif } else { manager_add_udev_link(m, d); } return 0; }
static void manager_add_udev_link(struct manager *m, struct udev_device *d) { struct link *l; unsigned int ifindex; const char *ifname; int r; ifindex = ifindex_from_udev_device(d); if (!ifindex) return; ifname = udev_device_get_property_value(d, "INTERFACE"); if (!ifname) return; if (interface_name && strcmp(interface_name, ifname)) { return; } /* ignore dynamic p2p interfaces */ if (shl_startswith(ifname, "p2p-")) return; r = link_new(m, ifindex, ifname, &l); if (r < 0) return; if (m->friendly_name && l->managed) link_set_friendly_name(l, m->friendly_name); if (m->config_methods) link_set_config_methods(l, m->config_methods); if(use_dev) link_use_dev(l); #ifdef RELY_UDEV bool managed = udev_device_has_tag(d, "miracle") && !lazy_managed; #else bool managed = (!interface_name || !strcmp(interface_name, ifname)) && !lazy_managed; #endif if (managed) { link_set_managed(l, true); } else { log_debug("ignored device: %s", ifname); } }
static int show_sysfs_one( struct udev *udev, const char *seat, struct udev_list_entry **item, const char *sub, const char *prefix, unsigned n_columns) { assert(udev); assert(seat); assert(item); assert(prefix); while (*item) { struct udev_list_entry *next, *lookahead; struct udev_device *d; const char *sn, *name, *sysfs, *subsystem, *sysname; char *l, *k; bool is_master; sysfs = udev_list_entry_get_name(*item); if (!path_startswith(sysfs, sub)) return 0; d = udev_device_new_from_syspath(udev, sysfs); if (!d) { *item = udev_list_entry_get_next(*item); continue; } sn = udev_device_get_property_value(d, "ID_SEAT"); if (isempty(sn)) sn = "seat0"; /* Explicitly also check for tag 'seat' here */ if (!streq(seat, sn) || !udev_device_has_tag(d, "seat")) { udev_device_unref(d); *item = udev_list_entry_get_next(*item); continue; } is_master = udev_device_has_tag(d, "seat-master"); name = udev_device_get_sysattr_value(d, "name"); if (!name) name = udev_device_get_sysattr_value(d, "id"); subsystem = udev_device_get_subsystem(d); sysname = udev_device_get_sysname(d); /* Look if there's more coming after this */ lookahead = next = udev_list_entry_get_next(*item); while (lookahead) { const char *lookahead_sysfs; lookahead_sysfs = udev_list_entry_get_name(lookahead); if (path_startswith(lookahead_sysfs, sub) && !path_startswith(lookahead_sysfs, sysfs)) { struct udev_device *lookahead_d; lookahead_d = udev_device_new_from_syspath(udev, lookahead_sysfs); if (lookahead_d) { const char *lookahead_sn; bool found; lookahead_sn = udev_device_get_property_value(d, "ID_SEAT"); if (isempty(lookahead_sn)) lookahead_sn = "seat0"; found = streq(seat, lookahead_sn) && udev_device_has_tag(lookahead_d, "seat"); udev_device_unref(lookahead_d); if (found) break; } } lookahead = udev_list_entry_get_next(lookahead); } k = ellipsize(sysfs, n_columns, 20); printf("%s%s%s\n", prefix, draw_special_char(lookahead ? DRAW_TREE_BRANCH : DRAW_TREE_RIGHT), k ? k : sysfs); free(k); if (asprintf(&l, "%s%s:%s%s%s%s", is_master ? "[MASTER] " : "", subsystem, sysname, name ? " \"" : "", name ? name : "", name ? "\"" : "") < 0) { udev_device_unref(d); return -ENOMEM; } k = ellipsize(l, n_columns, 70); printf("%s%s%s\n", prefix, lookahead ? draw_special_char(DRAW_TREE_VERT) : " ", k ? k : l); free(k); free(l); *item = next; if (*item) { char *p; p = strappend(prefix, lookahead ? draw_special_char(DRAW_TREE_VERT) : " "); show_sysfs_one(udev, seat, item, sysfs, p ? p : prefix, n_columns - 2); free(p); } udev_device_unref(d); } return 0; }
static void manager_add_udev_link(struct manager *m, struct udev_device *d) { struct link *l; unsigned int ifindex; const char *ifname; int r; ifindex = ifindex_from_udev_device(d); if (!ifindex) return; ifname = udev_device_get_property_value(d, "INTERFACE"); if (!ifname) return; if (interface_name && strcmp(interface_name, ifname)) { return; } /* ignore dynamic p2p interfaces */ if (shl_startswith(ifname, "p2p-")) return; r = link_new(m, ifindex, ifname, &l); if (r < 0) return; link_set_friendly_name(l, m->friendly_name); #ifdef RELY_UDEV if (udev_device_has_tag(d, "miracle")) { #else if (!interface_name || !strcmp(interface_name, ifname)) { #endif link_set_managed(l, true); } else { log_debug("ignored device: %s", ifname); } } static int manager_udev_fn(sd_event_source *source, int fd, uint32_t mask, void *data) { _cleanup_udev_device_ struct udev_device *d = NULL; struct manager *m = data; const char *action, *ifname; unsigned int ifindex; struct link *l; d = udev_monitor_receive_device(m->udev_mon); if (!d) return 0; ifindex = ifindex_from_udev_device(d); if (!ifindex) return 0; l = manager_find_link(m, ifindex); action = udev_device_get_action(d); if (action && !strcmp(action, "remove")) { if (l) link_free(l); } else if (l) { ifname = udev_device_get_property_value(d, "INTERFACE"); if (action && !strcmp(action, "move")) { if (ifname) link_renamed(l, ifname); } #ifdef RELY_UDEV if (udev_device_has_tag(d, "miracle")) link_set_managed(l, true); else link_set_managed(l, false); #else if (!interface_name || !strcmp(interface_name, ifname)) { link_set_managed(l, true); } else { log_debug("ignored device: %s", ifname); } #endif } else { manager_add_udev_link(m, d); } return 0; }