Commit graph

140 commits

Author SHA1 Message Date
Tom Gundersen 9c2dabd05f udevd: worker - move some fields from the worker to the event 2015-05-06 18:35:55 +02:00
Tom Gundersen 39c19cf13a udevd: worker - introduce worker_attach_event() 2015-05-06 18:35:55 +02:00
Tom Gundersen 3a19b32a67 udevd: worker - make refcounting clearer
Take and drop explicit references where it makes sense.
2015-05-06 18:35:55 +02:00
Tom Gundersen e03c7cc26e udevd: worker - only allocate the worker struct in the main process
This is not used in the worker, so avoid having to free it there.
2015-05-06 18:35:55 +02:00
Tom Gundersen f96a5160c4 udevd: rename worker_new() to worker_spawn() 2015-05-06 18:35:55 +02:00
Tom Gundersen 4914cb2ddc udevd: don't track worker exitcode
We used to use this to track failed events so they could be retriggered,
but that is no longer done, so the code can be dropped.
2015-05-06 18:35:55 +02:00
Tom Gundersen b66f29a1ea udevd: worker - log if worker result cannot be sent
If the main daemon is not notified about a worker finishing an event
the refcounting of the worker struct will be wrong, and we will lose
track of the number of children we have to wait for.

This should not happen, but if it does we better complain loudly about
it. Worst case udev will wait for 30 seconsd at shutdown waiting for
nonexistent workers.
2015-04-24 20:36:05 +02:00
Tom Gundersen c0bbfd72e7 udevd: worker - warn if unknown worker returns 2015-04-24 20:18:49 +02:00
Tom Gundersen 979558f322 udevd: worker - let the kernel attach the sender pid
No need to include this explicitly, just use SCM_CREDENTIALS.
2015-04-24 20:18:49 +02:00
Tom Gundersen e2f8d97a13 udevd: don't unref worker objects on SIGSTOP/SIGCONT
We should not be receiving these anyway, but let's be correct.
2015-04-24 19:13:48 +02:00
Tom Gundersen d1317d02e6 udevd: warn if we receive SIGCHLD from untracked worker 2015-04-24 19:13:48 +02:00
Tom Gundersen 70a93737ec udevd: improve logging in SIGCHLD handling
Remove some redundant logging, and reduce the log-level in most cases. The only
case that is really critical is if a worker failed while hanlding an event, so
keep that at error level.
2015-04-24 19:13:48 +02:00
Daniel Drake 07ba8037bf udevd: fix synchronization with settle when handling inotify events
udev uses inotify to implement a scheme where when the user closes
a writable device node, a change uevent is forcefully generated.
In the case of block devices, it actually requests a partition rescan.

This currently can't be synchronized with "udevadm settle", i.e. this
is not reliable in a script:

 sfdisk --change-id /dev/sda 1 81
 udevadm settle
 mount /dev/sda1 /foo

The settle call doesn't synchronize there, so at the same time we try
to mount the device, udevd is busy removing the partition device nodes and
readding them again. The mount call often happens in that moment where the
partition node has been removed but not readded yet.

This exact issue was fixed long ago:
http://git.kernel.org/cgit/linux/hotplug/udev.git/commit/?id=bb38678e3ccc02bcd970ccde3d8166a40edf92d3

but that fix is no longer valid now that sequence numbers are no longer
used.

Fix this by forcing another mainloop iteration after handling inotify events
before unblocking settle. If the inotify event caused us to generate a
"change" event, we'll pick that up in the following loop iteration, before
we reach the end of the loop where we respond to settle's control message,
unblocking it.
2015-04-11 13:10:52 +02:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
Tom Gundersen 401cb61499 sd-device,udevd: fix spelling /ammend/amend/ 2015-04-03 22:51:09 +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
David Herrmann ca2031fcc8 udev: dont use EWOULDBLOCK
EWOULDBLOCK is the same as EAGAIN, stop using it.
2015-03-13 14:09:55 +01:00
Tom Gundersen 6969c349df udevd: improve handling of failed worker
The information in the db is stale, so it does not make sense to
expose it any longer. Also, don't drop the kernel event, but simply
pass it on to userspace without ammending it.
2015-03-12 12:03:50 +01:00
Tom Gundersen 090b6bc520 udevd: don't free event when killing the worker, wait until it has been reaped
This will allow us to clean up the device when we are notified about the worker being killed.
2015-03-12 12:03:50 +01:00
Tom Gundersen dfc4b6acf0 udev: simplify event_queue_update() and add debug logging
This essentially replaces
  open("/run/udev/queue", O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444)
with
  open("/run/udev/queue", O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0644),
which is ok for our purposes.
2015-03-09 22:38:51 +01:00
Tom Gundersen db93e063bd udevd: close race in udev settle
The udev-settle guarantees that udevd is no longer processing any of the
events casued by udev-trigger. The way this works is that it sends a
synchronous PING to udevd after udev-trigger has ran, and when that returns
it knows that udevd has started processing the events from udev-trigger.
udev-settle will then wait for the event queue to empty before returning.

However, there was a race here, as we would only update the /run state at
the beginning of the event loop, before reading out new events and before
processing the ping.

That means that if the first uevent arrived in the same event-loop iteration
as the PING, we would return the ping before updating the queue state in /run
(which would happen on the next iteration).

The race window here is tiny (as the /run state would probably get updated
before udev-settle got a chance to read /run), but still a possibility.

Fix the problem by updating the /run state as the last step before returning
the PING.

We must still update it at the beginning of the loop as well, otherwise we
risk being stuck in poll() with a stale state in /run.

Reported-by: Daniel Drake <drake@endlessm.com>
2015-03-09 17:55:16 +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
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
Lennart Poettering 5ac0162c3a udevadm,..: make --help output of udev tools more like the output of the various other tools 2015-01-05 13:19:55 +01:00
Lennart Poettering d7b8eec7dc tmpfiles: add new line type 'v' for creating btrfs subvolumes 2014-12-28 02:08:40 +01:00
Shawn Paul Landden 0254e9448f util: fix strict aliasing violations in use of struct inotify_event v5
There is alot of cleanup that will have to happen to turn on
-fstrict-aliasing, but I think our code should be "correct" to the rule.
2014-12-24 16:53:04 +01:00
Lennart Poettering f7c1ad4fd4 core: unify how we iterate over inotify events
Let's add some syntactic sugar for iterating through inotify events, and
use it everywhere.
2014-12-10 01:48:39 +01:00
Tom Gundersen 523c620bcd udevd: don't take reference for NULL rtnl object 2014-12-03 21:36:10 +01: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
Tom Gundersen 6872b0ddc4 udevd: don't set receive buffer size when socket activated
The socket unit does this, so no need to redo it in udevd.
2014-11-28 17:41:58 +01:00
Michal Schmidt ff49bc3212 treewide: drop unnecessary trailing \n in log_*() calls 2014-11-28 14:26:31 +01: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
Kay Sievers adeba5008e udev: support ENV{}=="" global property matches 2014-11-13 20:35:06 +01:00
Kay Sievers 41b848b0ea udev: move global property handling from libudev to udevd 2014-11-13 13:50:01 +01:00
Kay Sievers 25e773eeb4 udev: switch to systemd logging functions 2014-11-13 13:12:57 +01:00
Lennart Poettering b5884878a2 util: simplify proc_cmdline() to reuse get_process_cmdline()
Also, make all parsing of the kernel cmdline non-fatal.
2014-11-07 01:19:56 +01:00
Harald Hoyer 3f85ef0f05 s/commandline/command line/g 2014-11-06 15:34:18 +01:00
David Herrmann cfe2061add udev: avoid magic constants in kernel-cmdline parsers
Lets recognize the fact that startswith() returns a pointer to the tail on
success. Use it instead of hard-coding string-lengths as magic constants.
2014-11-05 12:58:10 +01:00
Richard W.M. Jones f671774f52 udev: Fix parsing of udev.event-timeout kernel parameter. 2014-11-05 12:58:10 +01:00
WaLyong Cho cc56fafeeb mac: rename apis with mac_{selinux/smack}_ prefix 2014-10-23 17:13:15 +02:00
Tom Gundersen 25773e7fc5 udevd: don't fail if /run/udev exists 2014-09-18 21:57:49 +02:00
Tom Gundersen 65fea570f0 udev: fix typos
Spotted by Andreas Henriksson.
2014-09-18 20:25:33 +02:00
Tom Gundersen d457ff8319 udevd: check return of various functions
One reported by Coverity. Fixes CID #996252.
2014-09-18 19:10:23 +02:00
Tom Gundersen 6f5cf8a8b1 udevd: parse_argv - warn if argumens are invalid
Found by Coverity. Fixes CID #1238780.
2014-09-18 19:02:42 +02:00
Tom Gundersen f1e8664e4a udevd: use safe_ato*() in place of strto*() 2014-09-16 12:12:56 +02:00
Tom Gundersen 4d6dac13ad udev: apply permissions to static nodes before signallying READY
Processes expecting static nodes to have the right permissions may order themselves after systemd-udevd.service,
make sure that actually guarantees what is expected.
2014-09-16 12:12:56 +02:00
Tom Gundersen ebc164ef40 udev: only print after final log level has been determined
This delays label_init(), and drops the (duplicate) printing of version
information.
2014-09-16 12:12:56 +02:00
Tom Gundersen 3f56f784b9 udevd: initialize epoll_event structs on allocation
Also move the rest of event initialization next to the event loop (no functional change).
2014-09-16 12:12:56 +02:00