Commit Graph

78 Commits

Author SHA1 Message Date
Lennart Poettering 66e405837b tree-wide: make more code use safe_close()
Replace this:

        close(fd);
        fd = -1;

write this:

        fd = safe_close(fd);
2015-09-09 08:20:19 +02:00
Tom Gundersen bbf3520673 udev: event - simplify udev_event_spawn() logic
Push the extraction of the envp + argv as close as possible to their use, to avoid code
duplication. As a sideeffect fix logging when delaing execution.
2015-06-29 19:51:04 +02:00
Tom Gundersen f6e0a35376 udev: event - check return code of dup2()
This fixes CID#1304688.
2015-06-23 17:20:12 +02:00
Kay Sievers 15daf6a834 Merge pull request #144 from teg/udev-spawn-log-less-2
udevd: event - don't log about failures of spawn processes when this …
2015-06-14 20:19:54 +02:00
Tom Gundersen 1c4baffc18 sd-netlink: rename from sd-rtnl 2015-06-13 19:52:54 +02:00
Tom Gundersen 53318514cc udevd: event - don't log about failures of spawn processes when this is expected
PROGRAM and IMPORT{program} uses the exit code of the spawn process to decide if a rule matches or not,
a failing process is hence normal operation and not something we should warn about.

We still warn about other types of failing processes.
2015-06-10 17:55:53 +02:00
Thomas Hindoe Paaboel Andersen 920b52e490 tree-wide: remove spurious space 2015-06-08 23:11:26 +02:00
Tom Gundersen 8314de1d81 udevd: simplify signal mask handling
We used to block all signals, and restore the original signal mask before exec'ing
external processes.

Now we just block the signals we care about and unconditionally unblock all signals
before exec'ing.
2015-06-03 01:41:34 +02:00
Tom Gundersen 3b64e4d4f4 udev: add some asserts
Mostly for documentation purposes.
2015-06-02 18:12:47 +02:00
Lennart Poettering 24882e06c1 util: split out signal-util.[ch] from util.[ch]
No functional changes.
2015-05-29 20:14:11 +02:00
Tom Gundersen 8128f2297d udevd: event - port spawn_wait() to sd-event
This allows us to drop the special sigterm handling in spawn_wait()
as this will now be passed directly to the worker event loop.

We now log failing spawend processes at 'warning' level, and timeouts
are in terms of CLOCK_BOOTTIME when available, otherwise the behavior
is unchanged.
2015-05-29 18:52:13 +02:00
Tom Gundersen 107f2e2526 udevd: fix REMOVE handling
This reverts b67f944. Lazy loading of device properties does not work for devices
that are received over netlink, as these are sealed. Reinstate the unconditional
loading of the device db.

Reported by: Mantas Mikulėnas <grawity@gmail.com>.
2015-04-23 22:31:25 +02:00
Tom Gundersen 353f605867 udev: event - update tags before writing out db
The old tags are read from the db when deciding which tags to clear,
make sure we don't write out the new db before the old one has been
read.
2015-04-23 22:31:25 +02:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
Tom Gundersen 1b14c3cfbe udev: make set_usec_initialized() internal to libudev
Instead introduce ensure_usec_initialized(), which copies the timestamp if possible otherwise
sets it to now(CLOCK_MONOTONIC).
2015-03-13 18:47:07 +01:00
Tom Gundersen 8f0f13f045 libudev: introduce clone_with_db()
This allows us to move the db reading from udevd to libudev.
2015-03-12 12:03:50 +01:00
Tom Gundersen 3c0bab4aaf udevd: event - make db loading lazy in REMOVE event handling
We were explicitly eagerly loading the db, then deletenig the backing file and then processing the
rules/symlinks. Instead we delete the backnig db file as the last step and let the db loading be
lazy as everywhere else.

This may save us a bit of work in casese where the db is not needed, but more importantly it hides
some implementation details of libudev-device form udevd.
2015-03-12 12:03:50 +01:00
Tom Gundersen 1cd0a77022 libudev: introduce udev_device_properties_copy()
To copy properties from one device to another. Drop the equivalent functionality from udevd.
2015-03-12 11:59:04 +01:00
Tom Gundersen b94da8cf72 libudev: add missing hunks
This should have been committed with
  udev_device_add_property - implicitly mark properties for saving to db
2015-03-09 23:36:27 +01:00
Tom Gundersen 570b83cc62 libudev: udev_device_read_db - drop unused argument 2015-03-09 23:27:12 +01:00
Tom Gundersen 3738cc858d udev/libudev: event - move {OLD_,}INTERFACE handling from udevd to libudev
This should be internal to the library as it is only about reflecting the sysfs state in the udev_device.
2015-03-09 22:50:44 +01: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
Thomas Hindoe Paaboel Andersen 0a6f50c0af include <poll.h> instead of <sys/poll.h>
include-what-you-use automatically does this and it makes finding
unnecessary harder to spot. The only content of poll.h is a include
of sys/poll.h so should be harmless.
2015-02-12 20:47:38 +01:00
Tom Gundersen 04ef387ea9 udev: event - minor nit
Stay uniform and use 'dev' rather than 'event->dev', as these are aliases (and event->dev looks
like it may be a typo for event->dev_db).
2015-01-26 14:13:31 +01:00
Tom Gundersen fa639f3ae7 udev: event - introduce and use internal udev_device_shallow_clone() 2015-01-26 14:12:45 +01:00
Tom Gundersen 243d182543 udev: event - move renaming of udev_device to libudev
This is not exposed in the public API. We want to simplify the internal libudev-device API as much as possible
so that it will be simpler to rip the whole thing out in the future.
2015-01-26 13:33:00 +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
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01:00
Lennart Poettering 755bde375f udev,update-done: more log_xyz_errno() conversions 2014-11-28 16:32:26 +01:00
Michal Schmidt ff49bc3212 treewide: drop unnecessary trailing \n in log_*() calls 2014-11-28 14:26:31 +01:00
Kay Sievers adeba5008e udev: support ENV{}=="" global property matches 2014-11-13 20:35:06 +01:00
Kay Sievers 25e773eeb4 udev: switch to systemd logging functions 2014-11-13 13:12:57 +01:00
Robert Milasan 572016d1c2 udev: fix path for database names on 'change' event
If a device does not have a major/minor number attached, we use different
database names than if it does. On "change" events, we didn't copy the
devnum over, therefore, we used different paths than on 'add' or 'remove'
events (where devnum was properly copied).

Fix this by always copying the devnum into the udev-device.

(David: added commit-log from email)
2014-09-18 15:28:07 +02:00
Tom Gundersen 19c784c414 udev: event - modernize spawn_exec() 2014-09-17 22:19:53 +02:00
Tom Gundersen 3f796750b1 udev: event - explicitly don't read() from invalid fd
This fixes CID #1237641.
2014-09-17 22:19:53 +02:00
Tom Gundersen 4cd5d5adb6 udev: event - modernize spawn_read() 2014-09-17 22:19:53 +02:00
Tom Gundersen 6711741365 udev: timeout - warn after a third of the timeout before killing 2014-09-11 23:45:01 +02:00
Tom Gundersen 1187f20655 udev: netif_rename - don't log to kmsg
As of 3.17, the kernel will do this on its own, so just do regular log_debug() logging from udev.
2014-09-09 22:45:03 +02:00
Tom Gundersen 4c83d99456 udev: event - keep one rtnl per worker, rather than per event
Creating the rtnl context is cheap, but freeing it may not be, due to
synchronous close().

Also drop some excessive logging. We now log about the changing ifname
exactly once.
2014-09-09 15:30:10 +02:00
Tom Gundersen b081b27e14 udev: import the full db on MOVE events for devices without dev_t 2014-09-09 15:03:49 +02:00
Kay Sievers 9ec6e95b04 udev: place opening { at the same line as the function declaration 2014-07-29 15:49:25 +02:00
Kay Sievers dd5eddd28a udev: unify event timeout handling 2014-07-29 15:18:27 +02:00
Kay Sievers 1ea972174b udev: do not skip the execution of RUN when renaming a network device fails 2014-05-15 10:32:26 +02:00
Tom Gundersen 1514d70819 udev: rename netif - properly break lines in kmsg
Before:

30,997,4553484,-;systemd-udevd[439]: renamed network interface wwan0 to wwp0s20u4i6systemd-udevd[439]: renamed network interface wlan0 to wlp3s0
30,998,1175077801,c;systemd-udevd[2345]: renamed network interface wwan0 to wwp0s20u4i6

After:

30,834,4553484,-;systemd-udevd[439]: renamed network interface wwan0 to wwp0s20u4i6
30,835,4732949,-;systemd-udevd[439]: renamed network interface wlan0 to wlp3s0
30,988,1175077801,-;systemd-udevd[2345]: renamed network interface wwan0 to wwp0s20u4i6
2014-05-13 12:44:22 +02:00
Lukas Nykryn 66390abefa udev: properly detect reference to unexisting part of PROGRAM's result 2014-03-11 13:18:13 +01:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +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
Lennart Poettering cf6a891173 rtnl: drop "sd_" prefix from cleanup macros
The "sd_" prefix is supposed to be used on exported symbols only, and
not in the middle of names. Let's drop it from the cleanup macros hence,
to make things simpler.

The bus cleanup macros don't carry the "sd_" either, so this brings the
APIs a bit nearer.
2014-02-13 03:44:14 +01:00
Greg KH 29804cc1e0 use memzero(foo, length); for all memset(foo, 0, length); calls
In trying to track down a stupid linker bug, I noticed a bunch of
memset() calls that should be using memzero() to make it more "obvious"
that the options are correct (i.e. 0 is not the length, but the data to
set).  So fix up all current calls to memset(foo, 0, length) to
memzero(foo, length).
2014-01-31 11:55:01 +01:00