Commit Graph
2563 Commits
Author SHA1 Message Date
Lennart Poettering bd1ae17833 io-util: split out "struct iovec" related calls into their own .c/.h files
This is preparation for #28891, which adds a bunch more helpers around
"struct iovec", at which point this really deserves its own .c/.h file.

The idea is that we sooner or later can consider "struct iovec" as an
entirely generic mechanism to reference some binary blob, and is the
go-to type for this purpose whenever we need one.
2023-10-20 10:34:33 +02:00
Frantisek Sumsal 4820c9d417 fuzz: unify logging setup
Make sure we don't log anything when running in "fuzzing" mode. Also,
when at it, unify the setup logic into a helper, pretty similar to
the test_setup_logging() one.

Addresses:
  - https://github.com/systemd/systemd/pull/29558#pullrequestreview-1676060607
  - https://github.com/systemd/systemd/pull/29558#discussion_r1358940663
2023-10-19 10:05:20 +01:00
Franck Bui 6495361c7d meson: add build option for install path of main config files
This allows distros to install configuration file templates in /usr/lib/systemd
for example.

Currently we install "empty" config files in /etc/systemd/. They serve two
purposes:

- The file contains commented-out values that show the default settings.
- It is easier to edit the right file if it is already there, the user doesn't
  have to type in the path correctly, and the basic file structure is already in
  place so it's easier to edit.

Things that have happened since this approach was put in place:

- We started supporting drop-ins for config files, and drop-ins are the
  recommended way to create local configuration overrides.
- We have systemd-analyze cat-config which takes care of iterating over
  all possible locations (/etc, /run, /usr, /usr/local) and figuring out
  the right file.
- Because of the first two points, systemd-analyze cat-config is much better,
  because it takes care of finding all the drop-ins and figuring out the
  precedence. Looking at files manually is still possible of course, but not
  very convenient.

The disadvantages of the current approach with "empty" files in /etc:

- We clutter up /etc so it's harder to see what the local configuration actually is.
- If a user edits the file, package updates will not override the file (e.g.
  systemd.rpm uses %config(noreplace). This means that the "documented defaults"
  will become stale over time, if the user ever edits the main config file.

Thus, I think that it's reasonable to:

- Install the main config file to /usr/lib so that it serves as reference for
  syntax and option names and default values and is properly updated on package
  upgrades.
- Recommend to users to always use drop-ins for configuration and
  systemd-analyze cat-config to view the documentation.

This setting makes this change opt-in.

Fixes #18420.

[zjs: add more text to the description]
2023-10-17 18:57:45 +02:00
Zbigniew Jędrzejewski-Szmek ee691c802b Merge pull request #29242 from fbuihuu/update-main-config-file-headers
config files: update their header to reflect that they can be install…
2023-10-17 18:56:09 +02:00
Daan De Meyer a6b4b2fa01 udev: Enable filtering the output of udevadm info --export-db
Let's support the same filtering options that we also support in
udevadm trigger in udevadm info to filter the devices produced by
--export-db.

One difference is that all properties specified by --propery-match=
have to be satisfied in udevadm info unlike udevadm trigger where just
one of them has to be satisfied.
2023-10-16 17:02:00 +02:00
Daan De Meyer d6e5f170ef Add --json switch to udevadm info
This allows getting the udevadm info --export-db and query "all" output
as JSON.
2023-10-16 13:01:54 +02:00
Lennart Poettering bd1791b597 cgroup-util: drop "controller" argument from various cgroup helper calls
systemd's own cgroup hierarchy is special to us, we use it to actually
manage processes. Because of that many calls tha apply to cgroups are
only ever called with the SYSTEMD_CGROUP_CONTROLLER as controller
argument. Let's hence remove the argument altogether.

This in particular touches the kill and xattr routines.

This changes no behaviour, we just drop an argument that is always set
to the same value anyway.

This is preparation to eventually getting rid of the cgroupvs1, because
on cgroupvs2 the cgroup paths do not change for different controllers,
there's only a single hierarchy there.
2023-10-05 11:11:04 +02:00
Daan De Meyer 180d5aeaa7 Merge pull request #29403 from yuwata/journal-decouple-journald-and-journal-remote
journal: drop ManagedJournalFile and decouple journald and journal-remote
2023-10-04 07:55:52 +02:00
NRK 6c7b1ea1be udevadm: avoid side-effect in assert()
this was found when trying to use __builtin_assume() with clang:
https://github.com/systemd/systemd/pull/29409#issuecomment-1743575402
2023-10-02 22:58:45 +01:00
Yu Watanabe d287ece7f1 test: split test-tables into three
Let's drop dependency to libjournal_core and libudevd_core from
test-tables.
2023-10-02 10:52:45 +09:00
Daan De Meyer 4444564a95 Merge pull request #29193 from keszybz/path-util-adjustment
Make unit mangling follow paths
2023-09-29 11:33:12 +02:00
Lennart Poettering 1617424ce7 udev: raise RLIMIT_NOFILE as high as we can
We might need a lot of fds on large systems, hence raise RLIMIT_NOFILE
to what the service manager allows us, which is quite a lot these days.

udev already sets FORK_RLIMIT_NOFILE_SAFE when forking of chilren, thus
ensuring that forked off processes get their RLIMIT_NOFILE soft limit
reset to 1K for compat with crappy old select().

Replaces: #29298
Fixes: #28583
2023-09-26 13:01:02 +02:00
Zbigniew Jędrzejewski-Szmek 660087dc9c tree-wide: add path_simplify_alloc() and use it
path_simplify_full()/path_simplify() are changed to allow a NULL path, for
which a NULL is returned. Generally, callers have already asserted before that
the argument is nonnull. This way path_simplify_full()/path_simplify() and
path_simplify_alloc() behave consistently.

In sd-device.c, logging in device_set_syspath() is intentionally dropped: other
branches don't log.

In mount-tool.c, logging in parse_argv() is changed to log the user-specified
value, not the simplified string. In an error message, we should show the
actual argument we got, not some transformed version.
2023-09-22 08:13:34 +02:00
Franck Bui c60801738c config files: update their header to reflect that they can be installed in /usr
Follow-up for c76f2fb0e5.
2023-09-21 18:54:39 +02:00
Lennart Poettering 8fcacaf046 scsi_serial: convert from nanosleep() to usleep_safe() 2023-09-20 12:07:28 +02:00
Lennart Poettering 7b9da3861a Revert "tree-wide: Mount file descriptors via /proc/<pid>/fd" 2023-09-08 22:13:09 +01:00
Mike Yuan e22c60a9d5 io-util: introduce loop_write_full that takes a timeout
Also drop do_poll as the use case is covered
by timeout.
2023-09-07 20:30:44 +08:00
Daan De Meyer 2af02e6165 tree-wide: Always include <net/if.h> before related linux headers
Otherwise, we get redefinition errors if <net/if.h> is included later
on by another header.
2023-08-14 13:16:46 +02:00
Yu Watanabe 5cdcaf89be meson: drop unnecessary dependency on libidn 2023-08-12 20:04:51 +09:00
Yu Watanabe 8aa0aa40cf udev-builtin-net_id: use strjoin() if possible
Addresses the post-merge comment
https://github.com/systemd/systemd/pull/28623#pullrequestreview-1571307466.
2023-08-10 20:13:43 +09:00
Yu Watanabe f5f1e766ba udev-builtin-net_id: add more debugging logs 2023-08-10 20:09:11 +09:00
Yu Watanabe ce8ff47f74 udev-builtin-net_id: introduce get_first_syspath_component() helper function
Obtaining a component from syspath is a common pattern. Let's split out
the pattern. No functional change, just refactoring.
2023-08-10 20:09:11 +09:00
Yu Watanabe 5dc06b376f udev-builtin-net_id: introduce get_matching_parent() helper function
The pattern is common in many naming scheme. Let's split out the
pattern. No functional change, just refactoring.
2023-08-10 20:09:06 +09:00
Yu Watanabe c27d9c0ac1 udev-builtin-net_id: fix potential invalid memory access
Follow-up for 28141620d9.

Addresses post-merge review in #28269.
2023-08-10 05:13:17 +09:00
Yu Watanabe 3787934b54 proc-cmdline: make proc_cmdline_get_bool() take flags
All other command line parsers takes flags. Let's make
proc_cmdline_get_bool() also take flags. Though, currently,
no flag is set by the caller.
2023-08-09 17:46:41 +09:00
Yu Watanabe 9289e093ae meson: use install_emptydir() and drop meson-make-symlink.sh
The script is mostly equivalent to 'mkdir -p' and 'ln -sfr'.
Let's replace it with install_emptydir() builtin function and
inline meson call.
2023-08-08 22:11:34 +01:00
Yu Watanabe 2cba1d3753 udev: allow to set the maximum number of worker process to 0
In that case, the maximum is calculated based on the system resources.
2023-08-05 15:40:02 +09:00
Yu Watanabe ce5ddbc465 udev: split out manager_set_default_children_max() 2023-08-05 15:39:58 +09:00
Yu Watanabe cbc55c4cce meson: also merge declarations of fuzzers with other executables 2023-08-03 20:37:16 +09:00
Yu Watanabe 130c87b16a meson: merge declarations of normal and test executables 2023-08-03 20:37:16 +09:00
Yu Watanabe 09fa0a0721 test: rename udev-rule-runner -> test-udev-rule-runner
This partially revert 0454cf05d3.
The executable actually does not work with itself, but needs to be
combined with test-udev.py. But, even so, the executable is for testing.

In the next commit, test and normal executables are declared in the same
way, and naming of the executable becomes essential to classify them.
Let's rename the executable and prefix with 'test-'.
2023-08-03 20:37:16 +09:00
Yu Watanabe adedcd39a8 meson: use template to declare udev plugins 2023-08-03 20:37:16 +09:00
Yu Watanabe 12b4cffdae meson: introduce HAVE_DMI flag
The condition is used at several places. Let's introduce a simple flag
for that.
2023-08-03 20:37:16 +09:00
Luca Boccassi 6639ac474e Merge pull request #28623 from yuwata/udev-builtin-net_id-cleanups
udev: several cleanups for net_id builtin (part 4)
2023-08-01 22:09:32 +01:00
Daan De Meyer 54c3326066 Merge pull request #28620 from yuwata/meson-use-template-part5
meson: use template to declare executables (part 5)
2023-08-01 18:10:52 +02:00
Yu Watanabe 82cb5f2ad1 udev-builtin-net_id: first parse USB or BCMA identifier, then parse PCI properties
Previously, we first generate names based on the PCI slot and ACPI
onboard index, and then append an identifier based on USB or BCMA bus
if it exists in between the PCI bus and the interface.

However, if there exists USB or BCMA bus, the name based on the
ACPI onboard index is not used.

So, let's invert the order; first generate USB or BCMA identifier if the
bus exists, then prepend the name with the PCI slot identifier.

With this change, we can drop Names struct, and each naming logic
becomes self-consistent.
2023-08-02 00:00:32 +09:00
Yu Watanabe 415ade00aa udev-builtin-net_id: split out names_pci_onboard_label() from dev_pci_onboard()
Then call it only when it is necessary. The label is used only when the
interface is directly connected to the PCI bus, and it does not have the
SR-IOV feature (or the naming based on SR-IOV is disabled).
2023-08-01 23:35:34 +09:00
Yu Watanabe f831aef509 udev-builtin-net_id: drop redundant copy of BCMA identifier in names_bcma()
Then, this makes names based on the BCMA and PCI identifiers in
names_bcma().

No functional change, just refactoring.
2023-08-01 23:35:34 +09:00
Yu Watanabe d3523818e8 udev-builtin-net_id: split out get_bcma_specifier() from names_bcma()
This contains redundant copy of BCMA identifier, but that will be
dropped in the next commit.

No functional change, just refactoring and preparation for later
commits.
2023-08-01 23:35:34 +09:00
Yu Watanabe f7ae5d1857 udev-builtin-net_id: drop redundant copy of USB identifier in names_usb()
This makes the names based on the USB identifier (and possibly with PCI
specifier) built in names_usb()

No functional change, just refactoring.
2023-08-01 23:35:34 +09:00
Yu Watanabe 045fb967a7 udeb-builtin-net_id: split out get_usb_specifier() from names_usb()
This contains redundant copy of USB identifier, but that will be
dropped in the next commit.

No functional change, just refactoring and preparation for later
commits.
2023-08-01 23:35:34 +09:00
Yu Watanabe 5371c26933 meson: move declarations of socket-proxy, udevadm, quotacheck, and shutdown 2023-08-01 21:37:31 +09:00
Yu Watanabe 5660e68d65 udev-builtin-net_id: fix potential buffer overflow 2023-08-01 21:34:12 +09:00
Yu Watanabe a1008b2dab udev-builtin-net_id: various coding style cleanups 2023-08-01 21:34:12 +09:00
Yu Watanabe 64d2358397 udev-builtin-net_id: introduce device_is_stacked() helper function
Then, we can drop LinkInfo struct.
No functional change, just refactoring.
2023-08-01 21:34:12 +09:00
Yu Watanabe dc999c0346 udev-builtin-net_id: drop unused arguments 2023-08-01 21:34:12 +09:00
Yu Watanabe d6ec0fe229 udev-builtin-net_id: split-out pci_get_onboard_index() from dev_pci_onboard()
This also changes the onboard index type to unsigned, as it is at most
2^16 - 1. Hence, unsigned is enough.

Then, we can use device_get_sysattr_unsigned() helper function.

This also drops mostly redundant debugging logs. The index will be
logged later anyway.
2023-08-01 11:20:48 +09:00
Yu Watanabe 51524b82a2 udev-builtin-net_id: split-out get_pci_slot_specifiers()
Then, we can replace multiple strpcpyf() with single snprintf_ok().

No functional change, just refactoring.
2023-08-01 10:56:46 +09:00
Yu Watanabe 82234e2a21 udev-builtin-net_id: introduce get_port_specifier() helper function
To make the port specifier unified.
No functional change, just refactoring.
2023-08-01 10:56:26 +09:00
Yu Watanabe 4d756471d9 udev-builtin-net_id: split out get_dev_port() and make its failure critical
As dev_port and dev_id sysfs attributes are fundamental properties for
network interfaces. Hence, it should not fail.

Also, the type of dev_port is changed to unsigned. The kernel internally
uses 'unsigned short' for dev_port and dev_id. Hence, unsigned (that is,
32 bits) is still overkill, but should be enough.
2023-08-01 10:56:26 +09:00