summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-hwdb/sd-hwdb.c
Commit message (Collapse)AuthorAgeFilesLines
* sd-hwdb: fix NULL arg to %s in error messagesZbigniew Jędrzejewski-Szmek2022-06-071-14/+10
| | | | | gcc warns about $subject, and it is obviously correct. path may or may not be set.
* sd-hwdb: add sd_hwdb_new_from_pathNick Rosbrook2022-05-271-14/+31
| | | | | | | | | | The existing sd_hwdb_new function always initializes the hwdb from the first successful hwdb.bin it finds from hwdb_bin_paths. This means there is currently no way to initialize a hwdb from an explicit path, which would be useful for systemd-hwdb query. Add sd_hwdb_new_from_path to allow a sd_hwdb to be initialized from a custom path outside of hwdb_bin_paths.
* core: check size before mmapTobias Stoeckmann2022-03-031-0/+4
| | | | | | | | | | | | | | | The data type off_t can be 64 on 32 bit systems if they have large file support. Since mmap expects a size_t with 32 bits as second argument truncation could occur. At worst these huge files could lead to mmaps smaller than the previous check for small files. This in turn shouldn't have a lot of impact because mmap allocates at page size boundaries. This also made the PAGE_ALIGN call in open_mmap unneeded. In fact it was neither in sync with other mmap calls nor with its own munmap counterpart in error path. If such large files are encountered, which is very unlikely in these code paths, treat them with the same error as if they are too small.
* Move hwdb creation code to src/shared/Zbigniew Jędrzejewski-Szmek2021-06-241-49/+0
| | | | | hwdb_update() is the main entry point, and it is called from "udevadm hwdb" and "systemd-hwdb", so it belongs in shared/.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* tree-wide: assorted coccinelle fixesFrantisek Sumsal2020-10-091-4/+4
|
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-041-1/+0
|
* sd-hwdb: use return value from ordered_hashmap_iterate()Zbigniew Jędrzejewski-Szmek2019-08-031-2/+1
| | | | Why not? Coverity CID#1402329.
* headers: remove unneeded includes from util.hZbigniew Jędrzejewski-Szmek2019-03-271-0/+2
| | | | | This means we need to include many more headers in various files that simply included util.h before, but it seems cleaner to do it this way.
* util: split out nulstr related stuff to nulstr-util.[ch]Lennart Poettering2019-03-141-1/+1
|
* sd-hwdb: fix off_t vs. size_t confusion in castZbigniew Jędrzejewski-Szmek2019-03-041-1/+1
| | | | > on 32bit, size_t is 32bit, but .st_size is off_t hence 64bit
* sd-hwdb: some minor logging and style updatesZbigniew Jędrzejewski-Szmek2019-03-041-12/+11
|
* sd-hwdb: use non-atomic reference countersZbigniew Jędrzejewski-Szmek2019-03-041-4/+3
| | | | | | The sd-hwdb objects cannot be used concurrently from two threads in any meaningful way, because query and iteration operations modify the object. Thus atomic reference counts are pointless.
* sd-hwdb: fix matching for characters with an ord > 127Peter Hutterer2019-02-131-1/+1
| | | | | | | | | | | Devices like the "Microsoft Microsoft® 2.4GHz Transceiver v9.0 Mouse" contain characters higher than 127. That ® is correctly stored in the hwdb and passed into the search field during query, but the comparison fails. Our search string is a const char *, trie_string() returns a const char * but the current character is cast to uint8_t. This causes anything over 127 to fail the match. Fix this, we're dealing with characters everywhere here after all.
* sd_hwdb: update log messagesYu Watanabe2018-10-241-6/+6
|
* sd-hwdb: update error log a bitYu Watanabe2018-10-091-1/+1
|
* sd-hwdb: adjust included headersYu Watanabe2018-09-191-0/+1
|
* libsystemd: use DEFINE_ATOMIC_REF_UNREF_FUNC or frineds where applicableYu Watanabe2018-08-281-16/+8
|
* sd-hwdb: drop unused variableYu Watanabe2018-08-281-1/+0
|
* tree-wide: drop empty lines in commentsYu Watanabe2018-07-231-1/+0
|
* tree-wide: drop copyright headers from frequent contributorsZbigniew Jędrzejewski-Szmek2018-06-201-2/+0
| | | | | | | | Fixes #9320. for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms' done
* tree-wide: beautify remaining copyright statementsLennart Poettering2018-06-141-3/+3
| | | | | | Let's unify an beautify our remaining copyright statements, with a unicode ©. This means our copyright statements are now always formatted the same way. Yay.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-04-051-2/+1
|
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* build-sys: use #if Y instead of #ifdef Y everywhereZbigniew Jędrzejewski-Szmek2017-10-041-1/+1
| | | | | | | | | | | | | | | The advantage is that is the name is mispellt, cpp will warn us. $ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/" $ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;' $ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g' $ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g' + manual changes to meson.build squash! build-sys: use #if Y instead of #ifdef Y everywhere v2: - fix incorrect setting of HAVE_LIBIDN2
* sd-hwdb: drop caching of search stringZbigniew Jędrzejewski-Szmek2016-11-301-23/+1
| | | | | We have only two callers, and for neither this "optimization" is useful. So let's drop it an save some code and a malloc.
* hwdb, sd-hwdb: rework priority comparison when loading propertiesZbigniew Jędrzejewski-Szmek2016-11-301-4/+32
| | | | | | | | | | | | | | | | | | | | | | | We cannot compare filenames directly, because paths are not sortable lexicographically, e.g. /etc/udev is "later" (has higher priority) than /usr/lib/udev. The on-disk format is changed to have a separate field for "file priority", which is stored when writing the binary file, and then loaded and used in comparisons. For data in the previous format (as generated by systemd 232), this information is not available, and we use a trick where the offset into the string table is used as a proxy for priority. Most of the time strings are stored in the order in which the files were processed. This is not entirely reliable, but is good enough to properly order /usr/lib and /etc/, which are the two most common cases. This hack is included because it allows proper parsing of files until the binary hwdb is regenerated. Instead of adding a new field, I reduced the size of line_number from 64 to 32 bits, and added a 16 bit priority field, and 16 bits of padding. Adding a new field of 16 bytes would significantly screw up alignment and increase file size, and line number realistically don't need more than ~20 bits. Fixes #4750.
* Two small cleanupsZbigniew Jędrzejewski-Szmek2016-11-291-1/+1
|
* hwdb: use systemd-hwdb instead of obsolete udevadm hwdb (#4722)Michael Biebl2016-11-231-1/+1
| | | Fixes: #4721
* sd-hwdb: order properties by originDavid Herrmann2016-09-211-15/+28
| | | | | | | | | | | If we find duplicates in a property-lookup, make sure to order them by their origin. That is, matches defined "later" take precedence over earlier matches. The "later"-order is defined by file-name + line-number combination. That is, if a match is defined below another one in the same hwdb file, it takes precedence, same as if it is defined in a file ordered after another one. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
* sd-hwdb: fix child/value offset calculationDavid Herrmann2016-09-211-9/+14
| | | | | | | | | It is not legal to use hard-coded types to calculate offsets. We must always use the offsets of the hwdb header to calculate those. Otherwise, we will break horribly if run on hwdb files written by other implementations or written with future extensions. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
* tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easyLennart Poettering2015-11-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GLIB has recently started to officially support the gcc cleanup attribute in its public API, hence let's do the same for our APIs. With this patch we'll define an xyz_unrefp() call for each public xyz_unref() call, to make it easy to use inside a __attribute__((cleanup())) expression. Then, all code is ported over to make use of this. The new calls are also documented in the man pages, with examples how to use them (well, I only added docs where the _unref() call itself already had docs, and the examples, only cover sd_bus_unrefp() and sd_event_unrefp()). This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we tend to call our destructors these days. Note that this defines no public macro that wraps gcc's attribute and makes it easier to use. While I think it's our duty in the library to make our stuff easy to use, I figure it's not our duty to make gcc's own features easy to use on its own. Most likely, client code which wants to make use of this should define its own: #define _cleanup_(function) __attribute__((cleanup(function))) Or similar, to make the gcc feature easier to use. Making this logic public has the benefit that we can remove three header files whose only purpose was to define these functions internally. See #2008.
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-0/+1
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* util-lib: split our string related calls from util.[ch] into its own file ↵Lennart Poettering2015-10-241-6/+6
| | | | | | | | | | | | | | string-util.[ch] There are more than enough calls doing string manipulations to deserve its own files, hence do something about it. This patch also sorts the #include blocks of all files that needed to be updated, according to the sorting suggestions from CODING_STYLE. Since pretty much every file needs our string manipulation functions this effectively means that most files have sorted #include blocks now. Also touches a few unrelated include files.
* util: introduce safe_fclose() and port everything over to itLennart Poettering2015-09-091-2/+1
| | | | Adds a coccinelle script to port things over automatically.
* tree-wide: we place the opening bracket on the same line as the function nameLennart Poettering2015-08-271-7/+6
| | | | Let's do this everywhere the same way.
* hashmap: fix iterators to not skip entriesDavid Herrmann2015-06-141-2/+3
| | | | | | | | | | | | | | | Currently, the HASHMAP iterators stop at the first NULL entry in a hashmap. This is non-obvious and breaks users like sd-device, which legitimately store NULL values in a hashmap. Fix all the iterators by taking a pointer to the value storage, instead of returning it. The iterators now return a boolean that tells whether the end of the list was reached. Current users of HASHMAP_FOREACH() are *NOT* changed to explicitly check for NULL. If it turns out, there were users that inserted NULL into hashmaps, but didn't properly check for it during iteration, then we really want to find those and fix them.
* fix double semicolon typoThomas Hindoe Paaboel Andersen2015-06-021-1/+1
|
* remove unused includesThomas Hindoe Paaboel Andersen2015-02-231-2/+0
| | | | | | This patch removes includes that are not used. The removals were found with include-what-you-use which checks if any of the symbols from a header is in use.
* Assorted format fixesZbigniew Jędrzejewski-Szmek2015-01-221-1/+1
| | | | | Types used for pids and uids in various interfaces are unpredictable. Too bad.
* refcnt: refcnt is unsigned, fix comparisonsTom Gundersen2015-01-131-1/+1
| | | | This does not make a difference, but the code was confusing.
* libsystemd: add sd-hwdb libraryTom Gundersen2014-12-111-0/+471
This is libudev-hwdb, but decoupled from libudev and in the libsystemd style. The core code is unchanged, apart from the following minor changes: - hwdb.bin located in /**/systemd/hwdb/ take preference over the ones located in /**/udev/ - properties are stored internally in an OrderedHashmap, rather than a linked list. - a new API call allows individual properties to be queried directly, rather than iterating over them all - the iteration over properties have been moved inside the library, rather than exposing a list directly - the unused 'flags' parameter was dropped