Commit Graph

396 Commits

Author SHA1 Message Date
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
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
Tom Gundersen 5c67cf2774 udev: don't close std{in,out,err}
Rather than printing debug output to stderr and redirecting this to /dev/null when not wanted,
use the correct log_*() function in the first place.
2014-09-16 12:12:56 +02:00
Tom Gundersen 959d654105 udev: drop duplicate logging
Once upon a time logging during early boot was unreliable, so extra logging messages were
sent by udev to stderr. That is no longer a concern, so drop all fprintf() calls from udved.
2014-09-16 12:12:56 +02:00
Tom Gundersen bba7a48439 udev: split out parse_argv()
Also rename some global variables to arg_* to make it clearer where they come from.
2014-09-16 12:12:55 +02:00
Tom Gundersen ed216e1ff0 udev: split out help and modernise a bit 2014-09-16 12:12:55 +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 b5338a1986 udev: timeout - increase timeout
Some kernel modules still take more than one minute to insmod, we no longer rely on the timeout
killing insmod within a given period of time, so just bump this to a much higher value. Its only
purpose is to make sure that nothing stays aronud forever.
2014-09-10 18:10:06 +02:00
Tom Gundersen 9d19a679f2 udev - drop print_kmsg
The only remaining user was 'starting version XXX', which is now logged using log_info().
2014-09-09 22:48:57 +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
Kay Sievers 2e92633dba udev: bump event timeout to 60 seconds 2014-08-30 11:36:32 +02:00
Kay Sievers be2ea723b1 udev: remove userspace firmware loading support 2014-08-30 11:34:20 +02:00
Zbigniew Jędrzejewski-Szmek a2a5291b3f Reject invalid quoted strings
String which ended in an unfinished quote were accepted, potentially
with bad memory accesses.

Reject anything which ends in a unfished quote, or contains
non-whitespace characters right after the closing quote.

_FOREACH_WORD now returns the invalid character in *state. But this return
value is not checked anywhere yet.

Also, make 'word' and 'state' variables const pointers, and rename 'w'
to 'word' in various places. Things are easier to read if the same name
is used consistently.

mbiebl_> am I correct that something like this doesn't work
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-passwd "Unlock EncFS"'
mbiebl_> systemd seems to strip of the quotes
mbiebl_> systemctl status shows
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-password Unlock EncFS  $RootDir $MountPoint
mbiebl_> which is pretty weird
2014-07-31 04:00:31 -04: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
Hannes Reinecke 9719859c07 udevd: add --event-timeout commandline option
Some events take longer than the default 30 seconds. Killing those
events will leave the machine halfway configured.

Add a commandline option '--event-timeout' to handle these cases.
2014-07-29 13:45:07 +02:00
Kay Sievers 2e5b17d013 udev: exclude MD from block device ownership event locking
MD instantiates devices at open(). This is incomptible with the
locking logic, as the "change" event emitted when stopping a
device will bring it back.
2014-07-24 23:37:35 +02:00
Thomas Hindoe Paaboel Andersen 47a3fa0f76 udev: check the return value from udev_enumerate_scan_devices
The return value from udev_enumerate_scan_devices was stored but
never used. I assume this was meant to be checked.
2014-06-10 19:06:50 +02:00
Christian Hesse 638ca89c53 udev: really exclude device-mapper from block device ownership event locking
Arguments were wrong order, no?
This fixes commits:

e918a1b5a9
3d06f41834
2014-06-10 16:08:25 +02:00
Kay Sievers 02ba8fb335 udev: guard REREADPT by exclusive lock instead of O_EXCL 2014-06-04 16:28:03 +02:00
Kay Sievers e9fc29f4ec udev: make sure we always get "change" for the disk
The kernel will return 0 for REREADPT when no partition table
is found, we have to send out "change" ourselves.
2014-06-04 15:17:15 +02:00
Kay Sievers 10fab50a30 udev: guard REREADP logic with open(O_ECXL) 2014-06-04 14:09:31 +02:00
Kay Sievers ede344452a udev: try first re-reading the partition table
mounted partitions:
  # dd if=/dev/zero of=/dev/sda bs=1 count=1
  UDEV  [4157.369250] change   .../0:0:0:0/block/sda (block)
  UDEV  [4157.375059] change   .../0:0:0:0/block/sda/sda1 (block)
  UDEV  [4157.397088] change   .../0:0:0:0/block/sda/sda2 (block)
  UDEV  [4157.404842] change   .../0:0:0:0/block/sda/sda4 (block)

unmounted partitions:
  # dd if=/dev/zero of=/dev/sdb bs=1 count=1
  UDEV  [4163.450217] remove   .../target6:0:0/6:0:0:0/block/sdb/sdb1 (block)
  UDEV  [4163.593167] change   .../target6:0:0/6:0:0:0/block/sdb (block)
  UDEV  [4163.713982] add      .../target6:0:0/6:0:0:0/block/sdb/sdb1 (block)
2014-06-04 13:35:02 +02:00
Kay Sievers f3a740a5da udev: synthesize "change' events for partitions when tools change the disk
This should make sure that fdisk-like programs will automatically
cause an update of all partitions, just like mkfs-like programs cause
an update of the partition.
2014-06-04 12:21:44 +02:00
Kay Sievers edd32000c8 udevd: inotify - modernizations 2014-06-04 11:16:30 +02:00
Kay Sievers e918a1b5a9 udev: exclude device-mapper from block device ownership event locking 2014-06-03 16:49:38 +02:00
Kay Sievers 3d06f41834 udev: always close lock file descriptor
https://bugs.freedesktop.org/show_bug.cgi?id=79576
2014-06-03 11:06:43 +02:00
Thomas Hindoe Paaboel Andersen bf9bead187 udev: avoid use of uninitialized err
After 1ea972174b err is no longer
set unless we hit a special case. Initialize it to 0 and remove
a check that will never fail.
2014-05-17 08:41:48 +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
Kay Sievers 3ebdb81ef0 udev: serialize/synchronize block device event handling with file locks 2014-04-13 19:54:27 -07:00
Kay Sievers 9ea28c55a2 udev: remove seqnum API and all assumptions about seqnums
The way the kernel namespaces have been implemented breaks assumptions
udev made regarding uevent sequence numbers. Creating devices in a
namespace "steals" uevents and its sequence numbers from the host. It
confuses the "udevadmin settle" logic, which might block until util a
timeout is reached, even when no uevent is pending.

Remove any assumptions about sequence numbers and deprecate libudev's
API exposing these numbers; none of that can reliably be used anymore
when namespaces are involved.
2014-04-13 17:12:14 -07:00
Lennart Poettering c8a202b7d4 everywhere: always use O_CLOEXEC where it makes sense 2014-02-13 14:59:56 +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
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
Kay Sievers ed14edc04f udev: LOG_PRIORITY -> LOG_LEVEL 2013-12-29 18:05:25 +01: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
Kay Sievers e3dc56a219 udev: declare some symbols static 2013-11-12 18:09:08 +01:00
Lennart Poettering 74df0fca09 util: unify reading of /proc/cmdline
Instead of individually checking for containers in each user do this
once in a new call proc_cmdline() that read the file only if we are not
in a container.
2013-11-06 03:15:16 +01:00
Zbigniew Jędrzejewski-Szmek 97fec53e5e udev: use initialization instead of zeroing in one place 2013-10-13 17:56:55 -04:00
Colin Walters 73814ca287 Revert "udevd: simplify sigterm check"
This reverts commit 47e737dc13 - it
introduced a use-after-free.  The only way the code would get simpler
is with a cleanup function, but eh, not worth it for just this one
bit.

Reviewed by kay on IRC.
2013-08-22 17:07:02 -04:00
Kay Sievers 47e737dc13 udevd: simplify sigterm check 2013-08-15 19:55:32 +02:00
Tom Gundersen 689a97f523 udevd: respect the log-level set in /etc/udev/udev.conf
A regression introduced when we moved to systemd's logging is that the only
way to adjust the log-level of the udev daemon is via the env var, kernel
commandline or the commandline.

This reintroduces support for specifying this in the configuration file.
2013-08-09 01:38:17 +02:00
Tom Gundersen 84b6ad702e udev: export tags of "dead" device nodes to /run/udev/static_node-tags/
Based on a patch by Kay Sievers.

A tag is exported at boot as a symlinks to the device node in the folder
/run/udev/static_node-tags/<tagname>/, if the device node exists.

These tags are cleaned up by udevadm info --cleanup-db, but are otherwise
never removed.
2013-07-16 20:07:57 +02:00
Tom Gundersen edeb68c53f static-nodes: move creation of static nodes from udevd to tmpfiles
As of kmod v14, it is possible to export the static node information from
/lib/modules/`uname -r`/modules.devname in tmpfiles.d(5) format.

Use this functionality to let systemd-tmpfilesd create the static device nodes
at boot, and drop the functionality from systemd-udevd.

As an effect of this we can move from systemd-udevd to systemd-tmpfiles-setup-dev:

 * the conditional CAP_MKNOD (replaced by checking if /sys is mounted rw)
 * ordering before local-fs-pre.target (see 89d09e1b5c)
2013-07-08 21:26:24 +02:00
Lennart Poettering 7027ff61a3 nspawn: introduce the new /machine/ tree in the cgroup tree and move containers there
Containers will now carry a label (normally derived from the root
directory name, but configurable by the user), and the container's root
cgroup is /machine/<label>. This label is called "machine name", and can
cover both containers and VMs (as soon as libvirt also makes use of
/machine/).

libsystemd-login can be used to query the machine name from a process.

This patch also includes numerous clean-ups for the cgroup code.
2013-04-16 04:41:21 +02:00
Lennart Poettering 574d5f2dfc util: rename write_one_line_file() to write_string_file()
You can write much more than just one line with this call (and we
frequently do), so let's correct the naming.
2013-04-03 20:12:56 +02:00
Václav Pavlín f459285212 udev: check return value of uname. 2013-03-28 23:45:58 -04:00
Kay Sievers d8d4bee76c build-sys: fix HAVE/ENABLE_FIRMWARE
https://bugs.freedesktop.org/show_bug.cgi?id=62864
2013-03-28 15:28:10 +01:00
Harald Hoyer 8cc3f8c0bc udevd.c: set udev children_max according to CPU count
Setting children_max according to RAM leads to too much concurrent I/O.
2013-03-25 13:11:18 +01:00
Kay Sievers 61e536e1b7 udev: ifdef all firmware special handling 2013-03-18 15:22:32 +01:00
Kay Sievers 1d600df55b udev: remove database conversion code 2013-03-03 18:35:22 +01:00
Harald Hoyer a5c32cff1f honor SELinux labels, when creating and writing config files
Also split out some fileio functions to fileio.c and provide a SELinux
aware pendant in fileio-label.c

see https://bugzilla.redhat.com/show_bug.cgi?id=881577
2013-02-14 16:19:38 +01:00
Thomas Hindoe Paaboel Andersen 090be86534 use streq instead of strcmp 2013-02-13 18:14:20 +01:00
Kay Sievers d5a89d7dc1 udev: move string copy functions to shared/ 2013-01-09 19:06:46 +01:00
Lukas Nykryn 5bbbe461fd udevd: add missing ':' to getopt_long 'e'
Parameter -e is set without additional argument in getopt
and this leads to segfault when calling 'systemd-udevd -e'.
2012-12-22 15:19:15 +01:00
Kay Sievers 1298001ec5 use the same email address everywhere 2012-11-12 19:47:43 +01:00
Kay Sievers 40fe8b11be udev: use usec_t and now() 2012-11-12 01:03:14 +01:00
Kay Sievers ea6039a309 udev: allow firmware requests to bypass the dependency tracking
The removal of the TIMEOUT= handling in udevd put firmware requests into the
devpath parent/child dependency tracking. Drivers which block in module_init()
asking userspace for firmware ran into a 30 sec device timeout.

The whole firmware loading willl hopefully move into the kernel and
the fragile-since-day-one fake async driver-core device dance involving
udev can be retired:
  http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=abb139e75c2cdbb955e840d6331cb5863e409d0e
2012-10-07 18:22:14 +02:00
Thomas Hindoe Paaboel Andersen c53158818d man: fix a bunch of typos in docs
https://bugs.freedesktop.org/show_bug.cgi?id=54501
2012-09-13 19:34:24 +02:00
Lennart Poettering 01ed0e2307 dev-setup: make NULL as parameter for dev_setup() equivalent to "" 2012-08-21 17:23:03 +02:00
Dave Reisner 8f0e73f250 dev-setup: allow a path prefix for use in chroots
With this adjustment, we can reuse this code elsewhere, such as in
nspawn.
2012-08-21 17:19:35 +02:00
Kay Sievers 7781e063e8 udev: re-initialize builtins in the daemon process, not in the worker 2012-08-08 16:27:11 +02:00
Kay Sievers 023b9d33e9 udev: set log.c's log level from udev's kernel command line option 2012-07-30 22:34:07 +02:00
Kay Sievers c6eefe3664 udev: avoid creating /dev/kmsg with fopen() to support CONFIG_PRINTK=n 2012-07-14 00:33:59 +02:00
Lennart Poettering 4b2615684b log: correct usage of logging API at a few places 2012-07-13 15:45:45 +02:00
Kay Sievers 47ef94ac5f udev: add some O_CLOEXEC 2012-07-05 17:33:24 +02:00
Kay Sievers ef8a2bf648 udev: static nodes - fix default permissions if no rules is given
<falconindy> kay: just curious -- it looks like nodes created by udev from
  modules.devname all have 000 perms, and there's nothing in udev that attempts
  to change this. is it intended?
<falconindy> c---------   1 root root     10, 223 Jul  1 23:10 uinput
<kay> falconindy: we might miss the default of 0600
<falconindy> seems like it
<kay> falconindy: stuff that has a rule works i guess
<kay> falconindy: i'll add the 0600 now
2012-07-02 20:45:59 +02:00
Dave Reisner ddbe6850b2 udevd: fix bogus mkdir invocation
The filename parameter passed to mkdir can't contain anything but a
garbage value at this point. This was meant to be the full pathname to
the new udev DB, as the mkdir_parents() call before it won't create the
trailing child directory.

[replace mkdir_parents() + mkdir() with mkdir_p() -- kay]
2012-07-02 03:09:18 +02:00
Dave Reisner b80680eda9 udevd: use ROOTPREFIX to create path to modules.devname 2012-07-02 03:04:24 +02:00
Kay Sievers 72a2af7aa9 udev: use the matching binary name "systemd-udevd" in log messages 2012-06-27 15:29:55 +02:00
Kay Sievers e6f86cac16 udev: kernel cmdline - accept rd.* parameters 2012-06-04 22:46:32 +02:00
Kay Sievers 145dae7eb3 udev: reset /proc/self/oom_score_adj in worker processes
Only the main daemon process should be excluded from OOM handling,
not the worker processes or their child processes.
2012-06-04 18:10:50 +02:00
Kay Sievers d315bba6f6 udev: limit minimum worker count to 16 2012-06-04 16:40:31 +02:00
Lauri Kasanen a52289f7f5 udev: lower the starting children_max -> drop the minimum required RAM from 23mb to 5mb
Udev was the limiting factor for us on low-RAM systems.
Given an average RSS of 180kb, 128 workers would require ~23mb of RAM.

Now, please consider what happens when there is only, say, 15mb free.
Udev protects itself from OOM, and the kernel can do nothing but panic.

28 workers * 0.18mb = ~5mb. This change should not affect more powerful
systems much, given that they still get the addition from the amount of RAM.
2012-06-04 16:02:33 +02:00
Kay Sievers 0f9963a8b8 Revert "label: fix systemd-udev labeling of /run directory."
This reverts commit 9b5af248f0.

Udev now explicitely labels only files/directories in /dev. The selinux
array API is not released and will not work on other distros at this moment.
2012-05-31 13:34:41 +02:00
Kay Sievers 667e392408 udev: do not selinux label files in /run/udev 2012-05-31 13:20:06 +02:00
Kay Sievers d2e54fae5c mkdir: append _label to all mkdir() calls that explicitly set the selinux context 2012-05-31 12:40:20 +02:00
Daniel J Walsh 9b5af248f0 label: fix systemd-udev labeling of /run directory.
systemd-udev is currently incorrectly labeling /run/udev/* content because it is
using selinux prefix labeling of /dev.  This patch will allow systemd-udev to
use prefix labeling of /dev and /run.
2012-05-31 01:43:27 +02:00
Lucas De Marchi b27ee00bf5 udev: use container_of() macro 2012-04-29 19:15:08 +02:00
Kay Sievers c693ccc0a2 udev: use only oom_score_adj interface 2012-04-26 01:49:15 +02:00
Kay Sievers 5ba2dc259f udev: unify /dev static symlink setup 2012-04-17 22:31:38 +02:00
Kay Sievers e9a5ef7cdd selinux: unify systemd and udev code 2012-04-17 16:05:28 +02:00
Kay Sievers 3b49d09a3d udev: kill udev_selinux_setfscreateconat() 2012-04-17 02:20:32 +02:00
Kay Sievers 9e13dbae50 udev: replace util_create_path() with mkdir_parents() 2012-04-17 01:09:39 +02:00
Kay Sievers 6ada823a9a udev: remove configuration options for /dev, /sys, /run directories 2012-04-16 19:20:57 +02:00
Kay Sievers 8fef0ff25c udev: replace ARRAY_SIZE() with ELEMENTSOF() 2012-04-16 19:20:57 +02:00
Kay Sievers 194bbe3338 udev: cleanup the udev cgroup when the daemon enters the idle state 2012-04-15 03:11:08 +02:00
Kay Sievers b49d9b50cf udev: fix a few issues detected by the llvm static analyzer 2012-04-13 15:10:12 +02:00
Kay Sievers 04a9d3a00a udev: fix gcc warnings showing up after adding $(AM_CFLAGS) 2012-04-10 17:27:46 +02:00
Kay Sievers 07cd4fc168 udev: remove support for /lib/udev/devices/; tmpfiles should be used 2012-04-08 16:50:16 +02:00
Kay Sievers baa30fbc2c udev: switch to systemd logging functions 2012-04-08 16:06:20 +02:00
Kay Sievers 3e2147858f move imported udev into place 2012-04-04 05:05:07 +02:00
Renamed from src/udev/src/udevd.c (Browse further)