summaryrefslogtreecommitdiff
path: root/src/udev/udev-node.c
Commit message (Collapse)AuthorAgeFilesLines
* udev-node: make stack_directory_read_one() accept NULL for devnodeYu Watanabe2023-02-201-2/+11
| | | | | No functional change, as currently the function is always called with non-NULL argument. Just a preparation for #26048 or #25839.
* udev-node: drop unnecessary initializationYu Watanabe2023-02-201-1/+1
| | | | | | | | | The priority of device node symlink can be negative. So the initialization is confusing. Fortunately, this changes no functionality, as we only compare the priorities of symlinks only when we parsed at least one device node and its priority.
* udev: simplify a bit stack_directory_find_prioritized_devnode()Franck Bui2023-01-131-20/+15
| | | | | And make the new format the one we expect as it should replace the old one pretty quickly.
* udev: return ENODEV if link_directory_read_one() can't find the devnodeFranck Bui2023-01-131-1/+1
| | | | | That's usually the errno code we return when a device cannot be found because it's been unplugged.
* udev: let stack_directory_open() convert a slink into a dirname itselfFranck Bui2023-01-131-16/+18
| | | | | | | | | We likely always want to open the directory via a slink. There's currently only one caller so it doesn't make any difference in practice but I think it's still nicer. No functional change.
* udev: merge link_directory_lock() into link_directory_open()Franck Bui2023-01-131-39/+32
| | | | These 2 operations are inseparable.
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-5/+5
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* Merge pull request #24646 from yuwata/udev-node-symlink_atomicYu Watanabe2022-09-191-26/+7
|\ | | | | udev: introduce symlink_atomic_full() and use it
| * udev-node: use symlink_atomic_full_label() to create devlinkYu Watanabe2022-09-181-26/+7
| | | | | | | | | | | | | | | | | | | | | | | | If the filename of a device symlink is too long, then the temporary filename may become invalid, and we fail to create symlink. The function `tempfn_random()` used in symlink_atomic_full() generates a safe temporary filename. Note that, thanks to the PR #23043, now only one worker can handle the same symlink simultaneously. Hence, the device ID based temporary filename is not necessary.
* | udev-node: do not create symlink to a non-existing device nodeYu Watanabe2022-09-161-0/+7
| | | | | | | | | | | | | | | | | | | | | | Previously, the stack directory contains empty regular files named with device ID, and we create sd_device object from the device name. Hence, we implicitly checked the existence of the device node. However, now the files in the stack directory are symlink, and we retrieve the path to the device node and its priority from the symlink. Hence, the existence of the device node is not checked. Let's check if the device node is still exist.
* | udev-node: split out stack_directory_read_one()Yu Watanabe2022-09-161-55/+71
|/ | | | No functional changes, just refactoring.
* udev: cleanup stack directory /run/udev/links when all workers exitedYu Watanabe2022-09-031-0/+42
| | | | | | By the previous commit, the stack directories are not removed even if it is empty. To reduce the inode usage of /run, let's cleanup the directories.
* udev: use flock() when updating device node symlinksYu Watanabe2022-09-031-133/+40
| | | | | | By locking the stack directory, we can safely determine the device node with the highest priority for a symlink. So, the multiple try-and-wait loops can be dropped, and the code becomes quite simple.
* udev: make node_symlink() accept NULL devnameYu Watanabe2022-09-031-15/+9
|
* udev: use path_make_relative_parent()Yu Watanabe2022-09-031-6/+2
|
* udev: rename link_find_prioritized() and variablesYu Watanabe2022-09-031-31/+31
| | | | | | Also shorten code a bit. Just for consistency with other part and readability of the code.
* udev: use readlinkat_malloc()Yu Watanabe2022-09-031-8/+12
| | | | And try to read it only when the file is symlink.
* udev: do not remove stack directory even if it is emptyYu Watanabe2022-09-031-97/+61
| | | | | | | | Then, we can always assume the directory exists, and the code become slightly simpler. Note, unused directories are removed by the main udevd process in a later commit.
* udev: split link_update() and introduce stack_directory_get_name()Yu Watanabe2022-09-031-19/+33
| | | | No functionality is changed.
* udev: move udev_node_escape_path()Yu Watanabe2022-09-031-42/+42
| | | | No functionality is changed.
* mac: rework labelling code to be simpler, and less racyLennart Poettering2022-07-081-1/+1
| | | | | | | | | | | | | | This merges the various labelling calls into a single label_fix_full(), which can operate on paths, on inode fds, and in a dirfd/fname style (i.e. like openat()). It also systematically separates the path to look up in the db from the path we actually use to reference the inode to relabel. This then ports tmpfiles over to labelling by fd. This should make the code a bit less racy, as we'll try hard to always operate on the very same inode, pinning it via an fd. User-visibly the behaviour should not change.
* basic: split out dev_t related calls into new devno-util.[ch]Lennart Poettering2022-04-131-0/+1
| | | | | | | | | | | | | | No actual code changes, just splitting out of some dev_t handling related calls from stat-util.[ch], they are quite a number already, and deserve their own module now I think. Also, try to settle on the name "devnum" as the name for the concept, instead of "devno" or "dev" or "devid". "devnum" is the name exported in udev APIs, hence probably best to stick to that. (this just renames a few symbols to "devum", local variables are left untouched, to make the patch not too invasive) No actual code changes.
* udev: move apply_static_dev_perms() to udev-node.cYu Watanabe2022-04-061-0/+62
| | | | and make it internally use udev_node_apply_permissions_impl().
* udev: upgrade mode in udev_node_apply_permissions_impl()Yu Watanabe2022-04-061-0/+4
|
* udev: split udev_node_apply_permissions() into twoYu Watanabe2022-04-061-19/+37
|
* udev: drop unnecessary codeYu Watanabe2022-04-061-13/+1
| | | | Follow-up for 78e278ad48e0d2854f950f261804fde70121820e.
* udev: use sd_device_open() where appropriateYu Watanabe2022-04-011-13/+5
|
* tree-wide: make FOREACH_DIRENT_ALL define the iterator variableZbigniew Jędrzejewski-Szmek2021-12-151-6/+5
| | | | | | | | | The variable is not useful outside of the loop (it'll always be null after the loop is finished), so we can declare it inline in the loop. This saves one variable declaration and reduces the chances that somebody tries to use the variable outside of the loop. For consistency, 'de' is used everywhere for the var name.
* shared: clean up mkdir.h/label.h situationLennart Poettering2021-11-161-1/+1
| | | | | | | | | | Previously the mkdir_label() family of calls was implemented in src/shared/mkdir-label.c but its functions partly declared ins src/shared/label.h and partly in src/basic/mkdir.h (!!). That's weird (and wrong). Let's clean this up, and add a proper mkdir-label.h matching the .c file.
* tree-wide: use new RET_NERRNO() helper at various placesLennart Poettering2021-11-161-4/+1
|
* udev-node: do not ignore unexpected errors on removing symlink in stack ↵Yu Watanabe2021-09-121-9/+14
| | | | | | directory Only acceptable error here is -ENOENT.
* udev-node: simplify the example of raceYu Watanabe2021-09-121-5/+5
|
* udev-node: drop redundant trial of devlink creationYu Watanabe2021-09-021-8/+4
| | | | | | | | | Previously, the devlink was created based on the priority saved in udev database. So, we needed to reevaluate devlinks after database is saved. But now the priority is stored in the symlink under /run/udev/links, and the loop of devlink creation is controlled with the timestamp of the directory. So, the double evaluation is not necessary anymore.
* udev-node: add random delay on conflict in updating device node symlinkYu Watanabe2021-09-021-0/+12
| | | | | To make multiple workers not update the same device node symlink simultaneously.
* udev-node: shorten code a bit and update log messageYu Watanabe2021-09-021-3/+2
|
* udev-node: check stack directory change even if devlink is removedYu Watanabe2021-09-021-9/+6
| | | | | | | Otherwise, when multiple device additions and removals occur simultaneously, symlink to unexisting devnode may be created. Hopefully fixes #19946.
* udev-node: always atomically create symlink to device nodeYu Watanabe2021-09-021-33/+9
| | | | | | | | | | | By the previous commit, it is not necessary to distinguish if the devlink already exists. Also, I cannot find any significant advantages of the previous complecated logic, that is, first try to create directly, and then fallback to atomically creation. Moreover, such logic increases the chance of conflicts between multiple udev workers. This makes devlinks always created atomically. Hopefully, this reduces the conflicts between the workers.
* udev-node: assume no new claim to a symlink if /run/udev/links is not updatedYu Watanabe2021-09-021-5/+0
| | | | | | | During creating a symlink to a device node, if another device node which requests the same symlink is added/removed, `stat_inode_unmodified()` should always detects that. We do not need to continue the loop unconditionally.
* udev-node: always update timestamp of stack directoryYu Watanabe2021-09-021-3/+87
| | | | Please see the comments in the code.
* udev-node: save information about device node and priority in symlinkYu Watanabe2021-09-021-51/+121
| | | | | | | | | | Previously, we only store device IDs in /run/udev/links, and when creating/removing device node symlink, we create sd_device object corresponds to the IDs and read device node and priority from the object. That requires parsing uevent and udev database files. This makes link_find_prioritized() get the most prioritzed device node without parsing the files.
* udev-node: stack directory must exist when adding device node symlinkYu Watanabe2021-09-021-5/+6
|
* udev-node: split out permission handling from udev_node_add()Yu Watanabe2021-09-021-111/+93
| | | | And then merge udev_node_add() and udev_node_update_old_links().
* udev: always use last 11 chars for hash stringYu Watanabe2021-06-041-5/+4
| | | | | | | This makes the last 11 chars are always preserved for hashed string. So, it is hard to generate a path which conflicts to another path. Fixes an issue demonstrated in the previous commit.
* util: drop DEV_NUM_PATH_MAX and xsprintf_dev_num_path()Yu Watanabe2021-06-041-12/+1
|
* udev: warn and propagate error in creating device symlinkYu Watanabe2021-06-041-14/+15
| | | | | Also, this makes the file in /run/udev/links/ is kept on failure, as the target of the symbolic link may be belonging to another device.
* udev: try to create device symlink directly only when the link does not ↵Yu Watanabe2021-06-041-2/+3
| | | | exist yet
* udev: extract same logic of creating device symlinkYu Watanabe2021-06-041-26/+41
| | | | This also limits the number of trial.
* udev: use path_extract_directory() and path_equal()Yu Watanabe2021-06-041-4/+4
|
* udev: refuse to create device symlink when a non-symlink file already existsYu Watanabe2021-06-041-15/+16
|
* udev: make link_find_prioritized() return 0, 1, or negative errnoYu Watanabe2021-06-041-15/+17
|