Commit Graph

2108 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek b3d15d90c0
Merge pull request #15804 from poettering/hostnamed-instant-part1
four likely safe commits split out of #15624
2020-05-18 15:26:24 +02:00
Andreas Rammhold 32fcf399bf sd-netlink: remove unused RTNL_WQUEUE_MAX define
While investigating why some of my netlink calls would timeout I
stumbled upon the definition of the max write queue length. Finding this
constant made me believe we still had a write queue in the code - which
isn't true. The netlink write queue code was removed in #189.
2020-05-14 22:27:03 +02:00
Benjamin Robin b9c54c4665 tree-wide: Initialize _cleanup_ variables if needed 2020-05-13 22:56:42 +02:00
Benjamin Robin 179b4db439 netlink: Fix assert condition on n_containers 2020-05-13 22:56:42 +02:00
Lennart Poettering 491ce16103 sd-bus: introduce new SD_BUS_VTABLE_ABSOLUTE_OFFSET vtable flag
When set, the offset specified for the vtable entry is passed to the
handler as-is, and is not added to the userdata pointer. This is useful
in case methods/properties are mixed on the same vtable, that expect to
operate relative to some object in memory and that expect pointers to
absolute memory, or that just want a number passed.
2020-05-13 16:57:44 +02:00
Lennart Poettering 9e45fb09bf netlink: port to recvmsg_safe()
This also makes sure the control buffer is properly aligned. This
matters, as otherwise the control buffer might not be aligned and the
cmsg buffer counting might be off. The incorrect alignment is becoming
visible by using recvmsg_safe() as we suddenly notice the MSG_CTRUNC bit
set because of this.

That said, apparently this isn't enough to make this work on all
kernels. Since I couldn't figure this out, we now add 1K to the buffer
to be sure. We do this once already, also for a pktinfo structure
(though an IPv4/IPv6) one. I am puzzled by this, but this shouldn't
matter much. it works locally just fine, except for those ubuntu CI
kernels...

While we are at it, make some other changes too, to simplify and
modernize the function.
2020-05-12 10:47:06 +02:00
Zbigniew Jędrzejewski-Szmek 8acb7780df
Merge pull request #15623 from poettering/cmsg-cleanup
various CMSG_xyz clean-ups, split out of #15571
2020-05-08 11:05:06 +02:00
Zbigniew Jędrzejewski-Szmek 5cea17a177
Merge pull request #15635 from keszybz/set-put-strdup
Let set_put_strdup() allocate the set and related changes
2020-05-07 17:01:59 +02:00
Lennart Poettering fb29cdbef2 tree-wide: make sure our control buffers are properly aligned
We always need to make them unions with a "struct cmsghdr" in them, so
that things properly aligned. Otherwise we might end up at an unaligned
address and the counting goes all wrong, possibly making the kernel
refuse our buffers.

Also, let's make sure we initialize the control buffers to zero when
sending, but leave them uninitialized when reading.

Both the alignment and the initialization thing is mentioned in the
cmsg(3) man page.
2020-05-07 14:39:44 +02:00
Lennart Poettering a258f4915a tree-wide: use CMSG_SPACE() (and not CMSG_LEN()) to allocate control buffers
We need to use the CMSG_SPACE() macro to size the control buffers, not
CMSG_LEN(). The former is rounded up to next alignment boundary, the
latter is not. The former should be used for allocations, the latter for
encoding how much of it is actually initialized. See cmsg(3) man page
for details about this.

Given how confusing this is, I guess we don't have to be too ashamed
here, in most cases we actually did get this right.
2020-05-07 14:39:44 +02:00
gaurav 48a3b5c6db
netlink socket correct check (#15720) 2020-05-07 09:55:31 +02:00
Zbigniew Jędrzejewski-Szmek 476a63e9c0 sd-device: get rid of device_enumerator_clear_match_parent
This helper wasn't helping all that much. It seems better to verify args
first, and only then start modifying the state.
2020-05-06 17:02:10 +02:00
Zbigniew Jędrzejewski-Szmek 2204f018cd sd-device: optimize addition of already present matches
Our hashmap and set helpers return a different code whenever an entry
already exists, so let's use this to avoid unsetting scan_uptodate when
not necessary.

Thus, the return convention for
sd_device_enumerator_add_match_subsystem,
sd_device_enumerator_add_match_sysattr,
sd_device_enumerator_add_match_property,
sd_device_enumerator_add_match_sysname,
sd_device_enumerator_add_match_tag,
device_enumerator_add_match_parent_incremental,
sd_device_enumerator_add_match_parent,
sd_device_enumerator_allow_uninitialized,
device_enumerator_add_match_is_initialized
is that "1" is returned if action was taken, and "0" on noop.
2020-05-06 17:01:33 +02:00
Zbigniew Jędrzejewski-Szmek eb1c1dc029 sd-device: use hashmap_put_strdup() 2020-05-06 17:00:45 +02:00
Zbigniew Jędrzejewski-Szmek c73bb51364 sd-device: use string hash ops in device enumerator
There should be no functional change, except that when the same string is
added more than once, we skip the duplicate entries.
2020-05-06 16:55:50 +02:00
Zbigniew Jędrzejewski-Szmek be32732168 basic/set: let set_put_strdup() create the set with string hash ops
If we're using a set with _put_strdup(), most of the time we want to use
string hash ops on the set, and free the strings when done. This defines
the appropriate a new string_hash_ops_free structure to automatically free
the keys when removing the set, and makes set_put_strdup() and set_put_strdupv()
instantiate the set with those hash ops.

hashmap_put_strdup() was already doing something similar.

(It is OK to instantiate the set earlier, possibly with a different hash ops
structure. set_put_strdup() will then use the existing set. It is also OK
to call set_free_free() instead of set_free() on a set with
string_hash_ops_free, the effect is the same, we're just overriding the
override of the cleanup function.)

No functional change intended.
2020-05-06 16:54:06 +02:00
Zbigniew Jędrzejewski-Szmek b49ca3bc37 sd-bus: use STR_IN_SET() in one more place 2020-05-03 10:55:51 +02:00
Zbigniew Jędrzejewski-Szmek 2b6a1d155d bus-introspect: move xml string defines into the .c file 2020-05-03 10:55:51 +02:00
Zbigniew Jędrzejewski-Szmek 61d0df3919 bus-introspect: write <interface> from within introspect_write_interface() 2020-05-03 10:55:51 +02:00
Lennart Poettering 6eb35fd695
Merge pull request #15547 from kkdwivedi/notify-barrier
Introduce sd_notify_barrier
2020-05-01 08:48:42 +02:00
Kumar Kartikeya Dwivedi 4f07ddfa9b
Introduce sd_notify_barrier
This adds the sd_notify_barrier function, to allow users to synchronize against
the reception of sd_notify(3) status messages. It acts as a synchronization
point, and a successful return gurantees that all previous messages have been
consumed by the manager. This can be used to eliminate race conditions where
the sending process exits too early for systemd to associate its PID to a
cgroup and attribute the status message to a unit correctly.

systemd-notify now uses this function for proper notification delivery and be
useful for NotifyAccess=all units again in user mode, or in cases where it
doesn't have a control process as parent.

Fixes: #2739
2020-05-01 03:22:47 +05:30
Michal Sekletár d9e45bc3ab core: introduce support for cgroup freezer
With cgroup v2 the cgroup freezer is implemented as a cgroup
attribute called cgroup.freeze. cgroup can be frozen by writing "1"
to the file and kernel will send us a notification through
"cgroup.events" after the operation is finished and processes in the
cgroup entered quiescent state, i.e. they are not scheduled to
run. Writing "0" to the attribute file does the inverse and process
execution is resumed.

This commit exposes above low-level functionality through systemd's DBus
API. Each unit type must provide specialized implementation for these
methods, otherwise, we return an error. So far only service, scope, and
slice unit types provide the support. It is possible to check if a
given unit has the support using CanFreeze() DBus property.

Note that DBus API has a synchronous behavior and we dispatch the reply
to freeze/thaw requests only after the kernel has notified us that
requested operation was completed.
2020-04-30 19:02:51 +02:00
Zbigniew Jędrzejewski-Szmek 11f9379866
Merge pull request #15570 from poettering/cmsg-find
CMSG_FIND_DATA() and cmsg_find() work
2020-04-24 07:45:07 +02:00
Lennart Poettering 41ab8c67eb tree-wide: use structured initialization at various places 2020-04-24 07:44:42 +02:00
Lennart Poettering dac556fa7b tree-wide: use cmsg_find() helper at various places where appropriate 2020-04-23 19:41:15 +02:00
Lennart Poettering 0f4a141744
Merge pull request #15504 from poettering/cmsg-find-pure
just the recvmsg_safe() stuff from #15457
2020-04-23 17:28:19 +02:00
Lennart Poettering 2d69cf6eb0
Merge pull request #15543 from poettering/fix-ubsan-sd-bus
sd-bus: work around ubsan warning
2020-04-23 13:39:58 +02:00
Lennart Poettering 3691bcf3c5 tree-wide: use recvmsg_safe() at various places
Let's be extra careful whenever we return from recvmsg() and see
MSG_CTRUNC set. This generally means we ran into a programming error, as
we didn't size the control buffer large enough. It's an error condition
we should at least log about, or propagate up. Hence do that.

This is particularly important when receiving fds, since for those the
control data can be of any size. In particular on stream sockets that's
nasty, because if we miss an fd because of control data truncation we
cannot recover, we might not even realize that we are one off.

(Also, when failing early, if there's any chance the socket might be
AF_UNIX let's close all received fds, all the time. We got this right
most of the time, but there were a few cases missing. God, UNIX is hard
to use)
2020-04-23 09:41:47 +02:00
Lennart Poettering 0cd41757d0 sd-bus: work around ubsan warning
ubsan complains that we add an offset to a NULL ptr here in some cases.
Which isn't really a bug though, since we only use it as the end
condition for a for loop, but we can still fix it...

Fixes: #15522
2020-04-23 08:54:30 +02:00
Susant Sahani d64cc72e80 sd-network: Add support to retrive LPR servers 2020-04-22 14:49:52 +02:00
Lennart Poettering 75dff0f910
Merge pull request #15459 from keszybz/remove-seat_can_multi_session
Remove seat_can_multi_session
2020-04-17 19:15:28 +02:00
Zbigniew Jędrzejewski-Szmek 8f8cc84ba4 sd-login: get rid of seat_can_multi_session()
Follow-up for fa2cf64a91.
Backwards-compat is retained. A short note is added in docs, in case
people see sd_seat_can_multi_session() mentioned somewhere and wonder what
happened to it.

Also see https://github.com/systemd/systemd/pull/15337#issuecomment-610369404.
2020-04-17 16:15:30 +02:00
Zbigniew Jędrzejewski-Szmek 162392b75a tree-wide: spellcheck using codespell
Fixes #15436.
2020-04-16 18:00:40 +02:00
Lennart Poettering 648ba0ee81 hwdb: optimize isatty()-per-line away
Fixes: #15407
2020-04-13 11:27:35 +02:00
Daan De Meyer 59a77060e0 sd-bus: Use pointer syntax for sd_bus_set_exec argv parameter 2020-04-11 21:57:28 +02:00
Zbigniew Jędrzejewski-Szmek c3362c2f97 Remove message->priority field
A warning is emitted from sd_bus_message_{get,set}_priority. Those functions
are exposed by pystemd, so we have no easy way of checking if anything is
calling them.

Just making the functions always return without doing anything would be an
option, but then we could leave the caller with an undefined variable. So I
think it's better to make the functions emit a warnings and return priority=0
in the get operation.
2020-04-07 15:29:23 +02:00
Anita Zhang 4fbf39926e
Merge pull request #15290 from keszybz/unrelated-fixes
Three unrelated minor tweaks
2020-04-03 15:54:38 -07:00
Daan De Meyer 1e9a7c44a9 sd-bus: remove unused priority logic 2020-04-02 21:42:32 +02:00
Vito Caputo 935052a8aa sd-bus: add va_list variants of variadic convenience functions
Consumers of the sd-bus convenience API can't make convenience
helpers of their own without va_list variants.

This commit is a mechanical change splitting out the existing function
bodies into bare va_list variants having a 'v' suffixed to the names.

The original functions now simply create the va_list before forwarding
the call on to the va_list variant, and the va_list variants dispense
with those steps.
2020-04-02 10:26:18 +02:00
Zbigniew Jędrzejewski-Szmek 934cf0a9c7 sd-bus: simplify bus_maybe_reply_error
sd_bus_reply_method_errno already does the same two checks
(sd_bus_error_is_set(error), r < 0) internally. But it did them in opposite
order. The effect is the same, because sd_bus_reply_method_errno falls back to
sd_bus_reply_method_error, but it seems inelegant. So let's simplify
bus_maybe_reply_error() to offload the job fully to sd_bus_reply_method_errno().

No functional change.
2020-03-31 22:19:22 +02:00
Lennart Poettering 1f4faf21e8
Merge pull request #15197 from ssahani/smtp-dhcp
DHCP4: Add support to emit and receive SMTP servers.
2020-03-30 18:58:26 +02:00
Susant Sahani c1c6ff10a1 sd-network: Add support to emit and receive SMTP server information 2020-03-29 22:59:18 +02:00
Zbigniew Jędrzejewski-Szmek 4a874560c5
Merge pull request #15217 from keszybz/beef-up-sd-path
Export sd-path functions and beef up systemd-path to show more items
2020-03-29 22:57:53 +02:00
Susant Sahani 8102b9e710 sd-network: Add support to emit and receive pop3 server information 2020-03-28 03:34:27 +01:00
Zbigniew Jędrzejewski-Szmek f1bb691a5a sd-path: export "systemd-network-path"
Inspired by https://lists.freedesktop.org/archives/systemd-devel/2020-March/044169.html.
2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek 96d33e4ac0 Rename _PATH variables to _DIR when they refer to a directory
We were very inconsistent in this, but in general _PATH signifies
a search path (separated with :), and _DIR signifies a single directory.
2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek 9c5bb2033d path: show various systemd directories and search paths too
So far we had various ad hoc APIs to query search paths:
systemd-analyze unit-paths, lookup_paths_log(), the pkgconfig file,
debug logs emitted by systemd-analyze cat-config.
But answering a simple question "what is the search path for tmpfiles,
sysusers, .network files, ..." is surprisingly hard.

I think we should have an api that makes it easy to query this. Pkgconfig is
not bad, but it is primarily a development tool, so it's not available in many
context. Also it can't provide support for paths which are influenced by
environment variables, and I'd like to be able to answer the question "what is
the search path for ..., assuming that VAR_FOO=... is set?".

Extending sd-path to support more of our internal paths seems to be most
flexible solution. We already have systemd-path which provides a nice
way to query, and we can add stuff like optional descriptions later on.
We we essentially get a nice programmatic and commmandline apis for the price
of one.
2020-03-27 20:12:45 +01:00
Zbigniew Jędrzejewski-Szmek ce7eb6aa84 sd-path: simplify implementation of sd_path_lookup*()
The two functions were duplicating a lot of functionality and more
importantly, they both had explicit lists of types which are search
paths. I want to add more types, and I don't want to have to remember
to add them to both lists.
2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek a7addf32a5 sd-path,strv: add simple helper to wrap oom handling around strv_split_nulstr() 2020-03-27 20:12:44 +01:00
Zbigniew Jędrzejewski-Szmek 557afad2b7 libsystemd: install sd-path.h and export sd_path_lookup{,_strv}
Those are not terribly imporant functions, but we have them, and there's
no reason not to export them.
2020-03-27 20:12:44 +01:00