Commit graph

259 commits

Author SHA1 Message Date
Lidong Zhong e14b6f211c udev: fix parameter process 2015-07-24 16:39:55 +08:00
Michal Schmidt 3567afa5b4 udev: unify reporting of invalid cmdline keys
This way it does not need distinct string literals and it also preserves
the "rd." prefix.
2015-07-21 20:07:34 +02:00
Michal Schmidt e00f5bddde udev: fix crash with invalid udev.log-priority
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1245293
2015-07-21 20:07:34 +02:00
Daniel Mack ad118bda15 tree-wide: fix write_string_file() user that should not create files
The latest consolidation cleanup of write_string_file() revealed some users
of that helper which should have used write_string_file_no_create() in the
past but didn't. Basically, all existing users that write to files in /sys
and /proc should not expect to write to a file which is not yet existant.
2015-07-06 19:27:20 -04:00
Daniel Mack 4c1fc3e404 fileio: consolidate write_string_file*()
Merge write_string_file(), write_string_file_no_create() and
write_string_file_atomic() into write_string_file() and provide a flags mask
that allows combinations of atomic writing, newline appending and automatic
file creation. Change all users accordingly.
2015-07-06 19:19:25 -04:00
Daniel Mack b6b3475533 Merge pull request #463 from dvdhrm/udev-run
udev: destroy manager before cleaning environment
2015-07-01 13:42:16 -04:00
David Herrmann 077fc5e260 udev: destroy manager before cleaning environment
Due to our _cleanup_ usage for the udev manager, it will be destroyed
after the "exit:" label has finished. Therefore, it is the last
destruction done in main(). This has two side-effects:
  - mac_selinux is destroyed before the udev manager is, possible causing
    use-after-free if the manager-cleanup accesses selinux data
  - log_close() is called *before* the manager is destroyed, possibly
    re-opening the log if you use --debug (and thus not re-applying the
    --debug option)

Avoid this by moving the manager-handling into a new function called
run(). This function will be left before we enter the "exit:" label in
main(), hence, the manager object will be destroyed early.
2015-07-01 19:30:24 +02:00
Kay Sievers 78d3e041a5 udevd: force --debug mode to stderr
https://github.com/systemd/systemd/issues/462
2015-07-01 19:20:59 +02:00
Tom Gundersen b6aab8ef9c udev: worker - check return value of udev_monitor_enable_receiving()
Fixes CID#1297430.
2015-06-23 17:20:12 +02:00
Tom Gundersen 11b9fb15be udevd: suppress warning if we don't find cgroup
This is expected on non-systemd systems, so just log it at debug level.

This fixes issue #309.
2015-06-22 16:55:49 +02:00
Thomas Hindoe Paaboel Andersen 118786182b udved: remove dead code
Leftover from 6af5e6a4c9
2015-06-17 20:33:25 +02:00
Tom Gundersen 40e749b59b udevd: daemon - connect /dev/null to std{in,out,err} in debug mode
This is essentially a revert of 5c67cf2 and fixes issue #190.
2015-06-17 18:07:20 +02:00
David Herrmann ab7854df73 udev: don't close FDs before dropping them from epoll
Make sure we never close fds before we drop their related event-source.
This will cause horrible disruptions if the fd-num is re-used by someone
else. Under normal conditions, this should not cause any problems as the
close() will drop the fd from the epoll-set automatically. However, this
changes if you have any child processes with a copy of that fd.

This fixes issue #163.

Background:
        If you create an epoll-set via epoll_create() (lets call it 'EFD')
        you can add file-descriptors to it to watch for events. Whenever
        you call EPOLL_CTL_ADD on a file-descriptor you want to watch, the
        kernel looks up the attached "struct file" pointer, that this FD
        refers to. This combination of the FD-number and the "struct file"
        pointer is used as key to link it into the epoll-set (EFD).

        This means, if you duplicate your file-descriptor, you can watch
        this file-descriptor, too (because the duplicate will have a
        different FD-number, hence, the combination of FD-number and
        "struct file" is different as before).

        If you want to stop watching an FD, you use EPOLL_CTL_DEL and pass
        the FD to the kernel. The kernel again looks up your
        file-descriptor in your FD-table to find the linked "struct file".
        This FD-number and "struct file" combination is then dropped from
        the epoll-set (EFD).

        Last, but not least: If you close a file-descriptor that is linked
        to an epoll-set, the kernel does *NOTHING* regarding the
        epoll-set. This is a vital observation! Because this means, your
        epoll_wait() calls will still return the metadata you used to
        watch/subscribe your file-descriptor to events.
        There is one exception to this rule: If the file-descriptor that
        you just close()ed was the last FD that referred to the underlying
        "struct file", then _all_ epoll-set watches/subscriptions are
        destroyed. Hence, if you never dup()ed your FD, then a simple
        close() will also unsubscribe it from any epoll-set.

        With this in mind, lets look at fork():
                Assume you have an epoll-set (EFD) and a bunch of FDs
                subscribed to events on that EFD. If you now call fork(),
                the new process gets a copy of your file-descriptor table.
                This means, the whole table is copied and the "struct
                file" reference of each FD is increased by 1. It is
                important to notice that the FD-numbers in the child are
                exactly the same as in the parent (eg., FD #5 in the child
                refers to the same "struct file" as FD #5 in the parent).

                This means, if the child calls EPOLL_CTL_DEL on an FD, the
                kernel will look up the linked "struct file" and drop the
                FD-number and "struct file" combination from the epoll-set
                (EFD). However, this will effectively drop the
                subscription that was installed by the parent.

                To sum up: even though the child gets a duplicate of the
                EFD and all FDs, the subscriptions in the EFD are *NOT*
                duplicated!

Now, with this in mind, lets look at what udevd does:
        Udevd has a bunch of file-descriptors that it watches in its
        sd-event main-loop. Whenever a uevent is received, the event is
        dispatched on its workers. If no suitable worker is present, a new
        worker is fork()ed to handle the event. Inside of this worker, we
        try to free all resources we inherited. However, the fork() call
        is done from a call-stack that is never rewinded. Therefore, this
        call stack might own references that it drops once it is left.
        Those references we cannot deduce from the fork()'ed process;
        effectively causing us to leak objects in the worker (eg., the
        call to sd_event_dispatch() that dispatched our uevent owns a
        reference to the sd_event object it used; and drops it again once
        the function is left).

        (Another example is udev_monitor_ref() for each 'worker' that is
         also inherited by all children; thus keeping the udev-monitor and
         the uevent-fd alive in all children (which is the real cause for
         bug #163))

        (The extreme variant is sd_event_source_unref(), which explicitly
         keeps event-sources alive, if they're currently dispatched,
         knowing that the dispatcher will free the event once done. But
         if the dispatcher is in the parent, the child will never ever
         free that object, thus leaking it)

        This is usually not an issue. However, if such an object has a
        file-descriptor embedded, this FD is left open and never closed in
        the child.

In manager_exit(), if we now destroy an object (i.e., close its embedded
file-descriptor) before we destroy its related sd_event_source, then
sd-event will not be able to drop the FD from the epoll-set (EFD). This
is, because the FD is no longer valid at the time we call EPOLL_CTL_DEL.
Hence, the kernel cannot figure out the linked "struct file" and thus
cannot remove the FD-number plus "struct file" combination; effectively
leaving the subscription in the epoll-set.
Since we leak the uevent-fd in the children, they retain a copy of the FD
pointing to the same "struct file". Thus, the EFD-subscription are not
automatically removed by close() (as described above). Therefore, the main
daemon will still get its metadata back on epoll_watch() whenever an event
occurs (even though it already freed the metadata). This then causes the
free-after-use bug described in #163.

This patch fixes the order in which we destruct objects and related
sd-event-sources. Some open questions remain:

 * Why does source_io_unregister() not warn on EPOLL_CTL_DEL failures?
   This really needs to be turned into an assert_return().

 * udevd really should not leak file-descriptors into its children. Fixing
   this would *not* have prevented this bug, though (since the child-setup
   is still async).
   It's non-trivial to fix this, though. The stack-context of the caller
   cannot be rewinded, so we cannot figure out temporary refs. Maybe it's
   time to exec() the udev-workers?

 * Why does the kernel not copy FD-subscriptions across fork()?
   Or at least drop subscriptions if you close() your FD (it uses the
   FD-number as key, so it better subscribe to it)?
   Or it better used
         FD+"struct file_table*"+"struct file*"
   as key to not allow the childen to share the subscription table..
   *sigh*
   Seems like we have to live with that API forever.
2015-06-17 00:31:57 +02:00
Lennart Poettering 72c0a2c255 everywhere: port everything to sigprocmask_many() and friends
This ports a lot of manual code over to sigprocmask_many() and friends.

Also, we now consistly check for sigprocmask() failures with
assert_se(), since the call cannot realistically fail unless there's a
programming error.

Also encloses a few sd_event_add_signal() calls with (void) when we
ignore the return values for it knowingly.
2015-06-15 20:13:23 +02:00
Tom Gundersen 1c4baffc18 sd-netlink: rename from sd-rtnl 2015-06-13 19:52:54 +02:00
Lennart Poettering 2a1288ff89 util: introduce CMSG_FOREACH() macro and make use of it everywhere
It's only marginally shorter then the usual for() loop, but certainly
more readable.
2015-06-10 19:29:47 +02:00
Thomas Hindoe Paaboel Andersen 920b52e490 tree-wide: remove spurious space 2015-06-08 23:11:26 +02:00
Tom Gundersen 11b1dd8cec udevd: merge manager_new() and manager_listen() again
Now that listen_fds() have been split out, we can safely move the allocation
of the manager object after doing the forking (the fork is done to notify legcay
init-systems that the fds are ready).

Subsequently, we can merge manager_listen() back into managre_new().

This entails a minor behaviour change: the application of permissions to
static device nodes now happens after the fork (but still before notifying
systemd about being ready).
2015-06-03 02:10:58 +02:00
Tom Gundersen 7500cd5e96 udevd: make sd_notify independent of forknig/notify mode
This will simply silently fail on non-systemd systems, so there is no reason
to make it conditional.

Also make it clear that we notify systemd about being ready as the last step
before starting the event loop, whereas the forking might need to happen
earlier.
2015-06-03 02:03:17 +02:00
Tom Gundersen b7f74dd48f udevd: manager - split listen_fds() out of manager_new()
This will allow us in a follow-up commit to listen to fds before forking and
still allocate the manager only after the fork.
2015-06-03 02:03:15 +02:00
Tom Gundersen f59118ec79 udevd: unify fd handling in forking/notify modes
Hide the differenec in listen_fds, by simply opening the fds
here in case they are not passed in.
2015-06-03 02:01:46 +02:00
Tom Gundersen c26d1879c7 udevd: make cgroup logic independent of socket passing
This should have no behavioural change, but it is odd to tie the cgroup cleaning to
whether or not we are passed sockets.

The point really is if we are guaranteed to be in a dedicated cgroup, so instead
check for our parent being PID1 (we already implicitly only do this on systemd
systems).
2015-06-03 01:53:26 +02:00
Tom Gundersen bf6871639e udevd: only bind ctrl and netlink sockets when we open them
If they are passed from PID1 this is not necessary.
2015-06-03 01:41:35 +02:00
Tom Gundersen fcff1e7241 udevd: rename systemd_fds to listen_fds 2015-06-03 01:41:35 +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
Tom Gundersen 3d7dc8e4f9 udevd: open sockets before forking
The communication channels must all be opened before forknig in daemon mode,
or we cannot guarantee that udevadm will work correctly as soon as udevd is
started.
2015-05-31 23:58:39 +02:00
Tom Gundersen 49f997f3bc udevd: don't allocate sd_event object before fork
In daemon mode we would break sd-event as it cannot work accross different processes.
Simply delay the allocation to after the fork.
2015-05-31 23:52:53 +02:00
Tom Gundersen f6fd40d16a udevd: don't sanitize fd 0,1,2
Kay said: 'it is from ancient times, when we started udevd from the
kernel's usermodhelper which had no fd 0,1,2'.
2015-05-31 22:38:39 +02:00
Tom Gundersen b79aacbff6 udevd: notify - expose a bit more of the internal state
This notifies PID1 about config being flushed, about shutdown starting and shutdown finalizing.
2015-05-29 18:52:13 +02:00
Tom Gundersen 39fd2ca161 udevd: notify - keep NOTIFY_SOCKET around
Only unset the env var in the workers, but otherwise keep it around in the main daemon.
2015-05-29 18:52:13 +02:00
Tom Gundersen 3cbb20578b udevd: modernize status notification
Only log about starting in daemon mode, rely on PID1 to log this in notify mode. Also
explicitly set the STATUS variable, as is done in notify mode as is done for other
serivecs.
2015-05-29 18:52:13 +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 693d371d30 udevd: move main-loop to sd-event 2015-05-29 18:52:13 +02:00
Tom Gundersen 8302fe5a13 udevd: explicitly try to start event queue when it may be possible
Rather than trying to schedule new events on every main-loop iteration, do it explicitly when
processing an event finishes, a worker is killed, a new uevent is received, or the event queue
is explicitly restarted.
2015-05-29 18:52:13 +02:00
Tom Gundersen 7c4c7e8913 udevd: only check for changed config before scheduling new events
Also move builtin and rules initialization from main loop to
event_queue_start().

No functional change.
2015-05-29 18:52:13 +02:00
Tom Gundersen 62d43dac79 udevd: introduce manager_exit() and manager_reload()
The behavior is mostly unchanged, but rather than only ever calling these functions at
fixed points in the event loop, they are called directly whenever they are invoked.
2015-05-29 18:52:13 +02:00
Tom Gundersen 86c3bece38 udevd: fix SIGCHLD handling in --daemon mode
We were listening for SIGCHLD in the wrong process.
2015-05-27 18:44:02 +02:00
David Herrmann 185abfc3d6 udev: fix inotify handling
This partly reverts:

    commit 6d1b1e0bc6
    Author: Tom Gundersen <teg@jklm.no>
    Date:   Sun May 24 15:10:04 2015 +0200

        udevd: worker - fully clean up unnecessary fds

The inotify-fd _is_ used in the workers, so don't close it! Have a look at
udev-watch.c, which keeps track of the inotify-fd as a global variable
(ugh!).
2015-05-26 13:03:15 +02:00
Tom Gundersen 040e689654 udevd: event - fix event queue in daemenozied mode
We would enforce that events could only be added to the queue from the
main process, but that brake in daemonized mode. Relax the restriction
to only allow one process to add events to the queue.

Reported by Mantas Mikulėnas.
2015-05-24 15:29:48 +02:00
Tom Gundersen 2dd9f98d2d udevd: worker - modernize a bit
Initialize structs when declaring rather than using memzero().
2015-05-24 15:29:48 +02:00
Tom Gundersen 6d1b1e0bc6 udevd: worker - fully clean up unnecessary fds
These are only ever used in the parent process, so close them early in the worker.
2015-05-24 15:29:48 +02:00
Lennart Poettering 03cfe0d514 nspawn: finish user namespace support 2015-05-21 16:32:01 +02:00
Tom Gundersen f53d1fcdb3 udevd: main - use _exit() when daemonizing
Makes it a bit clearer what is going on, rather than jumping to the end of main().

No functional change.
2015-05-18 23:49:35 +02:00
Tom Gundersen 712cebf146 udevd: main - reshuffle
First parse config, then sanitize environment before donig any further setup.

No functional change.
2015-05-18 23:49:35 +02:00
Tom Gundersen 0561329d1f udevd: rename on_reque_{exit,reload} to on_sig{term,chld}
No functional change.
2015-05-18 23:49:35 +02:00
Tom Gundersen 4fa4d88555 udevd: introduce on_event_timeout{,_warning}
This uses kill_and_sigcont() instead of kill(), otherwise no functional change.
2015-05-18 23:49:35 +02:00
Tom Gundersen f29328d655 udevd: process all SIGCHLD events every time the handler is invoked
We were returning rather than continuing in some cases. The intention
was always to fully process all pending events before returning
from the SIGCHLD handler. Restore this behaviour.
2015-05-18 23:49:35 +02:00
Tom Gundersen b2d21d9318 udevd: init/exit the builtins in manager_new/free
No functional change.
2015-05-18 23:49:35 +02:00
Tom Gundersen e237d8cb0e udevd: move file descriptors to Manager
No functional change.
2015-05-18 23:49:35 +02:00
Tom Gundersen cb49a4f2dd udevd: queue - update queue state when events are queued/freed
This way it is more obvious that the queue flag file is always
up-to-date. Moreover, we only have to touch/unlink it when the
first/last event is allocated/freed.
2015-05-16 10:31:33 +02:00
Tom Gundersen 738a790778 udevd: on_worker - distinguish between EINTR and EAGAIN
EAGAIN means there are no more messages to read, so give up. EINTR means we got interrupted
reading a message, so try again.
2015-05-16 01:14:48 +02:00
Tom Gundersen 9a73bd7cab udevd: worker - use loop_write() rather than send()
When notifying the main daemon about event completion, make sure the message is sent
successfully, and not interrupted.
2015-05-16 01:14:48 +02:00
Tom Gundersen ecb17862ad udevd: manager - move a few global variables into the Manager object 2015-05-12 19:16:43 +02:00
Tom Gundersen c0c6806bf9 udevd: pass a Manager objcet to event handlers
Stop relying on global variables in event handlers, and move them
all to a Manager object instead.
2015-05-12 19:16:43 +02:00
Tom Gundersen 005e945cc4 udevd: remove stale comment 2015-05-12 17:06:21 +02:00
Tom Gundersen 799a108c07 udevd: explicitly update queue file before answering to ping
This avoids updating the flag files twice for every loop, and also removes another dependency
in the main-loop, so we are freer to reshufle it as we want.
2015-05-12 17:06:21 +02:00
Tom Gundersen a8389097c0 udevd: explicitly read out uevents we create ourselves
Rather than skippling ctrl handling whenever we have handlede inotify events
(and hence may have synthesized a 'change' event), just call the uevent
handling explicitly from on_inotify() so that the event queue is up-to-date.
2015-05-12 17:06:21 +02:00
Tom Gundersen e82e8fa5b1 udevd: move to sd-event-style event handlers 2015-05-12 17:06:20 +02:00
Tom Gundersen e4f66b7773 udevd: make udev_ctrl_connection global
This allows us to simplify the ctrl_msg handler. Eventually all this global state should move to
a Manager object or so.
2015-05-12 00:43:45 +02:00
Thomas Hindoe Paaboel Andersen 74bddd6f19 udevd: remove unused function 2015-05-07 07:27:38 +02:00
Tom Gundersen 020328e197 udevd: don't explicitly count the number of workers
Simply query the size of the hashmap keeping all the worker contexts instead.
2015-05-06 23:45:10 +02:00
Tom Gundersen a505965d95 udevd: keep workers in a hashmap rather than a list
This makes the code somewhat more readable.
2015-05-06 23:45:10 +02:00
Tom Gundersen c6aa11f200 udevd: worker - drop reference counting
Make the worker context have the same life-span as the worker process. It is created on fork()
and free'd on SIGCHLD.

The change means that we can get worker_returned() for a worker context that is no longer around,
this is not a problem and we can just drop the message. The only use for worker_returned() is to
know to reschedule events to workers that are still around, so if the worker has already exited
it is not important to keep track of. We still print a debug statement in this case to be on the
safe side.
2015-05-06 23:45:10 +02:00
David Herrmann f7e3c6f5f8 udev: fix weird coding-style
Eeeew!
2015-05-06 18:59:03 +02:00
Tom Gundersen c4fcf70a01 udevd: worker - allow passing NULL to worker_unref() 2015-05-06 18:35:55 +02:00
Tom Gundersen 8b46c3fc48 udevd: worker - use _exit() rather than exit()
Follow the coding style and avoid the exit handlers.
2015-05-06 18:35:55 +02:00
Tom Gundersen 6af5e6a4c9 udevd: modernize error handling
We never return magic exit codes, but just EXIT_FAILUER or EXIT_SUCCESS.
2015-05-06 18:35:55 +02:00
Tom Gundersen 614a823c44 udevd: use kernel cmdline parser 2015-05-06 18:35:55 +02:00
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