Commit Graph
25 Commits
Author SHA1 Message Date
Daan De Meyer 69a283c5f2 shared: Clean up includes
Split out of #37344.
2025-05-24 14:00:44 +02:00
Daan De Meyer 9ebbb785b0 serialize: Move some logic to the implementation file
This will allow removing the string-util.h include in #37344.
2025-05-15 04:25:47 +09:00
Mike Yuan 38a2c2bf6a shared/serialize: introduce serialize_id128() 2025-01-13 21:52:13 +01:00
Mike Yuan 3f03d39ca3 shared/serialize: make input params const 2025-01-13 16:56:08 +01:00
Lennart Poettering 5d1e57b820 serialize: add explicit calls for finishing serialization
These new calls will do three things:

1. in case of FILE* stuff: flush any pending bytes onto the fd, just in
   case
2. seal the backing memfd
3. seek back to the beginning.

Note that this adds sealing to serialization: once we serialized fully,
we'll seal the thing off for further modifications, before we pass the
fd over to the target process. This should add a bit of robustness, and
maybe finds a bug or two one day, if we accidentally write to a
serialization that is complete.
2024-12-17 18:26:15 +01:00
Zbigniew Jędrzejewski-Szmek 07a6647abb core: split out the helper to serialize/deserialize ratelimits 2023-11-17 17:47:37 +01:00
Lennart Poettering 3b444970e6 serialize: add serialize_fd_many() helper 2023-10-18 13:51:02 +02:00
Lennart Poettering c2e42d4b88 serialize: change order of deserialize_strv() parameters
The other deserializers put value first, and return parameter second,
let's do so here too.
2023-10-18 12:54:20 +02:00
Lennart Poettering af6321857d serialize: modernize deserialize_{usec|dual_timestamp}() a bit
Rename the return parameters "ret", and use compound initialization. Add
an assert() on input.
2023-10-18 12:54:20 +02:00
Lennart Poettering dff9808a62 serialize: add new helper deserialize_fd()
Currently, when we deserialize an fd we do a lot of manual work. Add a
common helper that makes this more robust and uniform.

Note that this sometimes changes behaviour slightly, but in ways that
shouldn't really matter: if we fail to deserialize an fd correctly we'll
unset (i.e. set to -EBADF) the fd in the deserialized data structure.
Previously, we'd leave the old value in place.

This should not change effective result (as in either case we'll be in a
bad state afterwards, just once we mix old/invalidated state with new
state, while now we'll reset the state explicitly to invalidated state
on failure). In particular as deserialization starts from an empty
structure generally, hence the old value should be unset anyway.

Another slight change is that if we fail to deserialize some object half
way, and we already have taken out one fd from the serialized fdset
we'll now just close it instead of returning it to/leaving it in the
fdset. Given that such "orphaned" fds are blanket closed after
deserialization finishes this also shouldn't change behaviour IRL.

Also, the idle_pipe was previously incorrectly serialized: we'd
serialize invalidated fds, which would fail, but because parsing errors
on this were ignored on the deserializatin noone noticed. This is fixed.
2023-10-18 12:54:20 +02:00
Luca Boccassi 665c6e46e3 serialize: add serialize_image_policy() 2023-10-12 13:37:22 +01:00
Luca Boccassi 81b913f076 serialize: add open_serialization_file() 2023-10-12 13:37:22 +01:00
Luca Boccassi 1b30ccd81b serialize: add serialize_string_set() 2023-10-12 13:37:22 +01:00
Luca Boccassi 5612426d7b serialize: add serialize_item_tristate() 2023-10-12 13:37:22 +01:00
Luca Boccassi 6dae20ec41 serialize: add serialize_item_base64mem() 2023-10-12 13:37:22 +01:00
Luca Boccassi 3f12c5ff2e serialize: add serialize_item_hexmem() 2023-10-12 13:37:22 +01:00
Lennart Poettering 2a7451dc5d pid1: serialize pidrefs as pidfds if possible
One major step towards total pidfdification of systemd.
2023-10-05 12:57:05 +02: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
Luca Boccassi 942c40c64c serialize: add serialize_bool_elide() helper
In many case we serialize into objects that have been zero-initialized.
To save some time and resources when there are a lot of booleans, add a
helper that serializes only when the boolean is true.
2023-07-29 11:25:05 +01:00
Luca Boccassi 1d6f1e2fa1 serialize: add deserialize_strv helper 2023-06-09 00:49:19 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Zbigniew Jędrzejewski-Szmek 55fced5a19 util-lib: move yes_no() and friends to string-util.h 2019-09-16 18:06:20 +02: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 0a2152f005 util-lib: move open_serialization_fd() to serialize.c
It definitely fits better there.

No code changes, just some rearranging.
2018-12-02 13:22:29 +01:00
Lennart Poettering d68c645bd3 core: rework serialization
Let's be more careful with what we serialize: let's ensure we never
serialize strings that are longer than LONG_LINE_MAX, so that we know we
can read them back with read_line(…, LONG_LINE_MAX, …) safely.

In order to implement this all serialization functions are move to
serialize.[ch], and internally will do line size checks. We'd rather
skip a serialization line (with a loud warning) than write an overly
long line out. Of course, this is just a second level protection, after
all the data we serialize shouldn't be this long in the first place.

While we are at it also clean up logging: while serializing make sure to
always log about errors immediately. Also, (void)ify all calls we don't
expect errors in (or catch errors as part of the general
fflush_and_check() at the end.
2018-10-26 10:52:41 +02:00