Commit graph

227 commits

Author SHA1 Message Date
Yu Watanabe 5abba26e2f udev: add missing flag for OPTIONS=static_node
Fixes RHBZ#1740664.
2019-09-09 01:28:02 +09:00
Yu Watanabe 41c81c4a62 udev: do not try to import properties on commented out lines
Fixes #13257.
2019-08-04 14:41:47 +02:00
Lennart Poettering 1f57abb309 udev: warn on rules files with weird access modes 2019-07-29 18:51:38 +02:00
Yu Watanabe 8cec0a5c32 tree-wide: drop duplicated blank lines
```
$ for i in */*.[ch] */*/*.[ch]; do sed -e '/^$/ {N; s/\n$//g}' -i $i; done
$ git checkout HEAD -- basic/linux shared/linux
```
2019-07-15 18:41:27 +02:00
Lennart Poettering 2caa38e99f tree-wide: some more [static] related fixes
let's add [static] where it was missing so far

Drop [static] on parameters that can be NULL.

Add an assert() around parameters that have [static] and can't be NULL
hence.

Add some "const" where it was forgotten.
2019-07-12 16:40:10 +02:00
Yu Watanabe 9c69cd7ec0 udev: accept lines which have only PROGRAM=
As PROGRAM= may cause side effect, and users may expect that.
2019-07-01 14:13:31 +02:00
Zbigniew Jędrzejewski-Szmek 7504610ba0 udev-rules: add more info to errors about attr formats 2019-06-28 16:20:48 +02:00
Zbigniew Jędrzejewski-Szmek f85cc54c4b udev-rules: add precise information to rule failure logs
It is pretty hard to figure out what the problem actually is, esp. when the rule
is long.

On my machine:
systemd[1]: Starting udev Kernel Device Manager...
systemd-udevd[217399]: /usr/lib/udev/rules.d/11-dm-lvm.rules:40 Invalid value for OPTIONS key, ignoring: 'event_timeout=180'
systemd-udevd[217399]: /usr/lib/udev/rules.d/11-dm-lvm.rules:40 The line takes no effect, ignoring.
systemd-udevd[217399]: /etc/udev/rules.d/60-ipath.rules:4 Invalid value "kcopy/%02n" for NAME (char 7: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/65-md-incremental.rules:28 Invalid value "/sbin/mdadm -I $env{DEVNAME} --export $devnode --offroot ${DEVLINKS}" for IMPORT (char 58: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /etc/udev/rules.d/73-special-net-names.rules:14 Invalid value "/bin/sh -ec 'D=${DEVPATH#*/vio/}; D=${D%%%%/*}; D=${D#????}; D=${D#0}; D=${D#0}; D=${D#0}; D=${D#0}; echo ${D:-0}'" for PROGRAM (char 16: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/84-nm-drivers.rules:10 Invalid value "/bin/sh -c 'ethtool -i $1 | sed -n s/^driver:\ //p' -- $env{INTERFACE}" for PROGRAM (char 24: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/90-libgpod.rules:19 IMPORT key takes '==' or '!=' operator, assuming '==', but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/90-libgpod.rules:23 IMPORT key takes '==' or '!=' operator, assuming '==', but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/99-vmware-scsi-udev.rules:5 Invalid value "/bin/sh -c 'echo 180 >/sys$DEVPATH/device/timeout'" for RUN (char 27: invalid substitution type), ignoring, but please fix it.
systemd-udevd[217399]: /usr/lib/udev/rules.d/99-vmware-scsi-udev.rules:6 Invalid value "/bin/sh -c 'echo 180 >/sys$DEVPATH/device/timeout'" for RUN (char 27: invalid substitution type), ignoring, but please fix it.
systemd[1]: Started udev Kernel Device Manager.
2019-06-28 16:20:48 +02:00
Zbigniew Jędrzejewski-Szmek e79c228b52 udev: move rule structure definitions into the .c file
They are (and should) only be used there, no need to expose them.
2019-06-28 16:20:48 +02:00
Zbigniew Jędrzejewski-Szmek d4114f704f udev: move rules logging functions into the .c file
They are (and can) only be used there, no need to expose them.
2019-06-28 16:20:48 +02:00
Yu Watanabe d7aee41db3 udev: check formatting of attribute or value earlier 2019-06-03 08:35:33 +09:00
Yu Watanabe 1448820aad udev: evaluate formatting in RUN= key earlier
Closes #12291.
2019-06-03 08:35:33 +09:00
Yu Watanabe 25de7aa7b9 udev: modernize udev-rules.c
This does the following:
- rename enum udev_builtin_cmd -> UdevBuiltinCmd
- rename struct udev_builtin -> UdevBuiltin
- move type definitions to udev-rules.h
- move prototypes of functions defined in udev-rules.c to udev-rules.h
- drop to use strbuf
- propagate critical errors in applying rules,
- drop limitation for number of tokens per line.
2019-06-02 14:15:26 +09: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
Lennart Poettering 6cdc62aa97 udev: whitespace fix 2019-04-18 15:18:12 +02:00
Florian Dollinger 5a1ee07302 Check for final assignments in RUN keys (#12309)
As described in #12291
2019-04-15 15:59:36 +09:00
Lennart Poettering 568ee8fc46 udev: use strempty() where appropriate 2019-04-02 14:54:42 +02:00
Lennart Poettering b82f71c7ff tree-wide: constify a few static string tables 2019-03-25 14:04:34 +01:00
Yu Watanabe 7a2093236b udev: refuse to modify SEQNUM by udev rules 2019-03-12 03:49:53 +09:00
Yu Watanabe d4d690facd udevd: use device_get_action() and device_get_seqnum() 2019-03-12 03:49:53 +09:00
Franck Bui 3c37dadf62 udev: restore debug level when logging a failure in the external prog called by IMPORT{program}
It was already the case before commit a75211421f,
which upgraded the log to warning.

This seems an unintended side effect as the commit message doesn't mention it
and the old behavior looks more appropriate.
2019-03-05 13:53:25 +01: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 e8b2737f20 udev-rules: do not ignore short lines
Otherwise, a short line continues the previous continuation.

This fixes a bug introduced by f10aa08e3e.
2019-02-22 06:50:12 +09:00
Lennart Poettering bde06abd4f
Merge pull request #10408 from keszybz/analyze-cat-presets
systemd-analyze cat-presets
2019-02-18 16:02:45 +01:00
Zbigniew Jędrzejewski-Szmek 116b91e8cc udev: use the usual set of load paths for udev rules
This adds /usr/local/lib/udev/rules.d to the search path on non-split-usr systems.
On split-usr systems, the paths with /usr/-prefixes are added too.
In the past, on split-usr systems, it made sense to only load rules from
/lib/udev/rules.d, because /usr could be mounted late. But we don't support running
without /usr since 80758717a6, so in practice it doesn't matter whether the
rules files are in /lib/udev/rules.d or /usr/lib/udev/rules.d. Distributions
that maintain the illusion of functional split-usr are welcome to simply not put any
files in /usr/lib/udev/rules.d/.

In practice this doesn't change much, but it makes udev more consistent with the
rest of the systemd suite.
2019-02-18 10:29:33 +01:00
Yu Watanabe 72ca8f71c1 udev-rules: use parse_uid() or parse_gid() 2019-02-18 12:22:54 +09:00
Yu Watanabe 145e020ac3 udev-rules: use new() macro instead of malloc_multiply() 2019-02-18 12:22:54 +09:00
Yu Watanabe f10aa08e3e udev-rules: use read_line() and drop fgets() 2019-02-18 12:22:49 +09:00
Yu Watanabe 759fb3a904 udev-rules: use size_t for array index 2019-02-18 09:24:03 +09:00
Yu Watanabe 530727aed8 udev-rules: use GREEDY_REALLOC() macro where it applicable
This also changes types of several variables e.g. token_max to size_t.
2019-02-18 09:22:25 +09:00
Yu Watanabe 57f08d5cdd udev-rules: update log messages about OWNER= or GROUP= settings on --resolve=names=never
This also set lower log level for the messages.

6e2efb6c73 introduces the log messages.
But udevd may be started with --resolve-names=never, and the behavior
is expected.

Fixes #11720.
2019-02-16 07:21:28 +09:00
Lennart Poettering 683a1e7fd9
Merge pull request #11594 from yuwata/udev-rule-cleanups
udev-rule, ethtool: several coding style cleanups
2019-02-15 11:37:11 +01:00
Yu Watanabe 6e2efb6c73 udev-rule: make rule_add_key() return negative errno when too much tokens
As OPTIONS= rule introduce multiple tokens.

Fixes oss-fuzz#12980.
2019-02-13 04:14:21 +09:00
Yu Watanabe 76b9bdd96f udev-rule: check function retun value is negative or not, instead of non-zero
One exception is udev_event_spawn(), which returns negative or positive
value on failure.
2019-02-12 11:03:40 +09:00
Yu Watanabe 605aa52f83 udev-rule: make match_key() and match_attr() return boolean value 2019-02-12 11:03:40 +09:00
Yu Watanabe bb175a0338 udev-rule: drop unnecessary parentheses 2019-02-12 11:03:40 +09:00
Yu Watanabe 704dbfb279 udev-rule: make get_key() return negative errno 2019-02-12 11:03:40 +09:00
Yu Watanabe 1f362ff185 udev-rule: drop unnecessary assignments 2019-02-12 11:03:39 +09:00
Yu Watanabe ef660d072f udev-rule: propagate error cause in add_token() 2019-02-12 11:03:39 +09:00
Zbigniew Jędrzejewski-Szmek a6ca3c1921 udev: do logging before setting variables to NULL
gcc-9 diagnoses this as an error.
Reported by Jeff Law.
2019-01-15 13:58:45 +01:00
Topi Miettinen a1e92eee3e Remove 'inline' attributes from static functions in .c files (#11426)
Let the compiler perform inlining (see #11397).
2019-01-15 08:12:28 +01:00
Zbigniew Jędrzejewski-Szmek a75211421f udev: rework how we handle the return value from spawned programs
When running PROGRAM="...", we would log
systemd-udevd[447]: Failed to wait spawned command '...': Input/output error
no matter why the program actually failed, at error level.

The code wouldn't distinguish between an internal failure and a failure in the
program being called and run sd_event_exit(..., -EIO) on any kind of error. EIO
is rather misleading here, becuase it suggests a serious error.

on_spawn_sigchld is updated to set the return code to distinguish failure to
spawn, including the program being killed by a signal (a negative return value),
and the program failing (positive return value).

The logging levels are adjusted, so that for PROGRAM= calls, which are
essentially "if" statements, we only log at debug level (unless we get a
timeout or segfault or another unexpected error).
2019-01-07 18:36:04 +01:00
Zbigniew Jędrzejewski-Szmek 2e08871534 udev: use typedef for struct udev_event 2018-12-17 09:27:24 +01:00
Zbigniew Jędrzejewski-Szmek 9a07157dd5 udev: use typedef for struct udev_rules 2018-12-17 09:27:21 +01:00
Zbigniew Jędrzejewski-Szmek 1d79128121 udev: make udev_rules_new() return a proper error code 2018-12-14 10:20:43 +01:00
Yu Watanabe e924c60f69 udev: use hashmap_clear_free_key() and hashmap_free_free_key() 2018-12-02 12:18:54 +01:00
Yu Watanabe 49c603bd5e udev: drop duplicate whitespaces 2018-11-26 11:53:21 +09:00
Yu Watanabe b4ba2fe3f1 udev-rules: include device sysname in log messages 2018-11-26 11:37:29 +09:00
Yu Watanabe 8c19dc54d3 udev-rules: update log messages 2018-11-23 01:15:42 +09:00
Yu Watanabe 20e97dd3de meson: add option for debugging udev 2018-11-23 00:28:27 +09:00