Commit Graph

92 Commits

Author SHA1 Message Date
Yu Watanabe 9a56b87717 udev: move util_path_encode() and rename it to escape_path() 2020-12-16 02:14:47 +09:00
Franck Bui 4e1db59274 udev: link_update() should fail if the entry in symlink dir couldn't have been created
Follow-up for 30f6dce62c
2020-12-09 21:08:53 +01:00
Zbigniew Jędrzejewski-Szmek b8aac5014c
Merge pull request #17431 from msekletar/udev-link-update-race
udev: make algorithm that selects highest priority devlink less susceptible to race conditions
2020-11-10 09:41:57 +01:00
Yu Watanabe f13467ec23 license: GPL-2.0+ -> GPL-2.0-or-later 2020-11-09 13:25:50 +09:00
Michal Sekletár 30f6dce62c udev: make algorithm that selects highest priority devlink less susceptible to race conditions
Previously it was very likely, when multiple contenders for the symlink
appear in parallel, that algorithm would select wrong symlink (i.e. one
with lower-priority).

Now the algorithm is much more defensive and when we detect change in
set of contenders for the symlink we reevaluate the selection. Same
happens when new symlink replaces already existing symlink that points
to different device node.
2020-11-06 13:35:05 +01:00
Lennart Poettering a7fdc6cbd3 udev: apply access mode/ownership to device nodes with O_PATH
Let's open the device node to modify with O_PATH, and then adjust it
only after verifying everything is in order. This fixes a race where the
a device appears, disappears and quickly reappers, while we are still
running the rules for the first appearance: when going by path we'd
possibly adjust half of the old and half of the new node. By O_PATH we
can pin the node while we operate on it, thus removing the race.

Previously, we'd do a superficial racey check if the device node changed
undearneath us, and would propagate EEXIST in that case, failing the
rule set. With this change we'll instead gracefully handle this, exactly
like in the pre-existing case when the device node disappeared in the
meantime.
2020-09-28 18:45:54 +02:00
Yu Watanabe ab54f12b78 sd-device: make log_device_error() or friends return void 2020-09-09 02:34:38 +09:00
Zbigniew Jędrzejewski-Szmek 90e74a66e6 tree-wide: define iterator inside of the macro 2020-09-08 12:14:05 +02:00
Zbigniew Jędrzejewski-Szmek 9e79123884 tree-wide: use SYNTHETIC_ERRNO with log_device_* in more places 2020-07-16 22:08:12 +02:00
Yu Watanabe b64b83d13e udev: ignore error caused by device disconnection
During an add or change event, the device may be disconnected.

Fixes #13976.
2019-11-12 14:58:53 +09:00
Yu Watanabe 1405cb653a tree-wide: drop stdio.h when stdio-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Yu Watanabe 20f45f4bb6 udev-node: fix misleading log messages
This fixes the following logs:
```
drm_dp_aux2: Handling device node '/dev/drm_dp_aux2', devnum=c238:2, mode=037777777777, uid=4294967295, gid=4294967295
drm_dp_aux2: Preserve permissions of /dev/drm_dp_aux2, 037777777777, uid=4294967295, gid=4294967295
```
2019-08-03 06:04:40 +09:00
Zbigniew Jędrzejewski-Szmek 3708c0f455 udev: don't force device ownership and mode on every event
This partially reverts 25de7aa7b9. I don't think the
change was intended there.

The problem I'm trying to solve: for /dev/kvm we get first an ADD uevent, and
then CHANGE whenever something connects or disconnects to the character device.
The rules in 50-default-udev.rules set UID, GID, and MODE on ADD, but not on
CHANGE. When the change event happens, we would reset the ownership and
permissions.

This happens because node_permissions_apply() would (after 25de7aa7b9)
set uid=gid=0 if they weren't set by the rules.

So let's only pass uid/gid/mode to node_permissions_apply() if appropriately
configured. Also let node_permissions_apply() do the skip of uid/gid/mode if
not set, and rename "always_apply" to more closely reflect its meaning.
2019-06-29 16:10:49 +02:00
Zbigniew Jędrzejewski-Szmek ab3a7372d2 udev: tiny fix to debug message 2019-06-29 14:57:16 +02:00
Zbigniew Jędrzejewski-Szmek 6bf901a9b5
Merge pull request #12437 from poettering/chmod-and-chown-rewrite
chmod_and_chown() rewrite
2019-05-28 15:12:20 +02:00
Yu Watanabe 3fb1069019 udev: fix error message 2019-05-28 10:35:21 +02:00
Lennart Poettering 4b3b5bc71b tree-wide: port various places over to use chmod_and_chown()
Doing this properly is hard, hence let's unify the code.
2019-05-24 15:07:55 +02:00
Yu Watanabe 39a15c8a8d udev: run programs in the specified order
This fixes bugs introduced by 29448498c7
and d838e14515.

Previously, RUN and SECLABEL keys are stored in udev_list with its unique
flag is false. If the flag is false, then udev_list is just a linked
list and new entries are always added in the last.
So, we should use OrderedHashmap instead of Hashmap.

Fixes #11368.
2019-03-05 09:27:29 +01:00
Yu Watanabe a119328608 udev: use SYNTHETIC_ERRNO() macro in log_device_*_errno() 2019-01-13 17:50:47 +09:00
Yu Watanabe 82d9ac23fd udev-node: make link_find_prioritized() return negative value when nothing found
Fixes a bug introduced by a2554acec6.

Fixes RHBZ#1662303.
2019-01-08 19:21:44 +01:00
Zbigniew Jędrzejewski-Szmek 62a85ee0a9 tree-wide: rename path_join_many() to path_join()
$ git grep -e path_join_many -l|xargs sed -r -i 's/path_join_many/path_join/g'

The two test functions are merged into one.
2018-11-30 10:59:47 +01:00
Zbigniew Jędrzejewski-Szmek 30016f21b3 tree-wide: replace path_join with path_join_many 2018-11-30 10:40:38 +01:00
Yu Watanabe 5ea78a39e5 libudev-list: move libudev-list related definitions to libudev-list-internal.h
This also rename libudev-private.h to libudev-util.h, and cleanups
several unnecessary headers from udev.h and libudev-util.h
2018-11-20 14:38:35 +09:00
Yu Watanabe 6bee206591 udev-node: add one more debug log when failed to create symlink 2018-11-06 15:45:22 +09:00
Yu Watanabe a126a38a9f udev-node: drop redundant log message
As node_symlink() logs almost same message.
2018-11-06 15:45:22 +09:00
Yu Watanabe e0ca42e383 udev-node: use log_device_*() 2018-10-23 22:44:07 +09:00
Yu Watanabe d838e14515 udev: use Hashmap for storing SECLABEL 2018-10-17 06:48:53 +09:00
Yu Watanabe e7aa9512e4 udev: use readlink_malloc() or its friend
Follow-up for a2554acec6 and
7006860271.
2018-10-14 19:59:49 +02:00
Yu Watanabe a2554acec6 udev-node: replace udev_device by sd_device and modernize code a bit 2018-10-11 04:21:14 +09:00
Yu Watanabe c1ee267489 udev: use path_make_relative() 2018-09-26 22:58:57 +09:00
Yu Watanabe 2024ed616e udev: drop unused udev struct 2018-09-10 18:27:36 +09:00
Yu Watanabe f330408d62 tree-wide: drop empty lines in comments 2018-07-23 08:44:24 +02:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Zbigniew Jędrzejewski-Szmek 50d1760d26 Drop more license boilerplate
$ git grep -e 'This program is free software' -l |grep -v LICENSE | \
  xargs perl -i -0pe 's/ \* This program.*?for more details.\s*\*\n( \* You should have.*licenses.>.\n)?//gms'

For some reason they were missed previously. All those files seem to
have proper SDPX tags.
2018-06-14 13:05:41 +02:00
Lennart Poettering 810adae9e9 tree-wide: use proper unicode © instead of (C) where we can
Let's use a proper unicode copyright symbol where we can, it's prettier.

This important patch is very important.
2018-06-14 10:20:20 +02:00
Lennart Poettering 08c849815c label: rework label_fix() implementations (#8583)
This reworks the SELinux and SMACK label fixing calls in a number of
ways:

1. The two separate boolean arguments of these functions are converted
   into a flags type LabelFixFlags.

2. The operations are now implemented based on O_PATH. This should
   resolve TTOCTTOU races between determining the label for the file
   system object and applying it, as it it allows to pin the object
   while we are operating on it.

3. When changing a label fails we'll query the label previously set, and
   if matches what we want to set anyway we'll suppress the error.

Also, all calls to label_fix() are now (void)ified, when we ignore the
return values.

Fixes: #8566
2018-03-27 07:38:26 +02:00
Zbigniew Jędrzejewski-Szmek 87ac8d998f tree-wide: use "cannot" instead of "can not"
This is the usual spelling, and a bit shorter.
2018-02-08 10:34:52 +01:00
Lennart Poettering fbd0b64f44
tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us.

Follow-up for #7625.
2017-12-14 19:02:29 +01:00
Zbigniew Jędrzejewski-Szmek c67f84b025 Add a helper for /dev/block/major:minor paths 2017-11-30 12:59:23 +01:00
Zbigniew Jędrzejewski-Szmek e7145211c7 Add SPDX license identifiers to source files under the GPL 2017-11-19 19:08:15 +01:00
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
Reverend Homer 8fb3f00997 tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853) 2016-12-09 10:04:30 +01:00
Zbigniew Jędrzejewski-Szmek f97b34a629 Rename formats-util.h to format-util.h
We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.
2016-11-07 10:15:08 -05:00
Zbigniew Jędrzejewski-Szmek e02c613560 udev/udev-watch: calculate the real buffer sizes needed 2016-11-02 22:36:43 -04:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Daniel Mack d054f0a4d4 tree-wide: use xsprintf() where applicable
Also add a coccinelle receipt to help with such transitions.
2016-01-12 15:36:32 +01:00
Zbigniew Jędrzejewski-Szmek 3f65d73149 udev: add emacs header line
Otherwise emacs wants to use 2-space indentation and other
attrocities.
2015-12-07 00:45:08 -05:00
Michal Schmidt e1427b138f treewide: apply errno.cocci
with small manual cleanups for style.
2015-11-09 20:01:06 +01:00
Lennart Poettering f4f15635ec util-lib: move a number of fs operations into fs-util.[ch] 2015-10-27 13:25:56 +01:00