2 * libudev - interface to udev device information
4 * Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
24 #include <sys/ioctl.h>
25 #include <sys/socket.h>
26 #include <linux/sockios.h>
29 #include "libudev-private.h"
32 * SECTION:libudev-device
33 * @short_description: kernel sys devices
35 * Representation of kernel sys devices. Devices are uniquely identified
36 * by their syspath, every device has exactly one path in the kernel sys
37 * filesystem. Devices usually belong to a kernel subsystem, and and have
38 * a unique name inside that subsystem.
44 * Opaque object representing one kernel sys device.
48 struct udev_device *parent_device;
64 size_t monitor_buf_len;
65 struct udev_list_node devlinks_list;
66 struct udev_list_node properties_list;
67 struct udev_list_node sysattr_value_list;
68 struct udev_list_node sysattr_list;
69 struct udev_list_node tags_list;
70 unsigned long long int seqnum;
71 unsigned long long int usec_initialized;
83 bool devlinks_uptodate;
91 bool sysattr_list_read;
94 struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value)
96 udev_device->envp_uptodate = false;
98 struct udev_list_entry *list_entry;
100 list_entry = udev_device_get_properties_list_entry(udev_device);
101 list_entry = udev_list_entry_get_by_name(list_entry, key);
102 if (list_entry != NULL)
103 udev_list_entry_delete(list_entry);
106 return udev_list_entry_add(udev_device->udev, &udev_device->properties_list, key, value, 1, 0);
109 static struct udev_list_entry *udev_device_add_property_from_string(struct udev_device *udev_device, const char *property)
111 char name[UTIL_LINE_SIZE];
114 util_strscpy(name, sizeof(name), property);
115 val = strchr(name, '=');
122 return udev_device_add_property(udev_device, name, val);
126 * parse property string, and if needed, update internal values accordingly
128 * udev_device_add_property_from_string_parse_finish() needs to be
129 * called after adding properties, and its return value checked
131 * udev_device_set_info_loaded() needs to be set, to avoid trying
132 * to use a device without a DEVPATH set
134 void udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property)
136 if (strncmp(property, "DEVPATH=", 8) == 0) {
137 char path[UTIL_PATH_SIZE];
139 util_strscpyl(path, sizeof(path), udev_get_sys_path(udev_device->udev), &property[8], NULL);
140 udev_device_set_syspath(udev_device, path);
141 } else if (strncmp(property, "SUBSYSTEM=", 10) == 0) {
142 udev_device_set_subsystem(udev_device, &property[10]);
143 } else if (strncmp(property, "DEVTYPE=", 8) == 0) {
144 udev_device_set_devtype(udev_device, &property[8]);
145 } else if (strncmp(property, "DEVNAME=", 8) == 0) {
146 if (property[8] == '/')
147 udev_device_set_devnode(udev_device, &property[8]);
149 udev_device_set_knodename(udev_device, &property[8]);
150 } else if (strncmp(property, "DEVLINKS=", 9) == 0) {
151 char devlinks[UTIL_PATH_SIZE];
155 util_strscpy(devlinks, sizeof(devlinks), &property[9]);
157 next = strchr(slink, ' ');
158 while (next != NULL) {
160 udev_device_add_devlink(udev_device, slink, 0);
162 next = strchr(slink, ' ');
164 if (slink[0] != '\0')
165 udev_device_add_devlink(udev_device, slink, 0);
166 } else if (strncmp(property, "TAGS=", 5) == 0) {
167 char tags[UTIL_PATH_SIZE];
170 util_strscpy(tags, sizeof(tags), &property[5]);
171 next = strchr(tags, ':');
174 while (next[0] != '\0') {
178 next = strchr(tag, ':');
183 udev_device_add_tag(udev_device, tag);
186 } else if (strncmp(property, "DRIVER=", 7) == 0) {
187 udev_device_set_driver(udev_device, &property[7]);
188 } else if (strncmp(property, "ACTION=", 7) == 0) {
189 udev_device_set_action(udev_device, &property[7]);
190 } else if (strncmp(property, "MAJOR=", 6) == 0) {
191 udev_device->maj = strtoull(&property[6], NULL, 10);
192 } else if (strncmp(property, "MINOR=", 6) == 0) {
193 udev_device->min = strtoull(&property[6], NULL, 10);
194 } else if (strncmp(property, "DEVPATH_OLD=", 12) == 0) {
195 udev_device_set_devpath_old(udev_device, &property[12]);
196 } else if (strncmp(property, "SEQNUM=", 7) == 0) {
197 udev_device_set_seqnum(udev_device, strtoull(&property[7], NULL, 10));
198 } else if (strncmp(property, "TIMEOUT=", 8) == 0) {
199 udev_device_set_timeout(udev_device, strtoull(&property[8], NULL, 10));
200 } else if (strncmp(property, "IFINDEX=", 8) == 0) {
201 udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10));
203 udev_device_add_property_from_string(udev_device, property);
207 int udev_device_add_property_from_string_parse_finish(struct udev_device *udev_device)
209 if (udev_device->maj > 0)
210 udev_device_set_devnum(udev_device, makedev(udev_device->maj, udev_device->min));
211 udev_device->maj = 0;
212 udev_device->min = 0;
214 if (udev_device->devpath == NULL || udev_device->subsystem == NULL)
220 * udev_device_get_property_value:
221 * @udev_device: udev device
222 * @key: property name
224 * Returns: the value of a device property, or #NULL if there is no such property.
226 const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key)
228 struct udev_list_entry *list_entry;
230 if (udev_device == NULL)
235 list_entry = udev_device_get_properties_list_entry(udev_device);
236 list_entry = udev_list_entry_get_by_name(list_entry, key);
237 return udev_list_entry_get_value(list_entry);
240 int udev_device_read_db(struct udev_device *udev_device)
243 char filename[UTIL_PATH_SIZE];
244 char line[UTIL_LINE_SIZE];
247 if (udev_device->db_loaded)
249 udev_device->db_loaded = true;
251 id = udev_device_get_id_filename(udev_device);
254 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/.udev/db/", id, NULL);
255 f = fopen(filename, "re");
257 info(udev_device->udev, "no db file to read %s: %m\n", filename);
260 udev_device->is_initialized = true;
262 while (fgets(line, sizeof(line), f)) {
265 struct udev_list_entry *entry;
274 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL);
275 udev_device_set_devnode(udev_device, filename);
278 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL);
279 udev_device_add_devlink(udev_device, filename, 0);
282 udev_device_set_devlink_priority(udev_device, atoi(val));
285 entry = udev_device_add_property_from_string(udev_device, val);
286 udev_list_entry_set_flags(entry, 1);
289 udev_device_add_tag(udev_device, val);
292 udev_device_set_watch_handle(udev_device, atoi(val));
295 udev_device_set_usec_initialized(udev_device, strtoull(val, NULL, 10));
301 info(udev_device->udev, "device %p filled with db file data\n", udev_device);
305 int udev_device_read_uevent_file(struct udev_device *udev_device)
307 char filename[UTIL_PATH_SIZE];
309 char line[UTIL_LINE_SIZE];
313 if (udev_device->uevent_loaded)
316 util_strscpyl(filename, sizeof(filename), udev_device->syspath, "/uevent", NULL);
317 f = fopen(filename, "re");
320 udev_device->uevent_loaded = true;
322 while (fgets(line, sizeof(line), f)) {
325 pos = strchr(line, '\n');
330 if (strncmp(line, "DEVTYPE=", 8) == 0)
331 udev_device_set_devtype(udev_device, &line[8]);
332 else if (strncmp(line, "MAJOR=", 6) == 0)
333 maj = strtoull(&line[6], NULL, 10);
334 else if (strncmp(line, "MINOR=", 6) == 0)
335 min = strtoull(&line[6], NULL, 10);
336 else if (strncmp(line, "IFINDEX=", 8) == 0)
337 udev_device_set_ifindex(udev_device, strtoull(&line[8], NULL, 10));
338 else if (strncmp(line, "DEVNAME=", 8) == 0)
339 udev_device_set_knodename(udev_device, &line[8]);
341 udev_device_add_property_from_string(udev_device, line);
344 udev_device->devnum = makedev(maj, min);
349 void udev_device_set_info_loaded(struct udev_device *device)
351 device->info_loaded = true;
354 struct udev_device *udev_device_new(struct udev *udev)
356 struct udev_device *udev_device;
357 struct udev_list_entry *list_entry;
362 udev_device = calloc(1, sizeof(struct udev_device));
363 if (udev_device == NULL)
365 udev_device->refcount = 1;
366 udev_device->udev = udev;
367 udev_list_init(&udev_device->devlinks_list);
368 udev_list_init(&udev_device->properties_list);
369 udev_list_init(&udev_device->sysattr_value_list);
370 udev_list_init(&udev_device->sysattr_list);
371 udev_list_init(&udev_device->tags_list);
372 udev_device->event_timeout = -1;
373 udev_device->watch_handle = -1;
374 /* copy global properties */
375 udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev))
376 udev_device_add_property(udev_device,
377 udev_list_entry_get_name(list_entry),
378 udev_list_entry_get_value(list_entry));
379 dbg(udev_device->udev, "udev_device: %p created\n", udev_device);
384 * udev_device_new_from_syspath:
385 * @udev: udev library context
386 * @syspath: sys device path including sys directory
388 * Create new udev device, and fill in information from the sys
389 * device and the udev database entry. The syspath is the absolute
390 * path to the device, including the sys mount point.
392 * The initial refcount is 1, and needs to be decremented to
393 * release the resources of the udev device.
395 * Returns: a new udev device, or #NULL, if it does not exist
397 struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath)
401 char path[UTIL_PATH_SIZE];
404 struct udev_device *udev_device;
411 /* path starts in sys */
412 len = strlen(udev_get_sys_path(udev));
413 if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) {
414 info(udev, "not in sys :%s\n", syspath);
418 /* path is not a root directory */
419 subdir = &syspath[len+1];
420 pos = strrchr(subdir, '/');
421 if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) {
422 dbg(udev, "not a subdir :%s\n", syspath);
426 /* resolve possible symlink to real path */
427 util_strscpy(path, sizeof(path), syspath);
428 util_resolve_sys_link(udev, path, sizeof(path));
430 if (strncmp(&path[len], "/devices/", 9) == 0) {
431 char file[UTIL_PATH_SIZE];
433 /* all "devices" require a "uevent" file */
434 util_strscpyl(file, sizeof(file), path, "/uevent", NULL);
435 if (stat(file, &statbuf) != 0) {
436 dbg(udev, "not a device: %s\n", syspath);
440 /* everything else just needs to be a directory */
441 if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) {
442 dbg(udev, "directory not found: %s\n", syspath);
447 udev_device = udev_device_new(udev);
448 if (udev_device == NULL)
451 udev_device_set_syspath(udev_device, path);
452 info(udev, "device %p has devpath '%s'\n", udev_device, udev_device_get_devpath(udev_device));
458 * udev_device_new_from_devnum:
459 * @udev: udev library context
460 * @type: char or block device
461 * @devnum: device major/minor number
463 * Create new udev device, and fill in information from the sys
464 * device and the udev database entry. The device is looked-up
465 * by its major/minor number and type. Character and block device
466 * numbers are not unique across the two types.
468 * The initial refcount is 1, and needs to be decremented to
469 * release the resources of the udev device.
471 * Returns: a new udev device, or #NULL, if it does not exist
473 struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
475 char path[UTIL_PATH_SIZE];
476 const char *type_str;
480 else if (type == 'c')
485 /* use /sys/dev/{block,char}/<maj>:<min> link */
486 snprintf(path, sizeof(path), "%s/dev/%s/%u:%u",
487 udev_get_sys_path(udev), type_str, major(devnum), minor(devnum));
488 return udev_device_new_from_syspath(udev, path);
491 struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id)
495 char subsys[UTIL_PATH_SIZE];
501 if (sscanf(id, "%c%i:%i", &type, &maj, &min) != 3)
503 return udev_device_new_from_devnum(udev, type, makedev(maj, min));
507 struct udev_device *dev;
510 ifindex = strtoul(&id[1], NULL, 10);
514 sk = socket(PF_INET, SOCK_DGRAM, 0);
517 memset(&ifr, 0x00, sizeof(struct ifreq));
518 ifr.ifr_ifindex = ifindex;
519 if (ioctl(sk, SIOCGIFNAME, &ifr) != 0) {
525 dev = udev_device_new_from_subsystem_sysname(udev, "net", ifr.ifr_name);
528 if (udev_device_get_ifindex(dev) == ifindex)
530 udev_device_unref(dev);
534 util_strscpy(subsys, sizeof(subsys), &id[1]);
535 sysname = strchr(subsys, ':');
539 sysname = &sysname[1];
540 return udev_device_new_from_subsystem_sysname(udev, subsys, sysname);
547 * udev_device_new_from_subsystem_sysname:
548 * @udev: udev library context
549 * @subsystem: the subsystem of the device
550 * @sysname: the name of the device
552 * Create new udev device, and fill in information from the sys device
553 * and the udev database entry. The device is looked up by the subsystem
554 * and name string of the device, like "mem" / "zero", or "block" / "sda".
556 * The initial refcount is 1, and needs to be decremented to
557 * release the resources of the udev device.
559 * Returns: a new udev device, or #NULL, if it does not exist
561 struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname)
563 char path_full[UTIL_PATH_SIZE];
569 l = util_strpcpyl(&path, sizeof(path_full), udev_get_sys_path(udev), NULL);
571 if (strcmp(subsystem, "subsystem") == 0) {
572 util_strscpyl(path, l, "/subsystem/", sysname, NULL);
573 if (stat(path_full, &statbuf) == 0)
576 util_strscpyl(path, l, "/bus/", sysname, NULL);
577 if (stat(path_full, &statbuf) == 0)
580 util_strscpyl(path, l, "/class/", sysname, NULL);
581 if (stat(path_full, &statbuf) == 0)
586 if (strcmp(subsystem, "module") == 0) {
587 util_strscpyl(path, l, "/module/", sysname, NULL);
588 if (stat(path_full, &statbuf) == 0)
593 if (strcmp(subsystem, "drivers") == 0) {
594 char subsys[UTIL_NAME_SIZE];
597 util_strscpy(subsys, sizeof(subsys), sysname);
598 driver = strchr(subsys, ':');
599 if (driver != NULL) {
603 util_strscpyl(path, l, "/subsystem/", subsys, "/drivers/", driver, NULL);
604 if (stat(path_full, &statbuf) == 0)
607 util_strscpyl(path, l, "/bus/", subsys, "/drivers/", driver, NULL);
608 if (stat(path_full, &statbuf) == 0)
614 util_strscpyl(path, l, "/subsystem/", subsystem, "/devices/", sysname, NULL);
615 if (stat(path_full, &statbuf) == 0)
618 util_strscpyl(path, l, "/bus/", subsystem, "/devices/", sysname, NULL);
619 if (stat(path_full, &statbuf) == 0)
622 util_strscpyl(path, l, "/class/", subsystem, "/", sysname, NULL);
623 if (stat(path_full, &statbuf) == 0)
628 return udev_device_new_from_syspath(udev, path_full);
632 * udev_device_new_from_environment
633 * @udev: udev library context
635 * Create new udev device, and fill in information from the
636 * current process environment. This only works reliable if
637 * the process is called from a udev rule. It is usually used
638 * for tools executed from IMPORT= rules.
640 * The initial refcount is 1, and needs to be decremented to
641 * release the resources of the udev device.
643 * Returns: a new udev device, or #NULL, if it does not exist
645 struct udev_device *udev_device_new_from_environment(struct udev *udev)
648 struct udev_device *udev_device;
650 udev_device = udev_device_new(udev);
651 if (udev_device == NULL)
653 udev_device_set_info_loaded(udev_device);
655 for (i = 0; environ[i] != NULL; i++)
656 udev_device_add_property_from_string_parse(udev_device, environ[i]);
658 if (udev_device_add_property_from_string_parse_finish(udev_device) < 0) {
659 info(udev, "missing values, invalid device\n");
660 udev_device_unref(udev_device);
667 static struct udev_device *device_new_from_parent(struct udev_device *udev_device)
669 struct udev_device *udev_device_parent = NULL;
670 char path[UTIL_PATH_SIZE];
673 util_strscpy(path, sizeof(path), udev_device->syspath);
674 subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1];
678 pos = strrchr(subdir, '/');
679 if (pos == NULL || pos < &subdir[2])
682 udev_device_parent = udev_device_new_from_syspath(udev_device->udev, path);
683 if (udev_device_parent != NULL)
684 return udev_device_parent;
690 * udev_device_get_parent:
691 * @udev_device: the device to start searching from
693 * Find the next parent device, and fill in information from the sys
694 * device and the udev database entry.
696 * The returned the device is not referenced. It is attached to the
697 * child device, and will be cleaned up when the child device
700 * It is not necessarily just the upper level directory, empty or not
701 * recognized sys directories are ignored.
703 * It can be called as many times as needed, without caring about
706 * Returns: a new udev device, or #NULL, if it no parent exist.
708 struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
710 if (udev_device == NULL)
712 if (!udev_device->parent_set) {
713 udev_device->parent_set = true;
714 udev_device->parent_device = device_new_from_parent(udev_device);
716 if (udev_device->parent_device != NULL)
717 dbg(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
718 return udev_device->parent_device;
722 * udev_device_get_parent_with_subsystem_devtype:
723 * @udev_device: udev device to start searching from
724 * @subsystem: the subsystem of the device
725 * @devtype: the type (DEVTYPE) of the device
727 * Find the next parent device, with a matching subsystem and devtype
728 * value, and fill in information from the sys device and the udev
731 * If devtype is #NULL, only subsystem is checked, and any devtype will
734 * The returned the device is not referenced. It is attached to the
735 * child device, and will be cleaned up when the child device
738 * It can be called as many times as needed, without caring about
741 * Returns: a new udev device, or #NULL if no matching parent exists.
743 struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype)
745 struct udev_device *parent;
747 if (subsystem == NULL)
750 parent = udev_device_get_parent(udev_device);
751 while (parent != NULL) {
752 const char *parent_subsystem;
753 const char *parent_devtype;
755 parent_subsystem = udev_device_get_subsystem(parent);
756 if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0) {
759 parent_devtype = udev_device_get_devtype(parent);
760 if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0)
763 parent = udev_device_get_parent(parent);
769 * udev_device_get_udev:
770 * @udev_device: udev device
772 * Retrieve the udev library context the device was created with.
774 * Returns: the udev library context
776 struct udev *udev_device_get_udev(struct udev_device *udev_device)
778 if (udev_device == NULL)
780 return udev_device->udev;
785 * @udev_device: udev device
787 * Take a reference of a udev device.
789 * Returns: the passed udev device
791 struct udev_device *udev_device_ref(struct udev_device *udev_device)
793 if (udev_device == NULL)
795 udev_device->refcount++;
801 * @udev_device: udev device
803 * Drop a reference of a udev device. If the refcount reaches zero,
804 * the resources of the device will be released.
807 void udev_device_unref(struct udev_device *udev_device)
809 if (udev_device == NULL)
811 udev_device->refcount--;
812 if (udev_device->refcount > 0)
814 if (udev_device->parent_device != NULL)
815 udev_device_unref(udev_device->parent_device);
816 free(udev_device->syspath);
817 free(udev_device->sysname);
818 free(udev_device->devnode);
819 free(udev_device->subsystem);
820 free(udev_device->devtype);
821 udev_list_cleanup_entries(udev_device->udev, &udev_device->devlinks_list);
822 udev_list_cleanup_entries(udev_device->udev, &udev_device->properties_list);
823 udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_value_list);
824 udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_list);
825 udev_list_cleanup_entries(udev_device->udev, &udev_device->tags_list);
826 free(udev_device->action);
827 free(udev_device->driver);
828 free(udev_device->devpath_old);
829 free(udev_device->sysname_old);
830 free(udev_device->knodename);
831 free(udev_device->id_filename);
832 free(udev_device->envp);
833 free(udev_device->monitor_buf);
834 dbg(udev_device->udev, "udev_device: %p released\n", udev_device);
839 * udev_device_get_devpath:
840 * @udev_device: udev device
842 * Retrieve the kernel devpath value of the udev device. The path
843 * does not contain the sys mount point, and starts with a '/'.
845 * Returns: the devpath of the udev device
847 const char *udev_device_get_devpath(struct udev_device *udev_device)
849 if (udev_device == NULL)
851 return udev_device->devpath;
855 * udev_device_get_syspath:
856 * @udev_device: udev device
858 * Retrieve the sys path of the udev device. The path is an
859 * absolute path and starts with the sys mount point.
861 * Returns: the sys path of the udev device
863 const char *udev_device_get_syspath(struct udev_device *udev_device)
865 if (udev_device == NULL)
867 return udev_device->syspath;
871 * udev_device_get_sysname:
872 * @udev_device: udev device
874 * Returns: the sys name of the device device
876 const char *udev_device_get_sysname(struct udev_device *udev_device)
878 if (udev_device == NULL)
880 return udev_device->sysname;
884 * udev_device_get_sysnum:
885 * @udev_device: udev device
887 * Returns: the trailing number of of the device name
889 const char *udev_device_get_sysnum(struct udev_device *udev_device)
891 if (udev_device == NULL)
893 return udev_device->sysnum;
897 * udev_device_get_devnode:
898 * @udev_device: udev device
900 * Retrieve the device node file name belonging to the udev device.
901 * The path is an absolute path, and starts with the device directory.
903 * Returns: the device node file name of the udev device, or #NULL if no device node exists
905 const char *udev_device_get_devnode(struct udev_device *udev_device)
907 if (udev_device == NULL)
909 if (!udev_device->info_loaded) {
910 udev_device_read_uevent_file(udev_device);
911 udev_device_read_db(udev_device);
914 /* we might get called before we handled an event and have a db, use the kernel-provided name */
915 if (udev_device->devnode == NULL && udev_device_get_knodename(udev_device) != NULL) {
916 char filename[UTIL_NAME_SIZE];
918 util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/",
919 udev_device_get_knodename(udev_device), NULL);
920 udev_device_set_devnode(udev_device, filename);
921 return udev_device->devnode;
924 return udev_device->devnode;
928 * udev_device_get_subsystem:
929 * @udev_device: udev device
931 * Retrieve the subsystem string of the udev device. The string does not
934 * Returns: the subsystem name of the udev device, or #NULL if it can not be determined
936 const char *udev_device_get_subsystem(struct udev_device *udev_device)
938 char subsystem[UTIL_NAME_SIZE];
940 if (udev_device == NULL)
942 if (!udev_device->subsystem_set) {
943 udev_device->subsystem_set = true;
944 /* read "subsystem" link */
945 if (util_get_sys_subsystem(udev_device->udev, udev_device->syspath, subsystem, sizeof(subsystem)) > 0) {
946 udev_device_set_subsystem(udev_device, subsystem);
947 return udev_device->subsystem;
950 if (strncmp(udev_device->devpath, "/module/", 8) == 0) {
951 udev_device_set_subsystem(udev_device, "module");
952 return udev_device->subsystem;
954 if (strstr(udev_device->devpath, "/drivers/") != NULL) {
955 udev_device_set_subsystem(udev_device, "drivers");
956 return udev_device->subsystem;
958 if (strncmp(udev_device->devpath, "/subsystem/", 11) == 0 ||
959 strncmp(udev_device->devpath, "/class/", 7) == 0 ||
960 strncmp(udev_device->devpath, "/bus/", 5) == 0) {
961 udev_device_set_subsystem(udev_device, "subsystem");
962 return udev_device->subsystem;
965 return udev_device->subsystem;
969 * udev_device_get_devtype:
970 * @udev_device: udev device
972 * Retrieve the devtype string of the udev device.
974 * Returns: the devtype name of the udev device, or #NULL if it can not be determined
976 const char *udev_device_get_devtype(struct udev_device *udev_device)
978 if (udev_device == NULL)
980 if (!udev_device->devtype_set) {
981 udev_device->devtype_set = true;
982 udev_device_read_uevent_file(udev_device);
984 return udev_device->devtype;
988 * udev_device_get_devlinks_list_entry:
989 * @udev_device: udev device
991 * Retrieve the list of device links pointing to the device file of
992 * the udev device. The next list entry can be retrieved with
993 * udev_list_entry_next(), which returns #NULL if no more entries exist.
994 * The devlink path can be retrieved from the list entry by
995 * udev_list_entry_get_name(). The path is an absolute path, and starts with
996 * the device directory.
998 * Returns: the first entry of the device node link list
1000 struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device)
1002 if (udev_device == NULL)
1004 if (!udev_device->info_loaded)
1005 udev_device_read_db(udev_device);
1006 return udev_list_get_entry(&udev_device->devlinks_list);
1009 void udev_device_cleanup_devlinks_list(struct udev_device *udev_device)
1011 udev_device->devlinks_uptodate = false;
1012 udev_list_cleanup_entries(udev_device->udev, &udev_device->devlinks_list);
1016 * udev_device_get_properties_list_entry:
1017 * @udev_device: udev device
1019 * Retrieve the list of key/value device properties of the udev
1020 * device. The next list entry can be retrieved with udev_list_entry_next(),
1021 * which returns #NULL if no more entries exist. The property name
1022 * can be retrieved from the list entry by udev_list_get_name(),
1023 * the property value by udev_list_get_value().
1025 * Returns: the first entry of the property list
1027 struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device)
1029 if (udev_device == NULL)
1031 if (!udev_device->info_loaded) {
1032 udev_device_read_uevent_file(udev_device);
1033 udev_device_read_db(udev_device);
1035 if (!udev_device->devlinks_uptodate) {
1036 char symlinks[UTIL_PATH_SIZE];
1037 struct udev_list_entry *list_entry;
1039 udev_device->devlinks_uptodate = true;
1040 list_entry = udev_device_get_devlinks_list_entry(udev_device);
1041 if (list_entry != NULL) {
1046 l = util_strpcpyl(&s, sizeof(symlinks), udev_list_entry_get_name(list_entry), NULL);
1047 udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry))
1048 l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry), NULL);
1049 udev_device_add_property(udev_device, "DEVLINKS", symlinks);
1052 if (!udev_device->tags_uptodate) {
1053 udev_device->tags_uptodate = true;
1054 if (udev_device_get_tags_list_entry(udev_device) != NULL) {
1055 char tags[UTIL_PATH_SIZE];
1056 struct udev_list_entry *list_entry;
1061 l = util_strpcpyl(&s, sizeof(tags), ":", NULL);
1062 udev_list_entry_foreach(list_entry, udev_device_get_tags_list_entry(udev_device))
1063 l = util_strpcpyl(&s, l, udev_list_entry_get_name(list_entry), ":", NULL);
1064 udev_device_add_property(udev_device, "TAGS", tags);
1067 return udev_list_get_entry(&udev_device->properties_list);
1071 * udev_device_get_driver:
1072 * @udev_device: udev device
1074 * Returns: the driver string, or #NULL if there is no driver attached.
1076 const char *udev_device_get_driver(struct udev_device *udev_device)
1078 char driver[UTIL_NAME_SIZE];
1080 if (udev_device == NULL)
1082 if (!udev_device->driver_set) {
1083 udev_device->driver_set = true;
1084 if (util_get_sys_driver(udev_device->udev, udev_device->syspath, driver, sizeof(driver)) > 0)
1085 udev_device->driver = strdup(driver);
1087 return udev_device->driver;
1091 * udev_device_get_devnum:
1092 * @udev_device: udev device
1094 * Returns: the device major/minor number.
1096 dev_t udev_device_get_devnum(struct udev_device *udev_device)
1098 if (udev_device == NULL)
1099 return makedev(0, 0);
1100 if (!udev_device->info_loaded)
1101 udev_device_read_uevent_file(udev_device);
1102 return udev_device->devnum;
1106 * udev_device_get_action:
1107 * @udev_device: udev device
1109 * This is only valid if the device was received through a monitor. Devices read from
1110 * sys do not have an action string. Usual actions are: add, remove, change, online,
1113 * Returns: the kernel action value, or #NULL if there is no action value available.
1115 const char *udev_device_get_action(struct udev_device *udev_device)
1117 if (udev_device == NULL)
1119 return udev_device->action;
1123 * udev_device_get_devnum:
1124 * @udev_device: udev device
1126 * This is only valid if the device was received through a monitor. Devices read from
1127 * sys do not have a sequence number.
1129 * Returns: the kernel event sequence number, or 0 if there is no sequence number available.
1131 unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device)
1133 if (udev_device == NULL)
1135 return udev_device->seqnum;
1139 * udev_device_get_usec_since_initialized:
1140 * @udev_device: udev device
1142 * Return the number of microseconds passed since udev set up the
1143 * device for the first time.
1145 * This is only implemented for devices with need to store properties
1146 * in the udev database. All other devices return 0 here.
1148 * Returns: the number of microseconds since the device was first seen.
1150 unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device)
1152 unsigned long long now;
1154 if (udev_device == NULL)
1156 if (!udev_device->info_loaded)
1157 udev_device_read_db(udev_device);
1158 if (udev_device->usec_initialized == 0)
1160 now = usec_monotonic();
1163 return now - udev_device->usec_initialized;
1166 unsigned long long udev_device_get_usec_initialized(struct udev_device *udev_device)
1168 return udev_device->usec_initialized;
1171 void udev_device_set_usec_initialized(struct udev_device *udev_device, unsigned long long usec_initialized)
1173 udev_device->usec_initialized = usec_initialized;
1177 * udev_device_get_sysattr_value:
1178 * @udev_device: udev device
1179 * @sysattr: attribute name
1181 * The retrieved value is cached in the device. Repeated calls will return the same
1182 * value and not open the attribute again.
1184 * Returns: the content of a sys attribute file, or #NULL if there is no sys attribute value.
1186 const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr)
1188 struct udev_list_entry *list_entry;
1189 char path[UTIL_PATH_SIZE];
1191 struct stat statbuf;
1194 const char *val = NULL;
1196 if (udev_device == NULL)
1198 if (sysattr == NULL)
1201 /* look for possibly already cached result */
1202 udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_device->sysattr_value_list)) {
1203 if (strcmp(udev_list_entry_get_name(list_entry), sysattr) == 0) {
1204 dbg(udev_device->udev, "got '%s' (%s) from cache\n",
1205 sysattr, udev_list_entry_get_value(list_entry));
1206 return udev_list_entry_get_value(list_entry);
1210 util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", sysattr, NULL);
1211 if (lstat(path, &statbuf) != 0) {
1212 dbg(udev_device->udev, "no attribute '%s', keep negative entry\n", path);
1213 udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, NULL, 0, 0);
1217 if (S_ISLNK(statbuf.st_mode)) {
1218 char target[UTIL_NAME_SIZE];
1222 /* some core links return the last element of the target path */
1223 if (strcmp(sysattr, "driver") != 0 &&
1224 strcmp(sysattr, "subsystem") != 0 &&
1225 strcmp(sysattr, "module") != 0)
1228 len = readlink(path, target, sizeof(target));
1229 if (len <= 0 || len == sizeof(target))
1233 pos = strrchr(target, '/');
1236 dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, pos);
1237 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, pos, 0, 0);
1238 val = udev_list_entry_get_value(list_entry);
1244 /* skip directories */
1245 if (S_ISDIR(statbuf.st_mode))
1248 /* skip non-readable files */
1249 if ((statbuf.st_mode & S_IRUSR) == 0)
1252 /* read attribute value */
1253 fd = open(path, O_RDONLY|O_CLOEXEC);
1255 dbg(udev_device->udev, "attribute '%s' can not be opened\n", path);
1258 size = read(fd, value, sizeof(value));
1262 if (size == sizeof(value))
1265 /* got a valid value, store it in cache and return it */
1267 util_remove_trailing_chars(value, '\n');
1268 dbg(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
1269 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, value, 0, 0);
1270 val = udev_list_entry_get_value(list_entry);
1275 static int udev_device_sysattr_list_read(struct udev_device *udev_device)
1277 struct dirent *dent;
1281 if (udev_device == NULL)
1283 if (udev_device->sysattr_list_read)
1286 dir = opendir(udev_device_get_syspath(udev_device));
1288 dbg(udev_device->udev, "sysfs dir '%s' can not be opened\n",
1289 udev_device_get_syspath(udev_device));
1293 for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
1294 char path[UTIL_PATH_SIZE];
1295 struct stat statbuf;
1297 /* only handle symlinks and regular files */
1298 if (dent->d_type != DT_LNK && dent->d_type != DT_REG)
1301 util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", dent->d_name, NULL);
1302 if (lstat(path, &statbuf) != 0)
1304 if ((statbuf.st_mode & S_IRUSR) == 0)
1307 udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list,
1308 dent->d_name, NULL, 0, 0);
1313 dbg(udev_device->udev, "found %d sysattrs for '%s'\n", num, udev_device_get_syspath(udev_device));
1314 udev_device->sysattr_list_read = true;
1320 * udev_device_get_sysattr_list_entry:
1321 * @udev_device: udev device
1323 * Retrieve the list of available sysattrs, with value being empty;
1324 * This just return all available sysfs attributes for a particular
1325 * device without reading their values.
1327 * Returns: the first entry of the property list
1329 struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device)
1331 if (!udev_device->sysattr_list_read) {
1333 ret = udev_device_sysattr_list_read(udev_device);
1338 return udev_list_get_entry(&udev_device->sysattr_list);
1341 int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath)
1346 free(udev_device->syspath);
1347 udev_device->syspath = strdup(syspath);
1348 if (udev_device->syspath == NULL)
1350 udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
1351 udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath);
1353 pos = strrchr(udev_device->syspath, '/');
1356 udev_device->sysname = strdup(&pos[1]);
1357 if (udev_device->sysname == NULL)
1360 /* some devices have '!' in their name, change that to '/' */
1362 while (udev_device->sysname[len] != '\0') {
1363 if (udev_device->sysname[len] == '!')
1364 udev_device->sysname[len] = '/';
1368 /* trailing number */
1369 while (len > 0 && isdigit(udev_device->sysname[--len]))
1370 udev_device->sysnum = &udev_device->sysname[len];
1372 /* sysname is completely numeric */
1374 udev_device->sysnum = NULL;
1379 int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
1381 free(udev_device->subsystem);
1382 udev_device->subsystem = strdup(subsystem);
1383 if (udev_device->subsystem == NULL)
1385 udev_device->subsystem_set = true;
1386 udev_device_add_property(udev_device, "SUBSYSTEM", udev_device->subsystem);
1390 int udev_device_set_devtype(struct udev_device *udev_device, const char *devtype)
1392 free(udev_device->devtype);
1393 udev_device->devtype = strdup(devtype);
1394 if (udev_device->devtype == NULL)
1396 udev_device->devtype_set = true;
1397 udev_device_add_property(udev_device, "DEVTYPE", udev_device->devtype);
1401 int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode)
1403 free(udev_device->devnode);
1404 udev_device->devnode = strdup(devnode);
1405 if (udev_device->devnode == NULL)
1407 udev_device_add_property(udev_device, "DEVNAME", udev_device->devnode);
1411 int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink, int unique)
1413 struct udev_list_entry *list_entry;
1415 udev_device->devlinks_uptodate = false;
1416 list_entry = udev_list_entry_add(udev_device->udev, &udev_device->devlinks_list, devlink, NULL, 1, 0);
1417 if (list_entry == NULL)
1420 udev_list_entry_set_flags(list_entry, 1);
1424 const char *udev_device_get_id_filename(struct udev_device *udev_device)
1426 if (udev_device->id_filename == NULL) {
1427 if (udev_device_get_subsystem(udev_device) == NULL)
1430 if (major(udev_device_get_devnum(udev_device)) > 0) {
1431 /* use dev_t -- b259:131072, c254:0 */
1432 if (asprintf(&udev_device->id_filename, "%c%u:%u",
1433 strcmp(udev_device_get_subsystem(udev_device), "block") == 0 ? 'b' : 'c',
1434 major(udev_device_get_devnum(udev_device)),
1435 minor(udev_device_get_devnum(udev_device))) < 0)
1436 udev_device->id_filename = NULL;
1437 } else if (udev_device_get_ifindex(udev_device) > 0) {
1438 /* use netdev ifindex -- n3 */
1439 if (asprintf(&udev_device->id_filename, "n%u", udev_device_get_ifindex(udev_device)) < 0)
1440 udev_device->id_filename = NULL;
1443 * use $subsys:$syname -- pci:0000:00:1f.2
1444 * sysname() has '!' translated, get it from devpath
1446 const char *sysname;
1447 sysname = strrchr(udev_device->devpath, '/');
1448 if (sysname == NULL)
1450 sysname = &sysname[1];
1451 if (asprintf(&udev_device->id_filename, "+%s:%s", udev_device_get_subsystem(udev_device), sysname) < 0)
1452 udev_device->id_filename = NULL;
1455 return udev_device->id_filename;
1459 * udev_device_get_is_initialized:
1460 * @udev_device: udev device
1462 * Check if udev has already handled the device and has set up
1463 * device node permissions and context, or has renamed a network
1466 * This is only implemented for devices with a device node
1467 * or network interfaces. All other devices return 1 here.
1469 * Returns: 1 if the device is set up. 0 otherwise.
1471 int udev_device_get_is_initialized(struct udev_device *udev_device)
1473 if (!udev_device->info_loaded)
1474 udev_device_read_db(udev_device);
1475 return udev_device->is_initialized;
1478 void udev_device_set_is_initialized(struct udev_device *udev_device)
1480 udev_device->is_initialized = true;
1483 int udev_device_add_tag(struct udev_device *udev_device, const char *tag)
1485 if (strchr(tag, ':') != NULL || strchr(tag, ' ') != NULL)
1487 udev_device->tags_uptodate = false;
1488 if (udev_list_entry_add(udev_device->udev, &udev_device->tags_list, tag, NULL, 1, 0) != NULL)
1493 void udev_device_cleanup_tags_list(struct udev_device *udev_device)
1495 udev_device->tags_uptodate = false;
1496 udev_list_cleanup_entries(udev_device->udev, &udev_device->tags_list);
1500 * udev_device_get_tags_list_entry:
1501 * @udev_device: udev device
1503 * Retrieve the list of tags attached to the udev device. The next
1504 * list entry can be retrieved with udev_list_entry_next(),
1505 * which returns #NULL if no more entries exist. The tag string
1506 * can be retrieved from the list entry by udev_list_get_name().
1508 * Returns: the first entry of the tag list
1510 struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device)
1512 if (udev_device == NULL)
1514 return udev_list_get_entry(&udev_device->tags_list);
1517 int udev_device_has_tag(struct udev_device *udev_device, const char *tag)
1519 struct udev_list_entry *list_entry;
1521 if (!udev_device->info_loaded)
1522 udev_device_read_db(udev_device);
1523 list_entry = udev_device_get_tags_list_entry(udev_device);
1524 list_entry = udev_list_entry_get_by_name(list_entry, tag);
1525 if (list_entry != NULL)
1530 #define ENVP_SIZE 128
1531 #define MONITOR_BUF_SIZE 4096
1532 static int update_envp_monitor_buf(struct udev_device *udev_device)
1534 struct udev_list_entry *list_entry;
1539 /* monitor buffer of property strings */
1540 free(udev_device->monitor_buf);
1541 udev_device->monitor_buf_len = 0;
1542 udev_device->monitor_buf = malloc(MONITOR_BUF_SIZE);
1543 if (udev_device->monitor_buf == NULL)
1546 /* envp array, strings will point into monitor buffer */
1547 if (udev_device->envp == NULL)
1548 udev_device->envp = malloc(sizeof(char *) * ENVP_SIZE);
1549 if (udev_device->envp == NULL)
1553 s = udev_device->monitor_buf;
1554 l = MONITOR_BUF_SIZE;
1555 udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
1558 key = udev_list_entry_get_name(list_entry);
1559 /* skip private variables */
1563 /* add string to envp array */
1564 udev_device->envp[i++] = s;
1565 if (i+1 >= ENVP_SIZE)
1568 /* add property string to monitor buffer */
1569 l = util_strpcpyl(&s, l, key, "=", udev_list_entry_get_value(list_entry), NULL);
1572 /* advance past the trailing '\0' that util_strpcpyl() guarantees */
1576 udev_device->envp[i] = NULL;
1577 udev_device->monitor_buf_len = s - udev_device->monitor_buf;
1578 udev_device->envp_uptodate = true;
1579 dbg(udev_device->udev, "filled envp/monitor buffer, %u properties, %zu bytes\n",
1580 i, udev_device->monitor_buf_len);
1584 char **udev_device_get_properties_envp(struct udev_device *udev_device)
1586 if (!udev_device->envp_uptodate)
1587 if (update_envp_monitor_buf(udev_device) != 0)
1589 return udev_device->envp;
1592 ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf)
1594 if (!udev_device->envp_uptodate)
1595 if (update_envp_monitor_buf(udev_device) != 0)
1597 *buf = udev_device->monitor_buf;
1598 return udev_device->monitor_buf_len;
1601 int udev_device_set_action(struct udev_device *udev_device, const char *action)
1603 free(udev_device->action);
1604 udev_device->action = strdup(action);
1605 if (udev_device->action == NULL)
1607 udev_device_add_property(udev_device, "ACTION", udev_device->action);
1611 int udev_device_set_driver(struct udev_device *udev_device, const char *driver)
1613 free(udev_device->driver);
1614 udev_device->driver = strdup(driver);
1615 if (udev_device->driver == NULL)
1617 udev_device->driver_set = true;
1618 udev_device_add_property(udev_device, "DRIVER", udev_device->driver);
1622 const char *udev_device_get_devpath_old(struct udev_device *udev_device)
1624 return udev_device->devpath_old;
1627 int udev_device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
1632 free(udev_device->devpath_old);
1633 udev_device->devpath_old = strdup(devpath_old);
1634 if (udev_device->devpath_old == NULL)
1636 udev_device_add_property(udev_device, "DEVPATH_OLD", udev_device->devpath_old);
1638 pos = strrchr(udev_device->devpath_old, '/');
1641 udev_device->sysname_old = strdup(&pos[1]);
1642 if (udev_device->sysname_old == NULL)
1645 /* some devices have '!' in their name, change that to '/' */
1647 while (udev_device->sysname_old[len] != '\0') {
1648 if (udev_device->sysname_old[len] == '!')
1649 udev_device->sysname_old[len] = '/';
1655 const char *udev_device_get_sysname_old(struct udev_device *udev_device)
1657 if (udev_device == NULL)
1659 return udev_device->sysname_old;
1662 const char *udev_device_get_knodename(struct udev_device *udev_device)
1664 return udev_device->knodename;
1667 int udev_device_set_knodename(struct udev_device *udev_device, const char *knodename)
1669 free(udev_device->knodename);
1670 udev_device->knodename = strdup(knodename);
1671 if (udev_device->knodename == NULL)
1673 /* do not overwrite the udev property with the kernel property */
1674 if (udev_device->devnode == NULL)
1675 udev_device_add_property(udev_device, "DEVNAME", udev_device->knodename);
1679 int udev_device_get_timeout(struct udev_device *udev_device)
1681 return udev_device->timeout;
1684 int udev_device_set_timeout(struct udev_device *udev_device, int timeout)
1686 udev_device->timeout = timeout;
1689 int udev_device_get_event_timeout(struct udev_device *udev_device)
1691 if (!udev_device->info_loaded)
1692 udev_device_read_db(udev_device);
1693 return udev_device->event_timeout;
1696 int udev_device_set_event_timeout(struct udev_device *udev_device, int event_timeout)
1700 udev_device->event_timeout = event_timeout;
1701 snprintf(num, sizeof(num), "%u", event_timeout);
1702 udev_device_add_property(udev_device, "TIMEOUT", num);
1706 int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
1710 udev_device->seqnum = seqnum;
1711 snprintf(num, sizeof(num), "%llu", seqnum);
1712 udev_device_add_property(udev_device, "SEQNUM", num);
1716 int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
1720 udev_device->devnum = devnum;
1722 snprintf(num, sizeof(num), "%u", major(devnum));
1723 udev_device_add_property(udev_device, "MAJOR", num);
1724 snprintf(num, sizeof(num), "%u", minor(devnum));
1725 udev_device_add_property(udev_device, "MINOR", num);
1729 int udev_device_get_devlink_priority(struct udev_device *udev_device)
1731 if (!udev_device->info_loaded)
1732 udev_device_read_db(udev_device);
1733 return udev_device->devlink_priority;
1736 int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio)
1738 udev_device->devlink_priority = prio;
1742 int udev_device_get_watch_handle(struct udev_device *udev_device)
1744 if (!udev_device->info_loaded)
1745 udev_device_read_db(udev_device);
1746 return udev_device->watch_handle;
1749 int udev_device_set_watch_handle(struct udev_device *udev_device, int handle)
1751 udev_device->watch_handle = handle;
1755 int udev_device_get_ifindex(struct udev_device *udev_device)
1757 if (!udev_device->info_loaded)
1758 udev_device_read_uevent_file(udev_device);
1759 return udev_device->ifindex;
1762 int udev_device_set_ifindex(struct udev_device *udev_device, int ifindex)
1766 udev_device->ifindex = ifindex;
1767 snprintf(num, sizeof(num), "%u", ifindex);
1768 udev_device_add_property(udev_device, "IFINDEX", num);