Commit Graph

51 Commits

Author SHA1 Message Date
Lennart Poettering 62d74c78b5 coccinelle: add reallocarray() coccinelle script
Let's systematically make use of reallocarray() whereever we invoke
realloc() with a product of two values.
2018-03-02 12:39:07 +01:00
Yu Watanabe 5639df9a80 udevadm: getopt() and help message cleanup
This adds missing options, mainly '--version' in getopt(), removes
an unused option from getopt().
Also, this adds a deprecate message in `udevadm hwdb`, and cleanups
help messages.

Follow-up for 65eb4378c3.
2017-12-05 23:30:10 +09:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lennart Poettering b50846055e exec-util,conf-files: skip non-executable files in execute_directories()
Fixes: #6787
2017-09-13 11:42:31 +02:00
Alan Jenkins 0675e94ab5 "Don't fear the fsync()"
For files which are vital to boot

1. Avoid opening any window where power loss will zero them out or worse.
   I know app developers all coded to the ext3 implementation, but
   the only formal documentation we have says we're broken if we actually
   rely on it.  E.g.

   * `man mount`, search for `auto_da_alloc`.
   * http://www.linux-mtd.infradead.org/faq/ubifs.html#L_atomic_change
   * https://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/

2. If we tell the kernel we're interested in writing them to disk, it will
   tell us if that fails.  So at minimum, this means we play our part in
   notifying the user about errors.

I refactored error-handling in `udevadm-hwdb` a little.  It turns out I did
exactly the same as had already been done in the `systemd-hwdb` version,
i.e. commit d702dcd.
2017-08-17 20:26:36 +01:00
Zbigniew Jędrzejewski-Szmek 948aaa7c52 tree-wide: standardize on $(PACKAGE_VERSION) for the version string
We defined both $(VERSION) and $(PACKAGE_VERSION) with the same contents.
$(PACKAGE_VERSION) is slightly more descriptive, so settle on that, and
drop the other define.
2017-04-04 20:36:09 -04:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Michal Sekletar 905c37e60e udevadm: explicitly relabel /etc/udev/hwdb.bin after rename (#3686)
This is basically the same change as ea68351.
2016-07-08 17:43:05 +02:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Zbigniew Jędrzejewski-Szmek 3f65d73149 udev: add emacs header line
Otherwise emacs wants to use 2-space indentation and other
attrocities.
2015-12-07 00:45:08 -05:00
Lennart Poettering 4afd3348c7 tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
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.
2015-11-27 19:19:36 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering f4f15635ec util-lib: move a number of fs operations into fs-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 0d39fa9c69 util-lib: move more file I/O related calls into fileio.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file 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.
2015-10-24 23:05:02 +02:00
Lennart Poettering efbea94798 Revert "hwdb: actually search /run/udev/hwdb.d" 2015-06-09 11:26:06 +02:00
Peter Hutterer 03dfe7b749 hwdb: actually search /run/udev/hwdb.d
The documentation claims hwdb entries may be placed in the volatile
/run/udev/hwdb.d directory but nothing actually looked at it.
2015-06-09 11:52:10 +10:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
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.
2015-02-23 23:53:42 +01:00
Zbigniew Jędrzejewski-Szmek 1fa2f38f0f Assorted format fixes
Types used for pids and uids in various interfaces are unpredictable.
Too bad.
2015-01-22 01:14:52 -05:00
Tom Gundersen 65eb4378c3 systemd-hwdb: introduce new tool
This pulls out the hwdb managment from udevadm into an independent tool.

The old code is left in place for backwards compatibility, and easy of
testing, but all documentation is dropped to encourage use of the new
tool instead.
2014-12-18 15:37:27 +01:00
Tom Gundersen d640c07d97 udevadm: port to sd-hwdb 2014-12-15 20:40:09 +01:00
Tom Gundersen 8b516fdea7 libudev: make libudev-hwdb a wrapper around sd-hwdb 2014-12-11 13:54:35 +01:00
Peter Hutterer 36afca67b6 udevadm hwdb: discard extra leading whitespaces in hwdb
Currently a property in the form of
  FOO=bar
is stored as " FOO=bar", i.e. the property name contains a leading space.
That's quite hard to spot.

This patch discards all extra whitespaces but the first one which is required
by libudev's hwdb_add_property.

[zj: modify the check a bit]

https://bugs.freedesktop.org/show_bug.cgi?id=82311
2014-11-28 14:30:50 -05:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Martin Pitt 33488f1979 udev hwdb: Support shipping pre-compiled database in system images
In some cases it is preferable to ship system images with a pre-generated
binary hwdb database, to avoid having to build it at runtime, avoid shipping
the source hwdb files, or avoid storing large binary files in /etc.

So if hwdb.bin does not exist in /etc/udev/, fall back to looking for it in
UDEVLIBEXECDIR. This keeps the possibility to add files to /etc/udev/hwdb.d/
and re-generating the database which trumps the one in /usr/lib.

Add a new --usr flag to "udevadm hwdb --update" which puts the database
into UDEVLIBEXECDIR.

Adjust systemd-udev-hwdb-update.service to not generate the file in /etc if we
already have it in /usr.
2014-10-28 14:28:18 +01:00
Tom Gundersen f901aaadd6 udevadm: hwdb - check return value of fseeko()
Fonud by Coverity. Fixes CID #996255.
2014-09-18 19:16:54 +02:00
Lennart Poettering d4f1ef4437 udev: make sure we always return a valid error code in trie_store() 2014-02-19 17:53:50 +01:00
Lennart Poettering 955d98c9c1 everywhere: make use of new0() and macro() macros, and stop using perror() 2014-02-13 14:45:51 +01:00
Zbigniew Jędrzejewski-Szmek 90b2de37b8 Update some message formats
Use PID_FMT/USEC_FMT/... in more places.

Also update logind error messages to print the full path to a file that
failed. This should make debugging easier for people who do not know
off the top of their head where logind stores it state.
2014-02-05 19:00:36 -05:00
Lennart Poettering 9f6445e34a log: log_error() and friends add a newline after each line anyway, so avoid including it in the log strings 2013-12-24 16:39:37 +01:00
Zbigniew Jędrzejewski-Szmek 7643ac9a8a udevadm,scsi_id: add short options to help strings and to the man page
Also clean things up a bit here and there.
2013-12-18 23:58:23 -05:00
Zbigniew Jędrzejewski-Szmek 872c8faaf2 Fix write-only use of a few variables
Since the invention of read-only memory, write-only memory has been
considered deprecated. Where appropriate, either make use of the
value, or avoid writing it, to make it clear that it is not used.
2013-10-13 17:56:54 -04:00
Zbigniew Jędrzejewski-Szmek ef89eef77e udev: fix two trivial memleaks in error path
Based-on-a-patch-by: Ian Stakenvicius <axs@gentoo.org>
2013-07-19 09:57:04 -04:00
Kay Sievers 06639c0940 hwdb: allow list of lookup keys per given record
This allows to specify:
  dmi:bvn*:bvr*:bd*:svnVENDOR:pn:Model 231*:pvr*
  dmi:bvn*:bvr*:bd*:svnVENDOR:pn:Series 12*:pvr*
   KEY_A=value
   KEY_B=value

Instead of:
  dmi:bvn*:bvr*:bd*:svnVENDOR:pn:Model 231*:pvr*
   KEY_A=value
   KEY_B=value

  dmi:bvn*:bvr*:bd*:svnVENDOR:pn:Series 12*:pvr*
   KEY_A=value
   KEY_B=value
2013-07-10 15:05:05 +02:00
Kay Sievers 3cf7b686e6 hwdb: remove support for (not fully implemented) conditional properties 2013-07-01 19:39:50 +02:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Zbigniew Jędrzejewski-Szmek 8c62ecf1a9 udevadm: do not free node on success
A fix for ff03aed06a.
2013-04-05 17:39:13 -04:00
Zbigniew Jędrzejewski-Szmek ff03aed06a udevadm-hwdb: avoid leak in error path 2013-04-04 22:46:19 -04:00
Zbigniew Jędrzejewski-Szmek 844ec79b3c catalog: open up catalog internals
In order to write tests for the catalog functions, they
are made non-static and start taking a 'database' parameter,
which is the name of a file with the preprocessed catalog
entries.

This makes it possible to make test-catalog part of the
normal test suite, since it now only operates on files
in /tmp.

Some more tests are added.
2013-03-28 23:45:59 -04:00
Kay Sievers 3e49f2ecb5 udev: udevadm hwdb - add --root=
https://bugs.freedesktop.org/show_bug.cgi?id=60398
2013-02-08 12:00:05 +01:00
Kay Sievers 7850b3b837 shared: conf-files - add root parameter 2013-02-08 10:23:04 +01:00
Kay Sievers beb23689e3 udev: remove HWDB_BIN 2013-02-07 21:54:49 +01:00
Tom Gundersen e32a4e1ef4 hwdb: fix usage
--create is not a valid option.
2012-11-21 02:49:24 +01:00
Zbigniew Jędrzejewski-Szmek ee623f0d0c hwdb: use $(localstatedir)/lib/udev/hwdb.bin for the binary database
It's not configuration, so it doesn't belong in udev.

Also, remove the catalog when uninstalling udev.
2012-11-16 23:29:56 +01:00
Kay Sievers 1298001ec5 use the same email address everywhere 2012-11-12 19:47:43 +01:00
Kay Sievers 3a4431ef72 udev: break over-long lines 2012-11-02 00:32:10 +01:00
Kay Sievers 23b7245397 udev: add "udevadm hwdb --test=<modalias>" 2012-10-28 04:41:15 +01:00
Kay Sievers 2001208c2a libudev: import hwdb and export lookup interface 2012-10-27 23:39:41 +02:00
Kay Sievers c225f2ffc8 udev: hwdb - properly initialize search structure 2012-10-25 21:44:33 +02:00