Commit Graph
45031 Commits
Author SHA1 Message Date
Luca Boccassi 93f42f034c Merge pull request #29156 from bluca/signal_dump_jobs
core: dump jobs list on sigrtmin+18 with 0x500
2023-09-11 20:41:09 +01:00
Lennart Poettering f96a32c7f0 serialize: don#t allocate 1M on the stack just like that
Prompted by: https://github.com/systemd/systemd/pull/27890#issuecomment-1712841117
2023-09-11 20:40:35 +01:00
Luca Boccassi e4aab5cf1a logind: add PrepareForShutdownWithMetadata signal
The existing signal doesn't say which type of shutdown is going to happen.
With the introduction of soft-reboot, it is useful to have this information
broadcasted, so that clients can choose to do different things based on the
reboot type.
Add a{sv} as the payload so that more metadata can be added later if
needed, without needing to add yet another signal.
Send both old and new signal for backward compatibility, and send the new
one first so that clients can just wait for the first one on both old and
new systems.
2023-09-11 12:56:00 +01:00
Luca Boccassi 0112c37ce4 core: dump jobs list on sigrtmin+18 with 0x500 2023-09-11 12:24:23 +01:00
Luca Boccassi 0213162743 core: use structured initialization in exec_context_init 2023-09-10 22:57:19 +01:00
Luca Boccassi fd0a804271 Merge pull request #29130 from poettering/unit-defaults
core: introduce UnitDefaults structure for unit defaults
2023-09-09 19:15:46 +01:00
Luca Boccassi 5cd4613f52 Merge pull request #29142 from poettering/pidref
core: first step towards a pidfd focused future
2023-09-09 18:39:16 +01:00
Mike Yuan 66e089af85 Merge pull request #29117 from Werkov/memory_available
Make MemoryAvailable= more useful
2023-09-09 20:52:05 +08:00
Lennart Poettering d8854ff1ac machined: port over to PidRef too 2023-09-09 14:11:03 +02:00
Lennart Poettering 89bad70f71 logind: also port session leader tracking over to PidRef 2023-09-09 14:10:58 +02:00
Lennart Poettering 894a30ef3f core: don't manually destroy timer when we can't spawn a child
Let's stop manually destroying the timers when we fail to spawn a child.
We don't do this in any of the similar codepaths in any of the unit
types, only in two specific ones in socket/swap. Destroying the timer is
unnecessary, since this is done anyway in the _set_state() call of each
unit type if not appropriate, and every failure path here runs through
that anyway.

This brings all these similar codepaths into sync.
2023-09-09 14:10:54 +02:00
Lennart Poettering 436cdf0a07 core: also port swap units to PidRef 2023-09-09 14:10:41 +02:00
Lennart Poettering 360f384fd9 core: also port mount units to PidRef 2023-09-09 14:03:31 +02:00
Lennart Poettering 43a19142cb core: convert Socket logic to PidRef too
Just like the previous commit, but for socket rather than service units.
2023-09-09 14:03:31 +02:00
Lennart Poettering c79ab77cd3 core: reference main/control pid of .service units via PidRef
The first conversion to PidRef. It's mostly an excercise of
search/replace, but with some special care taken for life-cycle (i.e. we
need to destroy the structure properly once done, to release the pidfd).

It also uses pidfd based killing for some of the killing but leaves most
as it is to make the conversion minimal.
2023-09-09 14:03:31 +02:00
Lennart Poettering 3bda3f17fa pidref: add structure that can reference a pid via both pidfd and pid_t
Let's start with the conversion of PID 1 to pidfds. Let's add a simple
structure with just two fields that can be used to maintain a reference
to arbitrary processes via both pid_t and pidfd.

This is an embeddable struct, to keep it in line with where we
previously used a pid_t directly to track a process.

Of course, since this might contain an fd on systems where we have pidfd
this structure has a proper lifecycle.

(Note that this is quite different from sd_event_add_child() event
source objects as that one is only for child processes and collects
process results, while this infra is much simpler and more generic and
can be used to reference any process, anywhere in the tree.)
2023-09-09 14:03:31 +02:00
Luca Boccassi 9aa642d4e9 Merge pull request #29127 from YHNdnzj/wall-followup
shared/wall: several cleanups
2023-09-09 01:30:51 +01:00
Luca Boccassi 2d17808200 Merge pull request #29116 from yuwata/network-sriov-debug
network/sr-iov: ignore EINVAL in reading dev_port sysfs attribute
2023-09-09 01:28:35 +01:00
Lennart Poettering 7b9da3861a Revert "tree-wide: Mount file descriptors via /proc/<pid>/fd" 2023-09-08 22:13:09 +01:00
Lennart Poettering 0df7d52576 serialize: add common deserialize_read_line() helper and use it everywhere
This introduces a common helper replacing three very similar uses.

Prompted by review of: #27890
2023-09-08 20:59:44 +01:00
Mike Yuan 560f15fc8f shared/wall: fall back to logind if utmpx database doesn't exist 2023-09-09 03:22:25 +08:00
Mike Yuan 056aff96b9 shared/wall: several cleanups
Follow-up for 53c0397b1d

* Split do_wall into wall_utmp and wall_logind
* Don't pass unused arguments
* Add missing asserts
* Modernize error handling
* Don't do anything if neither utmp nor logind is enabled
2023-09-09 03:19:22 +08:00
Mike Yuan 8b2d219316 utmp-wtmp: remove unneeded include 2023-09-09 01:33:32 +08:00
Michal Koutný 8db929a1e2 cgroup: Estimate MemoryAvailable= when DefaultMemoryAccounting=no
Without memory accounting explicitly disabled, we may not obtain current
consumption from all units on the ancestry path.
Use a descendant value as lower bound estimate for ancestors if
ancestor's consumption cannot be directly queried.

This makes MemoryAvailable= an upper bound of available values.
2023-09-08 19:07:12 +02:00
Michal Koutný 727cea7652 cgroup: Refactor MemoryAvailable= evaluation
unit_get_memory_available() duplicates similar logic contained in
unit_get_memory_current(). Instead, it can call it for each unit it
needs data for.
Additionally, simplify the flow by treating all units from leaf to root
uniformly in one loop.

Functional change when a queried unit does not have MemoryAccounting=yes
(or cgroup_path), we will try getting an estimate from ancestors.
2023-09-08 19:07:12 +02:00
Michal Koutný 3565c709f5 cgroup: Fix MemoryAvailable= by considering physical memory
Currently, querying a unit's available memory would result in infinity
if there are no limits set on the unit or ancestors.
That undermines semantics implied by the name, so look at the physical
memory if the search propagates up to the -.slice.
This makes sense even in systemd user instances, limits of -.slice are
still looked at too.

Also change printed representation of infinite MemoryAvailable which
means we could not figure out a good estimate.
2023-09-08 19:05:52 +02:00
Mike Yuan 93f1da4556 conf-parser: parse main config first only if not symlinked to/as drop-in
Otherwise we'll skip parsing main config directly.

Replaces #27152
Replaces #28956:
chase() is an overkill for determining whether
two files are the same. We only need to check
if the inodes are the same.
2023-09-08 16:25:12 +02:00
Mike Yuan fc159b2fd9 repart,bootspec: use set_ensure_consume 2023-09-08 16:25:12 +02:00
Alvin Alvarado a05fa30f88 ukify/man: Look for a config file in systemd folders if not specified
If the user does not specify a config file to use, ukify will try looking for one at {/run,/etc,/usr/local/lib,/usr/lib}/systemd/ukify.conf in order and then use the first one found. Also made sure the --config input is a pathlib.Path by specifying its type in its CONFIG_ITEMS entry.
Big cheers to Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> for helping!
2023-09-08 16:21:28 +02:00
Lennart Poettering ea09a416ed core: introduce unit_defaults_init() common initialization helper
THis adds a helper for initializing UnitDefaults to our default values.
Previously we'd do that differently in two different locations. Let's
unify this in one, and apply the exact same settings at both as
defaults.
2023-09-08 15:25:05 +02:00
Lennart Poettering bfb27b06da manager: add manager_set_unit_defaults() call that sets all unit defaults in one go
No change in behaviour. Just some refactoring.
2023-09-08 15:25:05 +02:00
Lennart Poettering c9e120e06f manager: move various fields that declare unit defaults into a new structure UnitDefaults
This adds a new structure UnitDefaults which embedds the various default
settings for units we maintain. We so far maintained two sets of
variables for this, one in main.c as static variables and one in the
Manager structure. This moves them into a common structure.

This is most just search/replace, i.e. very dumb refactoring.

The fact that we now use a common structure for this allows us further
refactorings later.

Inspired by the discussions on #27890
2023-09-08 14:19:45 +02:00
Yu Watanabe b9962da63f network/sr-iov: move common parts to link_set_sr_iov_ifindices()
This also adds several debugging logs.
No functional change, just refactoring.
2023-09-08 20:09:15 +09:00
Yu Watanabe 4b12a8dd33 network/sr-iov: ignore -EINVAL in reading dev_port sysfs attribute
Fixes #27369.
2023-09-08 20:08:18 +09:00
Mike Yuan b8f18c3089 Merge pull request #29123 from yuwata/conf-parser-cleanups-for-config-section
conf-parser: several cleanups and generalizations for ConfigSection
2023-09-08 18:11:12 +08:00
Luca Boccassi 30a0f7e310 Merge pull request #29121 from yuwata/network-drop-duplicated
network: drop duplicated checks and function calls
2023-09-08 10:42:08 +01:00
Lennart Poettering fea82394bc Merge pull request #29071 from YHNdnzj/loop-write-full
io-util: introduce loop_write_full and use it where appropriate
2023-09-08 10:24:39 +02:00
Yu Watanabe e63c6e9ffa conf-parser: introduce ordered_hashmap_by_section_find_unused_line() 2023-09-08 12:55:44 +09:00
Yu Watanabe d9171a230d conf-parser: check overflow in hashmap_find_free_section_line()
Also, this also renames the function, and makes it optionally takes
a filename.
2023-09-08 12:55:44 +09:00
Yu Watanabe 08ca764d0a conf-parser: modernize config_section_new()
- add assertions,
- rename argument to store result.
2023-09-08 12:55:44 +09:00
Yu Watanabe 7bf9e0d5f6 hashmap: introduce HASHMAP_BASE_FOREACH() and friend 2023-09-08 12:55:44 +09:00
Yu Watanabe f7f5028edc network: drop duplicated check
The same check is in network_adjust_dhcp_server().
2023-09-08 06:41:37 +09:00
Yu Watanabe 0ae8ff50ac network: drop duplicated address_set_broadcast()
It will be called later in link_request_address().
2023-09-08 06:41:37 +09:00
Lennart Poettering 4bba26aea6 tpm2-util: drop support for creating TPM2 trial sessions
This is unused these days, we instead calculate policy hashes ourselves
and do not need trial sessions for that anymore. Given how unreliable
they are in actual TPMs, we don't want to use them anyway, so I don't
think we ever want to readd this.

hence, let's drop this unused feature.
2023-09-07 20:41:54 +01:00
Jan Janssen b7801869d7 efi: Add some more paranoia asserts 2023-09-07 20:41:12 +01:00
Zbigniew Jędrzejewski-Szmek c63db5420c Merge pull request #29036 from YHNdnzj/hibernate-resume-when-battery-low
hibernate-resume: split out the logic of finding hibernate location and support battery-check better
2023-09-07 17:34:27 +02:00
наб ef658a63f8 parse_timestamp: accept RFC3339-style timezone and %FT%R[:%S[.%N]]
We basically parsed the RFC3339 format already, except with a space:
      NOTE: ISO 8601 defines date and time separated by "T".
      Applications using this syntax may choose, for the sake of
      readability, to specify a full-date and full-time separated by
      (say) a space character.
so now we handle both
  2012-11-23 11:12:13.456
  2012-11-23T11:12:13.456
as equivalent.

Parse directly-suffixed Z and +05:30 timezones as well:
  2012-11-23T11:12:13.456Z
  2012-11-23T11:12:13.456+02:00
as they're both defined by RFC3339.

We do /not/ allow z or t; the RFC says
      NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this
      syntax may alternatively be lower case "t" or "z" respectively.

      This date/time format may be used in some environments or contexts
      that distinguish between the upper- and lower-case letters 'A'-'Z'
      and 'a'-'z' (e.g. XML).  Specifications that use this format in
      such environments MAY further limit the date/time syntax so that
      the letters 'T' and 'Z' used in the date/time syntax must always
      be upper case.  Applications that generate this format SHOULD use
      upper case letters.
We /are/ in a case-sensitive environment, neither are in wide-spread
use, and "z" poses an issue of whether "todayz" should be the same
as "todayZ" ("today UTC") or an error (it should be an error).

Fractional seconds are limited to six digits (they're nominally
   time-secfrac    = "." 1*DIGIT
), since we only support 1µs-resolution timestamps, and limit to six
digits in our other sub-second formats.

Parsing
  2012-11-23T11:12
is an extension two ways (no seconds, no timezone),
mirroring our "canonical" format.

Fixes #5194
2023-09-07 17:33:15 +02:00
Mike Yuan 3a1fc3860f shared/wall: use loop_write_full 2023-09-07 20:32:45 +08: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
Mike Yuan a628d933cc hibernate-resume: split out the logic of finding hibernate location
Before this commit, the hibernate location logic only exists in
the generator. Also, we compare device nodes (devnode_same()) and
clear EFI variable HibernateLocation in the generator too. This is
not ideal though: when the generator gets to run, udev hasn't yet
started, so effectively devnode_same() always fails. Moreover, if
the boot process is interrupted by e.g. battery-check, the hibernate
information is lost.

Therefore, let's split out the logic of finding hibernate location.
The generator only does the initial validation of system info and
enables systemd-hibernate-resume.service, and when the service
actually runs we validate everything again, which includes comparing
the device nodes and clearing the EFI variable. This should make
things more robust, plus systems that don't utilize a systemd-enabled
initrd can use the exact same logic to resume using the EFI variable.
I.e., systemd-hibernate-resume can be used standalone.
2023-09-07 20:21:16 +08:00