Commit graph

1666 commits

Author SHA1 Message Date
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
Yu Watanabe b9683baffe missing: move btrfs related entries to missing_btrfs.h and missing_btrfs_tree.h 2018-12-04 07:46:59 +01:00
Yu Watanabe e924c60f69 udev: use hashmap_clear_free_key() and hashmap_free_free_key() 2018-12-02 12:18:54 +01:00
Lennart Poettering 49f3ee7e74 udevd: configure a child process name for worker processes 2018-12-01 12:50:45 +01:00
Lennart Poettering ece0fe12ad tree-wide: (void)ify some setsid() and related calls 2018-12-01 12:50:45 +01:00
Lennart Poettering 595225af7a tree-wide: invoke rlimit_nofile_safe() before various exec{v,ve,l}() invocations
Whenever we invoke external, foreign code from code that has
RLIMIT_NOFILE's soft limit bumped to high values, revert it to 1024
first. This is a safety precaution for compatibility with programs using
select() which cannot operate with fds > 1024.

This commit adds the call to rlimit_nofile_safe() to all invocations of
exec{v,ve,l}() and friends that either are in code that we know runs
with RLIMIT_NOFILE bumped up (which is PID 1 and all journal code for
starters) or that is part of shared code that might end up there.

The calls are placed as early as we can in processes invoking a flavour
of execve(), but after the last time we do fd manipulations, so that we
can still take benefit of the high fd limits for that.
2018-12-01 12:50:45 +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
Lennart Poettering 5cfa2c3dc0 tree-wide: use IOVEC_MAKE() at many places 2018-11-27 10:12:27 +01:00
Lennart Poettering a0ee3d93bb
Merge pull request #10919 from yuwata/sd-device-monitor-fixes
sd-device-monitor: several fixes
2018-11-26 18:08:41 +01:00
Yu Watanabe 938dbb292a
Merge pull request #10901 from poettering/startswith-list
add new STARTSWITH_SET() macro
2018-11-26 22:40:51 +09:00
Lennart Poettering 49fe5c0996 tree-wide: port various places over to STARTSWITH_SET() 2018-11-26 14:08:46 +01:00
Yu Watanabe 6acf1ccba5 udevd: do not call udev_ctrl_enable_receiving() if the socket is passed from pid1
Before c4b69e990f, if the socket fd is
passed from pid1, `udev_ctrl_enable_receiving()` was not called.
Let's preserve the original logic.
2018-11-26 11:57:48 +09:00
Yu Watanabe 49c603bd5e udev: drop duplicate whitespaces 2018-11-26 11:53:21 +09:00
Yu Watanabe 572909a38a udev-ctrl: update log messages 2018-11-26 11:52:40 +09:00
Yu Watanabe b4ba2fe3f1 udev-rules: include device sysname in log messages 2018-11-26 11:37:29 +09:00
Yu Watanabe 9315f853c4 udev-ctrl: fix coding style isuues 2018-11-26 11:10:46 +09:00
Yu Watanabe 986ab0d2dc udevd: do not set buffer size if the socket is passed from pid1
Before c4b69e990f, if the socket fd is
passed from pid1, `udev_monitor_set_receive_buffer_size()` (now it is
a wrapper of `sd_device_monitor_set_receive_buffer_size()`) was not
called. Let's preserve the original logic.
2018-11-25 20:17:25 +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
Yu Watanabe 67e4b38563 udev-rules: trivial coding style cleanups 2018-11-23 00:22:09 +09:00
Yu Watanabe 981fae90df udev: rename udev_rules_unref() to udev_rules_free()
As udev_rules do not have a reference counter.
2018-11-23 00:07:40 +09:00
Zbigniew Jędrzejewski-Szmek d4e98880e9 Also drop a few more unnecessary uses of synthethic errno 2018-11-22 10:54:38 +01:00
Zbigniew Jędrzejewski-Szmek 886cf317c4 coccinelle: also mark previous synthetic errnos as such 2018-11-22 10:54:38 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Lennart Poettering b390455cbb
Merge pull request #10866 from yuwata/libudev-util-cleanups
libudev-util: several cleanups and tests
2018-11-21 11:15:35 +01:00
Yu Watanabe 3839535a53 libudev: make util_resolve_subsys_kernel() return negative errno
This also replaces udev_device by sd_device in the function.
2018-11-21 17:31:16 +09:00
Yu Watanabe c0c591544a udev/scsi_id: fix buffer length 2018-11-21 17:30:49 +09:00
Zbigniew Jędrzejewski-Szmek 0c5a109a25 udevd: define main through macro
This removes the call to log_close(), and refactors how fork() is done. Now
the parent also goes through normal cleanup. This isn't necessary to use the
macro, but it feels cleaner this way.
2018-11-21 09:14:00 +01:00
Zbigniew Jędrzejewski-Szmek 138715dc12 udevadm: define main through macro
This removes a call to log_close(). I don't think this should matter.
The call to mac_selinux_init() is moved after parse_argv(). We probably
don't need selinux when printing help().
2018-11-21 09:14:00 +01:00
Zbigniew Jędrzejewski-Szmek 294bf0c34a Split out pretty-print.c and move pager.c and main-func.h to shared/
This is high-level functionality, and fits better in shared/ (which is for
our executables), than in basic/ (which is also for libraries).
2018-11-20 18:40:02 +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 02edd80d87 udev: move definition of READ_END and WRITE_END from libudev-private.h to udev.h 2018-11-20 14:38:35 +09:00
Lennart Poettering e16f425654
Merge pull request #10698 from yuwata/udevd-replace-udev-device
udevd: replace udev_device by sd_device
2018-11-19 11:28:45 +01:00
Zbigniew Jędrzejewski-Szmek 64d9f7568b basic/missing: drop _ETHTOOL_LINK_MODE_MAX
It was only used in one place, where we don't actually need it, and
it is too easy to forget to update it when adding new items to the table.
Let's just drop it.
2018-11-18 16:14:21 +01:00
Zbigniew Jędrzejewski-Szmek 5dd101186b udev: use an "inline" array instead of allocating for advertise mode
The code is a bit shorter and we don't allocate the uint32_t[127] array.
2018-11-18 16:14:19 +01:00
Yu Watanabe 2d18ac4491 ethtool: drop NetDevAdvertise
Fixes #10807.
2018-11-18 14:33:50 +09:00
Yu Watanabe eb546b3532 udevd: replace udev_device in struct event by sd_device 2018-11-17 21:45:03 +09:00
Yu Watanabe 044497e2a3 udevd: update several log messages 2018-11-17 21:45:03 +09:00
Yu Watanabe ba47b71c2d udevd: decrease indentation 2018-11-17 21:45:03 +09:00
Yu Watanabe d8f462b435 udevd: rename event sources in struct event 2018-11-17 21:45:03 +09:00
Yu Watanabe dc7faf2a6f udevd: capitalize log messages in on_sigchld() 2018-11-17 21:45:03 +09:00
Yu Watanabe e2130348ef udevd: also use sd_device_monitor_start() in worker_main() 2018-11-17 21:45:03 +09:00
Yu Watanabe f00d2b6dd2 udevd: use sd_device_monitor_start() in manager_new() 2018-11-17 21:45:03 +09:00
Yu Watanabe 7f2e3a1409 udevd: replace udev_monitor by sd_device_monitor 2018-11-17 21:45:03 +09:00
Yu Watanabe 7443654e5f udevd: use safe_fork() to spawn worker process 2018-11-17 21:45:03 +09:00
Yu Watanabe abde5ea854 udevd: make worker_process_device() take sd_device instead of udev_device 2018-11-17 21:45:03 +09:00
Yu Watanabe b97897e3e8 udevd: make worker_lock_block_device() take sd_device instead of udev_device
Also adds many debug logs.
2018-11-17 21:45:02 +09:00
Yu Watanabe 0bed242cbe udevd: split worker_spawn() and manager_free() in small pieces 2018-11-17 21:45:02 +09:00
Yu Watanabe 0725c4b9d1 udevd: use event_source_disable() 2018-11-16 22:57:42 +09:00
Yu Watanabe 6d63048a77 udevd: use event_reset_time() to update kill_workers_event 2018-11-16 22:57:42 +09:00
Yu Watanabe a6da77b71b udev-rules: fix possible assertion
On 'remove' action, event->dev_db_clone is NULL. So, `IMPORT{db}` rule
on 'remove' action triggers assertion. This fixes the issue.
2018-11-15 15:50:27 +01:00
Lennart Poettering 042cad5737
Merge pull request #10753 from keszybz/pager-no-interrupt
Add mode in journalctl where ^C is handled by the pager
2018-11-14 20:09:39 +01:00
Zbigniew Jędrzejewski-Szmek fde32028a4 Move LONG_LINE_MAX definition to fileio.h
All users of the macro (except for one, in serialize.c), use the macro in
connection with read_line(), so they must include fileio.h.  Let's not play
libc games and require multiple header file to be included for the most common
use of a function.

The removal of def.h includes is not exact. I mostly went over the commits that
switch over to use read_line() and add def.h at the same time and reverted the
addition of def.h in those files.
2018-11-14 16:25:32 +01:00
Lennart Poettering 8755568681
Merge pull request #10759 from keszybz/udevd-more-configuration
Udevd more configuration options
2018-11-14 16:21:14 +01:00
Zbigniew Jędrzejewski-Szmek 7fe0d0d5c0 udev: downgrade message when we fail to set inotify watch up
My logs are full of:

systemd-udevd[6586]: seq 13515 queued, 'add' 'block'
systemd-udevd[6586]: seq 13516 queued, 'change' 'block'
systemd-udevd[6586]: seq 13517 queued, 'change' 'block'
systemd-udevd[6586]: seq 13518 queued, 'remove' 'bdi'
systemd-udevd[6586]: seq 13519 queued, 'remove' 'block'
systemd-udevd[9865]: seq 13514 processed
systemd-udevd[9865]: seq 13515 running
systemd-udevd[9865]: GROUP 6 /usr/lib/udev/rules.d/50-udev-default.rules:59
systemd-udevd[9865]: IMPORT builtin 'blkid' /usr/lib/udev/rules.d/60-persistent-storage.rules:95
systemd-udevd[9865]: IMPORT builtin 'blkid' fails: No such file or directory
systemd-udevd[9865]: loop4: Failed to add device '/dev/loop4' to watch: No such file or directory
(the last line is at error level).
If we are too slow to set up a watch and the device is already gone by the time
we try, this is not an error.
2018-11-13 22:02:55 +01:00
Zbigniew Jędrzejewski-Szmek a14e7af162 udev: also allow resolve_names= to be specified in udev.conf 2018-11-13 14:35:36 +01:00
Zbigniew Jędrzejewski-Szmek bc768f0475 udev: move ResolveNameTiming definition and parsers to udev-util.h
Follow-up for c4d44cba4d. No functional change,
but the parser is moved to libsystemd-shared.so.
2018-11-13 14:04:29 +01:00
Zbigniew Jędrzejewski-Szmek 4b3ca79ea9 udevd: allow more parameters to be set through udev.conf
Rebooting to set change the kernel command line to set some udev parameters is
inconvenient. Let's allow setting more stuff in the config file.

Also drop quotes from around "info" in udev.conf. We need to accept them for
compatibility, but there is no reason to use them.
2018-11-13 14:03:47 +01:00
Zbigniew Jędrzejewski-Szmek 66f737b415 udev: do not pass timeout_warn_usec around, calculate it on demand
It was always set to one third of timeout_usec, so let's simplify things by
calculating it using a helper function right before it is used.

Before 9d9264ba39, udevd.c would avoid setting
timeout_warn_usec to 0, using 1 instead. This wasn't necessary, because when
timeout_warn_usec is finally used in spawn_wait(), it is ignored if
timeout_usec is 0 or timeout_warn_usec is 0. So there was no need to handle
this case specially.
2018-11-13 14:00:32 +01:00
Mathieu Trudel-Lapierre 55b6530baa Always rename an interface to its name specified in config if no NamePolicy= is specified
This is for issue #9006
2018-11-12 18:45:57 +01:00
Yu Watanabe 6f19b42f24 udev: use structured initializer at one more place 2018-11-12 23:25:59 +09:00
Yu Watanabe c4b69e990f udev: drop redundant initializations for file descriptors
As udev_ctrl_new_from_fd() or udev_monitor_new_from_netlink_fd()
creates fd if negative fd is passed.
2018-11-12 23:25:59 +09:00
Yu Watanabe c52cff0748 udev: handle sd_is_socket() failure 2018-11-12 23:25:59 +09:00
Yu Watanabe 46f0fbd8fd udev: drop util_log_priority() and use log_level_from_string()
The function util_log_priority() is almost same as
log_level_from_string(). The difference between them is only that
util_log_priority() accepts such that '3 hogehoge'.
2018-11-12 23:25:40 +09:00
Yu Watanabe 9d9264ba39 udev: use parse_sec() to parse --event-timeout option 2018-11-12 23:25:34 +09:00
Yu Watanabe 389f9bf2cf udev: include error cause of parsing --children-max option in log message 2018-11-12 23:21:49 +09:00
Yu Watanabe c4d44cba4d udev: introduce enum ResolveNameTiming for --resolve-names argument 2018-11-12 23:20:53 +09:00
Yu Watanabe 6b92f42934 udevd: use parse_sec() to parse --exec-delay option 2018-11-12 23:16:54 +09:00
Yu Watanabe 216e8bbe34 udevd: explicitly set default value of global variables 2018-11-12 23:12:06 +09:00
Lennart Poettering 192602cb1e
Merge pull request #10734 from yuwata/network-use-structured-initializers
network: several cleanups
2018-11-12 11:42:02 +01:00
Yu Watanabe 538f15cf06 tree-wide: use CONFIG_PARSER_PROTOTYPE() macro 2018-11-12 16:45:04 +09:00
Yu Watanabe edc81c1ccb udevd: do not treat negative value as valid ifindex
Also, some conditions in is_devpath_busy() are similified.
2018-11-12 13:07:10 +09:00
Yu Watanabe deb2b7348e sd-device: drop priority and description from sd_device_monitor_attach_event() and sd_device_monitor_start()
Now we have sd_device_monitor_get_event_soruce(). So, it is not
necessary to include these parameters in the functions for sd_device_monitor.
2018-11-10 22:53:00 +09:00
Yu Watanabe 77ad202c72 udevadm-test: replace udev_device by sd_device 2018-11-07 13:35:03 +09:00
Yu Watanabe cf28ad4689 udev-event: make udev_event_new() take sd_device instead of udev_device 2018-11-07 13:35:03 +09:00
Yu Watanabe cf697ec00e udev-rules: replace udev_device by sd_device in udev_rules_apply_to_event() 2018-11-07 13:35:03 +09:00
Yu Watanabe dbea7f24d2 udev-rules: replace two udev_list_entry_foreach() by corresponding FOREACH_DEVICE_*() macros 2018-11-07 13:35:03 +09:00
Yu Watanabe 1017d66bf5 udev-rules: use structured initializer 2018-11-07 13:35:03 +09:00
Yu Watanabe 92b80c6baa udev-rules: drop unused member file_list in struct udev_rules 2018-11-07 13:35:03 +09:00
Yu Watanabe 1ce7fecb4f udev-rules: make import_parent_into_properties() take sd_device 2018-11-07 13:35:03 +09:00
Yu Watanabe 13c7b75f2f udev-rules: make import_file_into_properties() take sd_device 2018-11-07 13:35:03 +09:00
Yu Watanabe 29b5eb5adf udev-rules: make import_property_from_string() take sd_device
Also, this makes the function return negative errno, though its
return value is always ignored.
2018-11-07 13:35:03 +09:00
Yu Watanabe f3d241feb2 udev: use sd_device for udev_event.dev_parent 2018-11-07 13:35:03 +09:00
Yu Watanabe 5ba7e79885 udev-rules: make match_attr() take sd_device instead of udev_device 2018-11-07 13:35:03 +09:00
Yu Watanabe 480ecb7d28 udev: use sd_device for udev_event.dev_db
Also, this adds sd_device_unref for the object in udev_event_free()
for safety and readability of code.
2018-11-07 13:35:03 +09:00
Yu Watanabe e0bb2ff94b udev-event: make udev_event_new() take sd_netlink and take a reference of that 2018-11-07 13:35:03 +09:00
Yu Watanabe 0f86dc900e udev-event: make udev_event_new() take exec_delay 2018-11-07 13:35:03 +09:00
Lennart Poettering 39adc47495
Merge pull request #10658 from yuwata/udevd-worker-performance
udev: improve performance
2018-11-06 20:01:37 +03:00
Lennart Poettering 9edcbc4f44
Merge pull request #10602 from yuwata/sd-device-logs
update log messages
2018-11-06 19:33:51 +03:00
Yu Watanabe faae64fa3d udevd: increase default number of workers
The uevent handling in udevd is not cpu hungry.
So, let's increase the default number of workers per cpu.
This decrease the number of queued uevents.

Without this commit (children_max is 16 on my laptop)
```
$ journalctl -b -u systemd-udevd.service | grep reached | wc -l
1544
```
With this commit (children_max is 30 on my laptop)
```
$ journalctl -b -u systemd-udevd.service | grep reached | wc -l
7
```
2018-11-07 00:25:20 +09:00
Yu Watanabe eca195ec23 udevd: wait 3 seconds before killing worker processes
During boot process, many worker processes are forked and killed.
To decrease cycles of forking and killing worker, let's wait
3 seconds before killing workers. If new uevent or inotify event
comes within the delay, the killing porcess will be cancelled.
2018-11-07 00:25:13 +09:00
Yu Watanabe da14313418 udevd: drop redundant logic of receiving uevent
If there exists pending uevents, then sd-event invokes uevent handler.
So, it is not necessary to receive the next uevent in inotify event.
2018-11-06 23:53:55 +09:00
Yu Watanabe b6107f010a udevd: decrease indentation 2018-11-06 23:53:50 +09:00
Yu Watanabe 05e6d9c64b udevd: merge conditions to decrease indentation 2018-11-06 23:21:25 +09:00
Yu Watanabe 57512c893e tree-wide: set WRITE_STRING_FILE_DISABLE_BUFFER flag when we write files under /proc or /sys 2018-11-06 21:24:03 +09:00
Yu Watanabe 76cdddfb9d udevd: use set_oom_score_adjust() to set OOM score 2018-11-06 21:24:03 +09:00
Yu Watanabe 92c40e1dc8 udevadm: use write_string_file() helper function 2018-11-06 21:24:03 +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 6174a243f9 udev: setting the same log level to SYSTEMD realm
Otherwise, many debug logs from libsystemd are dropped.
2018-11-06 15:45:22 +09:00
Yu Watanabe cc0bf5e148 udev-watch: adjust level of log messages 2018-11-06 11:15:39 +09:00
Yu Watanabe 7fe3324c5e udev-watch: make udev_watch_lookup() return 1 when device found 2018-11-06 11:15:39 +09:00
Yu Watanabe b7759e0403 udev: drop redundant log message and fix returned error code 2018-11-06 11:15:39 +09:00
Yu Watanabe 4375dab58d udev-event: fix timeout log messages
Follow-up for e81c3a4c5f.
2018-10-31 09:29:51 +09:00
Yu Watanabe 7af1c7808b udev-event: do not store unused devnum 2018-10-31 09:29:51 +09:00
Yu Watanabe d4a95a952e udev-event: check whether device has devnum before calling udev_node_remove()
This fixes a bug in 'remove' event handling, which was introduced by
eb1f9e30ec, as 'devnum' variable may
not be initialized.
2018-10-31 09:29:51 +09:00
Yu Watanabe 4cade7a15b udev-event: replace udev_device in subst_format_var() by sd_device 2018-10-27 07:25:27 +09:00
Yu Watanabe a315999de6 udev-event: drop prototype of nonexistent function 2018-10-27 07:25:27 +09:00
Yu Watanabe 9204d8023f udev-event: move definition of struct subst_map 2018-10-27 07:25:27 +09:00
Yu Watanabe eb1f9e30ec udev-event: replace udev_device in udev_event_execute_rules() by sd_device
Also, this adds many logs.
2018-10-27 07:25:27 +09:00
Yu Watanabe e52eaf5649 udev-event: move devnode handling logic to a new function
Also, replace udev_device by sd_device.
2018-10-27 07:25:27 +09:00
Yu Watanabe 2740750d40 udev-event: move conditions to rename network interface into rename_netif()
Also, replace udev_device by sd_device.
2018-10-27 07:24:03 +09:00
Yu Watanabe c1118ceba4 udev-event: rename udev_event_unref() to udev_event_free()
As struct udev_event does not have a reference counter.
2018-10-27 07:03:39 +09:00
Yu Watanabe d737197154 udev-event: fix memleak in udev_event
The leak was introduced by 29448498c7.
2018-10-27 07:03:39 +09:00
Yu Watanabe 89665d0920 udev-event: use structured initializer at one more place 2018-10-27 07:03:39 +09:00
Yu Watanabe a368732bc4 udev-event: add more assert() 2018-10-27 07:03:39 +09:00
Yu Watanabe dc8aec36a6 udev-event: check command is not empty before executing 2018-10-27 07:03:39 +09:00
Yu Watanabe e9343893f7 udev-event: include device name in error message one more place 2018-10-27 07:03:39 +09:00
Yu Watanabe 7606377e2c network,udev: drop unnecessary check whether ifindex is positive
As sd_device_get_ifindex() now returns positive ifindex when it
succeeds.
2018-10-27 07:03:39 +09:00
Lennart Poettering 7388cea30d udev: use right error variable to make level decision 2018-10-24 20:47:52 +02:00
Lennart Poettering dc4fedd8cb udev: fix bad if {}
CID 1396318
CID 1396319
2018-10-24 20:46:41 +02:00
Lennart Poettering d1db1c438f
Merge pull request #10484 from yuwata/udev-spawn-simplify
udev-event: cleanups about udev_event_spawn()
2018-10-24 10:57:45 +02:00
Lennart Poettering e7b48c45ae
Merge pull request #10498 from yuwata/udev-builtin-log
udev-builtin: use log_device_*() macros
2018-10-24 10:53:35 +02:00
Lennart Poettering 77d28bd10f
Merge pull request #10483 from yuwata/udev-cleanup-10
tree-wide: use log_device_*()
2018-10-24 10:51:53 +02:00