Commit graph

1690 commits

Author SHA1 Message Date
Yu Watanabe 5c2316c605 ethtool-util: move from src/udev/net/ to src/shared/ 2019-06-19 09:03:50 +09:00
Zbigniew Jędrzejewski-Szmek 96848152fa udev: introduce NAMING_STABLE_VIRTUAL_MACS (retroactively)
This is for 6d36464065. It turns out that this is causing more problems than
expected. Let's retroactively introduce naming scheme v241 to conditionalize
this change.

Follow-up for #12792 and 6d36464065. See also
https://bugzilla.suse.com/show_bug.cgi?id=1136600.

$ SYSTEMD_LOG_LEVEL=debug NET_NAMING_SCHEME=v240 build/udevadm test-builtin net_setup_link /sys/class/net/br11
$ SYSTEMD_LOG_LEVEL=debug NET_NAMING_SCHEME=v241 build/udevadm test-builtin net_setup_link /sys/class/net/br11
...
@@ -20,11 +20,13 @@
 link_config: could not set ethtool features for br11
 Could not set offload features of br11: Operation not permitted
 br11: Device has name_assign_type=3
-Using interface naming scheme 'v240'.
+Using interface naming scheme 'v241'.
 br11: Policy *keep*: keeping existing userspace name
 br11: Device has addr_assign_type=1
-br11: No stable identifying information found
-br11: Could not generate persistent MAC: No data available
+br11: Using "br11" as stable identifying information
+br11: Using generated persistent MAC address
+Could not set Alias=, MACAddress= or MTU= on br11: Operation not permitted
+br11: Could not apply link config, ignoring: Operation not permitted
 Unload module index
 Unloaded link configuration context.
 ID_NET_DRIVER=bridge
2019-06-17 13:43:18 +02:00
Zbigniew Jędrzejewski-Szmek 2ebe027b44 man: clean up naming scheme description a bit
This is in preparation for later changes.  Let's change the documentation of
net.naming-scheme= to also say that it applies to MAC addresses. This commit
doesn't actually implement that though.
2019-06-17 13:42:27 +02:00
Yu Watanabe 042526868a
Merge pull request #12508 from keszybz/no-root-checks
Drop many root checks
2019-06-06 21:31:19 +09:00
Yu Watanabe 99058cd66a udev: propagate errors in udev_event_execute_rules()
And do not set initialized flag to the device.
2019-06-05 10:44:17 +02:00
Zbigniew Jędrzejewski-Szmek 97afc0351a udevadm trigger: log errors and return first failure
When udevadm trigger is called, the list of devices to trigger is always
generated through enumeration, and devices can come and go, so we should not
treat -ENOENT as a failure. But other types of failure should be logged.
It seems they were logged until baa30fbc2c.

Also, return the first error. (I'm not sure if there are other failure modes
which we want to ignore. If they are, they'll need to be whitelisted like
-ENOENT.).
2019-06-05 09:54:54 +02:00
Yu Watanabe ae760f4b16 udevadm: add --wait-for-initialization option to "udevadm info" 2019-06-04 01:28:30 +09: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 7280153364 udev: use delete_trailing_chars() at one more place 2019-06-03 08:35:33 +09:00
Yu Watanabe 1b65f1ebc3 udev: replace xsprintf() + strpcpy() by strpcpyf() 2019-06-03 08:35:33 +09:00
Yu Watanabe ce4f94b8e9 udev: make parser for attribute of $result harder 2019-06-03 08:35:33 +09:00
Yu Watanabe 13cd553f91 udev: split udev_event_apply_format() into small pieces
Also, this makes the function refuse invalid formatting and
propagate error in substituing variable.
2019-06-03 08:35:08 +09:00
Yu Watanabe 3c209d6070 udev: comment that $tempnode and $sysfs formats are deprecated 2019-06-02 14:15:32 +09:00
Yu Watanabe ef315adaa4 udev: pass format type to udev_event_subst_format() 2019-06-02 14:15:32 +09:00
Yu Watanabe 7e9c23dd19 udev: rename enum subst_type -> FormatSubstitutionType 2019-06-02 14:15:32 +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
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
Yu Watanabe a54510c775 udev: suppress warning when interface matches 99-default.link
This suppress the following warning:
```
systemd-udevd[437]: Config file /usr/lib/systemd/network/99-default.link
applies to device based on potentially unpredictable interface name 'wlan0'
```

Follow-up for 84ea567eb4.
2019-05-28 10:04:12 +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
Zhang Xianwei 1f7b6872db udev/scsi_id: fix incorrect page length when get device identification VPD page
The length of device identification VPD page is filled with two bytes,
but scsi_id only gets the low byte. Fix it.

Signed-off-by: Zhang Xianwei <zhang.xianwei8@zte.com.cn>
2019-05-22 13:25:20 +09:00
Yu Watanabe c9f0f21e28
Merge pull request #12593 from AdrianBunk/master
Small changes from Yocto/musl builds
2019-05-18 10:25:59 +09:00
Adrian Bunk 010f917cf2 src/udev/udev-event.c must #include <sys/wait.h>
Fixes the following build failure with musl:
../git/src/udev/udev-event.c: In function 'spawn_wait':
../git/src/udev/udev-event.c:600:53: error: 'WEXITED' undeclared (first use in this function); did you mean 'WIFEXITED'?
         r = sd_event_add_child(e, NULL, spawn->pid, WEXITED, on_spawn_sigchld, spawn);
                                                     ^~~~~~~

This looks like a bug in udev-event.c that could also have broken
the compilation after some future glibc header reshuffle.
2019-05-17 09:35:43 +03:00
Franck Bui 88bd5a32e8 udevd: change the default value of udev.children-max (again)
Follow-up for faae64fa3d, which increased the
default number of udev workers per cpu regardless of how big the system is.

It's not really clear from the commit message if the new number of workers
improved the overall time for the boot process or only reduced the number of
times the max number of children limit was reached (and in this case
5406c36844 commit might have been more appropriate in the first place).

But systems with ~1000 CPUs are not rare these days and the worker numbers get
quite large with CPU factor of 8. Spawning more than 2000 workers can't be
healthy on any system, no matter how big.

Indeed the main mistake is the belief that udev is CPU-intensive, and thus the
number of allowed workers has to increase with the number of CPUs. It is not,
at probably has never been. It's I/O bound, and sometimes, bound by resources
such as locks.

This is an argument to:

 - scale only weakly with the number of CPUs, and the rationale to switch back
   to a scale factor C=2 but with a higher offset number which should affect
   systems with a small number of CPUs only. With this patch applied the offset
   is increased from O=8 to O=16.

 - put an absolute maximum limit to make sure no more than 2048 workers are
   spawned no matter how big the system is.

This still provides more workers for the laptop cases (where the number of CPUs
is limited), while avoiding sky-rocketing numbers for big systems.

Note that on most desktop systems, the memory limit will kick in. The following
table collects numbers about children-max. For each scenario, the first column
is the "cpu_limit" limit, and the second number is the minimum amount of memory
for the "cpu_limit" limit to become relevant (with less RAM, memory will limit
the number of children thus "mem_limit" will become the active limit).

       |    > v240    |    < v240     |  this patch   |
 CPUs  | C = 8, O = 8 | C = 2, O = 8  | C = 2, O = 16 |
-------------------------------------------------------
   1   |   16      2  |   10    1.3   |   18       2  |
   2   |   24      3  |   12    1.5   |   20       2  |
   4   |   40      5  |   16      2   |   24       3  |
   8   |   72      9  |   24      3   |   32       4  |
  16   |  136     17  |   40      5   |   48       5  |
  64   |  520     65  |  136     17   |  144      18  |
1024   | 8200   1025  | 2056    263   | 2048     256  |
2048   |16392   2049  | 4104    513   | 2048     256  |

This patch is mainly based on Martin Wilck's analyze and comments.
2019-05-16 23:09:41 +02:00
Zbigniew Jędrzejewski-Szmek 8c053c83ae udev: drop "en" prefix from ID_NET_NAME_ONBOARD
The comment in udev-builtin-net_id.c (removed in grandparent commit) showed the
property without the prefix. I assume that was always the intent, because it
doesn't make much sense to concatenate anything to an arbitrary user-specified
field.
2019-05-10 10:24:28 +02:00
Zbigniew Jędrzejewski-Szmek 4c27f691a5 udev: fix various comments
In particular: "re-renaming" was just a copy-paste error.
2019-05-10 10:24:28 +02:00
Zbigniew Jędrzejewski-Szmek 0b1e5b6ed8 man: describe naming schemes in a new man page
I decided to make this a separate man page because it is freakin' long.
This content could equally well go in systemd-udevd.service(8), systemd.link(5),
or a new man page for the net_id builtin.

v2:
- rename to systemd.net-naming-scheme
- add udevadm test-builtin net_id example
2019-05-10 10:24:03 +02:00
Zbigniew Jędrzejewski-Szmek 569ad251ad udevadm: drop pointless must_be_root() checks
Checking if we are root on the client side is generally pointless, since the
privileged operation will fail anyway and we can than log what precisly went
wrong.

A check like this makes sense only if:
- we need to do some expensive unprivileged operation before attempting the
  privileged operation, and the check allows us avoid wasting resources.
- the privileged operation would fail but in an unclear way.

Neither of those cases applies here.

This fixes calls like 'udevadm control -h' as unprivileged user.
2019-05-08 11:51:51 +02:00
Zbigniew Jędrzejewski-Szmek 099c77fd5f scsi_serial: replace some crazy strncpy() calls by strnlen()
gcc was warning about strncpy() leaving an unterminated string.
In this case, it was correct.

The code was doing strncpy()+strncat()+strlen() essentially to determine
if the strings have expected length. If the length was correct, a buffer
overread was performed (or at least some garbage bytes were used from the
uninitialized part of the buffer). Let's do the length check first and then
only copy stuff if everything agrees.

For some reason the function was called "prepend", when it obviously does
an "append".
2019-05-07 21:06:44 +02:00
Zbigniew Jędrzejewski-Szmek 881a62debb scsi_serial: replace &foo[n] by foo+n 2019-05-07 15:07:43 +02:00
Zbigniew Jędrzejewski-Szmek 64538af89b udev/cdrom_id: drop unneeded parentheses 2019-05-01 11:46:42 +02:00
Yu Watanabe 8b803ad634 udev: drop unnecessary brackets
Follow-up for ed0cb34682.
2019-04-30 19:10:35 +02:00
Lennart Poettering 0892f3f999
Merge pull request #12420 from mrc0mmand/coccinelle-tweaks
Coccinelle improvements
2019-04-30 11:37:19 +02:00
Frantisek Sumsal ed0cb34682 tree-wide: code improvements suggested by Coccinelle 2019-04-30 09:39:07 +02:00
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Frantisek Sumsal 4e361acc06 tree-wide: replace explicit NULL checks with their shorter variants
Done by coccinelle/equals-null.cocci
2019-04-28 14:28:49 +02:00
Franck Bui 5406c36844 udevd: notify when max number value of children is reached only once per batch of events
When booting with "udev.log-priority=debug" for example, the output might be
spammed with messages like this:

    systemd-udevd[23545]: maximum number (248) of children reached
    systemd-udevd[23545]: maximum number (248) of children reached
    systemd-udevd[23545]: maximum number (248) of children reached
    systemd-udevd[23545]: maximum number (248) of children reached
    systemd-udevd[23545]: maximum number (248) of children reached
    systemd-udevd[23545]: maximum number (248) of children reached
    systemd-udevd[23545]: maximum number (248) of children reached

While the message itself is useful, printing it per batch of events should be
enough.
2019-04-26 09:58:12 +02:00
Yu Watanabe 84ea567eb4 udev,network: warn when .link or .network file has no [Match] section
Closes #12098.
2019-04-25 08:41:10 +02:00
Zbigniew Jędrzejewski-Szmek f5f899ef04
Merge pull request #12346 from poettering/accept-flush
socket-util: make sure accept_flush() doesn't hang on EOPNOTSUPP
2019-04-23 15:03:29 +02:00
Jiri Pirko eaa9d507d8 udev: net_id: introduce predictable names for netdevsim
In order to properly and predictably name netdevsim netdevices,
introduce a separate implementation, as the netdevices reside on a
specific netdevsim bus. Note that this applies only to netdevsim devices
created using sysfs, because those expose phys_port_name attribute.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
2019-04-23 14:01:00 +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
Zbigniew Jędrzejewski-Szmek cc5549ca12 scripts: use 4 space indentation
We had all kinds of indentation: 2 sp, 3 sp, 4 sp, 8 sp, and mixed.
4 sp was the most common, in particular the majority of scripts under test/
used that. Let's standarize on 4 sp, because many commandlines are long and
there's a lot of nesting, and with 8sp indentation less stuff fits. 4 sp
also seems to be the default indentation, so this will make it less likely
that people will mess up if they don't load the editor config. (I think people
often use vi, and vi has no support to load project-wide configuration
automatically. We distribute a .vimrc file, but it is not loaded by default,
and even the instructions in it seem to discourage its use for security
reasons.)

Also remove the few vim config lines that were left. We should either have them
on all files, or none.

Also remove some strange stuff like '#!/bin/env bash', yikes.
2019-04-12 08:30:31 +02:00
Lennart Poettering 03abeb0baf
Merge pull request #12267 from keszybz/udev-settle-warning
Udev settle warning
2019-04-11 19:01:03 +02:00
Yu Watanabe 01234e1fe7 tree-wide: drop several missing_*.h and import relevant headers from kernel-5.0 2019-04-11 19:00:37 +02:00
Lennart Poettering 4ff9bc2ea6 tree-wide: port users over to use new ERRNO_IS_ACCEPT_AGAIN() call 2019-04-10 22:11:18 +02:00
Zbigniew Jędrzejewski-Szmek 1662732768 systemd-udev-settle.service: emit deprecation notice 2019-04-10 15:58:14 +02:00
Yu Watanabe 11efeca11e udevadm: drop unused option 2019-04-04 12:55:06 +09:00
Lennart Poettering 568ee8fc46 udev: use strempty() where appropriate 2019-04-02 14:54:42 +02:00
Yu Watanabe 76e62a4d22 udev: move udev_ctrl_cleanup() into manager_free() 2019-04-01 15:20:03 +02:00
Yu Watanabe 4b4a6c9b41 udev: shorten code a bit 2019-04-01 10:30:31 +09:00
Zbigniew Jędrzejewski-Szmek ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Lennart Poettering b82f71c7ff tree-wide: constify a few static string tables 2019-03-25 14:04:34 +01:00
Yu Watanabe 1beabe08d6 network,udev: explicitly declare 'conditions' is a list 2019-03-24 00:35:39 +09:00
Lennart Poettering 83276695c6
Merge pull request #12079 from keszybz/fuzz-nspawn-oci
Add fuzzer for nspawn-oci
2019-03-22 21:06:17 +01:00
Zbigniew Jędrzejewski-Szmek 54ed9f88dc udev/link-config: rename MACPolicy to MACAddressPolicy
Things are clearer if the same name is used everywhere, and we don't gain
much by saving a few bytes.
2019-03-22 17:16:17 +01:00
Lennart Poettering 0f4b93c4b5 udev: use string_table_lookup() where we can 2019-03-22 12:21:12 +01:00
Yu Watanabe c4f58deab5 network,udev: split static condition tests from net_match_config() 2019-03-21 23:37:39 +09:00
Lennart Poettering d449d63a0d
Merge pull request #11975 from keszybz/fuzzer-fixes-n
Fixes for a few fuzzer issues
2019-03-15 17:34:37 +01:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Lennart Poettering eefc66aa8f util: split out some stuff into a new file limits-util.[ch] 2019-03-13 12:16:43 +01:00
Zbigniew Jędrzejewski-Szmek 0fb729282b fuzz: limit the maximum size of test inputs for a few parsers
We have a few cases or reported issues which are about a timeout to parse
the input in 25 s. In all cases, the input is a few hundred kb. We don't really
care if the config parsers are super efficent, so let's set a limit on the input
size to avoid triggering such issues. The parsers often contain quadratic
algorithms. This is OK, because the numbers of elements are almost always very
small in real use. Rewriting the code to use more complicated data structures
to speed this up would not only complicate the code, but also pessimize behaviour
for the overwhelmingly common case of small samples. Note that in all those
cases, the input data is trusted. We care about memory correctness, and not
not so much about efficiency.

The size checks are done twice: using options for libfuzzer, and using an
internal check for afl. Those should be changed together. I didn't use a define,
because there is no easy mechanism to share the define between the two files.
2019-03-12 19:30:05 +01:00
Zbigniew Jędrzejewski-Szmek ec637f309f
Merge pull request #11943 from yuwata/device-action-seqnum-cleanups
sd-device: store parsed SEQNUM and ACTION string
2019-03-12 13:17:33 +01:00
Yu Watanabe 1f682e243f udev: fix memleak in 'udevadm trigger --settle'
Fixes #11966.
2019-03-12 09:15:02 +01:00
Yu Watanabe a12b87f59c udevadm-test: check action string earlier
The string will be checked later in device_new_from_synthetic_event(),
but let's check it earlier in parse_argv().
2019-03-12 03:49:53 +09:00
Yu Watanabe 2c18a85400 udevadm: use device_get_action() 2019-03-12 03:49:53 +09: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
Yu Watanabe dcee4a134c udevadm trigger: make --action option support all possible actions
This also make udevadm abort operations if invalid action is specified.
2019-03-07 15:19:02 +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
Lennart Poettering 73622e02fb
Merge pull request #11881 from yuwata/networkd-vs-interface-renaming
Networkd vs interface renaming
2019-03-05 10:05:57 +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 a4055a608e udev: set ID_RENAMING property when interface renaming is requested
And drop the property on the corresponding 'move' uevent.
2019-03-05 10:31:35 +09:00
Yu Watanabe 6d0fdf4513 udev: do not read UdevEvent object before checking it is non-NULL 2019-03-05 10:31:20 +09:00
Yu Watanabe 589384be8d udev: drop unnecessary copy of new interface name 2019-03-05 10:02:09 +09:00
Zbigniew Jędrzejewski-Szmek 760034bebe udev-builtin-usb_id: guard against overflow when reading descriptor data
CID#996458. Coverity warns that we trust desc->bLength as read in
the input data to adjust our position in the buffer. This value could
be anything, leading to overflow. It's unlikely that the kernel feeds
us invalid data, but let's me more careful.

If any error is encountered, more logs are given.
2019-02-28 11:57:51 +01:00
Zbigniew Jędrzejewski-Szmek 8bdca77c40 udev-builtin-usb_id: use strjoina to simplify code 2019-02-28 11:40:44 +01:00
Zbigniew Jędrzejewski-Szmek 60722ad778 meson: declare version.h as dep for various targets that include build.h
Should fix #11565.
2019-02-25 10:41:41 +01:00
Yu Watanabe a378400b3f fuzz: add fuzzer for parsing .link files
This also renames load_link() to link_load_one()
2019-02-25 12:35:51 +09:00
Yu Watanabe 84fb56d396 udev/ethtool: fix error detection of ethtool_link_mode_bit_from_string() 2019-02-25 12:35:40 +09:00
Yu Watanabe 391f6bc1db udev: fix memleak in conditions for .link file 2019-02-25 11:57:14 +09:00
Yu Watanabe 176d9c0e11 udev/net: drop .link files earlier when their conditions do not match system environment 2019-02-25 11:54:50 +09:00
Yu Watanabe 6cdab9f17f udev/net: use structured initializer at one more place 2019-02-25 11:53:57 +09:00
Yu Watanabe 79a60834e2 udev/net: use size_t for index at one more place 2019-02-25 11:51:32 +09:00
Yu Watanabe e8a42907ed udev/net: ignore errors in loading .link files but warn about that 2019-02-25 11:50:57 +09:00
Yu Watanabe f2d251cdb8 udev/net: shorten load_link() a little bit 2019-02-25 11:48:39 +09:00
Yu Watanabe c6b3370ab2 udev: drop unused Ethernet section 2019-02-25 11:45:34 +09: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
Yu Watanabe 78467aeb95 udev-ctrl: split out logic of waiting for reply to udev_ctrl_wait()
This makes `udevadm control` can send multiple commands in one
connection.
2019-02-20 06:17:42 +09:00
Zbigniew Jędrzejewski-Szmek a0b60b8a1b udevadm: print error if the commands fail
We'd exit with an error but no output. Print the error in the usual fashion.
2019-02-20 06:17:42 +09:00
Yu Watanabe d02c6f5461 udev-ctrl: use sd_event and introduce udev_ctrl_start()
Now the new callback function get enum udev_ctrl_msg_type.
So, this commit also drops udev_ctrl_connection and udev_ctrl_msg.
2019-02-20 06:17:42 +09:00
Yu Watanabe 204e9c3e29 udev: drop unused Manager::uevent_event 2019-02-20 06:17:42 +09:00
Yu Watanabe 53bba2fb1d udev-ctrl: refactor udev_ctrl_enable_receiving() 2019-02-20 06:17:42 +09:00
Yu Watanabe 100bc5bf98 udev-ctrl: make udev_ctrl_new() return negative errno on failure 2019-02-20 06:17:42 +09:00
Lennart Poettering 5f06ba8018
Merge pull request #11478 from yuwata/enumerate-match-parent
sd-device-enumerator: support multiple parents
2019-02-18 18:35:47 +01: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
Lennart Poettering 9c5675af76
Merge pull request #11729 from yuwata/fix-11721
sd-device: also store properties read from udev database to sd_device::properties_db
2019-02-18 16:02:26 +01:00
Lennart Poettering 1ff3e129ae
Merge pull request #11746 from yuwata/udev-rules-cleanup
udev-rules: several cleanups for udev-rules.c
2019-02-18 13:05:34 +01:00
Yu Watanabe 380d19016e udev-event: make subst_format_var() always provide null-terminated string on success
Fixes #11731.
2019-02-18 12:54:53 +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
Zbigniew Jędrzejewski-Szmek dc0d407851 udev,network: use standard paths for .network and .link files
This centralizes the configuration to one header file.
/usr/local/lib is now included in the search list, and documentation is
updated accordingly.
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 4f4daf418f udev,network: drop unused parent_driver argument from net_match_config()
The argument has never been used.
2019-02-17 00:47:49 +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 bbd8598f8b
Merge pull request #11589 from yuwata/udevd-is-device-busy
udevd: refactoring is_device_busy()
2019-02-15 12:16:37 +01:00
Michael Olbrich 646876105f v4l_id: use device_caps if available
According to the specification[1] the 'capabilities' describe the physical
device as a whole and the 'device_caps' describe the current device node.
The existence of 'device_caps' is indicated by the V4L2_CAP_DEVICE_CAPS
capability flag.
Use the 'device_caps' if available to generate the correct
ID_V4L_CAPABILITIES for the current device node.

This is relevant for UVC devices with current kernels: Two /dev/videoX
devices exist for those. One for video and one for metadata. The
 V4L2_CAP_VIDEO_CAPTURE flag is present in the 'capabilities' for both
device nodes but only in the 'device_caps' of the video device node.

Without this, the ID_V4L_CAPABILITIES of the metadata device node
incorrectly contains 'capture'.

[1] https://www.linuxtv.org/downloads/v4l-dvb-apis-new/uapi/v4l/vidioc-querycap.html
2019-02-15 12:14:05 +01: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
Lennart Poettering e5d21c24a0
Merge pull request #11382 from keszybz/udev-predictable-macs
Allow MACAddressPolicy=persistent for all virtual devices
2019-02-15 11:31:25 +01:00
Zbigniew Jędrzejewski-Szmek dc9cced4ac
Merge pull request #11704 from yuwata/fix-oss-fuzz-12980
udev-rule: make rule_add_key() return negative errno when too much tokens
2019-02-13 23:27:12 +01:00
Yu Watanabe 31cbd20253 udev: check whether systemd is running, and do not use cg_kill() if not
Fixes #11645.
2019-02-13 17:07:56 +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 ee60be466b ethtool: make find_feature_index() return negative errno 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
Mantas Mikulėnas 6d6308f677 udevadm info: "-a" should enumerate sysfs attributes, not envs (#11642)
This fixes a bug introduced by 13aca84769.
2019-02-05 06:30:49 +02:00
Yu Watanabe 8671411668 udevd: save the result of devnum or ifindex blocker 2019-01-29 14:07:21 +01:00
Yu Watanabe baa461fc05 udevd: always block follwoing events with same devpath
Originally commented as "devices names might have changed/swapped in the meantime",
but may not. For safety, let's block the following events with same
devpath.

This may fix #6514.
2019-01-29 14:04:43 +01:00
Yu Watanabe 0bd0407efc udevd: trivial refactoring of is_device_busy() 2019-01-29 13:53:19 +01:00
Yu Watanabe 5b3b0733c9 udevadm: trigger: support multiple arguments
Closes #6098.
2019-01-23 15:22:16 +09:00
Yu Watanabe 2277e84560 udevadm info: make --export-prefix imply --export
Setting --export without --export-prefix is meaningless.
2019-01-22 15:07:27 +09:00
Zbigniew Jędrzejewski-Szmek 015b097cce udev: add debug logging about the choice of MAC 2019-01-21 17:33:53 +01:00
Zbigniew Jędrzejewski-Szmek 6d36464065 udev,networkd: use the interface name as fallback basis for MAC and IPv4LL seed
Fixes #3374. The problem is that we set MACPolicy=persistent (i.e. we would
like to generate persistent MAC addresses for interfaces which don't have a
fixed MAC address), but various virtual interfaces including bridges, tun/tap,
bonds, etc., do not not have the necessary ID_NET_NAME_* attributes and udev
would not assing the address and warn:
  Could not generate persistent MAC address for $name: No such file or directory

Basic requirements which I think a solution for this needs to satisfy:

1. No changes to MAC address generation for those cases which are currently
  handled successfully. This means that net_get_unique_predictable_data() must
  keep returning the same answer, which in turn means net_get_name() must keep
  returning the same answer. We can only add more things we look at with lower
  priority so that we start to cover cases which were not covered before.

2. Like 1, but for IPvLL seed and DHCP IAD. This is less important, but "nice
  to have".

3. Keep MACPolicy=persistent. If people don't want it, they can always apply
  local configuration, but in general stable MACs are a good thing. I have never
  seen anyone complain about that.

== Various approaches that have been proposed

=== https://github.com/systemd/systemd/issues/3374#issuecomment-223753264 (tomty89)
if !ID_BUS and INTERFACE, use INTERFACE

I think this almost does the good thing, but I don't see the reason to reject ID_BUS
(i.e. physical hardware). Stable MACs are very useful for physical hardware that has
no physical MAC.

=== https://github.com/systemd/systemd/issues/3374#issuecomment-224733069 (teg)
if (should_rename(device, true))

This means looking at name_assign_type. In particular for
NET_NAME_USER should_rename(..., true) returns true. It only returns false
for NET_NAME_PREDICTABLE. So this would cover stuff like br0, bond0, etc,
but would not cover lo and other devices with predictable names. That doesn't
make much sense.

But did teg mean should_rename() or !should_rename()?

=== https://github.com/systemd/systemd/issues/3374#issuecomment-234628502 (tomty89):
+ if (!should_rename(device, true))
+        return udev_device_get_sysname(device)

This covers only devices with NET_NAME_PREDICTABLE. Since the problem applies as
much to bridges and such, this isn't neough.

=== https://github.com/systemd/systemd/issues/3374#issuecomment-281745967  (grafi-tt)
+        /* if the machine doesn't provide data about the device, use the ifname specified by userspace
+        * (this is the case when the device is virtual, e.g., bridge or bond) */
+        s = udev_device_get_sysattr_value(device, "name_assign_type");
+        if (s && safe_atou(s, &type) >= 0 && type == NET_NAME_USER)
+                return udev_device_get_sysname(device);

This does not cover bond0, vnet0, tun/tap and similar.
grafi-tt also proposes patching the kernel, but *not* setting name_assign_type
seems intentional in those cases, because the device name is a result of
enumeration, not set by the userspace.

=== https://github.com/systemd/systemd/issues/3374#issuecomment-288882355 (tomty89)
(also PR #11372)
- MACAddressPolicy=persistent

This break requirement 3. above. It would solve the immediate problem, but I
think the disruption is too big.

=== This patch

This patch means that we will set a "stable" MAC for pretty much any virtual
device by default, where "stable" means keyed off the machine-id and interface
name.

It seems like a big change, but we already did this for most physical devices.
Doing it also for virtual devices doesn't seem like a big issue. It will make
the setup and monitoring of virtualized networks slightly nicer. I don't think
anyone is depending on having the MAC address changed when those devices are
destoryed and recreated. If they do, they'd have to change MACAddressPolicy=.

== Implementation
net_get_name() is called from dhcp_ident_set_iaid() so I didn't change
net_get_name() like in grafi-tt's patch, but net_get_unique_predictable_data().

net_get_unique_predictable_data() is called from get_mac() in link-config.c
and sd_ipv4ll_set_address_seed(), so both of those code paths are affected
and will now get data in some cases where they errored out previously.

The return code is changed to -ENODATA since that gives a nicer error string.
2019-01-21 17:33:09 +01:00
Zbigniew Jędrzejewski-Szmek b0a28c2956
Merge pull request #11349 from yuwata/udevadm-control-ping
Add 'udevadm control --ping'
2019-01-18 17:41:00 +01:00
Yu Watanabe d30f43eec5 udevd: rename control command SYNC -> PING in log message 2019-01-18 16:10:01 +01:00
Yu Watanabe 2001622c58 udevadm: add --wait-daemon option to 'trigger' command 2019-01-18 16:10:01 +01:00
Yu Watanabe a82340cc03 udevadm: add --ping option to 'control' command
This exposes `udev_ctrl_send_ping()`.
2019-01-18 16:10:01 +01:00
Lennart Poettering 8274a4132c
Merge pull request #11449 from keszybz/udev-link-naming-again
Make udev link re-renaming conditional
2019-01-17 20:06:55 +01:00
Zbigniew Jędrzejewski-Szmek 73d2bb0881 link-config: default to "keep" policy if naming-scheme<=239 is used
This makes the new (>=240) behaviour conditional, restoring backwards compat, as least
as long as an old naming scheme is used.
2019-01-17 13:56:02 +01:00
Zbigniew Jędrzejewski-Szmek 35b351900f udev: move naming-scheme bits into their own file 2019-01-17 13:56:02 +01:00
Zbigniew Jędrzejewski-Szmek 3907446f02 link-config: add "keep" policy and use it by default
If "keep" policy is specified, and the interface has a name that is
NET_NAME_USER or NET_NAME_RENAMED, we stop processing rules. "keep" should
probably be specified either first or last depending on the preference.

This partially reimplements 55b6530baa, in the
sense that if the "keep" policy is not specified, and if the interface has
a NamingPolicy, it will be renamed, even if it had a name previously.
So this breaks backwards compatibility in this case, but that's more in line
with what users expect.

Closes #9006.
2019-01-17 13:56:02 +01:00
Jan Janssen a0e1ad10ea ethtool: Make sure advertise is actually set when autonegotiation is used 2019-01-17 09:15:09 +01:00
Zbigniew Jędrzejewski-Szmek 0b189e8fa7 link-config: unentangle the renaming logic and add logging
What policy we dicide to use it rather important, but this bit of information
wasn't logged. Let's always do that.

The code was also written in a confusing way, which probably contributed to the
unintended effects of 55b6530baa and other commits.
We would loop over all policies, and note if "kernel" was specified, and then
possibly unset the result at the end. Let's immediately log the result and cut
to the end if we can figure out the answer.

No functional change intended, except for the new log lines.
Using goto is not very elegant, but we can't use break because of the switch,
and there are multiple conditions to break the loop, so using goto is cleanest.
2019-01-16 22:20:04 +01:00
Yu Watanabe 7e8bd58eb1 udev: 'val' may be NULL, use strempty() 2019-01-16 13:34:04 +01:00
Zbigniew Jędrzejewski-Szmek ed30802324 Revert "Always rename an interface to its name specified in config if no NamePolicy= is specified"
This reverts commit 55b6530baa.

This commit description says "Always rename an interface to its name specified
in config if no NamePolicy= is specified", but it does much more:
1. It completely changes the meaning of NamePolicy=kernel. Before, it meant that an interface
   with type==NAMEPOLICY_KERNEL would not be renamed. After, the kernel name only works as
   a fallback, if no policy matches.
2. The "if no NamePolicy= is specified" part is not true at all, the interface will be renamed
   according to the specified NamePolicy=.

After 55b6530baa, the should_rename() function is named very misleadingly: it is only used
to mean "respect kernel predictable name if no naming policy matches".

Let's revert, and start with a clean slate. This fixes #11436.
2019-01-16 13:28:41 +01: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
Yu Watanabe 0eba88dc9f udevadm: fix segfault
Fixes #11416.
2019-01-14 06:34:19 +09:00
Yu Watanabe 8d6c4b310d udev: use ENODATA when 'No entry found from hwdb'
Before:
IMPORT builtin 'hwdb' fails: No such file or directory

After:
IMPORT builtin 'hwdb' fails: No data available

Previous log is confusing and may be understood as hwdb file not exist.
2019-01-13 18:04:10 +09:00
Yu Watanabe a119328608 udev: use SYNTHETIC_ERRNO() macro in log_device_*_errno() 2019-01-13 17:50:47 +09:00
Yu Watanabe 3797776e11 udev: use usec_t for timeout in udev_ctrl_send_*() 2019-01-13 07:37:49 +09:00
Yu Watanabe b1d1cb5b47 udevadm: also set LOG_DEBUG to LOG_REAL_SYSTEMD when --debug is passed 2019-01-13 07:37:49 +09:00
Yu Watanabe c809f33719 udev: also update log level for LOG_REALM_SYSTEMD
Now, not a few udevd debug logs come from sd-device or sd-hwdb.
Only setting LOG_REALM_UDEV may not sufficient to debug.
We have already similar code in main() and udevadm.
2019-01-13 07:37:49 +09:00
Yu Watanabe 47c8fcbeb7 udevadm: use SYNTHETIC_ERRNO() macro 2019-01-13 07:37:49 +09:00
Yu Watanabe cf7f501353 udevadm: improve error message when no option specified for 'control' command
Also drop redundant block, use SYNTHETIC_ERRNO(), and add log_oom().
2019-01-13 07:37:49 +09:00
Topi Miettinen 7ae3561a5a Delete duplicate lines
Found by inspecting results of running this small program:

int main(int argc, const char **argv) {
	for (int i = 1; i < argc; i++) {
		FILE *f;
		char line[1024], prev[1024], *r;
		int lineno;

		prev[0] = '\0';
		lineno = 1;
		f = fopen(argv[i], "r");
		if (!f)
			exit(1);
		do {
			r = fgets(line, sizeof(line), f);
			if (!r)
				break;
			if (strcmp(line, prev) == 0)
				printf("%s:%d: error: dup %s", argv[i], lineno, line);
			lineno++;
			strcpy(prev, line);
		} while (!feof(f));
		fclose(f);
	}
}
2019-01-12 16:02:26 +01:00
Yu Watanabe e0b7a5d151 udevd: refuse devices which do not have ACTION property 2019-01-12 09:32:20 +09:00
Yu Watanabe 33ad742a84 udevd: drop unnecessary brackets 2019-01-12 09:32:20 +09:00
Yu Watanabe c0ff3d6cbc udevd: make worker also log ACTION property 2019-01-12 09:32:20 +09:00
Yu Watanabe 25d4f5b071 udevd: reject devices which do not have SEQNUM 2019-01-12 09:32:20 +09:00
Yu Watanabe 956833b417 udevd: provide worker_hash_ops and drop manager_workers_free() 2019-01-12 09:32:20 +09:00
Yu Watanabe d40534643b udevd: use structured initializer at one more place 2019-01-12 09:32:20 +09:00
Yu Watanabe 1f3f6bd007 udevd: use worker_free() on failure in worker_new()
Otherwise, worker_monitor may not unrefed correctly.
2019-01-12 09:32:20 +09:00
Zbigniew Jędrzejewski-Szmek a1b939dfc7
Merge pull request #11376 from yuwata/11365-v2
udev: initialize sockets before fork()
2019-01-10 09:08:57 +01:00
Zbigniew Jędrzejewski-Szmek b5af8c8cdf udev: open control and netlink sockets before daemonization
c4b69e990f effectively moved the initalization of socket.
Before that commit:
run → listen_fds → udev_ctrl_new → udev_ctrl_new_from_fd → socket()
After:
run → main_loop → manager_new → udev_ctrl_new_from_fd → socket()

The problem is that main_loop was called after daemonization. Move manager_new
out of main_loop and before daemonization.

Fixes #11314 (hopefully ;)).

v2: Yu Watanabe
sd_event is initialized in main_loop().
2019-01-10 14:09:15 +09:00
Zbigniew Jędrzejewski-Szmek 44dcf454b6 udevd: drop redundant call to sd_event_get_exit_code
sd_event_loop returns the same thing anyway.
2019-01-10 14:09:01 +09:00
Zbigniew Jędrzejewski-Szmek 1b2a7d92af Fix a few comments 2019-01-08 23:11:26 +01: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
Yu Watanabe c494b739a4 udevadm: refuse to run trigger, control, settle and monitor commands in chroot
Closes #11333.
2019-01-08 10:31:19 +01:00
Yu Watanabe 44909f1c9f ethtool: minimize the size of port_table
Note that `_NET_DEV_PORT_MAX` is 0x100.
2019-01-08 03:30:15 +09:00
Yu Watanabe 1637c3575b ethtool: use kernel defined values for NET_DEV_PORT_* 2019-01-08 03:28:47 +09: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 88514e7bae
Merge pull request #11244 from yuwata/revert-udev-changes
udev: revert bind/unbind patch and one more
2019-01-03 16:28:30 +01:00
Yu Watanabe a92f2af28a
Merge pull request #11230 from keszybz/version-string-alt
Generate version string from git describe (alternative approach)
2019-01-03 21:33:55 +09:00
Zbigniew Jędrzejewski-Szmek 48020979d6 udevadm: add a workaround for dracut
Also add a comment, so we don't fall into the same trap again.
2019-01-02 10:26:16 +01:00
Yu Watanabe ff86c92e30 Revert "udevd: configure a child process name for worker processes"
This reverts commit 49f3ee7e74.
2019-01-02 04:01:07 +09:00
Yu Watanabe adeb26c1af udev-event: do not read stdout or stderr if the pipefd is not created
Fixes #11255.
2018-12-28 12:51:40 +01:00
Yu Watanabe a3ebe5eb62 udevadm: add two more assertions
Suggested by Coverity.

Closes CID#1397033 and CID#1395708.
2018-12-21 15:49:18 +01:00
Zbigniew Jędrzejewski-Szmek 3d3075e309 meson: simplify handling of pkgconfigdatadir=no, pkgconfiglibdir=no
The idea was that those vars could be configured to 'no' to not install the .pc
files, or they could be set to '', and then they would be built but not
installed. This was inherited from the autoconf build system. This couldn't
work because '' is replaced by the default value. Also, having this level of
control doesn't seem necessary, since creating those files is very
quick. Skipping with 'no' was implemented only for systemd.pc and not the other
.pc files. Let's simplify things and skip installation if the target dir
is configured as 'no' for all .pc files.
2018-12-21 13:43:20 +01:00
Zbigniew Jędrzejewski-Szmek 681bd2c524 meson: generate version tag from git
$ build/systemctl --version
systemd 239-3555-g6178cbb5b5
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid
$ git tag v240 -m 'v240'
$ ninja -C build
ninja: Entering directory `build'
[76/76] Linking target fuzz-unit-file.
$ build/systemctl --version
systemd 240
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid

This is very useful during development, because a precise version string is
embedded in the build product and displayed during boot, so we don't have to
guess answers for questions like "did I just boot the latest version or the one
from before?".

This change creates an overhead for "noop" builds. On my laptop, 'ninja -C
build' that does nothing goes from 0.1 to 0.5 s. It would be nice to avoid
this, but I think that <1 s is still acceptable.

Fixes #7183.

PACKAGE_VERSION is renamed to GIT_VERSION, to make it obvious that this is the
more dynamically changing version string.

Why save to a file? It would be easy to generate the version tag using
run_command(), but we want to go through a file so that stuff gets rebuilt when
this file changes. If we just defined an variable in meson, ninja wouldn't know
it needs to rebuild things.
2018-12-21 13:43:20 +01:00
Zbigniew Jędrzejewski-Szmek b9da6a098b udev: modernize ctrl_send and use PROJECT_VERSION
PROJECT_VERSION is used in preparation for future changes. Let's simplify the
code by using structured initialization. If the string written to .version ever
became to long, the compiler will truncate it and tell us:

../src/udev/udev-ctrl.c: In function ‘ctrl_send’:
../src/udev/udev-ctrl.c:221:28: warning: initializer-string for array of chars is too long
                 .version = "udev-" STRINGIFY(R_VERSION),
                            ^~~~~~~
../src/udev/udev-ctrl.c:221:28: note: (near initialization for ‘ctrl_msg_wire.version’)

No functional change.
2018-12-21 13:36:26 +01:00
Zbigniew Jędrzejewski-Szmek a67c318df8 meson: define PROJECT_VERSION as the "bare" project version
Let's not use atoi() if we can simply provide the project version as a number.

In C code, this is the numerical project version. In substitutions in other
files, this is just the bare substitution.

The "PACKAGE_" prefix is from autotools, and is strange. We call systemd a
"project", and "package" is something that distros build. Let's rename.

PACKAGE_URL is renamed to PROJECT_URL for the same reasons and for consistency.

(This leave PACKAGE_VERSION as the stringified define for C code.)
2018-12-20 21:35:29 +01:00
Lennart Poettering e4abfc77c4
Merge pull request #11197 from keszybz/various-fixups
Various fixups
2018-12-18 14:35:00 +01:00
Zbigniew Jędrzejewski-Szmek 3fa3dc9e44 meson: rename two more variables from _c to _sources
_c is misleading because .h files should be included in those lists too
(this tells meson that the build outputs should be rebuilt if the header
files change).

Follow-up for 1437822638.
2018-12-18 12:19:52 +01:00
Lennart Poettering 4f9cf94c4a
Merge pull request #11144 from keszybz/dissect-image-fix
Fix for dissect-image use in nspawn
2018-12-17 19:36:36 +01:00
Lennart Poettering 95cde1ed24
Merge pull request #11159 from keszybz/udev-typedef
Udev typedef and normal error reporting
2018-12-17 16:19:10 +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 ebcc52fad6 sd-device: reduce the number of implementations of device_read_db() we keep around
We had two very similar functions: device_read_db_aux and device_read_db,
and a number of wrappers for them:

device_read_db_aux
  ← device_read_db (in sd-device.c)
    ← all functions in sd-device.c, including sd_device_is_initialized

  ← device_read_db_force
     ← event_execute_rules_on_remove (in udev-event.c)

device_read_db (in device-private.c)
  ← functions in device_private.c (but not device_read_db_force):
    device_get_devnode_{mode,uid,gid}
    device_get_devlink_priority
    device_get_watch_handle
    device_clone_with_db
    ← called from udevadm, udev-{node,event,watch}.c

Before 7141e4f62c (sd-device: don't retry loading
uevent/db files more than once), the two implementations were the same. In that
commit, device_read_db_aux was changed. Those changes were reverted in the parent
commit, so the two implementations are now again the same except for superficial
differences. This commit removes device_read_db (in sd-device.c), and renames
device_read_db_aux to device_read_db_internal and makes everyone use this one
implementation. There should be no functional change.
2018-12-16 20:17:39 +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 903893237a sd-device: do not change buffer size if the socket is already bound
From the results of CIs in #11076, changing buffer size may cause
issue #10754. So, let's prohibit to change the size if it is already
bound.

This also reverts commit 986ab0d2dc.
2018-12-14 09:33:06 +09:00
Zbigniew Jędrzejewski-Szmek 06da5c63dd meson: make net.naming-scheme= default configurable
This is useful for distributions, where the stability of interface names should
be preseved after an upgrade of systemd. So when some specific release of the
distro is made available, systemd defaults to the latest & greatest naming
scheme, and subsequent updates set the same default. This default may still
be overriden through the kernel and env var options.

A special value "latest" is also allowed. Without a specific name, it is harder
to verride from meson. In case of 'combo' options, meson reads the default
during the initial configuration, and "remembers" this choice. When systemd is
updated, old build/ directories could keep the old default, which would be
annoying. Hence, "latest" is introduced to make it explicit, yet follow the
upstream. This is actually useful for the user too, because it may be used
as an override, without having to actually specify a version.
2018-12-12 10:09:36 +01:00
Lennart Poettering f7e81fd96f udev: introduce udev net_id "naming schemes"
With this we can stabilize how naming works for network interfaces. A
user can request through a kernel cmdline option or an env var which
scheme to follow. The idea is that installers use this to set into stone
(a very soft stone though) the scheme used during installation so that
interface naming doesn't change afterwards anymore.

Why use env vars and kernel cmdline options, and not a config file of
its own?

Well, first of all there's no obvious existing one to use. But more
importantly: I have the feeling that this logic is kind of an incomplete
hack, and I simply don't want to do advertise this as a perfectly
working solution. So far we used env vars for the non-so-official
options and proper config files for the official stuff. Given how
incomplete this logic is (i.e. the big variable for naming remains the
kernel, which might expose sysfs attributes in newer versions that we
check for and didn't exist in older versions — and other problems like
this), I am simply not confident in giving this first-class exposure in
a primary configuration file.

Fixes: #10448
2018-12-11 23:29:46 +01:00
Lennart Poettering 66944c14f3
Merge pull request #11107 from keszybz/udevadm-info-args
Allow multiple args in udevadm info
2018-12-11 12:12:58 +01:00
Zbigniew Jędrzejewski-Szmek 3c79311a6a udevadm: allow multiple arguments to "info"
This matches udevadm trigger, which allows multiple arguments since
80877656a5.
2018-12-11 09:29:21 +01:00
Zbigniew Jędrzejewski-Szmek b6854081ff udevadm: allow a .device unit to be specified for query and trigger
This is convenient when working with device units in systemd. Instead of
converting the systemd unit name to a path to feed to udevadm, udevadm
info|trigger can be called directly on the unit name.

The man page is reworked a bit to describe the modern syntax with positional
arguments first. It's just simpler to use than the positional options.
2018-12-11 09:24:31 +01:00
Zbigniew Jędrzejewski-Szmek d539f79176 udevadm: use path_startswith and shorten code a bit 2018-12-11 09:21:08 +01:00
Zbigniew Jędrzejewski-Szmek 668e7c0cfd udevadm: improve error output when a device is not specified or specified wrong
udevadm would dump help() output, instead of printing a message about what is
wrong. That's just bad UX. Let's use a different message if the argument is
missing, and a different one if it is invalid.

Also, rework the code to separate the business logic from argument parsing.
Let's not use "default:" in switch statements. This way, the compiler will warn
us if we miss one of the cases.
2018-12-11 07:29:51 +01:00
Zbigniew Jędrzejewski-Szmek 871fa294ff Merge pull request #10935 from poettering/rlimit-nofile-safe
Merged by hand to resolve a trivial conflict in TODO.
2018-12-06 17:19:21 +01:00
Yu Watanabe e93672eeac tree-wide: drop missing.h from headers and use relevant missing_*.h 2018-12-06 13:31:16 +01:00
Yu Watanabe ef118d00eb util: drop missing.h from socket-util.h 2018-12-06 13:31:16 +01:00
Yu Watanabe 36dd5ffd5d util: drop missing.h from util.h 2018-12-04 10:00:34 +01:00