Commit graph

177 commits

Author SHA1 Message Date
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