From bb061708d5aa83579f213bdfb67253f7027217c3 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 13 Apr 2012 18:24:39 +0200 Subject: udev: move libudev, gudev to src/; move gudev/docs/, udev/docs/ to to docs/ --- docs/libudev/.gitignore | 18 ++++++ docs/libudev/Makefile.am | 99 ++++++++++++++++++++++++++++++ docs/libudev/libudev-docs.xml | 32 ++++++++++ docs/libudev/libudev-sections.txt | 126 ++++++++++++++++++++++++++++++++++++++ docs/libudev/libudev.types | 0 docs/libudev/version.xml.in | 1 + 6 files changed, 276 insertions(+) create mode 100644 docs/libudev/.gitignore create mode 100644 docs/libudev/Makefile.am create mode 100644 docs/libudev/libudev-docs.xml create mode 100644 docs/libudev/libudev-sections.txt create mode 100644 docs/libudev/libudev.types create mode 100644 docs/libudev/version.xml.in (limited to 'docs/libudev') diff --git a/docs/libudev/.gitignore b/docs/libudev/.gitignore new file mode 100644 index 0000000000..1fb9c51424 --- /dev/null +++ b/docs/libudev/.gitignore @@ -0,0 +1,18 @@ +Makefile +libudev-overrides.txt +html/ +tmpl/ +xml/ +*.stamp +*.bak +version.xml +libudev-decl-list.txt +libudev-decl.txt +libudev-undeclared.txt +libudev-undocumented.txt +libudev-unused.txt +libudev.args +libudev.hierarchy +libudev.interfaces +libudev.prerequisites +libudev.signals diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am new file mode 100644 index 0000000000..9d1e3646fb --- /dev/null +++ b/docs/libudev/Makefile.am @@ -0,0 +1,99 @@ +## Process this file with automake to produce Makefile.in + +# We require automake 1.10 at least. +AUTOMAKE_OPTIONS = 1.10 + +# This is a blank Makefile.am for using gtk-doc. +# Copy this to your project's API docs directory and modify the variables to +# suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples +# of using the various options. + +# The name of the module, e.g. 'glib'. +DOC_MODULE=libudev + +# Uncomment for versioned docs and specify the version of the module, e.g. '2'. +#DOC_MODULE_VERSION=2 + +# The top-level SGML file. You can change this if you want to. +DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml + +# The directory containing the source code. Relative to $(srcdir). +# gtk-doc will search all .c & .h files beneath here for inline comments +# documenting the functions and macros. +# e.g. DOC_SOURCE_DIR=../../../gtk +DOC_SOURCE_DIR=$(top_srcdir)/src/libudev + +# Extra options to pass to gtkdoc-scangobj. Not normally needed. +SCANGOBJ_OPTIONS= + +# Extra options to supply to gtkdoc-scan. +# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED" +SCAN_OPTIONS= + +# Extra options to supply to gtkdoc-mkdb. +# e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml +MKDB_OPTIONS=--sgml-mode --output-format=xml --name-space=udev + +# Extra options to supply to gtkdoc-mktmpl +# e.g. MKTMPL_OPTIONS=--only-section-tmpl +MKTMPL_OPTIONS= + +# Extra options to supply to gtkdoc-mkhtml +MKHTML_OPTIONS=--path=$(abs_srcdir) --path=$(abs_builddir) + +# Extra options to supply to gtkdoc-fixref. Not normally needed. +# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html +FIXXREF_OPTIONS= + +# Used for dependencies. The docs will be rebuilt if any of these change. +# e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h +# e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c +HFILE_GLOB=$(top_srcdir)/src/libudev/libudev*.h +CFILE_GLOB=$(top_srcdir)/src/libudev/libudev*.c + +# Extra header to include when scanning, which are not under DOC_SOURCE_DIR +# e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h +EXTRA_HFILES= + +# Header files to ignore when scanning. Use base file name, no paths +# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h +IGNORE_HFILES = libudev-private.h + +# Images to copy into HTML directory. +# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png +HTML_IMAGES= + +# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE). +# e.g. content_files=running.sgml building.sgml changes-2.0.sgml +content_files = version.xml + +# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded +# These files must be listed here *and* in content_files +# e.g. expand_content_files=running.sgml +expand_content_files= + +# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library. +# Only needed if you are using gtkdoc-scangobj to dynamically query widget +# signals and properties. +# e.g. GTKDOC_CFLAGS=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS) +# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib) +GTKDOC_CFLAGS= +GTKDOC_LIBS= + +# This includes the standard gtk-doc make rules, copied by gtkdocize. +include $(top_srcdir)/gtk-doc.make + +# Other files to distribute +# e.g. EXTRA_DIST += version.xml.in +EXTRA_DIST += version.xml.in + +# Files not to distribute +# for --rebuild-types in $(SCAN_OPTIONS), e.g. $(DOC_MODULE).types +# for --rebuild-sections in $(SCAN_OPTIONS) e.g. $(DOC_MODULE)-sections.txt +#DISTCLEANFILES += + +# Comment this out if you want your docs-status tested during 'make check' +if ENABLE_GTK_DOC +#TESTS_ENVIRONMENT = cd $(srcsrc) +#TESTS = $(GTKDOC_CHECK) +endif diff --git a/docs/libudev/libudev-docs.xml b/docs/libudev/libudev-docs.xml new file mode 100644 index 0000000000..b7feb45529 --- /dev/null +++ b/docs/libudev/libudev-docs.xml @@ -0,0 +1,32 @@ + + +]> + + + libudev Reference Manual + for libudev version &version; + + 2009-2011 + Kay Sievers <kay.sievers@vrfy.org> + + + + + libudev + + + + + + + + + + + API Index + + + diff --git a/docs/libudev/libudev-sections.txt b/docs/libudev/libudev-sections.txt new file mode 100644 index 0000000000..83b2b79ee2 --- /dev/null +++ b/docs/libudev/libudev-sections.txt @@ -0,0 +1,126 @@ +
+libudev +udev +udev +udev_ref +udev_unref +udev_new +udev_set_log_fn +udev_get_log_priority +udev_set_log_priority +udev_get_sys_path +udev_get_dev_path +udev_get_run_path +udev_get_userdata +udev_set_userdata +
+ +
+libudev-list +udev_list +udev_list_entry +udev_list_entry_get_next +udev_list_entry_get_by_name +udev_list_entry_get_name +udev_list_entry_get_value +udev_list_entry_foreach +
+ +
+libudev-device +udev_device +udev_device +udev_device_ref +udev_device_unref +udev_device_get_udev +udev_device_new_from_syspath +udev_device_new_from_devnum +udev_device_new_from_subsystem_sysname +udev_device_new_from_environment +udev_device_get_parent +udev_device_get_parent_with_subsystem_devtype +udev_device_get_devpath +udev_device_get_subsystem +udev_device_get_devtype +udev_device_get_syspath +udev_device_get_sysname +udev_device_get_sysnum +udev_device_get_devnode +udev_device_get_is_initialized +udev_device_get_devlinks_list_entry +udev_device_get_properties_list_entry +udev_device_get_tags_list_entry +udev_device_get_property_value +udev_device_get_driver +udev_device_get_devnum +udev_device_get_action +udev_device_get_sysattr_value +udev_device_get_sysattr_list_entry +udev_device_get_seqnum +udev_device_get_usec_since_initialized +udev_device_has_tag +
+ +
+libudev-monitor +udev_monitor +udev_monitor +udev_monitor_ref +udev_monitor_unref +udev_monitor_get_udev +udev_monitor_new_from_netlink +udev_monitor_enable_receiving +udev_monitor_set_receive_buffer_size +udev_monitor_get_fd +udev_monitor_receive_device +udev_monitor_filter_add_match_subsystem_devtype +udev_monitor_filter_add_match_tag +udev_monitor_filter_update +udev_monitor_filter_remove +
+ +
+libudev-enumerate +udev_enumerate +udev_enumerate +udev_enumerate_ref +udev_enumerate_unref +udev_enumerate_get_udev +udev_enumerate_new +udev_enumerate_add_match_subsystem +udev_enumerate_add_nomatch_subsystem +udev_enumerate_add_match_sysattr +udev_enumerate_add_nomatch_sysattr +udev_enumerate_add_match_property +udev_enumerate_add_match_tag +udev_enumerate_add_match_parent +udev_enumerate_add_match_is_initialized +udev_enumerate_add_match_sysname +udev_enumerate_add_syspath +udev_enumerate_scan_devices +udev_enumerate_scan_subsystems +udev_enumerate_get_list_entry +
+ +
+libudev-queue +udev_queue +udev_queue +udev_queue_ref +udev_queue_unref +udev_queue_get_udev +udev_queue_new +udev_queue_get_udev_is_active +udev_queue_get_queue_is_empty +udev_queue_get_seqnum_is_finished +udev_queue_get_seqnum_sequence_is_finished +udev_queue_get_queued_list_entry +udev_queue_get_kernel_seqnum +udev_queue_get_udev_seqnum +
+ +
+libudev-util +udev_util +udev_util_encode_string +
diff --git a/docs/libudev/libudev.types b/docs/libudev/libudev.types new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/libudev/version.xml.in b/docs/libudev/version.xml.in new file mode 100644 index 0000000000..d78bda9342 --- /dev/null +++ b/docs/libudev/version.xml.in @@ -0,0 +1 @@ +@VERSION@ -- cgit v1.2.3-54-g00ecf From 5f86ae43857e39e2bf5701449502f39d66d80c7c Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 13 Apr 2012 21:46:35 +0200 Subject: update .gitignore --- docs/gudev/.gitignore | 35 ++++++++++++++++++----------------- docs/libudev/.gitignore | 36 ++++++++++++++++++------------------ src/gudev/.gitignore | 2 -- src/libudev/.gitignore | 1 + src/udev/.gitignore | 19 +------------------ 5 files changed, 38 insertions(+), 55 deletions(-) create mode 100644 src/libudev/.gitignore (limited to 'docs/libudev') diff --git a/docs/gudev/.gitignore b/docs/gudev/.gitignore index 5d7d73d9a6..a6da0cceea 100644 --- a/docs/gudev/.gitignore +++ b/docs/gudev/.gitignore @@ -1,17 +1,18 @@ -Makefile -gudev-overrides.txt -gudev-decl-list.txt -gudev-decl.txt -gudev-undeclared.txt -gudev-undocumented.txt -gudev-unused.txt -gudev.args -gudev.hierarchy -gudev.interfaces -gudev.prerequisites -gudev.signals -html.stamp -html/* -xml/* -tmpl/* -*.stamp +/gtk-doc.make +/version.xml +/Makefile +/gudev-overrides.txt +/gudev-decl-list.txt +/gudev-decl.txt +/gudev-undeclared.txt +/gudev-undocumented.txt +/gudev-unused.txt +/gudev.args +/gudev.hierarchy +/gudev.interfaces +/gudev.prerequisites +/gudev.signals +/html/* +/xml/* +/tmpl/* +/*.stamp diff --git a/docs/libudev/.gitignore b/docs/libudev/.gitignore index 1fb9c51424..a04df47ece 100644 --- a/docs/libudev/.gitignore +++ b/docs/libudev/.gitignore @@ -1,18 +1,18 @@ -Makefile -libudev-overrides.txt -html/ -tmpl/ -xml/ -*.stamp -*.bak -version.xml -libudev-decl-list.txt -libudev-decl.txt -libudev-undeclared.txt -libudev-undocumented.txt -libudev-unused.txt -libudev.args -libudev.hierarchy -libudev.interfaces -libudev.prerequisites -libudev.signals +/gtk-doc.make +/version.xml +/Makefile +/libudev-overrides.txt +/libudev-decl-list.txt +/libudev-decl.txt +/libudev-undeclared.txt +/libudev-undocumented.txt +/libudev-unused.txt +/libudev.args +/libudev.hierarchy +/libudev.interfaces +/libudev.prerequisites +/libudev.signals +/html/* +/xml/* +/tmpl/* +/*.stamp diff --git a/src/gudev/.gitignore b/src/gudev/.gitignore index d20fa523e4..4577903c40 100644 --- a/src/gudev/.gitignore +++ b/src/gudev/.gitignore @@ -1,5 +1,3 @@ -gtk-doc.make -docs/version.xml gudev-1.0.pc gudevenumtypes.c gudevenumtypes.h diff --git a/src/libudev/.gitignore b/src/libudev/.gitignore new file mode 100644 index 0000000000..aa0de7ee12 --- /dev/null +++ b/src/libudev/.gitignore @@ -0,0 +1 @@ +libudev.pc diff --git a/src/udev/.gitignore b/src/udev/.gitignore index e697a57ec3..3e375a7726 100644 --- a/src/udev/.gitignore +++ b/src/udev/.gitignore @@ -1,18 +1 @@ -/gtk-doc.make -/udevd -/udevadm -/test-udev -/test-libudev -/accelerometer -/ata_id -/cdrom_id -/collect -/mtd_probe -/v4l_id -/keymap -/scsi_id -*.[78] -*.html -udev.pc -libudev.pc -udev*.service +/udev.pc -- cgit v1.2.3-54-g00ecf From 690804ca8edf15ac49f637ca9e0b19da8aaa690e Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 13 Apr 2012 23:50:52 +0200 Subject: build-sys: add 'make doc-sync' target --- Makefile.am | 6 +++++- docs/libudev/libudev-docs.xml | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'docs/libudev') diff --git a/Makefile.am b/Makefile.am index dec810637a..c87b4d7a1d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3198,8 +3198,12 @@ DISTCHECK_CONFIGURE_FLAGS = \ upload: all distcheck cp -v systemd-$(VERSION).tar.xz /home/lennart/git.fedora/systemd/ scp systemd-$(VERSION).tar.xz fdo:/srv/www.freedesktop.org/www/software/systemd/ - scp man/*.html fdo:/srv/www.freedesktop.org/www/software/systemd/man/ scp man/*.html tango:public/systemd-man/ +doc-sync: all + rsync -av --delete docs/libudev/html/ www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/libudev/ + rsync -av --delete docs/gudev/html/ www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/gudev/ + rsync -av --delete man/*.html www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/man/ + git-tag: git tag "v$(VERSION)" -m "systemd $(VERSION)" diff --git a/docs/libudev/libudev-docs.xml b/docs/libudev/libudev-docs.xml index b7feb45529..6a5ba0cc2a 100644 --- a/docs/libudev/libudev-docs.xml +++ b/docs/libudev/libudev-docs.xml @@ -9,8 +9,8 @@ libudev Reference Manual for libudev version &version; - 2009-2011 - Kay Sievers <kay.sievers@vrfy.org> + 2009-2012 + Kay Sievers <kay@vrfy.org> -- cgit v1.2.3-54-g00ecf From 3306a5316851e3c7af12514d45c46da590f37311 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 14 Apr 2012 21:16:31 +0200 Subject: udev: trivial gtk-doc update --- docs/gudev/Makefile.am | 2 +- docs/gudev/gudev-docs.xml | 5 +++-- docs/libudev/Makefile.am | 2 +- rules/99-systemd.rules.in | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) (limited to 'docs/libudev') diff --git a/docs/gudev/Makefile.am b/docs/gudev/Makefile.am index 803a2bbd80..f2e953247a 100644 --- a/docs/gudev/Makefile.am +++ b/docs/gudev/Makefile.am @@ -32,7 +32,7 @@ SCAN_OPTIONS= # Extra options to supply to gtkdoc-mkdb. # e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml -MKDB_OPTIONS=--sgml-mode --output-format=xml --name-space=g_udev +MKDB_OPTIONS=--xml-mode --output-format=xml --name-space=g_udev # Extra options to supply to gtkdoc-mktmpl # e.g. MKTMPL_OPTIONS=--only-section-tmpl diff --git a/docs/gudev/gudev-docs.xml b/docs/gudev/gudev-docs.xml index 2798edabac..cf83d143f0 100644 --- a/docs/gudev/gudev-docs.xml +++ b/docs/gudev/gudev-docs.xml @@ -1,7 +1,8 @@ + "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" +[ + ]> diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am index 9d1e3646fb..9eb5c5cbf6 100644 --- a/docs/libudev/Makefile.am +++ b/docs/libudev/Makefile.am @@ -32,7 +32,7 @@ SCAN_OPTIONS= # Extra options to supply to gtkdoc-mkdb. # e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml -MKDB_OPTIONS=--sgml-mode --output-format=xml --name-space=udev +MKDB_OPTIONS=--xml-mode --output-format=xml --name-space=udev # Extra options to supply to gtkdoc-mktmpl # e.g. MKTMPL_OPTIONS=--only-section-tmpl diff --git a/rules/99-systemd.rules.in b/rules/99-systemd.rules.in index e2e7292c51..c117529020 100644 --- a/rules/99-systemd.rules.in +++ b/rules/99-systemd.rules.in @@ -28,7 +28,7 @@ SUBSYSTEM=="block", KERNEL!="ram*|loop*", ENV{DM_UUID}=="CRYPT-*", ENV{ID_PART_T # accessible or not does not matter as long as it is unique and in the # filesystem namespace. # -# http://git.kernel.org/?p=linux/hotplug/udev.git;a=blob;f=libudev/libudev-enumerate.c;h=da831449dcaf5e936a14409e8e68ab12d30a98e2;hb=HEAD#l742 +# http://cgit.freedesktop.org/systemd/systemd/tree/src/libudev/libudev-enumerate.c#n922 SUBSYSTEM=="net", KERNEL!="lo", TAG+="systemd", ENV{SYSTEMD_ALIAS}="/sys/subsystem/net/devices/$name" SUBSYSTEM=="bluetooth", TAG+="systemd", ENV{SYSTEMD_ALIAS}="/sys/subsystem/bluetooth/devices/%k" -- cgit v1.2.3-54-g00ecf From 9d77f8751b4d5b05f1c54f47ddee89d403863d6d Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sun, 15 Apr 2012 03:31:12 +0200 Subject: udev: doc - sync libudev and gudev --- docs/gudev/gudev-docs.xml | 13 ++++--------- docs/libudev/libudev-docs.xml | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'docs/libudev') diff --git a/docs/gudev/gudev-docs.xml b/docs/gudev/gudev-docs.xml index 4c3267998e..ff0195980e 100644 --- a/docs/gudev/gudev-docs.xml +++ b/docs/gudev/gudev-docs.xml @@ -7,7 +7,7 @@ GUDev Reference Manual - For GUdev version &version; + for GUdev version &version; 2009-2012 @@ -16,18 +16,12 @@ - + API Reference - - - This part presents the class and function reference for the - libgudev library. - - - + Object Hierarchy @@ -37,6 +31,7 @@ Index + Index of new symbols in 165 diff --git a/docs/libudev/libudev-docs.xml b/docs/libudev/libudev-docs.xml index 6a5ba0cc2a..0325839287 100644 --- a/docs/libudev/libudev-docs.xml +++ b/docs/libudev/libudev-docs.xml @@ -15,7 +15,7 @@ - libudev + API Reference @@ -26,7 +26,7 @@ - API Index + Index -- cgit v1.2.3-54-g00ecf From 6ada823a9a0979ea145fd70add1007c21caa45c0 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 16 Apr 2012 17:21:22 +0200 Subject: udev: remove configuration options for /dev, /sys, /run directories --- Makefile.am | 26 +++++-- TODO | 5 +- docs/libudev/libudev-sections.txt | 4 +- man/udev.xml | 8 --- src/libudev/libudev-device-private.c | 11 ++- src/libudev/libudev-device.c | 69 +++++++++---------- src/libudev/libudev-enumerate.c | 25 ++----- src/libudev/libudev-private.h | 6 +- src/libudev/libudev-queue-private.c | 16 ++--- src/libudev/libudev-queue.c | 8 +-- src/libudev/libudev-selinux-private.c | 2 +- src/libudev/libudev.c | 119 +++------------------------------ src/test/test-libudev.c | 10 +-- src/test/test-udev.c | 2 +- src/udev/accelerometer/accelerometer.c | 7 +- src/udev/collect/collect.c | 2 +- src/udev/udev-builtin-firmware.c | 2 +- src/udev/udev-ctrl.c | 3 +- src/udev/udev-event.c | 30 +++------ src/udev/udev-node.c | 11 ++- src/udev/udev-rules.c | 72 ++++++++++++++------ src/udev/udev-watch.c | 46 +++++-------- src/udev/udev.h | 1 + src/udev/udevadm-info.c | 62 ++++++----------- src/udev/udevadm-settle.c | 4 +- src/udev/udevadm-test-builtin.c | 4 +- src/udev/udevadm-test.c | 4 +- src/udev/udevadm-trigger.c | 4 +- src/udev/udevadm.c | 2 - src/udev/udevd.c | 55 +++------------ test/udev-test.pl | 79 ++++++++-------------- 31 files changed, 253 insertions(+), 446 deletions(-) (limited to 'docs/libudev') diff --git a/Makefile.am b/Makefile.am index 0d2cb70349..7df3915b75 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1501,12 +1501,30 @@ test_libudev_LDADD = \ libudev.la test_udev_SOURCES = \ - src/test/test-udev.c + src/test/test-udev.c \ + $(libudev_core_la_SOURCES) \ + $(libudev_private_la_SOURCES) + +# The test-udev program needs everything compiled with relative path +# names for /sys, /dev, /run prefixed, pointing to our test/ directory. +test_udev_CFLAGS = \ + -DTEST_PREFIX=\"test\" \ + $(libudev_core_la_CFLAGS) \ + $(libudev_private_la_CFLAGS) + +test_udev_CPPFLAGS =\ + $(libudev_core_la_CPPFLAGS) test_udev_LDADD = \ - libudev-core.la \ - libudev-private.la \ - libsystemd-shared.la + libsystemd-shared.la \ + $(BLKID_LIBS) \ + $(KMOD_LIBS) \ + $(SELINUX_LIBS) + +if HAVE_ACL +test_udev_LDADD += \ + libsystemd-acl.la +endif check_DATA += \ test/sys diff --git a/TODO b/TODO index 292ee21708..d2145f99d1 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,9 @@ Features: * suspend/hibernate/hybrid support, auto-suspend logic with idle hint -* udev: remove /sys and /dev configurability +* udev: unify selinux stuff with systemd + +* udev: move udev's recursive mkdir to shared/ * udev: find a way to tell udev to not cancel firmware requests when running in initramfs @@ -31,6 +33,7 @@ Features: - return object with *_unref() - kill: udev_monitor_from_socket() - kill: udev_queue_get_failed_list_entry() + - kill: udev_get_{dev,sys,run}_path() * allow configuration of console width/height in vconsole.conf diff --git a/docs/libudev/libudev-sections.txt b/docs/libudev/libudev-sections.txt index 83b2b79ee2..31f356f295 100644 --- a/docs/libudev/libudev-sections.txt +++ b/docs/libudev/libudev-sections.txt @@ -8,11 +8,11 @@ udev_new udev_set_log_fn udev_get_log_priority udev_set_log_priority +udev_get_userdata +udev_set_userdata udev_get_sys_path udev_get_dev_path udev_get_run_path -udev_get_userdata -udev_set_userdata
diff --git a/man/udev.xml b/man/udev.xml index 417fb11ebc..458d351658 100644 --- a/man/udev.xml +++ b/man/udev.xml @@ -64,14 +64,6 @@ It consists of a set of variables allowing the user to override default udev values. The following variables can be set: - - - - Specifies where to place the device nodes in the filesystem. - The default value is /dev. - - - diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c index 91fd06c025..c58cde2ff6 100644 --- a/src/libudev/libudev-device-private.c +++ b/src/libudev/libudev-device-private.c @@ -31,7 +31,7 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add) id = udev_device_get_id_filename(dev); if (id == NULL) return; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags/", tag, "/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/tags/", tag, "/", id, NULL); if (add) { int fd; @@ -108,7 +108,7 @@ int udev_device_update_db(struct udev_device *udev_device) return -1; has_info = device_has_info(udev_device); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); /* do not store anything for otherwise empty devices */ if (!has_info && @@ -138,10 +138,8 @@ int udev_device_update_db(struct udev_device *udev_device) struct udev_list_entry *list_entry; if (major(udev_device_get_devnum(udev_device)) > 0) { - size_t devlen = strlen(udev_get_dev_path(udev))+1; - udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(udev_device)) - fprintf(f, "S:%s\n", &udev_list_entry_get_name(list_entry)[devlen]); + fprintf(f, "S:%s\n", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/")); if (udev_device_get_devlink_priority(udev_device) != 0) fprintf(f, "L:%i\n", udev_device_get_devlink_priority(udev_device)); if (udev_device_get_watch_handle(udev_device) >= 0) @@ -173,13 +171,12 @@ int udev_device_update_db(struct udev_device *udev_device) int udev_device_delete_db(struct udev_device *udev_device) { const char *id; - struct udev *udev = udev_device_get_udev(udev_device); char filename[UTIL_PATH_SIZE]; id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); unlink(filename); return 0; } diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 257d6355fe..212163bb92 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -356,7 +356,7 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, if (strncmp(property, "DEVPATH=", 8) == 0) { char path[UTIL_PATH_SIZE]; - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev_device->udev), &property[8], NULL); + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys", &property[8], NULL); udev_device_set_syspath(udev_device, path); } else if (strncmp(property, "SUBSYSTEM=", 10) == 0) { udev_device_set_subsystem(udev_device, &property[10]); @@ -473,7 +473,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) id = udev_device_get_id_filename(udev_device); if (id == NULL) return -1; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_device->udev), "/data/", id, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/run/udev/data/", id, NULL); dbfile = filename; } @@ -496,7 +496,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile) val = &line[2]; switch(line[0]) { case 'S': - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/", val, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", val, NULL); udev_device_add_devlink(udev_device, filename, 0); break; case 'L': @@ -624,7 +624,6 @@ struct udev_device *udev_device_new(struct udev *udev) **/ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) { - size_t len; const char *subdir; char path[UTIL_PATH_SIZE]; char *pos; @@ -637,14 +636,13 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con return NULL; /* path starts in sys */ - len = strlen(udev_get_sys_path(udev)); - if (strncmp(syspath, udev_get_sys_path(udev), len) != 0) { + if (strncmp(syspath, TEST_PREFIX "/sys", strlen(TEST_PREFIX "/sys")) != 0) { dbg(udev, "not in sys :%s\n", syspath); return NULL; } /* path is not a root directory */ - subdir = &syspath[len+1]; + subdir = syspath + strlen(TEST_PREFIX "/sys"); pos = strrchr(subdir, '/'); if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) return NULL; @@ -653,7 +651,7 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con util_strscpy(path, sizeof(path), syspath); util_resolve_sys_link(udev, path, sizeof(path)); - if (strncmp(&path[len], "/devices/", 9) == 0) { + if (strncmp(path + strlen(TEST_PREFIX "/sys"), "/devices/", 9) == 0) { char file[UTIL_PATH_SIZE]; /* all "devices" require a "uevent" file */ @@ -705,8 +703,8 @@ _public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char return NULL; /* use /sys/dev/{block,char}/: link */ - snprintf(path, sizeof(path), "%s/dev/%s/%u:%u", - udev_get_sys_path(udev), type_str, major(devnum), minor(devnum)); + snprintf(path, sizeof(path), TEST_PREFIX "/sys/dev/%s/%u:%u", + type_str, major(devnum), minor(devnum)); return udev_device_new_from_syspath(udev, path); } @@ -782,32 +780,27 @@ struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id **/ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname) { - char path_full[UTIL_PATH_SIZE]; - char *path; - size_t l; + char path[UTIL_PATH_SIZE]; struct stat statbuf; - path = path_full; - l = util_strpcpyl(&path, sizeof(path_full), udev_get_sys_path(udev), NULL); - if (strcmp(subsystem, "subsystem") == 0) { - util_strscpyl(path, l, "/subsystem/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/bus/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/class/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; goto out; } if (strcmp(subsystem, "module") == 0) { - util_strscpyl(path, l, "/module/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/module/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; goto out; } @@ -822,32 +815,32 @@ _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev driver[0] = '\0'; driver = &driver[1]; - util_strscpyl(path, l, "/subsystem/", subsys, "/drivers/", driver, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsys, "/drivers/", driver, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/bus/", subsys, "/drivers/", driver, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsys, "/drivers/", driver, NULL); + if (stat(path, &statbuf) == 0) goto found; } goto out; } - util_strscpyl(path, l, "/subsystem/", subsystem, "/devices/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/subsystem/", subsystem, "/devices/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/bus/", subsystem, "/devices/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/bus/", subsystem, "/devices/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; - util_strscpyl(path, l, "/class/", subsystem, "/", sysname, NULL); - if (stat(path_full, &statbuf) == 0) + util_strscpyl(path, sizeof(path), TEST_PREFIX "/sys/class/", subsystem, "/", sysname, NULL); + if (stat(path, &statbuf) == 0) goto found; out: return NULL; found: - return udev_device_new_from_syspath(udev, path_full); + return udev_device_new_from_syspath(udev, path); } /** @@ -893,7 +886,7 @@ static struct udev_device *device_new_from_parent(struct udev_device *udev_devic const char *subdir; util_strscpy(path, sizeof(path), udev_device->syspath); - subdir = &path[strlen(udev_get_sys_path(udev_device->udev))+1]; + subdir = path + strlen(TEST_PREFIX "/sys/"); for (;;) { char *pos; @@ -1438,7 +1431,7 @@ int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath udev_device->syspath = strdup(syspath); if (udev_device->syspath == NULL) return -ENOMEM; - udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))]; + udev_device->devpath = udev_device->syspath + strlen(TEST_PREFIX "/sys"); udev_device_add_property(udev_device, "DEVPATH", udev_device->devpath); pos = strrchr(udev_device->syspath, '/'); @@ -1471,7 +1464,7 @@ int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode { free(udev_device->devnode); if (devnode[0] != '/') { - if (asprintf(&udev_device->devnode, "%s/%s", udev_get_dev_path(udev_device->udev), devnode) < 0) + if (asprintf(&udev_device->devnode, TEST_PREFIX "/dev/%s", devnode) < 0) udev_device->devnode = NULL; } else { udev_device->devnode = strdup(devnode); diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 7b9a732ce6..ed4f62c66c 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -204,12 +204,10 @@ static bool devices_delay_end(struct udev *udev, const char *syspath) "/block/dm-", NULL }; - size_t len; int i; - len = strlen(udev_get_sys_path(udev)); for (i = 0; delay_device_list[i] != NULL; i++) { - if (strstr(&syspath[len], delay_device_list[i]) != NULL) + if (strstr(syspath + strlen("/sys"), delay_device_list[i]) != NULL) return true; } return false; @@ -624,7 +622,6 @@ static bool match_sysname(struct udev_enumerate *udev_enumerate, const char *sys static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir1, const char *subdir2) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); char path[UTIL_PATH_SIZE]; size_t l; char *s; @@ -632,7 +629,7 @@ static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate, struct dirent *dent; s = path; - l = util_strpcpyl(&s, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL); + l = util_strpcpyl(&s, sizeof(path), "/sys/", basedir, NULL); if (subdir1 != NULL) l = util_strpcpyl(&s, l, "/", subdir1, NULL); if (subdir2 != NULL) @@ -707,13 +704,11 @@ static bool match_subsystem(struct udev_enumerate *udev_enumerate, const char *s static int scan_dir(struct udev_enumerate *udev_enumerate, const char *basedir, const char *subdir, const char *subsystem) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); - char path[UTIL_PATH_SIZE]; DIR *dir; struct dirent *dent; - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL); + util_strscpyl(path, sizeof(path), "/sys/", basedir, NULL); dir = opendir(path); if (dir == NULL) return -1; @@ -756,7 +751,6 @@ _public_ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, c static int scan_devices_tags(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); struct udev_list_entry *list_entry; /* scan only tagged devices, use tags reverse-index, instead of searching all devices in /sys */ @@ -765,8 +759,7 @@ static int scan_devices_tags(struct udev_enumerate *udev_enumerate) struct dirent *dent; char path[UTIL_PATH_SIZE]; - util_strscpyl(path, sizeof(path), udev_get_run_path(udev), "/tags/", - udev_list_entry_get_name(list_entry), NULL); + util_strscpyl(path, sizeof(path), "/run/udev/tags/", udev_list_entry_get_name(list_entry), NULL); dir = opendir(path); if (dir == NULL) continue; @@ -861,12 +854,9 @@ static int scan_devices_children(struct udev_enumerate *enumerate) static int scan_devices_all(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); - char base[UTIL_PATH_SIZE]; struct stat statbuf; - util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL); - if (stat(base, &statbuf) == 0) { + if (stat("/sys/subsystem", &statbuf) == 0) { /* we have /subsystem/, forget all the old stuff */ scan_dir(udev_enumerate, "subsystem", "devices", NULL); } else { @@ -907,8 +897,6 @@ _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) **/ _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); - char base[UTIL_PATH_SIZE]; struct stat statbuf; const char *subsysdir; @@ -919,8 +907,7 @@ _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerat if (match_subsystem(udev_enumerate, "module")) scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL); - util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL); - if (stat(base, &statbuf) == 0) + if (stat("/sys/subsystem", &statbuf) == 0) subsysdir = "subsystem"; else subsysdir = "bus"; diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 91f92264dd..986c40c91e 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -19,9 +19,13 @@ #include "macro.h" #include "libudev.h" -#define READ_END 0 +#define READ_END 0 #define WRITE_END 1 +#ifndef TEST_PREFIX +#define TEST_PREFIX "" +#endif + /* avoid (sometimes expensive) calculations of parameters for debug output */ #define udev_log_cond(udev, prio, arg...) \ do { \ diff --git a/src/libudev/libudev-queue-private.c b/src/libudev/libudev-queue-private.c index ca6d229a2c..f653e6db4c 100644 --- a/src/libudev/libudev-queue-private.c +++ b/src/libudev/libudev-queue-private.c @@ -101,14 +101,10 @@ struct udev_queue_export *udev_queue_export_unref(struct udev_queue_export *udev void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export) { - char filename[UTIL_PATH_SIZE]; - if (udev_queue_export == NULL) return; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL); - unlink(filename); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL); - unlink(filename); + unlink("/run/udev/queue.tmp"); + unlink("/run/udev/queue.bin"); } static int skip_to(FILE *file, long offset) @@ -201,8 +197,6 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) { unsigned long long int seqnum; struct queue_devpaths *devpaths = NULL; - char filename[UTIL_PATH_SIZE]; - char filename_tmp[UTIL_PATH_SIZE]; FILE *new_queue_file = NULL; unsigned int i; @@ -218,8 +212,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) } /* create new queue file */ - util_strscpyl(filename_tmp, sizeof(filename_tmp), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL); - new_queue_file = fopen(filename_tmp, "w+"); + new_queue_file = fopen("/run/udev/queue.tmp", "w+"); if (new_queue_file == NULL) goto error; seqnum = udev_queue_export->seqnum_max; @@ -252,8 +245,7 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export) goto error; /* rename the new file on top of the old one */ - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL); - if (rename(filename_tmp, filename) != 0) + if (rename("/run/udev/queue.tmp", "/run/udev/queue.bin") != 0) goto error; if (udev_queue_export->queue_file != NULL) diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index 0e0df8597d..ca23002307 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -121,14 +121,12 @@ _public_ struct udev *udev_queue_get_udev(struct udev_queue *udev_queue) unsigned long long int udev_get_kernel_seqnum(struct udev *udev) { - char filename[UTIL_PATH_SIZE]; unsigned long long int seqnum; int fd; char buf[32]; ssize_t len; - util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), "/kernel/uevent_seqnum", NULL); - fd = open(filename, O_RDONLY|O_CLOEXEC); + fd = open("/sys/kernel/uevent_seqnum", O_RDONLY|O_CLOEXEC); if (fd < 0) return 0; len = read(fd, buf, sizeof(buf)); @@ -210,7 +208,7 @@ static FILE *open_queue_file(struct udev_queue *udev_queue, unsigned long long i char filename[UTIL_PATH_SIZE]; FILE *queue_file; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue->udev), "/queue.bin", NULL); + util_strscpyl(filename, sizeof(filename), "/run/udev/queue.bin", NULL); queue_file = fopen(filename, "re"); if (queue_file == NULL) return NULL; @@ -437,7 +435,7 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu snprintf(seqnum_str, sizeof(seqnum_str), "%llu", seqnum); s = syspath; - l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev_queue->udev), NULL); + l = util_strpcpy(&s, sizeof(syspath), "/sys"); len = udev_queue_read_devpath(queue_file, s, l); if (len < 0) break; diff --git a/src/libudev/libudev-selinux-private.c b/src/libudev/libudev-selinux-private.c index d68097f991..e9e65ad41d 100644 --- a/src/libudev/libudev-selinux-private.c +++ b/src/libudev/libudev-selinux-private.c @@ -29,7 +29,7 @@ void udev_selinux_init(struct udev *udev) dbg(udev, "selinux=%i\n", selinux_enabled); if (!selinux_enabled) return; - matchpathcon_init_prefix(NULL, udev_get_dev_path(udev)); + matchpathcon_init_prefix(NULL, TEST_PREFIX "/dev"); if (getfscreatecon(&selinux_prev_scontext) < 0) { err(udev, "getfscreatecon failed\n"); selinux_prev_scontext = NULL; diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index 74b53cbf1b..212c5fdd75 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -41,12 +41,6 @@ struct udev { int priority, const char *file, int line, const char *fn, const char *format, va_list args); void *userdata; - char *sys_path; - char *dev_path; - char *rules_path[4]; - unsigned long long rules_path_ts[4]; - int rules_path_count; - char *run_path; struct udev_list properties_list; int log_priority; }; @@ -100,14 +94,6 @@ _public_ void udev_set_userdata(struct udev *udev, void *userdata) udev->userdata = userdata; } -static char *set_value(char **s, const char *v) -{ - free(*s); - *s = strdup(v); - util_remove_trailing_chars(*s, '/'); - return *s; -} - /** * udev_new: * @@ -123,7 +109,6 @@ _public_ struct udev *udev_new(void) { struct udev *udev; const char *env; - char *config_file = NULL; FILE *f; udev = calloc(1, sizeof(struct udev)); @@ -134,21 +119,7 @@ _public_ struct udev *udev_new(void) udev->log_priority = LOG_ERR; udev_list_init(udev, &udev->properties_list, true); - /* custom config file */ - env = getenv("UDEV_CONFIG_FILE"); - if (env != NULL) { - if (set_value(&config_file, env) == NULL) - goto err; - udev_add_property(udev, "UDEV_CONFIG_FILE", config_file); - } - - /* default config file */ - if (config_file == NULL) - config_file = strdup(SYSCONFDIR "/udev/udev.conf"); - if (config_file == NULL) - goto err; - - f = fopen(config_file, "re"); + f = fopen(SYSCONFDIR "/udev/udev.conf", "re"); if (f != NULL) { char line[UTIL_LINE_SIZE]; int line_nr = 0; @@ -172,7 +143,7 @@ _public_ struct udev *udev_new(void) /* split key/value */ val = strchr(key, '='); if (val == NULL) { - err(udev, "missing = in '%s'[%i], skip line\n", config_file, line_nr); + err(udev, "missing = in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); continue; } val[0] = '\0'; @@ -204,7 +175,7 @@ _public_ struct udev *udev_new(void) /* unquote */ if (val[0] == '"' || val[0] == '\'') { if (val[len-1] != val[0]) { - err(udev, "inconsistent quoting in '%s'[%i], skip line\n", config_file, line_nr); + err(udev, "inconsistent quoting in " SYSCONFDIR "/udev/udev.conf[%i]; skip line\n", line_nr); continue; } val[len-1] = '\0'; @@ -215,23 +186,6 @@ _public_ struct udev *udev_new(void) udev_set_log_priority(udev, util_log_priority(val)); continue; } - if (strcmp(key, "udev_root") == 0) { - set_value(&udev->dev_path, val); - continue; - } - if (strcmp(key, "udev_run") == 0) { - set_value(&udev->run_path, val); - continue; - } - if (strcmp(key, "udev_sys") == 0) { - set_value(&udev->sys_path, val); - continue; - } - if (strcmp(key, "udev_rules") == 0) { - set_value(&udev->rules_path[0], val); - udev->rules_path_count = 1; - continue; - } } fclose(f); } @@ -241,44 +195,7 @@ _public_ struct udev *udev_new(void) if (env != NULL) udev_set_log_priority(udev, util_log_priority(env)); - /* set defaults */ - if (udev->dev_path == NULL) - if (set_value(&udev->dev_path, "/dev") == NULL) - goto err; - - if (udev->sys_path == NULL) - if (set_value(&udev->sys_path, "/sys") == NULL) - goto err; - - if (udev->run_path == NULL) - if (set_value(&udev->run_path, "/run/udev") == NULL) - goto err; - - if (udev->rules_path[0] == NULL) { - /* /usr/lib/udev -- system rules */ - udev->rules_path[0] = strdup(UDEVLIBEXECDIR "/rules.d"); - if (!udev->rules_path[0]) - goto err; - - /* /run/udev -- runtime rules */ - if (asprintf(&udev->rules_path[1], "%s/rules.d", udev->run_path) < 0) - goto err; - - /* /etc/udev -- local administration rules */ - udev->rules_path[2] = strdup(SYSCONFDIR "/udev/rules.d"); - if (!udev->rules_path[2]) - goto err; - - udev->rules_path_count = 3; - } - - free(config_file); return udev; -err: - free(config_file); - err(udev, "context creation failed\n"); - udev_unref(udev); - return NULL; } /** @@ -313,12 +230,6 @@ _public_ void udev_unref(struct udev *udev) if (udev->refcount > 0) return; udev_list_cleanup(&udev->properties_list); - free(udev->dev_path); - free(udev->sys_path); - free(udev->rules_path[0]); - free(udev->rules_path[1]); - free(udev->rules_path[2]); - free(udev->run_path); free(udev); } @@ -372,21 +283,11 @@ _public_ void udev_set_log_priority(struct udev *udev, int priority) udev_add_property(udev, "UDEV_LOG", num); } -int udev_get_rules_path(struct udev *udev, char **path[], unsigned long long *stamp_usec[]) -{ - *path = udev->rules_path; - if (stamp_usec) - *stamp_usec = udev->rules_path_ts; - return udev->rules_path_count; -} - /** * udev_get_sys_path: * @udev: udev library context * - * Retrieve the sysfs mount point. The default is "/sys". For - * testing purposes, it can be overridden with udev_sys= - * in the udev configuration file. + * Returns always "/sys"; deprecated, will be removed in a future version. * * Returns: the sys mount point **/ @@ -394,16 +295,14 @@ _public_ const char *udev_get_sys_path(struct udev *udev) { if (udev == NULL) return NULL; - return udev->sys_path; + return "/sys"; } /** * udev_get_dev_path: * @udev: udev library context * - * Retrieve the device directory path. The default value is "/dev", - * the actual value may be overridden in the udev configuration - * file. + * Returns always "/dev"; deprecated, will be removed in a future version. * * Returns: the device directory path **/ @@ -411,14 +310,14 @@ _public_ const char *udev_get_dev_path(struct udev *udev) { if (udev == NULL) return NULL; - return udev->dev_path; + return "/dev"; } /** * udev_get_run_path: * @udev: udev library context * - * Retrieve the udev runtime directory path. The default is "/run/udev". + * Returns always "/run/udev"; deprecated, will be removed in a future version. * * Returns: the runtime directory path **/ @@ -426,7 +325,7 @@ _public_ const char *udev_get_run_path(struct udev *udev) { if (udev == NULL) return NULL; - return udev->run_path; + return "/run/udev"; } struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value) diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c index 6161fb3e31..f5c7ae2c30 100644 --- a/src/test/test-libudev.c +++ b/src/test/test-libudev.c @@ -434,7 +434,6 @@ int main(int argc, char *argv[]) const char *syspath = "/devices/virtual/mem/null"; const char *subsystem = NULL; char path[1024]; - const char *str; udev = udev_new(); printf("context: %p\n", udev); @@ -474,14 +473,9 @@ int main(int argc, char *argv[]) } } - str = udev_get_sys_path(udev); - printf("sys_path: '%s'\n", str); - str = udev_get_dev_path(udev); - printf("dev_path: '%s'\n", str); - /* add sys path if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) { - snprintf(path, sizeof(path), "%s%s", udev_get_sys_path(udev), syspath); + if (strncmp(syspath, "/sys", strlen("/sys")) != 0) { + snprintf(path, sizeof(path), "/sys/%s", syspath); syspath = path; } diff --git a/src/test/test-udev.c b/src/test/test-udev.c index 150cb16a31..b843e5f648 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) rules = udev_rules_new(udev, 1); - util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL); + util_strscpyl(syspath, sizeof(syspath), TEST_PREFIX "/sys", devpath, NULL); dev = udev_device_new_from_syspath(udev, syspath); if (dev == NULL) { log_debug("unknown device '%s'\n", devpath); diff --git a/src/udev/accelerometer/accelerometer.c b/src/udev/accelerometer/accelerometer.c index 4c5e47d0b7..08be363370 100644 --- a/src/udev/accelerometer/accelerometer.c +++ b/src/udev/accelerometer/accelerometer.c @@ -294,7 +294,7 @@ int main (int argc, char** argv) } /* get the device */ - snprintf(devpath, sizeof(devpath), "%s/%s", udev_get_sys_path(udev), argv[optind]); + snprintf(devpath, sizeof(devpath), "/sys/%s", argv[optind]); dev = udev_device_new_from_syspath(udev, devpath); if (dev == NULL) { fprintf(stderr, "unable to access '%s'\n", devpath); @@ -307,9 +307,8 @@ int main (int argc, char** argv) return 0; } - /* Get the children devices and find the devnode - * FIXME: use udev_enumerate_add_match_children() instead - * when it's available */ + /* Get the children devices and find the devnode */ + /* FIXME: use udev_enumerate_add_match_parent() instead */ devnode = NULL; enumerate = udev_enumerate_new(udev); udev_enumerate_add_match_property(enumerate, "ID_PATH", id_path); diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index 076fe479e2..882564a5f5 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -405,7 +405,7 @@ int main(int argc, char **argv) if (debug) fprintf(stderr, "Using checkpoint '%s'\n", checkpoint); - util_strscpyl(tmpdir, sizeof(tmpdir), udev_get_run_path(udev), "/collect", NULL); + util_strscpyl(tmpdir, sizeof(tmpdir), "/run/udev/collect", NULL); fd = prepare(tmpdir, checkpoint); if (fd < 0) { ret = 3; diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c index 5ba712c89d..bd2716fdc8 100644 --- a/src/udev/udev-builtin-firmware.c +++ b/src/udev/udev-builtin-firmware.c @@ -112,7 +112,7 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo } util_path_encode(firmware, fwencpath, sizeof(fwencpath)); - util_strscpyl(misspath, sizeof(misspath), udev_get_run_path(udev), "/firmware-missing/", fwencpath, NULL); + util_strscpyl(misspath, sizeof(misspath), "/run/udev/firmware-missing/", fwencpath, NULL); util_strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL); if (fwfile == NULL) { diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 71c330f6f9..fcb0cd48a6 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -93,8 +93,7 @@ struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd) } uctrl->saddr.sun_family = AF_LOCAL; - util_strscpyl(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), - udev_get_run_path(udev), "/control", NULL); + util_strscpy(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path), "/run/udev/control"); uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.sun_path); return uctrl; } diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index eab1bae27f..d330062ebf 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -318,46 +318,38 @@ subst: if (dev_parent == NULL) break; devnode = udev_device_get_devnode(dev_parent); - if (devnode != NULL) { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; - - l = util_strpcpy(&s, l, &devnode[devlen]); - } + if (devnode != NULL) + l = util_strpcpy(&s, l, devnode + strlen(TEST_PREFIX "/dev/")); break; } case SUBST_DEVNODE: if (udev_device_get_devnode(dev) != NULL) l = util_strpcpy(&s, l, udev_device_get_devnode(dev)); break; - case SUBST_NAME: { - if (event->name != NULL) { + case SUBST_NAME: + if (event->name != NULL) l = util_strpcpy(&s, l, event->name); - } else if (udev_device_get_devnode(dev) != NULL) { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; - - l = util_strpcpy(&s, l, &udev_device_get_devnode(dev)[devlen]); - } else { + else if (udev_device_get_devnode(dev) != NULL) + l = util_strpcpy(&s, l, udev_device_get_devnode(dev) + strlen(TEST_PREFIX "/dev/")); + else l = util_strpcpy(&s, l, udev_device_get_sysname(dev)); - } break; - } case SUBST_LINKS: { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; struct udev_list_entry *list_entry; list_entry = udev_device_get_devlinks_list_entry(dev); if (list_entry == NULL) break; - l = util_strpcpy(&s, l, &udev_list_entry_get_name(list_entry)[devlen]); + l = util_strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/")); udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) - l = util_strpcpyl(&s, l, " ", &udev_list_entry_get_name(list_entry)[devlen], NULL); + l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"), NULL); break; } case SUBST_ROOT: - l = util_strpcpy(&s, l, udev_get_dev_path(event->udev)); + l = util_strpcpy(&s, l, TEST_PREFIX "/dev"); break; case SUBST_SYS: - l = util_strpcpy(&s, l, udev_get_sys_path(event->udev)); + l = util_strpcpy(&s, l, TEST_PREFIX "/sys"); break; case SUBST_ENV: if (attr == NULL) { diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 8e1318872a..26a43e9623 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -203,8 +203,8 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) const char *target; char buf[UTIL_PATH_SIZE]; - util_path_encode(&slink[strlen(udev_get_dev_path(udev))+1], name_enc, sizeof(name_enc)); - util_strscpyl(dirname, sizeof(dirname), udev_get_run_path(udev), "/links/", name_enc, NULL); + util_path_encode(slink + strlen(TEST_PREFIX "/dev"), name_enc, sizeof(name_enc)); + util_strscpyl(dirname, sizeof(dirname), TEST_PREFIX "/run/udev/links/", name_enc, NULL); util_strscpyl(filename, sizeof(filename), dirname, "/", udev_device_get_id_filename(dev), NULL); if (!add && unlink(filename) == 0) @@ -329,8 +329,7 @@ void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) return; /* always add /dev/{block,char}/$major:$minor */ - snprintf(filename, sizeof(filename), "%s/%s/%u:%u", - udev_get_dev_path(udev), + snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u", strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); node_symlink(udev, udev_device_get_devnode(dev), filename); @@ -347,7 +346,6 @@ void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid) void udev_node_remove(struct udev_device *dev) { - struct udev *udev = udev_device_get_udev(dev); struct udev_list_entry *list_entry; char filename[UTIL_PATH_SIZE]; @@ -356,8 +354,7 @@ void udev_node_remove(struct udev_device *dev) link_update(dev, udev_list_entry_get_name(list_entry), 0); /* remove /dev/{block,char}/$major:$minor */ - snprintf(filename, sizeof(filename), "%s/%s/%u:%u", - udev_get_dev_path(udev), + snprintf(filename, sizeof(filename), TEST_PREFIX "/dev/%s/%u:%u", strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); unlink(filename); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 55d7e30c02..1ec817872d 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -36,6 +36,13 @@ #define PREALLOC_STRBUF 32 * 1024 #define PREALLOC_TRIE 256 +/* configuration directories with last modification timestamp */ +static const char *rules_dirs[] = { + TEST_PREFIX UDEVLIBEXECDIR "/rules.d", + TEST_PREFIX "/run/udev/rules.d", + TEST_PREFIX SYSCONFDIR "/udev/rules.d", +}; + struct uid_gid { unsigned int name_off; union { @@ -58,6 +65,7 @@ struct trie_node { struct udev_rules { struct udev *udev; + unsigned long long dirs_ts_usec[ELEMENTSOF(rules_dirs)]; int resolve_names; /* every key in the rules file becomes a token */ @@ -664,7 +672,6 @@ static gid_t add_gid(struct udev_rules *rules, const char *group) static int import_property_from_string(struct udev_device *dev, char *line) { - struct udev *udev = udev_device_get_udev(dev); char *key; char *val; size_t len; @@ -724,7 +731,7 @@ static int import_property_from_string(struct udev_device *dev, char *line) log_debug("updating devpath from '%s' to '%s'\n", udev_device_get_devpath(dev), val); - util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), val, NULL); + util_strscpyl(syspath, sizeof(syspath), "/sys", val, NULL); udev_device_set_syspath(dev, syspath); } else { struct udev_list_entry *entry; @@ -807,7 +814,6 @@ static int import_parent_into_properties(struct udev_device *dev, const char *fi #define WAIT_LOOP_PER_SECOND 50 static int wait_for_file(struct udev_device *dev, const char *file, int timeout) { - struct udev *udev = udev_device_get_udev(dev); char filepath[UTIL_PATH_SIZE]; char devicepath[UTIL_PATH_SIZE]; struct stat stats; @@ -816,8 +822,7 @@ static int wait_for_file(struct udev_device *dev, const char *file, int timeout) /* a relative path is a device attribute */ devicepath[0] = '\0'; if (file[0] != '/') { - util_strscpyl(devicepath, sizeof(devicepath), - udev_get_sys_path(udev), udev_device_get_devpath(dev), NULL); + util_strscpyl(devicepath, sizeof(devicepath), udev_device_get_syspath(dev), NULL); util_strscpyl(filepath, sizeof(filepath), devicepath, "/", file, NULL); file = filepath; } @@ -1746,7 +1751,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) struct udev_list file_list; struct udev_list_entry *file_loop; struct token end_token; - char **s; + unsigned int i; rules = calloc(1, sizeof(struct udev_rules)); if (rules == NULL) @@ -1786,8 +1791,8 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) memset(rules->trie_nodes, 0x00, sizeof(struct trie_node)); rules->trie_nodes_cur = 1; - for (udev_get_rules_path(udev, &s, NULL); *s != NULL; s++) - add_matching_files(udev, &file_list, *s, ".rules"); + for (i = 0; i < ELEMENTSOF(rules_dirs); i++) + add_matching_files(udev, &file_list, rules_dirs[i], ".rules"); /* add all filenames to the string buffer */ udev_list_entry_foreach(file_loop, udev_list_get_entry(&file_list)) { @@ -1884,6 +1889,33 @@ struct udev_rules *udev_rules_unref(struct udev_rules *rules) return NULL; } +bool udev_rules_check_timestamp(struct udev_rules *rules) +{ + unsigned int i; + bool changed = false; + + for (i = 0; i < ELEMENTSOF(rules_dirs); i++) { + struct stat stats; + + if (stat(rules_dirs[i], &stats) < 0) + continue; + + if (rules->dirs_ts_usec[i] == ts_usec(&stats.st_mtim)) + continue; + + /* first check */ + if (rules->dirs_ts_usec[i] != 0) { + log_debug("reload - timestamp of '%s' changed\n", rules_dirs[i]); + changed = true; + } + + /* update timestamp */ + rules->dirs_ts_usec[i] = ts_usec(&stats.st_mtim); + } + + return changed; +} + static int match_key(struct udev_rules *rules, struct token *token, const char *val) { char *key_value = &rules->buf[token->key.value_off]; @@ -2054,14 +2086,13 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event goto nomatch; break; case TK_M_DEVLINK: { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; struct udev_list_entry *list_entry; bool match = false; udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(event->dev)) { const char *devlink; - devlink = &udev_list_entry_get_name(list_entry)[devlen]; + devlink = udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"); if (match_key(rules, cur, devlink) == 0) { match = true; break; @@ -2534,15 +2565,12 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (count > 0) log_debug("%i character(s) replaced\n", count); } - if (major(udev_device_get_devnum(event->dev))) { - size_t devlen = strlen(udev_get_dev_path(event->udev))+1; - - if (strcmp(name_str, &udev_device_get_devnode(event->dev)[devlen]) != 0) { - log_error("NAME=\"%s\" ignored, kernel device nodes " - "can not be renamed; please fix it in %s:%u\n", name, - &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - break; - } + if (major(udev_device_get_devnum(event->dev)) && + (strcmp(name_str, udev_device_get_devnode(event->dev) + strlen(TEST_PREFIX "/dev/")) != 0)) { + log_error("NAME=\"%s\" ignored, kernel device nodes " + "can not be renamed; please fix it in %s:%u\n", name, + &rules->buf[rule->rule.filename_off], rule->rule.filename_line); + break; } free(event->name); event->name = strdup(name_str); @@ -2583,7 +2611,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event next[0] = '\0'; log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); while (isspace(next[1])) next++; @@ -2593,7 +2621,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event if (pos[0] != '\0') { log_debug("LINK '%s' %s:%u\n", pos, &rules->buf[rule->rule.filename_off], rule->rule.filename_line); - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(event->udev), "/", pos, NULL); + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", pos, NULL); udev_device_add_devlink(event->dev, filename, cur->key.devlink_unique); } break; @@ -2703,7 +2731,7 @@ void udev_rules_apply_static_dev_perms(struct udev_rules *rules) /* we assure, that the permissions tokens are sorted before the static token */ if (mode == 0 && uid == 0 && gid == 0) goto next; - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(rules->udev), "/", + util_strscpyl(filename, sizeof(filename), TEST_PREFIX "/dev/", &rules->buf[cur->key.value_off], NULL); if (stat(filename, &stats) != 0) goto next; diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 968728eba9..7d5b30bd68 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -49,41 +49,33 @@ int udev_watch_init(struct udev *udev) */ void udev_watch_restore(struct udev *udev) { - char filename[UTIL_PATH_SIZE], oldname[UTIL_PATH_SIZE]; - if (inotify_fd < 0) return; - util_strscpyl(oldname, sizeof(oldname), udev_get_run_path(udev), "/watch.old", NULL); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/watch", NULL); - if (rename(filename, oldname) == 0) { + if (rename("/run/udev/watch", "/run/udev/watch.old") == 0) { DIR *dir; struct dirent *ent; - dir = opendir(oldname); + dir = opendir("/run/udev/watch.old"); if (dir == NULL) { - log_error("unable to open old watches dir '%s', old watches will not be restored: %m", oldname); + log_error("unable to open old watches dir /run/udev/watch.old; old watches will not be restored: %m"); return; } for (ent = readdir(dir); ent != NULL; ent = readdir(dir)) { char device[UTIL_PATH_SIZE]; - char *s; - size_t l; ssize_t len; struct udev_device *dev; if (ent->d_name[0] == '.') continue; - s = device; - l = util_strpcpy(&s, sizeof(device), udev_get_sys_path(udev)); - len = readlinkat(dirfd(dir), ent->d_name, s, l); - if (len <= 0 || len == (ssize_t)l) + len = readlinkat(dirfd(dir), ent->d_name, device, sizeof(device)); + if (len <= 0 || len == (ssize_t)sizeof(device)) goto unlink; - s[len] = '\0'; + device[len] = '\0'; - dev = udev_device_new_from_id_filename(udev, s); + dev = udev_device_new_from_id_filename(udev, device); if (dev == NULL) goto unlink; @@ -95,10 +87,10 @@ unlink: } closedir(dir); - rmdir(oldname); + rmdir("/run/udev/watch.old"); } else if (errno != ENOENT) { - log_error("unable to move watches dir '%s', old watches will not be restored: %m", filename); + log_error("unable to move watches dir /run/udev/watch; old watches will not be restored: %m"); } } @@ -118,7 +110,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) return; } - snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); + snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); util_create_path(udev, filename); unlink(filename); symlink(udev_device_get_id_filename(dev), filename); @@ -141,7 +133,7 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev) log_debug("removing watch on '%s'\n", udev_device_get_devnode(dev)); inotify_rm_watch(inotify_fd, wd); - snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); + snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); unlink(filename); udev_device_set_watch_handle(dev, -1); @@ -150,21 +142,17 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev) struct udev_device *udev_watch_lookup(struct udev *udev, int wd) { char filename[UTIL_PATH_SIZE]; - char majmin[UTIL_PATH_SIZE]; - char *s; - size_t l; + char device[UTIL_NAME_SIZE]; ssize_t len; if (inotify_fd < 0 || wd < 0) return NULL; - snprintf(filename, sizeof(filename), "%s/watch/%d", udev_get_run_path(udev), wd); - s = majmin; - l = util_strpcpy(&s, sizeof(majmin), udev_get_sys_path(udev)); - len = readlink(filename, s, l); - if (len <= 0 || (size_t)len == l) + snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd); + len = readlink(filename, device, sizeof(device)); + if (len <= 0 || (size_t)len == sizeof(device)) return NULL; - s[len] = '\0'; + device[len] = '\0'; - return udev_device_new_from_id_filename(udev, s); + return udev_device_new_from_id_filename(udev, device); } diff --git a/src/udev/udev.h b/src/udev/udev.h index 681660ecb7..ed5f768ea8 100644 --- a/src/udev/udev.h +++ b/src/udev/udev.h @@ -65,6 +65,7 @@ struct udev_watch { struct udev_rules; struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names); struct udev_rules *udev_rules_unref(struct udev_rules *rules); +bool udev_rules_check_timestamp(struct udev_rules *rules); int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, const sigset_t *sigmask); void udev_rules_apply_static_dev_perms(struct udev_rules *rules); diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 39221b7374..3b14139459 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -131,26 +131,22 @@ static int print_device_chain(struct udev_device *device) static void print_record(struct udev_device *device) { - size_t len; const char *str; int i; struct udev_list_entry *list_entry; printf("P: %s\n", udev_device_get_devpath(device)); - len = strlen(udev_get_dev_path(udev_device_get_udev(device))); str = udev_device_get_devnode(device); if (str != NULL) - printf("N: %s\n", &str[len+1]); + printf("N: %s\n", str + strlen("/dev/")); i = udev_device_get_devlink_priority(device); if (i != 0) printf("L: %i\n", i); - udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) { - len = strlen(udev_get_dev_path(udev_device_get_udev(device))); - printf("S: %s\n", &udev_list_entry_get_name(list_entry)[len+1]); - } + udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) + printf("S: %s\n", udev_list_entry_get_name(list_entry) + strlen("/dev/")); udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device)) printf("E: %s=%s\n", @@ -233,42 +229,35 @@ static void cleanup_dir(DIR *dir, mode_t mask, int depth) static void cleanup_db(struct udev *udev) { - char filename[UTIL_PATH_SIZE]; DIR *dir; - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/queue.bin", NULL); - unlink(filename); + unlink("/run/udev/queue.bin"); - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/data"); if (dir != NULL) { cleanup_dir(dir, S_ISVTX, 1); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/links", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/links"); if (dir != NULL) { cleanup_dir(dir, 0, 2); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/tags"); if (dir != NULL) { cleanup_dir(dir, 0, 2); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/watch", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/watch"); if (dir != NULL) { cleanup_dir(dir, 0, 1); closedir(dir); } - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/firmware-missing", NULL); - dir = opendir(filename); + dir = opendir("/run/udev/firmware-missing"); if (dir != NULL) { cleanup_dir(dir, 0, 1); closedir(dir); @@ -335,9 +324,9 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) rc = 2; goto exit; } - /* remove /dev if given */ - if (strncmp(optarg, udev_get_dev_path(udev), strlen(udev_get_dev_path(udev))) != 0) - util_strscpyl(name, sizeof(name), udev_get_dev_path(udev), "/", optarg, NULL); + /* add /dev if not given */ + if (strncmp(optarg, "/dev", strlen("/dev")) != 0) + util_strscpyl(name, sizeof(name), "/dev/", optarg, NULL); else util_strscpy(name, sizeof(name), optarg); util_remove_trailing_chars(name, '/'); @@ -372,8 +361,8 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) goto exit; } /* add sys dir if needed */ - if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), optarg, NULL); + if (strncmp(optarg, "/sys", strlen("/sys")) != 0) + util_strscpyl(path, sizeof(path), "/sys", optarg, NULL); else util_strscpy(path, sizeof(path), optarg); util_remove_trailing_chars(path, '/'); @@ -408,7 +397,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) root = true; break; case 'R': - printf("%s\n", udev_get_run_path(udev)); + printf("/run/udev\n"); goto exit; case 'd': action = ACTION_DEVICE_ID_FILE; @@ -476,26 +465,19 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) goto exit; } - if (root) { + if (root) printf("%s\n", udev_device_get_devnode(device)); - } else { - size_t len = strlen(udev_get_dev_path(udev)); - - printf("%s\n", &udev_device_get_devnode(device)[len+1]); - } + else + printf("%s\n", udev_device_get_devnode(device) + strlen("/dev/")); break; } case QUERY_SYMLINK: list_entry = udev_device_get_devlinks_list_entry(device); while (list_entry != NULL) { - if (root) { + if (root) printf("%s", udev_list_entry_get_name(list_entry)); - } else { - size_t len; - - len = strlen(udev_get_dev_path(udev_device_get_udev(device))); - printf("%s", &udev_list_entry_get_name(list_entry)[len+1]); - } + else + printf("%s", udev_list_entry_get_name(list_entry) + strlen("/dev/")); list_entry = udev_list_entry_get_next(list_entry); if (list_entry != NULL) printf(" "); @@ -543,7 +525,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) rc = 1; break; case ACTION_ROOT: - printf("%s\n", udev_get_dev_path(udev)); + printf("/dev\n"); break; default: fprintf(stderr, "missing option\n"); diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 19c1e99ccb..e70b351eb9 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -152,8 +152,8 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) if (pfd[0].fd < 0) { log_error("inotify_init failed: %m\n"); } else { - if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_MOVED_TO) < 0) { - log_error("watching '%s' failed\n", udev_get_run_path(udev)); + if (inotify_add_watch(pfd[0].fd, "/run/udev" , IN_MOVED_TO) < 0) { + log_error("watching /run/udev failed\n"); close(pfd[0].fd); pfd[0].fd = -1; } diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 94bb24f5f8..e63b1f4eb7 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -95,8 +95,8 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) } /* add /sys if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL); + if (strncmp(syspath, "/sys", strlen("/sys")) != 0) + util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else util_strscpy(filename, sizeof(filename), syspath); util_remove_trailing_chars(filename, '/'); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index f963c1b510..0c8a762540 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -112,8 +112,8 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) } /* add /sys if needed */ - if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL); + if (strncmp(syspath, "/sys", strlen("/sys")) != 0) + util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else util_strscpy(filename, sizeof(filename), syspath); util_remove_trailing_chars(filename, '/'); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 99ef12cb85..a910121ecd 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -164,8 +164,8 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) struct udev_device *dev; /* add sys dir if needed */ - if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) - util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), optarg, NULL); + if (strncmp(optarg, "/sys", strlen("/sys")) != 0) + util_strscpyl(path, sizeof(path), "/sys", optarg, NULL); else util_strscpy(path, sizeof(path), optarg); util_remove_trailing_chars(path, '/'); diff --git a/src/udev/udevadm.c b/src/udev/udevadm.c index 0858c37be8..2b4a845d77 100644 --- a/src/udev/udevadm.c +++ b/src/udev/udevadm.c @@ -128,8 +128,6 @@ int main(int argc, char *argv[]) } command = argv[optind]; - log_debug("runtime dir '%s'\n", udev_get_run_path(udev)); - if (command != NULL) for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) { if (strcmp(udevadm_cmds[i]->name, command) == 0) { diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 24f0bf6d1e..d6de2aa222 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -856,7 +856,7 @@ static void static_dev_create_from_modules(struct udev *udev) else continue; - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/", devname, NULL); + util_strscpyl(filename, sizeof(filename), "/dev/", devname, NULL); util_create_path_selinux(udev, filename); udev_selinux_setfscreatecon(udev, filename, mode); log_debug("mknod '%s' %c%u:%u\n", filename, type, maj, min); @@ -885,7 +885,7 @@ static void static_dev_create_links(struct udev *udev) }; unsigned int i; - dir = opendir(udev_get_dev_path(udev)); + dir = opendir("/dev"); if (dir == NULL) return; @@ -934,16 +934,15 @@ static int convert_db(struct udev *udev) struct udev_list_entry *list_entry; /* current database */ - util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data", NULL); - if (access(filename, F_OK) >= 0) + if (access("/run/udev/data", F_OK) >= 0) return 0; /* make sure we do not get here again */ - util_create_path(udev, filename); + util_create_path(udev, "/run/udev/data"); mkdir(filename, 0755); /* old database */ - util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db", NULL); + util_strscpyl(filename, sizeof(filename), "/dev/.udev/db", NULL); if (access(filename, F_OK) < 0) return 0; @@ -976,7 +975,7 @@ static int convert_db(struct udev *udev) /* find database in old location */ id = udev_device_get_id_filename(device); - util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", id, NULL); + util_strscpyl(from, sizeof(from), "/dev/.udev/db/", id, NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -986,9 +985,8 @@ static int convert_db(struct udev *udev) } /* find old database with $subsys:$sysname name */ - util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), - "/.udev/db/", udev_device_get_subsystem(device), ":", - udev_device_get_sysname(device), NULL); + util_strscpyl(from, sizeof(from), "/dev/.udev/db/", + udev_device_get_subsystem(device), ":", udev_device_get_sysname(device), NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -999,7 +997,7 @@ static int convert_db(struct udev *udev) /* find old database with the encoded devpath name */ util_path_encode(udev_device_get_devpath(device), devpath, sizeof(devpath)); - util_strscpyl(from, sizeof(from), udev_get_dev_path(udev), "/.udev/db/", devpath, NULL); + util_strscpyl(from, sizeof(from), "/dev/.udev/db/", devpath, NULL); if (lstat(from, &stats) == 0) { if (!have_db) { udev_device_read_db(device, from); @@ -1054,36 +1052,6 @@ static int systemd_fds(struct udev *udev, int *rctrl, int *rnetlink) return 0; } -static bool check_rules_timestamp(struct udev *udev) -{ - char **p; - unsigned long long *stamp_usec; - int i, n; - bool changed = false; - - n = udev_get_rules_path(udev, &p, &stamp_usec); - for (i = 0; i < n; i++) { - struct stat stats; - - if (stat(p[i], &stats) < 0) - continue; - - if (stamp_usec[i] == ts_usec(&stats.st_mtim)) - continue; - - /* first check */ - if (stamp_usec[i] != 0) { - log_debug("reload - timestamp of '%s' changed\n", p[i]); - changed = true; - } - - /* update timestamp */ - stamp_usec[i] = ts_usec(&stats.st_mtim); - } - - return changed; -} - int main(int argc, char *argv[]) { struct udev *udev; @@ -1216,8 +1184,7 @@ int main(int argc, char *argv[]) chdir("/"); umask(022); - /* /run/udev */ - mkdir(udev_get_run_path(udev), 0755); + mkdir("/run/udev", 0755); /* create standard links, copy static nodes, create nodes from modules */ static_dev_create_links(udev); @@ -1557,7 +1524,7 @@ int main(int argc, char *argv[]) /* check for changed config, every 3 seconds at most */ if ((now_usec() - last_usec) > 3 * 1000 * 1000) { - if (check_rules_timestamp(udev)) + if (udev_rules_check_timestamp(rules)) reload = true; if (udev_builtin_validate(udev)) reload = true; diff --git a/test/udev-test.pl b/test/udev-test.pl index 0a2571a1d5..d80b00c374 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -14,20 +14,19 @@ # After creation and removal the result is checked against the # expected value and the result is printed. # -# Copyright (C) 2004-2011 Kay Sievers +# Copyright (C) 2004-2012 Kay Sievers # Copyright (C) 2004 Leann Ogasawara use warnings; use strict; -my $PWD = $ENV{PWD}; -my $sysfs = "test/sys"; my $udev_bin = "./test-udev"; my $valgrind = 0; my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin"; -my $udev_root = "udev-root"; -my $udev_conf = "udev-test.conf"; -my $udev_rules = "udev-test.rules"; +my $udev_dev = "test/dev"; +my $udev_run = "test/run"; +my $udev_rules_dir = "$udev_run/udev/rules.d"; +my $udev_rules = "$udev_rules_dir/udev-test.rules"; my @tests = ( { @@ -251,15 +250,6 @@ EOF exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" , rules => < "import of shell-value file", - devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", - exp_name => "subdir/err/node" , - rules => < "tty33", exp_perms => "0:0:0600", rules => < "udev_root substitution", devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", - exp_name => "start-udev-root-end", + exp_name => "start-test/dev-end", rules => <$udev_rules" || die "unable to create rules file: $udev_rules"; print CONF $$rules; close CONF; @@ -1416,13 +1404,15 @@ sub major_minor_test { } } -sub make_udev_root { - system("rm -rf $udev_root"); - mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; - # setting group and mode of udev_root ensures the tests work +sub udev_setup { + system("rm", "-rf", "$udev_dev"); + mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n"; + # setting group and mode of udev_dev ensures the tests work # even if the parent directory has setgid bit enabled. - chown (0, 0, $udev_root) || die "unable to chown $udev_root\n"; - chmod (0755, $udev_root) || die "unable to chmod $udev_root\n"; + chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n"; + chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n"; + + system("rm", "-rf", "$udev_run"); } sub run_test { @@ -1433,19 +1423,19 @@ sub run_test { udev("add", $rules->{devpath}, \$rules->{rules}); if (defined($rules->{not_exp_name})) { - if ((-e "$PWD/$udev_root/$rules->{not_exp_name}") || - (-l "$PWD/$udev_root/$rules->{not_exp_name}")) { + if ((-e "$udev_dev/$rules->{not_exp_name}") || + (-l "$udev_dev/$rules->{not_exp_name}")) { print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n"; $error++; sleep(1); } } - if ((-e "$PWD/$udev_root/$rules->{exp_name}") || - (-l "$PWD/$udev_root/$rules->{exp_name}")) { + if ((-e "$udev_dev/$rules->{exp_name}") || + (-l "$udev_dev/$rules->{exp_name}")) { my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, - $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root/$rules->{exp_name}"); + $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}"); if (defined($rules->{exp_perms})) { permissions_test($rules, $uid, $gid, $mode); @@ -1460,7 +1450,7 @@ sub run_test { print " as expected\n"; } else { print "\n"; - system("tree $udev_root"); + system("tree", "$udev_dev"); print "\n"; $error++; sleep(1); @@ -1473,14 +1463,14 @@ sub run_test { } udev("remove", $rules->{devpath}, \$rules->{rules}); - if ((-e "$PWD/$udev_root/$rules->{exp_name}") || - (-l "$PWD/$udev_root/$rules->{exp_name}")) { + if ((-e "$udev_dev/$rules->{exp_name}") || + (-l "$udev_dev/$rules->{exp_name}")) { print "remove: error"; if ($rules->{exp_rem_error}) { print " as expected\n"; } else { print "\n"; - system("tree $udev_root"); + system("tree", "$udev_dev"); print "\n"; $error++; sleep(1); @@ -1492,7 +1482,7 @@ sub run_test { print "\n"; if (defined($rules->{option}) && $rules->{option} eq "clean") { - make_udev_root(); + udev_setup(); } } @@ -1504,17 +1494,7 @@ if (!($<==0)) { exit; } -# prepare -make_udev_root(); - -# create config file -open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf"; -print CONF "udev_root=\"$udev_root\"\n"; -print CONF "udev_run=\"$udev_root/.udev\"\n"; -print CONF "udev_sys=\"$sysfs\"\n"; -print CONF "udev_rules=\"$PWD\"\n"; -print CONF "udev_log=\"err\"\n"; -close CONF; +udev_setup(); my $test_num = 1; my @list; @@ -1550,9 +1530,8 @@ if ($list[0]) { print "$error errors occured\n\n"; # cleanup -system("rm -rf $udev_root"); -unlink($udev_rules); -unlink($udev_conf); +system("rm", "-rf", "$udev_dev"); +system("rm", "-rf", "$udev_run"); if ($error > 0) { exit(1); -- cgit v1.2.3-54-g00ecf From 1e8ebcdb5968d6e3bcfe6cf1ca4ed73dd1b671b3 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Tue, 17 Apr 2012 19:02:23 +0200 Subject: udev: docs - updated index page to match common gtk style --- docs/gudev/gudev-docs.xml | 9 +++++++-- docs/libudev/libudev-docs.xml | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'docs/libudev') diff --git a/docs/gudev/gudev-docs.xml b/docs/gudev/gudev-docs.xml index ff0195980e..30be836694 100644 --- a/docs/gudev/gudev-docs.xml +++ b/docs/gudev/gudev-docs.xml @@ -7,8 +7,13 @@ GUDev Reference Manual - for GUdev version &version; - + + For version &version; — the latest version of this + documentation can be found at + + http://www.freedesktop.org/software/systemd/gudev/ + . + 2009-2012 David Zeuthen <davidz@redhat.com> diff --git a/docs/libudev/libudev-docs.xml b/docs/libudev/libudev-docs.xml index 0325839287..2d856ced0e 100644 --- a/docs/libudev/libudev-docs.xml +++ b/docs/libudev/libudev-docs.xml @@ -7,7 +7,13 @@ libudev Reference Manual - for libudev version &version; + + For version &version; — the latest version of this + documentation can be found at + + http://www.freedesktop.org/software/systemd/libudev/ + . + 2009-2012 Kay Sievers <kay@vrfy.org> -- cgit v1.2.3-54-g00ecf From 9e45e7d8f0d8d3f31d790f85694585d0d4b368b8 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Thu, 19 Apr 2012 15:06:25 +0100 Subject: docs: do not generate tmpl files Its not needed as all the documentation is inline source code, not in separate *.tmpl files --- configure.ac | 2 +- docs/gudev/.gitignore | 1 - docs/libudev/.gitignore | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) (limited to 'docs/libudev') diff --git a/configure.ac b/configure.ac index 67c5e007c6..4632059119 100644 --- a/configure.ac +++ b/configure.ac @@ -64,7 +64,7 @@ AC_PATH_PROG([M4], [m4]) # gtkdocize greps for '^GTK_DOC_CHECK', so it needs to be on its own line m4_ifdef([GTK_DOC_CHECK], [ -GTK_DOC_CHECK([1.18]) +GTK_DOC_CHECK([1.18],[--flavour no-tmpl]) ],[ AM_CONDITIONAL([ENABLE_GTK_DOC],[false]) ]) GOBJECT_INTROSPECTION_CHECK([1.31.1]) diff --git a/docs/gudev/.gitignore b/docs/gudev/.gitignore index a6da0cceea..67ffcfd598 100644 --- a/docs/gudev/.gitignore +++ b/docs/gudev/.gitignore @@ -14,5 +14,4 @@ /gudev.signals /html/* /xml/* -/tmpl/* /*.stamp diff --git a/docs/libudev/.gitignore b/docs/libudev/.gitignore index a04df47ece..c05d03d795 100644 --- a/docs/libudev/.gitignore +++ b/docs/libudev/.gitignore @@ -14,5 +14,4 @@ /libudev.signals /html/* /xml/* -/tmpl/* /*.stamp -- cgit v1.2.3-54-g00ecf From 80037e4d17d0c8f28d0ff610902babc9e2b4e2f9 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Thu, 19 Apr 2012 19:00:35 +0200 Subject: docs: rebase html documentation for online and local use --- Makefile.am | 2 ++ TODO | 2 +- docs/gudev/Makefile.am | 3 +++ docs/libudev/Makefile.am | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) (limited to 'docs/libudev') diff --git a/Makefile.am b/Makefile.am index a84cc13686..4d13eea841 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3252,7 +3252,9 @@ upload: all distcheck scp man/*.html tango:public/systemd-man/ doc-sync: all + gtkdoc-rebase --html-dir=docs/libudev/html --online rsync -av --delete docs/libudev/html/ www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/libudev/ + gtkdoc-rebase --html-dir=docs/gudev/html --online rsync -av --delete docs/gudev/html/ www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/gudev/ rsync -av man/*.html www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/man/ diff --git a/TODO b/TODO index 9723024354..efe76f31f1 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,7 @@ Bugfixes: * remove MS_SHARED from src/core/execute.c and src/test/test-ns.c. They are always combined with MS_REMOUNT, which currently does nothing in the kernel, but might which fail in the - future. + future; https://bugzilla.redhat.com/show_bug.cgi?id=813563 * check systemd-tmpfiles for selinux context hookup for mknod(), symlink() and similar diff --git a/docs/gudev/Makefile.am b/docs/gudev/Makefile.am index 5c82167471..f984eb5cbc 100644 --- a/docs/gudev/Makefile.am +++ b/docs/gudev/Makefile.am @@ -103,3 +103,6 @@ if ENABLE_GTK_DOC #TESTS_ENVIRONMENT = cd $(srcsrc) #TESTS = $(GTKDOC_CHECK) endif + +install-data-hook: + $(AM_V_GEN)gtkdoc-rebase --html-dir=$(top_builddir)/docs/gudev/html --relative diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am index 9eb5c5cbf6..0aff6008f4 100644 --- a/docs/libudev/Makefile.am +++ b/docs/libudev/Makefile.am @@ -97,3 +97,6 @@ if ENABLE_GTK_DOC #TESTS_ENVIRONMENT = cd $(srcsrc) #TESTS = $(GTKDOC_CHECK) endif + +install-data-hook: + $(AM_V_GEN)gtkdoc-rebase --html-dir=$(top_builddir)/docs/gudev/html --relative -- cgit v1.2.3-54-g00ecf From 21dbe43aece5b6fc87860de175f067b56649e7d1 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 20 Apr 2012 03:25:36 +0200 Subject: docs: hook-up gtk-doc to 'make check' --- docs/gudev/Makefile.am | 10 +++++----- docs/gudev/gudev-docs.xml | 10 ++++++++-- docs/gudev/gudev-sections.txt | 13 ------------- docs/libudev/Makefile.am | 4 ++-- docs/libudev/libudev-docs.xml | 3 ++- src/libudev/libudev-device.c | 29 ++++++++++++++++++++++++----- src/libudev/libudev-enumerate.c | 31 ++++++++++++++++++++++++++++--- src/libudev/libudev-list.c | 12 ++++++++++-- src/libudev/libudev-queue.c | 20 +++++++++++++++++--- src/libudev/libudev-util.c | 2 ++ 10 files changed, 98 insertions(+), 36 deletions(-) (limited to 'docs/libudev') diff --git a/docs/gudev/Makefile.am b/docs/gudev/Makefile.am index f984eb5cbc..11312b679a 100644 --- a/docs/gudev/Makefile.am +++ b/docs/gudev/Makefile.am @@ -57,7 +57,7 @@ EXTRA_HFILES= # Header files to ignore when scanning. Use base file name, no paths # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h -IGNORE_HFILES= +IGNORE_HFILES=gudevenumtypes.h gudevmarshal.h # Images to copy into HTML directory. # e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png @@ -83,8 +83,8 @@ GTKDOC_CFLAGS = \ -I$(top_builddir)/src/gudev GTKDOC_LIBS = \ - $(GLIB_LIBS) \ - $(top_builddir)/libgudev-1.0.la + $(GLIB_LIBS) \ + $(top_builddir)/libgudev-1.0.la # This includes the standard gtk-doc make rules, copied by gtkdocize. include $(top_srcdir)/gtk-doc.make @@ -100,8 +100,8 @@ EXTRA_DIST += version.xml.in # Comment this out if you want your docs-status tested during 'make check' if ENABLE_GTK_DOC -#TESTS_ENVIRONMENT = cd $(srcsrc) -#TESTS = $(GTKDOC_CHECK) +TESTS_ENVIRONMENT = cd $(top_srcdir) +TESTS = $(GTKDOC_CHECK) endif install-data-hook: diff --git a/docs/gudev/gudev-docs.xml b/docs/gudev/gudev-docs.xml index 30be836694..847d24252e 100644 --- a/docs/gudev/gudev-docs.xml +++ b/docs/gudev/gudev-docs.xml @@ -33,8 +33,9 @@ - - Index + + API Index + @@ -42,5 +43,10 @@ + + Index of deprecated API + + + diff --git a/docs/gudev/gudev-sections.txt b/docs/gudev/gudev-sections.txt index 213e1a7465..b25c13bcb1 100644 --- a/docs/gudev/gudev-sections.txt +++ b/docs/gudev/gudev-sections.txt @@ -98,16 +98,3 @@ G_UDEV_ENUMERATOR_GET_CLASS GUdevEnumeratorPrivate
- -
-gudevmarshal - -g_udev_marshal_VOID__STRING_OBJECT -
- -
-gudevenumtypes - -G_TYPE_UDEV_DEVICE_TYPE -g_udev_device_type_get_type -
diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am index 0aff6008f4..0b01274aad 100644 --- a/docs/libudev/Makefile.am +++ b/docs/libudev/Makefile.am @@ -94,8 +94,8 @@ EXTRA_DIST += version.xml.in # Comment this out if you want your docs-status tested during 'make check' if ENABLE_GTK_DOC -#TESTS_ENVIRONMENT = cd $(srcsrc) -#TESTS = $(GTKDOC_CHECK) +TESTS_ENVIRONMENT = cd $(top_srcdir) +TESTS = $(GTKDOC_CHECK) endif install-data-hook: diff --git a/docs/libudev/libudev-docs.xml b/docs/libudev/libudev-docs.xml index 2d856ced0e..d8248aaafa 100644 --- a/docs/libudev/libudev-docs.xml +++ b/docs/libudev/libudev-docs.xml @@ -29,10 +29,11 @@ + Index - + diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 6a2b1d039a..97cf6654ee 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -136,7 +136,9 @@ static int udev_device_set_ifindex(struct udev_device *udev_device, int ifindex) * udev_device_get_devnum: * @udev_device: udev device * - * Returns: the device major/minor number. + * Get the device major/minor number. + * + * Returns: the dev_t number. **/ _public_ dev_t udev_device_get_devnum(struct udev_device *udev_device) { @@ -185,7 +187,9 @@ static int udev_device_set_devpath_old(struct udev_device *udev_device, const ch * udev_device_get_driver: * @udev_device: udev device * - * Returns: the driver string, or #NULL if there is no driver attached. + * Get the kernel driver name. + * + * Returns: the driver name string, or #NULL if there is no driver attached. **/ _public_ const char *udev_device_get_driver(struct udev_device *udev_device) { @@ -440,7 +444,9 @@ int udev_device_add_property_from_string_parse_finish(struct udev_device *udev_d * @udev_device: udev device * @key: property name * - * Returns: the value of a device property, or #NULL if there is no such property. + * Get the value of a given property. + * + * Returns: the property string, or #NULL if there is no such property. **/ _public_ const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key) { @@ -1081,7 +1087,9 @@ _public_ const char *udev_device_get_syspath(struct udev_device *udev_device) * udev_device_get_sysname: * @udev_device: udev device * - * Returns: the sys name of the device device + * Get the kernel device name in /sys. + * + * Returns: the name string of the device device **/ _public_ const char *udev_device_get_sysname(struct udev_device *udev_device) { @@ -1094,7 +1102,9 @@ _public_ const char *udev_device_get_sysname(struct udev_device *udev_device) * udev_device_get_sysnum: * @udev_device: udev device * - * Returns: the trailing number of of the device name + * Get the instance number of the device. + * + * Returns: the trailing number string of of the device name **/ _public_ const char *udev_device_get_sysnum(struct udev_device *udev_device) { @@ -1583,6 +1593,15 @@ _public_ struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_dev return udev_list_get_entry(&udev_device->tags_list); } +/** + * udev_device_has_tag: + * @udev_device: udev device + * @tag: tag name + * + * Check if a given device has a certain tag associated. + * + * Returns: 1 if the tag is found. 0 otherwise. + **/ _public_ int udev_device_has_tag(struct udev_device *udev_device, const char *tag) { struct udev_list_entry *list_entry; diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 4725912c36..9e6f4677e5 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -65,7 +65,9 @@ struct udev_enumerate { * udev_enumerate_new: * @udev: udev library context * - * Returns: an enumeration context + * Create an enumeration context to scan /sys. + * + * Returns: an enumeration context. **/ _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) { @@ -138,7 +140,9 @@ _public_ void udev_enumerate_unref(struct udev_enumerate *udev_enumerate) * udev_enumerate_get_udev: * @udev_enumerate: context * - * Returns: the udev library context. + * Get the udev library context. + * + * Returns: a pointer to the context. */ _public_ struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate) { @@ -243,7 +247,9 @@ static size_t devices_delay_later(struct udev *udev, const char *syspath) * udev_enumerate_get_list_entry: * @udev_enumerate: context * - * Returns: the first entry of the sorted list of device paths. + * Get the first entry of the sorted list of device paths. + * + * Returns: a udev_list_entry. */ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate) { @@ -321,6 +327,8 @@ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume * @udev_enumerate: context * @subsystem: filter for a subsystem of the device to include in the list * + * Match only devices belonging to a certain kernel subsystem. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem) @@ -339,6 +347,8 @@ _public_ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enum * @udev_enumerate: context * @subsystem: filter for a subsystem of the device to exclude from the list * + * Match only devices not belonging to a certain kernel subsystem. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem) @@ -358,6 +368,8 @@ _public_ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_en * @sysattr: filter for a sys attribute at the device to include in the list * @value: optional value of the sys attribute * + * Match only devices with a certain /sys device attribute. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value) @@ -377,6 +389,8 @@ _public_ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumer * @sysattr: filter for a sys attribute at the device to exclude from the list * @value: optional value of the sys attribute * + * Match only devices not having a certain /sys device attribute. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value) @@ -416,6 +430,8 @@ exit: * @property: filter for a property of the device to include in the list * @value: value of the property * + * Match only devices with a certain property. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value) @@ -434,6 +450,8 @@ _public_ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enume * @udev_enumerate: context * @tag: filter for a tag of the device to include in the list * + * Match only devices with a certain tag. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag) @@ -503,6 +521,8 @@ _public_ int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev * @udev_enumerate: context * @sysname: filter for the name of the device to include in the list * + * Match only devices with a given /sys device name. + * * Returns: 0 on success, otherwise a negative error value. */ _public_ int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname) @@ -867,6 +887,9 @@ static int scan_devices_all(struct udev_enumerate *udev_enumerate) * udev_enumerate_scan_devices: * @udev_enumerate: udev enumeration context * + * Scan /sys for all devices which match the given filters. No matches + * will return all currently available devices. + * * Returns: 0 on success, otherwise a negative error value. **/ _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) @@ -890,6 +913,8 @@ _public_ int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate) * udev_enumerate_scan_subsystems: * @udev_enumerate: udev enumeration context * + * Scan /sys for all kernel subsystems, including buses, classes, drivers. + * * Returns: 0 on success, otherwise a negative error value. **/ _public_ int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate) diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c index 054c0a931c..1fe46f3f28 100644 --- a/src/libudev/libudev-list.c +++ b/src/libudev/libudev-list.c @@ -261,7 +261,9 @@ struct udev_list_entry *udev_list_get_entry(struct udev_list *list) * udev_list_entry_get_next: * @list_entry: current entry * - * Returns: the next entry from the list, #NULL is no more entries are found. + * Get the next entry from the list. + * + * Returns: udev_list_entry, #NULL if no more entries are available. */ _public_ struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry) { @@ -281,7 +283,9 @@ _public_ struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry * @list_entry: current entry * @name: name string to match * - * Returns: the entry where @name matched, #NULL if no matching entry is found. + * Lookup an entry in the list with a certain name. + * + * Returns: udev_list_entry, #NULL if no matching entry is found. */ _public_ struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name) { @@ -303,6 +307,8 @@ _public_ struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_en * udev_list_entry_get_name: * @list_entry: current entry * + * Get the name of a list entry. + * * Returns: the name string of this entry. */ _public_ const char *udev_list_entry_get_name(struct udev_list_entry *list_entry) @@ -316,6 +322,8 @@ _public_ const char *udev_list_entry_get_name(struct udev_list_entry *list_entry * udev_list_entry_get_value: * @list_entry: current entry * + * Get the value of list entry. + * * Returns: the value string of this entry. */ _public_ const char *udev_list_entry_get_value(struct udev_list_entry *list_entry) diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index ca23002307..e2e6319188 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -142,7 +142,9 @@ unsigned long long int udev_get_kernel_seqnum(struct udev *udev) * udev_queue_get_kernel_seqnum: * @udev_queue: udev queue context * - * Returns: the current kernel event sequence number. + * Get the current kernel event sequence number. + * + * Returns: the sequence number. **/ _public_ unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) { @@ -226,7 +228,9 @@ static FILE *open_queue_file(struct udev_queue *udev_queue, unsigned long long i * udev_queue_get_udev_seqnum: * @udev_queue: udev queue context * - * Returns: the last known udev event sequence number. + * Get the last known udev event sequence number. + * + * Returns: the sequence number. **/ _public_ unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) { @@ -258,6 +262,8 @@ _public_ unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *ud * udev_queue_get_udev_is_active: * @udev_queue: udev queue context * + * Check if udev is active on the system. + * * Returns: a flag indicating if udev is active. **/ _public_ int udev_queue_get_udev_is_active(struct udev_queue *udev_queue) @@ -277,6 +283,8 @@ _public_ int udev_queue_get_udev_is_active(struct udev_queue *udev_queue) * udev_queue_get_queue_is_empty: * @udev_queue: udev queue context * + * Check if udev is currently processing any events. + * * Returns: a flag indicating if udev is currently handling events. **/ _public_ int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue) @@ -331,6 +339,8 @@ out: * @start: first event sequence number * @end: last event sequence number * + * Check if udev is currently processing any events in a given sequence number range. + * * Returns: a flag indicating if any of the sequence numbers in the given range is currently active. **/ _public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue, @@ -393,6 +403,8 @@ _public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_ * @udev_queue: udev queue context * @seqnum: sequence number * + * Check if udev is currently processing a given sequence number. + * * Returns: a flag indicating if the given sequence number is currently active. **/ _public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) @@ -407,7 +419,9 @@ _public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, un * udev_queue_get_queued_list_entry: * @udev_queue: udev queue context * - * Returns: the first entry of the list of queued events. + * Get the first entry of the list of queued events. + * + * Returns: a udev_list_entry. **/ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) { diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index aed4393d58..944d9dfcbb 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -30,6 +30,8 @@ /** * SECTION:libudev-util * @short_description: utils + * + * Utilities useful when dealing with devices and device node names. */ int util_delete_path(struct udev *udev, const char *path) -- cgit v1.2.3-54-g00ecf From cc85759ac99cfff7c1daefadb9832a66c3d22b67 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 20 Apr 2012 08:22:18 +0200 Subject: docs: remove duplicated install hook --- docs/gudev/Makefile.am | 3 --- docs/libudev/Makefile.am | 3 --- 2 files changed, 6 deletions(-) (limited to 'docs/libudev') diff --git a/docs/gudev/Makefile.am b/docs/gudev/Makefile.am index 11312b679a..a592afa66f 100644 --- a/docs/gudev/Makefile.am +++ b/docs/gudev/Makefile.am @@ -103,6 +103,3 @@ if ENABLE_GTK_DOC TESTS_ENVIRONMENT = cd $(top_srcdir) TESTS = $(GTKDOC_CHECK) endif - -install-data-hook: - $(AM_V_GEN)gtkdoc-rebase --html-dir=$(top_builddir)/docs/gudev/html --relative diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am index 0b01274aad..4f0d19650a 100644 --- a/docs/libudev/Makefile.am +++ b/docs/libudev/Makefile.am @@ -97,6 +97,3 @@ if ENABLE_GTK_DOC TESTS_ENVIRONMENT = cd $(top_srcdir) TESTS = $(GTKDOC_CHECK) endif - -install-data-hook: - $(AM_V_GEN)gtkdoc-rebase --html-dir=$(top_builddir)/docs/gudev/html --relative -- cgit v1.2.3-54-g00ecf From 843605d372aa000a1ad120bb9d06d04e8b1da50c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 15 May 2012 13:53:05 +0200 Subject: build-sys: move gtk-doc stuff into its own subdir and reindent autogen.sh We moved most other build noise files into their own subdirs, so let's do this for gtk-doc too --- autogen.sh | 35 ++++++++++++++++++----------------- docs/gudev/.gitignore | 6 ++++-- docs/libudev/.gitignore | 6 ++++-- 3 files changed, 26 insertions(+), 21 deletions(-) (limited to 'docs/libudev') diff --git a/autogen.sh b/autogen.sh index be88a8d6f3..51b9d81d58 100755 --- a/autogen.sh +++ b/autogen.sh @@ -16,25 +16,25 @@ # along with systemd; If not, see . if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then - cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit && \ - chmod +x .git/hooks/pre-commit && \ - echo "Activated pre-commit hook." + cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit && \ + chmod +x .git/hooks/pre-commit && \ + echo "Activated pre-commit hook." fi GTKDOCIZE=$(which gtkdocize 2>/dev/null) if test -z $GTKDOCIZE; then - echo "You don't have gtk-doc installed, and thus won't be able to generate the documentation." - echo 'EXTRA_DIST =' > gtk-doc.make + echo "You don't have gtk-doc installed, and thus won't be able to generate the documentation." + echo 'EXTRA_DIST =' > gtk-doc.make else - gtkdocize - gtkdocargs=--enable-gtk-doc + gtkdocize --docdir docs/ + gtkdocargs=--enable-gtk-doc fi intltoolize --force --automake autoreconf --force --install --symlink libdir() { - echo $(cd $1/$(gcc -print-multi-os-directory); pwd) + echo $(cd $1/$(gcc -print-multi-os-directory); pwd) } args="\ @@ -51,14 +51,15 @@ args="$args \ " fi -echo -echo "----------------------------------------------------------------" -echo "Initialized build system. For a common configuration please run:" -echo "----------------------------------------------------------------" -echo -echo "./configure CFLAGS='-g -O0 -Wp,-U_FORTIFY_SOURCE' $args" -echo if [ "x$1" == "xc" ]; then - ./configure CFLAGS='-g -O0 -Wp,-U_FORTIFY_SOURCE' $args - make clean + ./configure CFLAGS='-g -O0 -Wp,-U_FORTIFY_SOURCE' $args + make clean +else + echo + echo "----------------------------------------------------------------" + echo "Initialized build system. For a common configuration please run:" + echo "----------------------------------------------------------------" + echo + echo "./configure CFLAGS='-g -O0 -Wp,-U_FORTIFY_SOURCE' $args" + echo fi diff --git a/docs/gudev/.gitignore b/docs/gudev/.gitignore index 67ffcfd598..e6f2371ab1 100644 --- a/docs/gudev/.gitignore +++ b/docs/gudev/.gitignore @@ -1,3 +1,4 @@ +/*.bak /gtk-doc.make /version.xml /Makefile @@ -12,6 +13,7 @@ /gudev.interfaces /gudev.prerequisites /gudev.signals -/html/* -/xml/* +/html/ +/xml/ /*.stamp +/tmpl/ diff --git a/docs/libudev/.gitignore b/docs/libudev/.gitignore index c05d03d795..f8dd67c50a 100644 --- a/docs/libudev/.gitignore +++ b/docs/libudev/.gitignore @@ -12,6 +12,8 @@ /libudev.interfaces /libudev.prerequisites /libudev.signals -/html/* -/xml/* +/html/ +/xml/ /*.stamp +/*.bak +/tmpl/ -- cgit v1.2.3-54-g00ecf From 04fb63514d1c98fdf9c9549639a1f6d9812444ac Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 15 May 2012 14:34:06 +0200 Subject: build-sys: fix build --- docs/gudev/Makefile.am | 2 +- docs/libudev/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/libudev') diff --git a/docs/gudev/Makefile.am b/docs/gudev/Makefile.am index a592afa66f..586dd8d190 100644 --- a/docs/gudev/Makefile.am +++ b/docs/gudev/Makefile.am @@ -87,7 +87,7 @@ GTKDOC_LIBS = \ $(top_builddir)/libgudev-1.0.la # This includes the standard gtk-doc make rules, copied by gtkdocize. -include $(top_srcdir)/gtk-doc.make +include $(top_srcdir)/docs/gtk-doc.make # Other files to distribute # e.g. EXTRA_DIST += version.xml.in diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am index 4f0d19650a..f9365b3fd0 100644 --- a/docs/libudev/Makefile.am +++ b/docs/libudev/Makefile.am @@ -81,7 +81,7 @@ GTKDOC_CFLAGS= GTKDOC_LIBS= # This includes the standard gtk-doc make rules, copied by gtkdocize. -include $(top_srcdir)/gtk-doc.make +include $(top_srcdir)/docs/gtk-doc.make # Other files to distribute # e.g. EXTRA_DIST += version.xml.in -- cgit v1.2.3-54-g00ecf From 20bbd54f603994a3cc211d2795de16550882ed8d Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Tue, 15 May 2012 22:57:58 +0200 Subject: udev: libudev - bump soname, remove deprecated functions, introduce symbol versions --- Makefile.am | 12 +++-- TODO | 8 ---- docs/libudev/libudev-sections.txt | 3 -- src/libudev/libudev-device.c | 7 +-- src/libudev/libudev-enumerate.c | 7 +-- src/libudev/libudev-monitor.c | 24 ++-------- src/libudev/libudev-queue.c | 15 ++---- src/libudev/libudev.c | 52 ++------------------- src/libudev/libudev.h | 13 ++---- src/libudev/libudev.sym | 97 +++++++++++++++++++++++++++++++++++++++ 10 files changed, 129 insertions(+), 109 deletions(-) create mode 100644 src/libudev/libudev.sym (limited to 'docs/libudev') diff --git a/Makefile.am b/Makefile.am index a4e3433c36..7c1b431093 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,9 +23,9 @@ AM_MAKEFLAGS = --no-print-directory SUBDIRS = . po -LIBUDEV_CURRENT=13 -LIBUDEV_REVISION=3 -LIBUDEV_AGE=13 +LIBUDEV_CURRENT=1 +LIBUDEV_REVISION=0 +LIBUDEV_AGE=0 LIBGUDEV_CURRENT=1 LIBGUDEV_REVISION=1 @@ -1330,7 +1330,8 @@ libudev_la_CFLAGS = \ libudev_la_LDFLAGS = \ $(AM_LDFLAGS) \ - -version-info $(LIBUDEV_CURRENT):$(LIBUDEV_REVISION):$(LIBUDEV_AGE) + -version-info $(LIBUDEV_CURRENT):$(LIBUDEV_REVISION):$(LIBUDEV_AGE) \ + -Wl,--version-script=$(top_srcdir)/src/libudev/libudev.sym libudev_la_LIBADD = \ libsystemd-shared.la @@ -1339,7 +1340,8 @@ pkgconfiglib_DATA += \ src/libudev/libudev.pc EXTRA_DIST += \ - src/libudev/libudev.pc.in + src/libudev/libudev.pc.in \ + src/libudev/libudev.sym CLEANFILES += \ src/libudev/libudev.pc diff --git a/TODO b/TODO index a3b4165559..5d18a64b17 100644 --- a/TODO +++ b/TODO @@ -87,14 +87,6 @@ Features: * udev: add trigger --subsystem-match=usb/usb_device device -* udev: libudev.so.1 - - use symbol versioning - - always return object with *_unref() - - remove deprecated symbols - - udev_monitor_from_socket() - - udev_queue_get_failed_list_entry() - - udev_get_{dev,sys,run}_path() - * allow configuration of console width/height in vconsole.conf * fstab should take priority over units in /usr diff --git a/docs/libudev/libudev-sections.txt b/docs/libudev/libudev-sections.txt index 31f356f295..9f41ca6ac5 100644 --- a/docs/libudev/libudev-sections.txt +++ b/docs/libudev/libudev-sections.txt @@ -10,9 +10,6 @@ udev_get_log_priority udev_set_log_priority udev_get_userdata udev_set_userdata -udev_get_sys_path -udev_get_dev_path -udev_get_run_path
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 9ef4610a6a..f0aab5d464 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -1023,13 +1023,13 @@ _public_ struct udev_device *udev_device_ref(struct udev_device *udev_device) * the resources of the device will be released. * **/ -_public_ void udev_device_unref(struct udev_device *udev_device) +_public_ struct udev_device *udev_device_unref(struct udev_device *udev_device) { if (udev_device == NULL) - return; + return NULL; udev_device->refcount--; if (udev_device->refcount > 0) - return; + return udev_device; if (udev_device->parent_device != NULL) udev_device_unref(udev_device->parent_device); free(udev_device->syspath); @@ -1049,6 +1049,7 @@ _public_ void udev_device_unref(struct udev_device *udev_device) free(udev_device->envp); free(udev_device->monitor_buf); free(udev_device); + return NULL; } /** diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 9e6f4677e5..671bfd7bcf 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -112,15 +112,15 @@ _public_ struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_e * Drop a reference of an enumeration context. If the refcount reaches zero, * all resources of the enumeration context will be released. **/ -_public_ void udev_enumerate_unref(struct udev_enumerate *udev_enumerate) +_public_ struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate) { unsigned int i; if (udev_enumerate == NULL) - return; + return NULL; udev_enumerate->refcount--; if (udev_enumerate->refcount > 0) - return; + return udev_enumerate; udev_list_cleanup(&udev_enumerate->sysattr_match_list); udev_list_cleanup(&udev_enumerate->sysattr_nomatch_list); udev_list_cleanup(&udev_enumerate->subsystem_match_list); @@ -134,6 +134,7 @@ _public_ void udev_enumerate_unref(struct udev_enumerate *udev_enumerate) free(udev_enumerate->devices[i].syspath); free(udev_enumerate->devices); free(udev_enumerate); + return NULL; } /** diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index 5f448e6d47..96506fe580 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -97,23 +97,6 @@ static struct udev_monitor *udev_monitor_new(struct udev *udev) return udev_monitor; } -/** - * udev_monitor_new_from_socket: - * @udev: udev library context - * @socket_path: unix socket path - * - * This function is removed from libudev and will not do anything. - * - * Returns: #NULL - **/ -struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path); -_public_ struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path) -{ - udev_err(udev, "udev_monitor_new_from_socket() does not do anything; please migrate to netlink\n"); - errno = ENOSYS; - return NULL; -} - struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const char *name, int fd) { struct udev_monitor *udev_monitor; @@ -418,18 +401,19 @@ _public_ struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor * will be released. * **/ -_public_ void udev_monitor_unref(struct udev_monitor *udev_monitor) +_public_ struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor) { if (udev_monitor == NULL) - return; + return NULL; udev_monitor->refcount--; if (udev_monitor->refcount > 0) - return; + return udev_monitor; if (udev_monitor->sock >= 0) close(udev_monitor->sock); udev_list_cleanup(&udev_monitor->filter_subsystem_list); udev_list_cleanup(&udev_monitor->filter_tag_list); free(udev_monitor); + return NULL; } /** diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index 81f40db208..15a7f558b1 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -93,15 +93,16 @@ _public_ struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue) * Drop a reference of a udev queue context. If the refcount reaches zero, * the resources of the queue context will be released. **/ -_public_ void udev_queue_unref(struct udev_queue *udev_queue) +_public_ struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue) { if (udev_queue == NULL) - return; + return NULL; udev_queue->refcount--; if (udev_queue->refcount > 0) - return; + return udev_queue; udev_list_cleanup(&udev_queue->queue_list); free(udev_queue); + return NULL; } /** @@ -469,11 +470,3 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu return udev_list_get_entry(&udev_queue->queue_list); } - -struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *udev_queue); -_public_ struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *udev_queue) -{ - udev_err(udev_queue->udev, "udev_queue_get_failed_list_entry() does not return anything; failed events are not recorded\n"); - errno = ENOSYS; - return NULL; -} diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index a0ec39d027..5b754a22a4 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -222,15 +222,16 @@ _public_ struct udev *udev_ref(struct udev *udev) * reaches zero, the resources of the context will be released. * **/ -_public_ void udev_unref(struct udev *udev) +_public_ struct udev *udev_unref(struct udev *udev) { if (udev == NULL) - return; + return NULL; udev->refcount--; if (udev->refcount > 0) - return; + return udev; udev_list_cleanup(&udev->properties_list); free(udev); + return NULL; } /** @@ -283,51 +284,6 @@ _public_ void udev_set_log_priority(struct udev *udev, int priority) udev_add_property(udev, "UDEV_LOG", num); } -/** - * udev_get_sys_path: - * @udev: udev library context - * - * Returns always "/sys"; deprecated, will be removed in a future version. - * - * Returns: the sys mount point - **/ -_public_ const char *udev_get_sys_path(struct udev *udev) -{ - if (udev == NULL) - return NULL; - return "/sys"; -} - -/** - * udev_get_dev_path: - * @udev: udev library context - * - * Returns always "/dev"; deprecated, will be removed in a future version. - * - * Returns: the device directory path - **/ -_public_ const char *udev_get_dev_path(struct udev *udev) -{ - if (udev == NULL) - return NULL; - return "/dev"; -} - -/** - * udev_get_run_path: - * @udev: udev library context - * - * Returns always "/run/udev"; deprecated, will be removed in a future version. - * - * Returns: the runtime directory path - **/ -_public_ const char *udev_get_run_path(struct udev *udev) -{ - if (udev == NULL) - return NULL; - return "/run/udev"; -} - struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value) { if (value == NULL) { diff --git a/src/libudev/libudev.h b/src/libudev/libudev.h index 79842e69de..86439849b1 100644 --- a/src/libudev/libudev.h +++ b/src/libudev/libudev.h @@ -28,7 +28,7 @@ extern "C" { */ struct udev; struct udev *udev_ref(struct udev *udev); -void udev_unref(struct udev *udev); +struct udev *udev_unref(struct udev *udev); struct udev *udev_new(void); void udev_set_log_fn(struct udev *udev, void (*log_fn)(struct udev *udev, @@ -36,9 +36,6 @@ void udev_set_log_fn(struct udev *udev, const char *format, va_list args)); int udev_get_log_priority(struct udev *udev); void udev_set_log_priority(struct udev *udev, int priority); -const char *udev_get_sys_path(struct udev *udev); -const char *udev_get_dev_path(struct udev *udev); -const char *udev_get_run_path(struct udev *udev); void *udev_get_userdata(struct udev *udev); void udev_set_userdata(struct udev *udev, void *userdata); @@ -71,7 +68,7 @@ const char *udev_list_entry_get_value(struct udev_list_entry *list_entry); */ struct udev_device; struct udev_device *udev_device_ref(struct udev_device *udev_device); -void udev_device_unref(struct udev_device *udev_device); +struct udev_device *udev_device_unref(struct udev_device *udev_device); struct udev *udev_device_get_udev(struct udev_device *udev_device); struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath); struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum); @@ -110,7 +107,7 @@ int udev_device_has_tag(struct udev_device *udev_device, const char *tag); */ struct udev_monitor; struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor); -void udev_monitor_unref(struct udev_monitor *udev_monitor); +struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor); struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor); /* kernel and udev generated events over netlink */ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name); @@ -133,7 +130,7 @@ int udev_monitor_filter_remove(struct udev_monitor *udev_monitor); */ struct udev_enumerate; struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate); -void udev_enumerate_unref(struct udev_enumerate *udev_enumerate); +struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate); struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate); struct udev_enumerate *udev_enumerate_new(struct udev *udev); /* device properties filter */ @@ -160,7 +157,7 @@ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *ude */ struct udev_queue; struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue); -void udev_queue_unref(struct udev_queue *udev_queue); +struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue); struct udev *udev_queue_get_udev(struct udev_queue *udev_queue); struct udev_queue *udev_queue_new(struct udev *udev); unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue); diff --git a/src/libudev/libudev.sym b/src/libudev/libudev.sym new file mode 100644 index 0000000000..47683ecda4 --- /dev/null +++ b/src/libudev/libudev.sym @@ -0,0 +1,97 @@ +/*** + This file is part of systemd. + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. +***/ + +LIBUDEV_183 { +global: + udev_device_get_action; + udev_device_get_devlinks_list_entry; + udev_device_get_devnode; + udev_device_get_devnum; + udev_device_get_devpath; + udev_device_get_devtype; + udev_device_get_driver; + udev_device_get_is_initialized; + udev_device_get_parent; + udev_device_get_parent_with_subsystem_devtype; + udev_device_get_properties_list_entry; + udev_device_get_property_value; + udev_device_get_seqnum; + udev_device_get_subsystem; + udev_device_get_sysattr_list_entry; + udev_device_get_sysattr_value; + udev_device_get_sysname; + udev_device_get_sysnum; + udev_device_get_syspath; + udev_device_get_tags_list_entry; + udev_device_get_udev; + udev_device_get_usec_since_initialized; + udev_device_has_tag; + udev_device_new_from_devnum; + udev_device_new_from_environment; + udev_device_new_from_subsystem_sysname; + udev_device_new_from_syspath; + udev_device_ref; + udev_device_unref; + udev_enumerate_add_match_is_initialized; + udev_enumerate_add_match_parent; + udev_enumerate_add_match_property; + udev_enumerate_add_match_subsystem; + udev_enumerate_add_match_sysattr; + udev_enumerate_add_match_sysname; + udev_enumerate_add_match_tag; + udev_enumerate_add_nomatch_subsystem; + udev_enumerate_add_nomatch_sysattr; + udev_enumerate_add_syspath; + udev_enumerate_get_list_entry; + udev_enumerate_get_udev; + udev_enumerate_new; + udev_enumerate_ref; + udev_enumerate_scan_devices; + udev_enumerate_scan_subsystems; + udev_enumerate_unref; + udev_get_log_priority; + udev_get_userdata; + udev_list_entry_get_by_name; + udev_list_entry_get_name; + udev_list_entry_get_next; + udev_list_entry_get_value; + udev_monitor_enable_receiving; + udev_monitor_filter_add_match_subsystem_devtype; + udev_monitor_filter_add_match_tag; + udev_monitor_filter_remove; + udev_monitor_filter_update; + udev_monitor_get_fd; + udev_monitor_get_udev; + udev_monitor_new_from_netlink; + udev_monitor_new_from_socket; + udev_monitor_receive_device; + udev_monitor_ref; + udev_monitor_set_receive_buffer_size; + udev_monitor_unref; + udev_new; + udev_queue_get_kernel_seqnum; + udev_queue_get_queue_is_empty; + udev_queue_get_queued_list_entry; + udev_queue_get_seqnum_is_finished; + udev_queue_get_seqnum_sequence_is_finished; + udev_queue_get_udev; + udev_queue_get_udev_is_active; + udev_queue_get_udev_seqnum; + udev_queue_new; + udev_queue_ref; + udev_queue_unref; + udev_ref; + udev_set_log_fn; + udev_set_log_priority; + udev_set_userdata; + udev_unref; + udev_util_encode_string; +local: + *; +}; -- cgit v1.2.3-54-g00ecf From 27a7a46429b889fe6835016638e798e5f94dd215 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 8 Aug 2012 19:00:35 +0200 Subject: build-sys: really override CFLAGS for gtk-doc In 29a00c41 an override was added, but commandline variables have higher precedence than Makefile variables, so the override was not effective for commandline variables. While at it, duplicate for libudev. --- docs/gudev/Makefile.am | 4 ++-- docs/libudev/Makefile.am | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'docs/libudev') diff --git a/docs/gudev/Makefile.am b/docs/gudev/Makefile.am index 152cd3c018..55172f2c33 100644 --- a/docs/gudev/Makefile.am +++ b/docs/gudev/Makefile.am @@ -77,8 +77,8 @@ expand_content_files= # be listed only once. # Kill CFLAGS here because gtk-doc thinks adding CFLAGS to CC _and_ also # adding CFLAGS itself again would work. -CFLAGS= -LDFLAGS= +override CFLAGS= +override LDFLAGS= # CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library. # Only needed if you are using gtkdoc-scangobj to dynamically query widget diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am index f9365b3fd0..13e448ace0 100644 --- a/docs/libudev/Makefile.am +++ b/docs/libudev/Makefile.am @@ -72,6 +72,14 @@ content_files = version.xml # e.g. expand_content_files=running.sgml expand_content_files= +# Hack, hack. You silly gtk-doc, you must not add CFLAGS multiple +# times when calling gcc; it surely can not work with options that must +# be listed only once. +# Kill CFLAGS here because gtk-doc thinks adding CFLAGS to CC _and_ also +# adding CFLAGS itself again would work. +override CFLAGS= +override LDFLAGS= + # CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library. # Only needed if you are using gtkdoc-scangobj to dynamically query widget # signals and properties. -- cgit v1.2.3-54-g00ecf From dbf61afb29e016fe1b4ac48312a782df1d60a3e6 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 10 Aug 2012 19:56:57 +0200 Subject: udev: export udev_device_new_from_device_id() --- Makefile.am | 6 +++--- docs/libudev/libudev-sections.txt | 1 + src/libudev/libudev-device.c | 20 +++++++++++++++++++- src/libudev/libudev-enumerate.c | 2 +- src/libudev/libudev-private.h | 1 - src/libudev/libudev.h | 1 + src/libudev/libudev.sym | 5 +++++ src/udev/udev-node.c | 2 +- src/udev/udev-watch.c | 4 ++-- 9 files changed, 33 insertions(+), 9 deletions(-) (limited to 'docs/libudev') diff --git a/Makefile.am b/Makefile.am index ad8f71d821..9062dd65df 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,9 +26,9 @@ SUBDIRS = . po # remove targets if the command fails .DELETE_ON_ERROR: -LIBUDEV_CURRENT=1 -LIBUDEV_REVISION=4 -LIBUDEV_AGE=0 +LIBUDEV_CURRENT=2 +LIBUDEV_REVISION=0 +LIBUDEV_AGE=1 LIBGUDEV_CURRENT=1 LIBGUDEV_REVISION=2 diff --git a/docs/libudev/libudev-sections.txt b/docs/libudev/libudev-sections.txt index 9f41ca6ac5..11e8e1cdf5 100644 --- a/docs/libudev/libudev-sections.txt +++ b/docs/libudev/libudev-sections.txt @@ -33,6 +33,7 @@ udev_device_get_udev udev_device_new_from_syspath udev_device_new_from_devnum udev_device_new_from_subsystem_sysname +udev_device_new_from_device_id udev_device_new_from_environment udev_device_get_parent udev_device_get_parent_with_subsystem_devtype diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 98077e777d..1bef70962c 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -714,7 +714,25 @@ _public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char return udev_device_new_from_syspath(udev, path); } -struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id) +/** + * udev_device_new_from_device_id: + * @udev: udev library context + * @id: text string identifying a kernel device + * + * Create new udev device, and fill in information from the sys + * device and the udev database entry. The device is looked-up + * by a special string: + * b8:2 - block device major:minor + * c128:1 - char device major:minor + * n3 - network device ifindex + * +sound:card29 - kernel driver core subsystem:device name + * + * The initial refcount is 1, and needs to be decremented to + * release the resources of the udev device. + * + * Returns: a new udev device, or #NULL, if it does not exist + **/ +_public_ struct udev_device *udev_device_new_from_device_id(struct udev *udev, char *id) { char type; int maj, min; diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index a945758e38..f0305a488b 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -789,7 +789,7 @@ static int scan_devices_tags(struct udev_enumerate *udev_enumerate) if (dent->d_name[0] == '.') continue; - dev = udev_device_new_from_id_filename(udev_enumerate->udev, dent->d_name); + dev = udev_device_new_from_device_id(udev_enumerate->udev, dent->d_name); if (dev == NULL) continue; diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 5990605445..42342234a2 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -47,7 +47,6 @@ struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev); /* libudev-device.c */ struct udev_device *udev_device_new(struct udev *udev); -struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id); mode_t udev_device_get_devnode_mode(struct udev_device *udev_device); int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath); int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode); diff --git a/src/libudev/libudev.h b/src/libudev/libudev.h index 86439849b1..799f47096e 100644 --- a/src/libudev/libudev.h +++ b/src/libudev/libudev.h @@ -73,6 +73,7 @@ struct udev *udev_device_get_udev(struct udev_device *udev_device); struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath); struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum); struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname); +struct udev_device *udev_device_new_from_device_id(struct udev *udev, char *id); struct udev_device *udev_device_new_from_environment(struct udev *udev); /* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */ struct udev_device *udev_device_get_parent(struct udev_device *udev_device); diff --git a/src/libudev/libudev.sym b/src/libudev/libudev.sym index 47683ecda4..5b2c3d32cc 100644 --- a/src/libudev/libudev.sym +++ b/src/libudev/libudev.sym @@ -95,3 +95,8 @@ global: local: *; }; + +LIBUDEV_189 { +global: + udev_device_new_from_device_id; +} LIBUDEV_183; diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 738d02fa25..df4c8f0152 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -159,7 +159,7 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons if (strcmp(dent->d_name, udev_device_get_id_filename(dev)) == 0) continue; - dev_db = udev_device_new_from_id_filename(udev, dent->d_name); + dev_db = udev_device_new_from_device_id(udev, dent->d_name); if (dev_db != NULL) { const char *devnode; diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 1091ec8d69..c27a280bd3 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -75,7 +75,7 @@ void udev_watch_restore(struct udev *udev) goto unlink; device[len] = '\0'; - dev = udev_device_new_from_id_filename(udev, device); + dev = udev_device_new_from_device_id(udev, device); if (dev == NULL) goto unlink; @@ -154,5 +154,5 @@ struct udev_device *udev_watch_lookup(struct udev *udev, int wd) return NULL; device[len] = '\0'; - return udev_device_new_from_id_filename(udev, device); + return udev_device_new_from_device_id(udev, device); } -- cgit v1.2.3-54-g00ecf From 2001208c2ab631a69896d1f670c26846b70d1fb7 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 27 Oct 2012 20:59:01 +0200 Subject: libudev: import hwdb and export lookup interface --- Makefile.am | 11 +- docs/libudev/Makefile.am | 2 +- docs/libudev/libudev-docs.xml | 1 + docs/libudev/libudev-sections.txt | 10 + src/libudev/libudev-hwdb-def.h | 74 ++++++++ src/libudev/libudev-hwdb.c | 391 ++++++++++++++++++++++++++++++++++++++ src/libudev/libudev-private.h | 14 +- src/libudev/libudev.h | 11 ++ src/libudev/libudev.sym | 8 + src/test/test-libudev.c | 16 ++ src/udev/udev-builtin-hwdb.c | 314 ++++-------------------------- src/udev/udev-hwdb.h | 69 ------- src/udev/udevadm-hwdb.c | 39 ++-- 13 files changed, 585 insertions(+), 375 deletions(-) create mode 100644 src/libudev/libudev-hwdb-def.h create mode 100644 src/libudev/libudev-hwdb.c delete mode 100644 src/udev/udev-hwdb.h (limited to 'docs/libudev') diff --git a/Makefile.am b/Makefile.am index 634c67d13f..3d96500c89 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,9 +26,9 @@ SUBDIRS = . po # remove targets if the command fails .DELETE_ON_ERROR: -LIBUDEV_CURRENT=2 -LIBUDEV_REVISION=6 -LIBUDEV_AGE=1 +LIBUDEV_CURRENT=3 +LIBUDEV_REVISION=0 +LIBUDEV_AGE=2 LIBGUDEV_CURRENT=1 LIBGUDEV_REVISION=2 @@ -1688,7 +1688,9 @@ libudev_la_SOURCES =\ src/libudev/libudev-device.c \ src/libudev/libudev-enumerate.c \ src/libudev/libudev-monitor.c \ - src/libudev/libudev-queue.c + src/libudev/libudev-queue.c \ + src/libudev/libudev-hwdb-def.h \ + src/libudev/libudev-hwdb.c libudev_la_CFLAGS = \ $(AM_CFLAGS) \ @@ -1833,7 +1835,6 @@ noinst_LTLIBRARIES += \ libudev_core_la_SOURCES = \ src/udev/udev.h \ - src/udev/udev-hwdb.h \ src/udev/udev-event.c \ src/udev/udev-watch.c \ src/udev/udev-node.c \ diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am index 13e448ace0..6a346a653f 100644 --- a/docs/libudev/Makefile.am +++ b/docs/libudev/Makefile.am @@ -57,7 +57,7 @@ EXTRA_HFILES= # Header files to ignore when scanning. Use base file name, no paths # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h -IGNORE_HFILES = libudev-private.h +IGNORE_HFILES = libudev-private.h libudev-hwdb-def.h # Images to copy into HTML directory. # e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png diff --git a/docs/libudev/libudev-docs.xml b/docs/libudev/libudev-docs.xml index d8248aaafa..454cd31646 100644 --- a/docs/libudev/libudev-docs.xml +++ b/docs/libudev/libudev-docs.xml @@ -28,6 +28,7 @@ + diff --git a/docs/libudev/libudev-sections.txt b/docs/libudev/libudev-sections.txt index 11e8e1cdf5..067a3f5b95 100644 --- a/docs/libudev/libudev-sections.txt +++ b/docs/libudev/libudev-sections.txt @@ -117,6 +117,16 @@ udev_queue_get_kernel_seqnum udev_queue_get_udev_seqnum
+
+libudev-hwdb +udev_hwdb +udev_hwdb +udev_hwdb_ref +udev_hwdb_unref +udev_hwdb_new +udev_hwdb_get_properties_list_entry +
+
libudev-util udev_util diff --git a/src/libudev/libudev-hwdb-def.h b/src/libudev/libudev-hwdb-def.h new file mode 100644 index 0000000000..8bc694457a --- /dev/null +++ b/src/libudev/libudev-hwdb-def.h @@ -0,0 +1,74 @@ +/*** + This file is part of systemd. + + Copyright 2012 Kay Sievers + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#ifndef _LIBUDEV_HWDB_DEF_H_ +#define _LIBUDEV_HWDB_DEF_H_ + +#include "sparse-endian.h" + +#define HWDB_SIG { 'K', 'S', 'L', 'P', 'H', 'H', 'R', 'H' } + +/* on-disk trie objects */ +_packed_ struct trie_header_f { + uint8_t signature[8]; + + /* version of tool which created the file */ + le64_t tool_version; + le64_t file_size; + + /* size of structures to allow them to grow */ + le64_t header_size; + le64_t node_size; + le64_t child_entry_size; + le64_t value_entry_size; + + /* offset of the root trie node */ + le64_t nodes_root_off; + + /* size of the nodes and string section */ + le64_t nodes_len; + le64_t strings_len; +}; + +_packed_ struct trie_node_f { + /* prefix of lookup string, shared by all children */ + le64_t prefix_off; + /* size of children entry array appended to the node */ + uint8_t children_count; + uint8_t padding[7]; + /* size of value entry array appended to the node */ + le64_t values_count; +}; + +/* array of child entries, follows directly the node record */ +_packed_ struct trie_child_entry_f { + /* index of the child node */ + uint8_t c; + uint8_t padding[7]; + /* offset of the child node */ + le64_t child_off; +}; + +/* array of value entries, follows directly the node record/child array */ +_packed_ struct trie_value_entry_f { + le64_t key_off; + le64_t value_off; +}; + +#endif diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c new file mode 100644 index 0000000000..92c58b61a2 --- /dev/null +++ b/src/libudev/libudev-hwdb.c @@ -0,0 +1,391 @@ +/*** + This file is part of systemd. + + Copyright 2012 Kay Sievers + Copyright 2008 Alan Jenkins + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libudev-private.h" +#include "libudev-hwdb-def.h" + +/** + * SECTION:libudev-hwdb + * @short_description: retrieve properties from the hardware database + * + * Libuded hardware database interface. + */ + +/** + * udev_hwdb: + * + * Opaque object representing the hardware database. + */ +struct udev_hwdb { + struct udev *udev; + int refcount; + + FILE *f; + struct stat st; + union { + struct trie_header_f *head; + const char *map; + }; + + struct udev_list properties_list; +}; + +struct linebuf { + char bytes[LINE_MAX]; + size_t size; + size_t len; +}; + +static void linebuf_init(struct linebuf *buf) { + buf->size = 0; + buf->len = 0; +} + +static const char *linebuf_get(struct linebuf *buf) { + if (buf->len + 1 >= sizeof(buf->bytes)) + return NULL; + buf->bytes[buf->len] = '\0'; + return buf->bytes; +} + +static bool linebuf_add(struct linebuf *buf, const char *s, size_t len) { + if (buf->len + len >= sizeof(buf->bytes)) + return false; + memcpy(buf->bytes + buf->len, s, len); + buf->len += len; + return true; +} + +static bool linebuf_add_char(struct linebuf *buf, char c) +{ + if (buf->len + 1 >= sizeof(buf->bytes)) + return false; + buf->bytes[buf->len++] = c; + return true; +} + +static void linebuf_rem(struct linebuf *buf, size_t count) { + assert(buf->len >= count); + buf->len -= count; +} + +static void linebuf_rem_char(struct linebuf *buf) { + linebuf_rem(buf, 1); +} + +static const struct trie_child_entry_f *trie_node_children(struct udev_hwdb *hwdb, const struct trie_node_f *node) { + return (const struct trie_child_entry_f *)((const char *)node + le64toh(hwdb->head->node_size)); +} + +static const struct trie_value_entry_f *trie_node_values(struct udev_hwdb *hwdb, const struct trie_node_f *node) { + const char *base = (const char *)node; + + base += le64toh(hwdb->head->node_size); + base += node->children_count * le64toh(hwdb->head->child_entry_size); + return (const struct trie_value_entry_f *)base; +} + +static const struct trie_node_f *trie_node_from_off(struct udev_hwdb *hwdb, le64_t off) { + return (const struct trie_node_f *)(hwdb->map + le64toh(off)); +} + +static const char *trie_string(struct udev_hwdb *hwdb, le64_t off) { + return hwdb->map + le64toh(off); +} + +static int trie_children_cmp_f(const void *v1, const void *v2) { + const struct trie_child_entry_f *n1 = v1; + const struct trie_child_entry_f *n2 = v2; + + return n1->c - n2->c; +} + +static const struct trie_node_f *node_lookup_f(struct udev_hwdb *hwdb, const struct trie_node_f *node, uint8_t c) { + struct trie_child_entry_f *child; + struct trie_child_entry_f search; + + search.c = c; + child = bsearch(&search, trie_node_children(hwdb, node), node->children_count, + le64toh(hwdb->head->child_entry_size), trie_children_cmp_f); + if (child) + return trie_node_from_off(hwdb, child->child_off); + return NULL; +} + +static int hwdb_add_property(struct udev_hwdb *hwdb, const char *key, const char *value) { + /* TODO: add sub-matches (+) against DMI data */ + if (key[0] != ' ') + return 0; + if (udev_list_entry_add(&hwdb->properties_list, key+1, value) == NULL) + return -ENOMEM; + return 0; +} + +static int trie_fnmatch_f(struct udev_hwdb *hwdb, const struct trie_node_f *node, size_t p, + struct linebuf *buf, const char *search) { + size_t len; + size_t i; + const char *prefix; + int err; + + prefix = trie_string(hwdb, node->prefix_off); + len = strlen(prefix + p); + linebuf_add(buf, prefix + p, len); + + for (i = 0; i < node->children_count; i++) { + const struct trie_child_entry_f *child = &trie_node_children(hwdb, node)[i]; + + linebuf_add_char(buf, child->c); + err = trie_fnmatch_f(hwdb, trie_node_from_off(hwdb, child->child_off), 0, buf, search); + if (err < 0) + return err; + linebuf_rem_char(buf); + } + + if (node->values_count && fnmatch(linebuf_get(buf), search, 0) == 0) + for (i = 0; i < node->values_count; i++) { + err = hwdb_add_property(hwdb, trie_string(hwdb, trie_node_values(hwdb, node)[i].key_off), + trie_string(hwdb, trie_node_values(hwdb, node)[i].value_off)); + if (err < 0) + return err; + } + + linebuf_rem(buf, len); + return 0; +} + +static int trie_search_f(struct udev_hwdb *hwdb, const char *search) { + struct linebuf buf; + const struct trie_node_f *node; + size_t i = 0; + int err; + + linebuf_init(&buf); + + node = trie_node_from_off(hwdb, hwdb->head->nodes_root_off); + while (node) { + const struct trie_node_f *child; + size_t p = 0; + + if (node->prefix_off) { + uint8_t c; + + for (; (c = trie_string(hwdb, node->prefix_off)[p]); p++) { + if (c == '*' || c == '?' || c == '[') + return trie_fnmatch_f(hwdb, node, p, &buf, search + i + p); + if (c != search[i + p]) + return 0; + } + i += p; + } + + child = node_lookup_f(hwdb, node, '*'); + if (child) { + linebuf_add_char(&buf, '*'); + err = trie_fnmatch_f(hwdb, child, 0, &buf, search + i); + if (err < 0) + return err; + linebuf_rem_char(&buf); + } + + child = node_lookup_f(hwdb, node, '?'); + if (child) { + linebuf_add_char(&buf, '?'); + err = trie_fnmatch_f(hwdb, child, 0, &buf, search + i); + if (err < 0) + return err; + linebuf_rem_char(&buf); + } + + child = node_lookup_f(hwdb, node, '['); + if (child) { + linebuf_add_char(&buf, '['); + err = trie_fnmatch_f(hwdb, child, 0, &buf, search + i); + if (err < 0) + return err; + linebuf_rem_char(&buf); + } + + if (search[i] == '\0') { + size_t n; + + for (n = 0; n < node->values_count; n++) { + err = hwdb_add_property(hwdb, trie_string(hwdb, trie_node_values(hwdb, node)[n].key_off), + trie_string(hwdb, trie_node_values(hwdb, node)[n].value_off)); + if (err < 0) + return err; + } + return 0; + } + + child = node_lookup_f(hwdb, node, search[i]); + node = child; + i++; + } + return 0; +} + +/** + * udev_hwdb_new: + * @udev: udev library context + * + * Create a hardware database context to query properties for devices. + * + * Returns: a hwdb context. + **/ +_public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) { + struct udev_hwdb *hwdb; + const char sig[] = HWDB_SIG; + + hwdb = new0(struct udev_hwdb, 1); + if (!hwdb) + return NULL; + + hwdb->refcount = 1; + udev_list_init(udev, &hwdb->properties_list, true); + + hwdb->f = fopen("/etc/udev/hwdb.bin", "re"); + if (!hwdb->f) { + log_debug("error reading /etc/udev/hwdb.bin: %m"); + udev_hwdb_unref(hwdb); + return NULL; + } + + if (fstat(fileno(hwdb->f), &hwdb->st) < 0 || + (size_t)hwdb->st.st_size < offsetof(struct trie_header_f, strings_len) + 8) { + log_debug("error reading /etc/udev/hwdb.bin: %m"); + udev_hwdb_unref(hwdb); + return NULL; + } + + hwdb->map = mmap(0, hwdb->st.st_size, PROT_READ, MAP_SHARED, fileno(hwdb->f), 0); + if (hwdb->map == MAP_FAILED) { + log_debug("error mapping /etc/udev/hwdb.bin: %m"); + udev_hwdb_unref(hwdb); + return NULL; + } + + if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 || + (size_t)hwdb->st.st_size != le64toh(hwdb->head->file_size)) { + log_debug("error recognizing the format of /etc/udev/hwdb.bin"); + udev_hwdb_unref(hwdb); + return NULL; + } + + log_debug("=== trie on-disk ===\n"); + log_debug("tool version: %llu", (unsigned long long)le64toh(hwdb->head->tool_version)); + log_debug("file size: %8llu bytes\n", (unsigned long long)hwdb->st.st_size); + log_debug("header size %8llu bytes\n", (unsigned long long)le64toh(hwdb->head->header_size)); + log_debug("strings %8llu bytes\n", (unsigned long long)le64toh(hwdb->head->strings_len)); + log_debug("nodes %8llu bytes\n", (unsigned long long)le64toh(hwdb->head->nodes_len)); + return hwdb; +} + +/** + * udev_hwdb_ref: + * @hwdb: context + * + * Take a reference of a hwdb context. + * + * Returns: the passed enumeration context + **/ +_public_ struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb) { + if (!hwdb) + return NULL; + hwdb->refcount++; + return hwdb; +} + +/** + * udev_hwdb_unref: + * @hwdb: context + * + * Drop a reference of a hwdb context. If the refcount reaches zero, + * all resources of the hwdb context will be released. + * + * Returns: the passed hwdb context if it has still an active reference, or #NULL otherwise. + **/ +_public_ struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb) { + if (!hwdb) + return NULL; + hwdb->refcount--; + if (hwdb->refcount > 0) + return hwdb; + if (hwdb->f) + fclose(hwdb->f); + if (hwdb->map) + munmap((void *)hwdb->map, hwdb->st.st_size); + udev_list_cleanup(&hwdb->properties_list); + free(hwdb); + return NULL; +} + +bool udev_hwdb_validate(struct udev_hwdb *hwdb) { + struct stat st; + + if (!hwdb) + return false; + if (!hwdb->f) + return false; + if (fstat(fileno(hwdb->f), &st) < 0) + return true; + if (ts_usec(&hwdb->st.st_mtim) != ts_usec(&st.st_mtim)) + return true; + return false; +} + +/** + * udev_hwdb_get_properties_list_entry: + * @hwdb: context + * @modalias: modalias string + * @flags: (unused) + * + * Lookup a matching device in the hardware database. The lookup key is a + * modalias string, whose formats are defined for the Linux kernel modules. + * Examples are: pci:v00008086d00001C2D*, usb:v04F2pB221*. The first entry + * of a list of retrieved properties is returned. + * + * Returns: a udev_list_entry. + */ +_public_ struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags) { + int err; + + if (!hwdb->f) { + errno = EINVAL; + return NULL; + } + + err = trie_search_f(hwdb, modalias); + if (err < 0) { + errno = -err; + return NULL; + } + return udev_list_get_entry(&hwdb->properties_list); +} diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h index 2add8b3577..d233565fb8 100644 --- a/src/libudev/libudev-private.h +++ b/src/libudev/libudev-private.h @@ -140,11 +140,14 @@ void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export); int udev_queue_export_device_queued(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device); int udev_queue_export_device_finished(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device); +/* libudev-hwdb.c */ +bool udev_hwdb_validate(struct udev_hwdb *hwdb); + /* libudev-util.c */ -#define UTIL_PATH_SIZE 1024 -#define UTIL_NAME_SIZE 512 -#define UTIL_LINE_SIZE 16384 -#define UDEV_ALLOWED_CHARS_INPUT "/ $%?," +#define UTIL_PATH_SIZE 1024 +#define UTIL_NAME_SIZE 512 +#define UTIL_LINE_SIZE 16384 +#define UDEV_ALLOWED_CHARS_INPUT "/ $%?," ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const char *syspath, char *value, size_t size); int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size); int util_log_priority(const char *priority); @@ -163,8 +166,7 @@ uint64_t util_string_bloom64(const char *str); int util_delete_path(struct udev *udev, const char *path); uid_t util_lookup_user(struct udev *udev, const char *user); gid_t util_lookup_group(struct udev *udev, const char *group); -int util_resolve_subsys_kernel(struct udev *udev, const char *string, - char *result, size_t maxsize, int read_value); +int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value); unsigned long long ts_usec(const struct timespec *ts); unsigned long long now_usec(void); ssize_t print_kmsg(const char *fmt, ...) __attribute__((format(printf, 1, 2))); diff --git a/src/libudev/libudev.h b/src/libudev/libudev.h index 799f47096e..cab2323dea 100644 --- a/src/libudev/libudev.h +++ b/src/libudev/libudev.h @@ -170,6 +170,17 @@ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue, unsigned long long int start, unsigned long long int end); struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue); +/* + * udev_hwdb + * + * access to the static hardware properties database + */ +struct udev_hwdb; +struct udev_hwdb *udev_hwdb_new(struct udev *udev); +struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb); +struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb); +struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags); + /* * udev_util * diff --git a/src/libudev/libudev.sym b/src/libudev/libudev.sym index 5b2c3d32cc..df6a1aeddf 100644 --- a/src/libudev/libudev.sym +++ b/src/libudev/libudev.sym @@ -100,3 +100,11 @@ LIBUDEV_189 { global: udev_device_new_from_device_id; } LIBUDEV_183; + +LIBUDEV_196 { +global: + udev_hwdb_new; + udev_hwdb_ref; + udev_hwdb_unref; + udev_hwdb_get_properties_list_entry; +} LIBUDEV_189; diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c index 481ce65dbf..b89d900121 100644 --- a/src/test/test-libudev.c +++ b/src/test/test-libudev.c @@ -421,6 +421,20 @@ static int test_enumerate(struct udev *udev, const char *subsystem) return 0; } +static int test_hwdb(struct udev *udev, const char *modalias) { + struct udev_hwdb * hwdb; + struct udev_list_entry *entry; + + hwdb = udev_hwdb_new(udev); + + udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0)) + printf("'%s'='%s'\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry)); + printf("\n"); + + hwdb = udev_hwdb_unref(hwdb); + return 0; +} + int main(int argc, char *argv[]) { struct udev *udev = NULL; @@ -489,6 +503,8 @@ int main(int argc, char *argv[]) test_queue(udev); + test_hwdb(udev, "usb:v0D50p0011*"); + test_monitor(udev); out: udev_unref(udev); diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c index 14e9edab82..60f647183f 100644 --- a/src/udev/udev-builtin-hwdb.c +++ b/src/udev/udev-builtin-hwdb.c @@ -2,7 +2,6 @@ This file is part of systemd. Copyright 2012 Kay Sievers - Copyright 2008 Alan Jenkins systemd is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -24,210 +23,39 @@ #include #include #include -#include #include -#include #include "udev.h" -#include "udev-hwdb.h" -struct linebuf { - char bytes[LINE_MAX]; - size_t size; - size_t len; -}; - -static void linebuf_init(struct linebuf *buf) { - buf->size = 0; - buf->len = 0; -} - -static const char *linebuf_get(struct linebuf *buf) { - if (buf->len + 1 >= sizeof(buf->bytes)) - return NULL; - buf->bytes[buf->len] = '\0'; - return buf->bytes; -} - -static bool linebuf_add(struct linebuf *buf, const char *s, size_t len) { - if (buf->len + len >= sizeof(buf->bytes)) - return false; - memcpy(buf->bytes + buf->len, s, len); - buf->len += len; - return true; -} - -static bool linebuf_add_char(struct linebuf *buf, char c) -{ - if (buf->len + 1 >= sizeof(buf->bytes)) - return false; - buf->bytes[buf->len++] = c; - return true; -} - -static void linebuf_rem(struct linebuf *buf, size_t count) { - assert(buf->len >= count); - buf->len -= count; -} - -static void linebuf_rem_char(struct linebuf *buf) { - linebuf_rem(buf, 1); -} +static struct udev_hwdb *hwdb; -struct trie_f { - struct udev_device *dev; - bool test; - FILE *f; - uint64_t file_time_usec; - union { - struct trie_header_f *head; - const char *map; +static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool test) { + static const struct option options[] = { + { "subsystem", required_argument, NULL, 's' }, + {} }; - size_t map_size; -}; - -static const struct trie_child_entry_f *trie_node_children(struct trie_f *trie, const struct trie_node_f *node) { - return (const struct trie_child_entry_f *)((const char *)node + le64toh(trie->head->node_size)); -} - -static const struct trie_value_entry_f *trie_node_values(struct trie_f *trie, const struct trie_node_f *node) { - const char *base = (const char *)node; - - base += le64toh(trie->head->node_size); - base += node->children_count * le64toh(trie->head->child_entry_size); - return (const struct trie_value_entry_f *)base; -} - -static const struct trie_node_f *trie_node_from_off(struct trie_f *trie, le64_t off) { - return (const struct trie_node_f *)(trie->map + le64toh(off)); -} - -static const char *trie_string(struct trie_f *trie, le64_t off) { - return trie->map + le64toh(off); -} - -static int trie_children_cmp_f(const void *v1, const void *v2) { - const struct trie_child_entry_f *n1 = v1; - const struct trie_child_entry_f *n2 = v2; - - return n1->c - n2->c; -} - -static const struct trie_node_f *node_lookup_f(struct trie_f *trie, const struct trie_node_f *node, uint8_t c) { - struct trie_child_entry_f *child; - struct trie_child_entry_f search; - - search.c = c; - child = bsearch(&search, trie_node_children(trie, node), node->children_count, - le64toh(trie->head->child_entry_size), trie_children_cmp_f); - if (child) - return trie_node_from_off(trie, child->child_off); - return NULL; -} - -static void trie_fnmatch_f(struct trie_f *trie, const struct trie_node_f *node, size_t p, - struct linebuf *buf, const char *search, - void (*cb)(struct trie_f *trie, const char *key, const char *value)) { - size_t len; - size_t i; - const char *prefix; - - prefix = trie_string(trie, node->prefix_off); - len = strlen(prefix + p); - linebuf_add(buf, prefix + p, len); - - for (i = 0; i < node->children_count; i++) { - const struct trie_child_entry_f *child = &trie_node_children(trie, node)[i]; - - linebuf_add_char(buf, child->c); - trie_fnmatch_f(trie, trie_node_from_off(trie, child->child_off), 0, buf, search, cb); - linebuf_rem_char(buf); - } - - if (node->values_count && fnmatch(linebuf_get(buf), search, 0) == 0) - for (i = 0; i < node->values_count; i++) - cb(trie, trie_string(trie, trie_node_values(trie, node)[i].key_off), - trie_string(trie, trie_node_values(trie, node)[i].value_off)); - - linebuf_rem(buf, len); -} - -static void trie_search_f(struct trie_f *trie, const char *search, - void (*cb)(struct trie_f *trie, const char *key, const char *value)) { - struct linebuf buf; - const struct trie_node_f *node; - size_t i = 0; - - linebuf_init(&buf); - - node = trie_node_from_off(trie, trie->head->nodes_root_off); - while (node) { - const struct trie_node_f *child; - size_t p = 0; - - if (node->prefix_off) { - uint8_t c; - - for (; (c = trie_string(trie, node->prefix_off)[p]); p++) { - if (c == '*' || c == '?' || c == '[') { - trie_fnmatch_f(trie, node, p, &buf, search + i + p, cb); - return; - } - if (c != search[i + p]) - return; - } - i += p; - } - - child = node_lookup_f(trie, node, '*'); - if (child) { - linebuf_add_char(&buf, '*'); - trie_fnmatch_f(trie, child, 0, &buf, search + i, cb); - linebuf_rem_char(&buf); - } + const char *subsys = NULL; + struct udev_device *d; + const char *modalias; + char str[UTIL_NAME_SIZE]; + struct udev_list_entry *entry; - child = node_lookup_f(trie, node, '?'); - if (child) { - linebuf_add_char(&buf, '?'); - trie_fnmatch_f(trie, child, 0, &buf, search + i, cb); - linebuf_rem_char(&buf); - } + if (!hwdb) + return EXIT_FAILURE; - child = node_lookup_f(trie, node, '['); - if (child) { - linebuf_add_char(&buf, '['); - trie_fnmatch_f(trie, child, 0, &buf, search + i, cb); - linebuf_rem_char(&buf); - } + for (;;) { + int option; - if (search[i] == '\0') { - size_t n; + option = getopt_long(argc, argv, "s", options, NULL); + if (option == -1) + break; - for (n = 0; n < node->values_count; n++) - cb(trie, trie_string(trie, trie_node_values(trie, node)[n].key_off), - trie_string(trie, trie_node_values(trie, node)[n].value_off)); - return; + switch (option) { + case 's': + subsys = optarg; + break; } - - child = node_lookup_f(trie, node, search[i]); - node = child; - i++; } -} - -static void value_cb(struct trie_f *trie, const char *key, const char *value) { - /* TODO: add sub-matches (+) against DMI data */ - if (key[0] == ' ') - udev_builtin_add_property(trie->dev, trie->test, key + 1, value); -} - -static struct trie_f trie; - -static int hwdb_lookup(struct udev_device *dev, const char *subsys) { - struct udev_device *d; - const char *modalias; - char str[UTIL_NAME_SIZE]; - int rc = EXIT_SUCCESS; /* search the first parent device with a modalias */ for (d = dev; d; d = udev_device_get_parent(d)) { @@ -266,113 +94,35 @@ static int hwdb_lookup(struct udev_device *dev, const char *subsys) { if (!modalias) return EXIT_FAILURE; - trie_search_f(&trie, modalias, value_cb); - return rc; -} - -static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool test) { - static const struct option options[] = { - { "subsystem", required_argument, NULL, 's' }, - {} - }; - const char *subsys = NULL; - - if (!trie.f) - return EXIT_SUCCESS; - - for (;;) { - int option; - - option = getopt_long(argc, argv, "s", options, NULL); - if (option == -1) - break; - - switch (option) { - case 's': - subsys = optarg; - break; - } - } - - trie.dev = dev; - trie.test = test; - if (hwdb_lookup(dev, subsys) < 0) - return EXIT_FAILURE; + udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0)) + if (udev_builtin_add_property(dev, test, + udev_list_entry_get_name(entry), + udev_list_entry_get_value(entry)) < 0) + return EXIT_FAILURE; return EXIT_SUCCESS; } /* called at udev startup and reload */ static int builtin_hwdb_init(struct udev *udev) { - struct stat st; - const char sig[] = HWDB_SIG; - - if (trie.f) + if (hwdb) return 0; - - trie.f = fopen(SYSCONFDIR "/udev/hwdb.bin", "re"); - if (!trie.f) { - if (errno != EEXIST) - log_error("Error reading " SYSCONFDIR "/udev/hwdb.bin: %m"); - return -errno; - } - - if (fstat(fileno(trie.f), &st) < 0 || (size_t)st.st_size < offsetof(struct trie_header_f, strings_len) + 8) { - log_error("Error reading " SYSCONFDIR "/udev/hwdb.bin: %m"); - fclose(trie.f); - zero(trie); - return -EINVAL; - } - - trie.map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fileno(trie.f), 0); - if (trie.map == MAP_FAILED) { - log_error("Error mapping " SYSCONFDIR "/udev/hwdb.bin: %m"); - fclose(trie.f); - return -EINVAL; - } - trie.file_time_usec = ts_usec(&st.st_mtim); - trie.map_size = st.st_size; - - if (memcmp(trie.map, sig, sizeof(trie.head->signature)) != 0 || (size_t)st.st_size != le64toh(trie.head->file_size)) { - log_error("Unable to recognize the format of " SYSCONFDIR "/udev/hwdb.bin."); - log_error("Please try 'udevadm hwdb --update' to re-create it."); - munmap((void *)trie.map, st.st_size); - fclose(trie.f); - zero(trie); - return EINVAL; - } - - log_debug("=== trie on-disk ===\n"); - log_debug("tool version: %llu", (unsigned long long)le64toh(trie.head->tool_version)); - log_debug("file size: %8zi bytes\n", st.st_size); - log_debug("header size %8zu bytes\n", (size_t)le64toh(trie.head->header_size)); - log_debug("strings %8zu bytes\n", (size_t)le64toh(trie.head->strings_len)); - log_debug("nodes %8zu bytes\n", (size_t)le64toh(trie.head->nodes_len)); + hwdb = udev_hwdb_new(udev); + if (!hwdb) + return -ENOMEM; return 0; } /* called on udev shutdown and reload request */ static void builtin_hwdb_exit(struct udev *udev) { - if (!trie.f) - return; - munmap((void *)trie.map, trie.map_size); - fclose(trie.f); - zero(trie); + hwdb = udev_hwdb_unref(hwdb); } /* called every couple of seconds during event activity; 'true' if config has changed */ static bool builtin_hwdb_validate(struct udev *udev) { - struct stat st; - - if (!trie.f) - return false; - if (fstat(fileno(trie.f), &st) < 0) - return true; - if (trie.file_time_usec != ts_usec(&st.st_mtim)) - return true; - return false; + return udev_hwdb_validate(hwdb); } const struct udev_builtin udev_builtin_hwdb = { diff --git a/src/udev/udev-hwdb.h b/src/udev/udev-hwdb.h deleted file mode 100644 index 8a9955eb60..0000000000 --- a/src/udev/udev-hwdb.h +++ /dev/null @@ -1,69 +0,0 @@ -/*** - This file is part of systemd. - - Copyright 2012 Kay Sievers - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see . -***/ - -#include "sparse-endian.h" - -#define HWDB_SIG { 'K', 'S', 'L', 'P', 'H', 'H', 'R', 'H' } - -/* on-disk trie objects */ -_packed_ struct trie_header_f { - uint8_t signature[8]; - - /* version of tool which created the file */ - le64_t tool_version; - le64_t file_size; - - /* size of structures to allow them to grow */ - le64_t header_size; - le64_t node_size; - le64_t child_entry_size; - le64_t value_entry_size; - - /* offset of the root trie node */ - le64_t nodes_root_off; - - /* size of the nodes and string section */ - le64_t nodes_len; - le64_t strings_len; -}; - -_packed_ struct trie_node_f { - /* prefix of lookup string, shared by all children */ - le64_t prefix_off; - /* size of children entry array appended to the node */ - uint8_t children_count; - uint8_t padding[7]; - /* size of value entry array appended to the node */ - le64_t values_count; -}; - -/* array of child entries, follows directly the node record */ -_packed_ struct trie_child_entry_f { - /* index of the child node */ - uint8_t c; - uint8_t padding[7]; - /* offset of the child node */ - le64_t child_off; -}; - -/* array of value entries, follows directly the node record/child array */ -_packed_ struct trie_value_entry_f { - le64_t key_off; - le64_t value_off; -}; diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index ce8eff4811..5587094e63 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -27,7 +27,7 @@ #include "conf-files.h" #include "udev.h" -#include "udev-hwdb.h" +#include "libudev-hwdb-def.h" /* * Generic udev properties, key/value database based on modalias strings. @@ -35,7 +35,7 @@ */ static const char * const conf_file_dirs[] = { - SYSCONFDIR "/udev/hwdb.d", + "/etc/udev/hwdb.d", UDEVLIBEXECDIR "/hwdb.d", NULL }; @@ -291,7 +291,7 @@ static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node) { .children_count = node->children_count, .values_count = htole64(node->values_count), }; - struct trie_child_entry_f *children; + struct trie_child_entry_f *children = NULL; int64_t node_off; if (node->children_count) { @@ -390,12 +390,15 @@ static int trie_store(struct trie *trie, const char *filename) { } log_debug("=== trie on-disk ===\n"); - log_debug("size: %8zi bytes\n", size); + log_debug("size: %8llu bytes\n", (unsigned long long)size); log_debug("header: %8zu bytes\n", sizeof(struct trie_header_f)); - log_debug("nodes: %8zu bytes (%8zi)\n", t.nodes_count * sizeof(struct trie_node_f), t.nodes_count); - log_debug("child pointers: %8zu bytes (%8zi)\n", t.children_count * sizeof(struct trie_child_entry_f), t.children_count); - log_debug("value pointers: %8zu bytes (%8zi)\n", t.values_count * sizeof(struct trie_value_entry_f), t.values_count); - log_debug("string store: %8zu bytes\n", trie->strings->len); + log_debug("nodes: %8llu bytes (%8llu)\n", + (unsigned long long)t.nodes_count * sizeof(struct trie_node_f), (unsigned long long)t.nodes_count); + log_debug("child pointers: %8llu bytes (%8llu)\n", + (unsigned long long)t.children_count * sizeof(struct trie_child_entry_f), (unsigned long long)t.children_count); + log_debug("value pointers: %8llu bytes (%8llu)\n", + (unsigned long long)t.values_count * sizeof(struct trie_value_entry_f), (unsigned long long)t.values_count); + log_debug("string store: %8llu bytes\n", (unsigned long long)trie->strings->len); log_debug("strings start: %8llu\n", (unsigned long long) t.strings_off); out: free(filename_tmp); @@ -406,12 +409,14 @@ static int import_file(struct trie *trie, const char *filename) { FILE *f; char line[LINE_MAX]; char match[LINE_MAX]; + char cond[LINE_MAX]; f = fopen(filename, "re"); if (f == NULL) return -errno; match[0] = '\0'; + cond[0] = '\0'; while (fgets(line, sizeof(line), f)) { size_t len; @@ -421,6 +426,7 @@ static int import_file(struct trie *trie, const char *filename) { /* new line, new record */ if (line[0] == '\n') { match[0] = '\0'; + cond[0] = '\0'; continue; } @@ -433,9 +439,19 @@ static int import_file(struct trie *trie, const char *filename) { /* start of new record */ if (match[0] == '\0') { strcpy(match, line); + cond[0] = '\0'; continue; } + if (line[0] == '+') { + strcpy(cond, line); + continue; + } + + /* TODO: support +; skip the entire record until we support it */ + if (cond[0] != '\0') + continue; + /* value lines */ if (line[0] == ' ') { char *value; @@ -535,13 +551,12 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) { log_debug("strings incoming: %8zu bytes (%8zu)\n", trie->strings->in_len, trie->strings->in_count); log_debug("strings dedup'ed: %8zu bytes (%8zu)\n", trie->strings->dedup_len, trie->strings->dedup_count); - mkdir_parents(SYSCONFDIR "/udev/hwdb.bin", 0755); - err = trie_store(trie, SYSCONFDIR "/udev/hwdb.bin"); + mkdir_parents("/etc/udev/hwdb.bin", 0755); + err = trie_store(trie, "/etc/udev/hwdb.bin"); if (err < 0) { - log_error("Failure writing hardware database '%s': %s", SYSCONFDIR "/udev/hwdb.bin", strerror(-err)); + log_error("Failure writing hardware database '%s': %s", "/etc/udev/hwdb.bin", strerror(-err)); rc = EXIT_FAILURE; } - out: if (trie->root) trie_node_cleanup(trie->root); -- cgit v1.2.3-54-g00ecf From 924ee2cb0caa0c116ff6cf8c16f54588c4d4a4d8 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 3 Nov 2012 22:04:06 +0100 Subject: docs: gtk-doc warnings are annoying --- docs/gudev/Makefile.am | 2 +- docs/libudev/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/libudev') diff --git a/docs/gudev/Makefile.am b/docs/gudev/Makefile.am index 55172f2c33..57334b6ddc 100644 --- a/docs/gudev/Makefile.am +++ b/docs/gudev/Makefile.am @@ -43,7 +43,7 @@ MKHTML_OPTIONS=--path=$(abs_srcdir) --path=$(abs_builddir) # Extra options to supply to gtkdoc-fixref. Not normally needed. # e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html -FIXXREF_OPTIONS= +FIXXREF_OPTIONS=>/dev/null 2>&1 # Used for dependencies. The docs will be rebuilt if any of these change. # e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h diff --git a/docs/libudev/Makefile.am b/docs/libudev/Makefile.am index 6a346a653f..c6d7b8ca25 100644 --- a/docs/libudev/Makefile.am +++ b/docs/libudev/Makefile.am @@ -43,7 +43,7 @@ MKHTML_OPTIONS=--path=$(abs_srcdir) --path=$(abs_builddir) # Extra options to supply to gtkdoc-fixref. Not normally needed. # e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html -FIXXREF_OPTIONS= +FIXXREF_OPTIONS=>/dev/null 2>&1 # Used for dependencies. The docs will be rebuilt if any of these change. # e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h -- cgit v1.2.3-54-g00ecf