Commit Graph

220 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek bc130b6858 Fix typo in function name 2020-02-04 18:54:12 +01:00
Lennart Poettering 1068447e69 sd-bus: introduce API for re-enqueuing incoming messages
When authorizing via PolicyKit we want to process incoming method calls
twice: once to process and figure out that we need PK authentication,
and a second time after we aquired PK authentication to actually execute
the operation. With this new call sd_bus_enqueue_for_read() we have a
way to put an incoming message back into the read queue for this
purpose.

This might have other uses too, for example debugging.
2020-02-04 18:47:31 +01:00
Lennart Poettering 5905d7cf5b tree-wide: use SD_ID128_STRING_MAX where appropriate 2019-12-10 11:56:18 +01:00
Lennart Poettering 19fa17c7c4 sd-bus: invalidate connection when Hello() fails
Fixes: #13969
2019-11-16 13:47:32 +01:00
Yu Watanabe f5947a5e92 tree-wide: drop missing.h 2019-10-31 17:57:03 +09:00
Zbigniew Jędrzejewski-Szmek 61252bae91 sd-bus: adjust indentation of comments 2019-08-27 19:49:09 +02:00
Lennart Poettering 6b39223cd3 sd-bus: when installing a match make sure not to apply it to already queued messages
This tweaks match installation a bit: the match callbacks are now only
called for messages read after the AddMatch() reply was received and
never anything already read before. Thus, installing a match gives you a
time guarantee: only messages received after it will be matched.

This is useful when listening to PropertiesChanged signals as an example
to ensure that only changes after the point the match was installed are
honoured, nothing before.
2019-07-11 12:18:51 +02:00
Lennart Poettering 3cf8dd5359 sd-bus: destroy AddMatch() reply slot in failure case too
If AddMatch() doesn't work, let's destroy the slot for it too as soon as
we received the failure for it.

This way the mere existance of the slot tells us whether the AddMatch()
method call is still pending or is complete.
2019-07-11 12:18:51 +02:00
Lennart Poettering f1617a3b61 sd-bus: maintain a counter for incoming msgs
Let's count incoming messages and attach the current counter when we
first read them to the message objects. This allows us to nicely order
messages later on.
2019-07-11 12:18:51 +02:00
Yu Watanabe 657ee2d82b tree-wide: replace strjoin() with path_join() 2019-06-21 03:26:16 +09:00
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Lennart Poettering f60a028a4e tree-wide: use ERRNO_IS_DISCONNECT() at more places 2019-03-19 15:41:30 +01:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Zbigniew Jędrzejewski-Szmek 42541a71a2 bus: make reference counting non-atomic
We had atomic counters, but all other operations were non-serialized. This
means that concurrent access to the bus object was only safe if _all_ threads
were doing read-only access. Even sending of messages from threads would not be
possible, because after sending of the message we usually want to remove it
from the send queue in the bus object, which would race. Let's just kill this.
2019-03-04 14:16:24 +01:00
Lennart Poettering c1757a70ea sd-bus: use "queue" message references for managing r/w message queues in connection objects
Let's make use of the new concept the previous commit added.

See: #4846
2019-03-01 15:37:39 +01:00
Lennart Poettering 39feb2ce41 sd-bus: drop two inappropriate empty lines 2019-03-01 15:19:45 +01:00
Lennart Poettering c0bc4ec5cc sd-bus: make sure dispatch_rqueue() initializes return parameter on all types of success
Let's make sure our own code follows coding style and initializes all
return values on all types of success (and leaves it uninitialized in
all types of failure).
2019-03-01 15:19:45 +01:00
Lennart Poettering 143d4e045a sd-bus: make rqueue/wqueue sizes of type size_t
Let's do this like we usually do and size arrays with size_t.

We already do this for the "allocated" counter correctly, and externally
we expose the queue sizes as uint64_t anyway, hence there's really no
point in usigned "unsigned" internally.
2019-03-01 15:19:45 +01:00
Lennart Poettering 2fe9a10d76 sd-bus: initialize mutex after we allocated the wqueue
That way the mutex doesn't have to be destroyed when we exit early due
to OOM.
2019-03-01 15:19:45 +01:00
Lennart Poettering 1f82f5bb42 sd-bus: deal with cookie overruns
Apparently this happens IRL. Let's carefully deal with issues like this:
when we overrun, let's not go back to zero but instead leave the highest
cookie bit set. We use that as indication that we are in "overrun
territory", and then are particularly careful with checking cookies,
i.e. that they haven't been used for still outstanding replies yet. This
should retain the quick cookie generation behaviour we used to have, but
permits dealing with overruns.

Replaces: #11804
Fixes: #11809
2019-02-28 13:44:05 +01:00
Lennart Poettering bd62b74486 sd-bus: add sd_bus_close_unref() helper
It's similar to sd_bus_flush_close_unref() but doesn't do the flushing.
This is useful since this will still discnnect the connection properly
but not synchronously wait for the peer to take our messages.

Primary usecase is within _cleanup_() expressions where synchronously
waiting on the peer is not OK.
2019-01-17 16:12:38 +01:00
Lennart Poettering 5dd9527883 tree-wide: remove various unused functions
All found with "cppcheck --enable=unusedFunction".
2018-12-02 13:35:34 +09:00
Lennart Poettering c4e48030cf sd-bus: make "close+flush-on-exit" optional when using sd-event with sd-bus
This adds a new pair of API calls sd_bus_set_close_on_exit() and
sd_bus_get_close_on_exit(). They control whether an sd_bus object
attached to a an sd-event loop shall automatically be flushed/closed
when the event loop goes down. Usually that's a good thing, except for
very few cases where the bus connection is longer living than the event
loop it is attached on. Specifically, this is the case for nspawn, where
we run the event loop only while the container is up, but afterwards
still want to be able to use the bus connection.
2018-11-09 17:08:59 +01:00
Lennart Poettering 490c5a37cb tree-wide: some automatic coccinelle fixes (#10463)
Nothing fancy, just coccinelle doing its work.
2018-10-20 00:07:46 +09:00
Lennart Poettering 95cb14b068 sd-bus: rework how we initialize struct sockaddr_un
Let's use structured initialization, but more importantly, let's
increase salen by 1, if we reference AF_UNIX sockets in the file system,
so that they also contain the trailing NUL byte. This is what unix(7)
suggests to do, hence follow it.
2018-10-15 19:40:51 +02:00
Lennart Poettering 1d261418e2 sd-bus: make parsing of AF_UNIX socket addresses more strict
Insist on NUL termination, just to be safe rather than sorry. The kernel
doesn't require it, but it's really annoying if people rely on this,
hence refuse this early.
2018-10-15 19:40:51 +02:00
Lennart Poettering 44ed5214ad tree-wide: use structured initialization for sockaddr_un 2018-10-15 19:35:00 +02:00
Yu Watanabe 9c57a73b13 tree-wide: use CMP() macros where applicable 2018-10-09 14:45:55 +02:00
Yu Watanabe 1c71f7f329 libsystemd: use DEFINE_ATOMIC_REF_UNREF_FUNC or frineds where applicable 2018-08-28 05:09:40 +09:00
Shawn Landden 6a5558491b sd-bus: fix test cases on host handling 2018-08-06 14:30:53 -07:00
Shawn Landden b85b4a70d7 sd-bus rework host handling
--machine has been missing for a while in systemd-stdio-bridge
this syntax can be switched to be more standard.

v2: Support the old syntax too.

timedatectl -H server1.myhostingcompany.com:5555/container1

Closes: #8071
2018-08-06 14:30:53 -07:00
Lennart Poettering 1e5057b904 sd-bus: allow connecting to the pseudo-container ".host"
machined exposes the pseudo-container ".host" as a reference to the host
system, and this means "machinectl login .host" and "machinectl shell
.host" get your a login/shell on the host. systemd-run currently doesn't
allow that. Let's fix that, and make sd-bus understand ".host" as an
alias for connecting to the host system.
2018-07-25 22:48:11 +02:00
Yu Watanabe 2e7e8e34aa sd-bus: make bus_slot_disconnect() also unref the slot object
This makes bus_slot_disconnect() unref the slot object from bus when
`unref == true` and it is floating, as the function removes the
reference from the relevant bus object.

This reverts 20d4ee2cbc, as it
introduces #9604.

Fixes #9604.
2018-07-18 20:54:19 +02:00
Zbigniew Jędrzejewski-Szmek 6d77a30c09 bus: add comment to explain assert 2018-07-18 16:36:37 +02:00
Zbigniew Jędrzejewski-Szmek 7ae8edcd03 bus: move BUS_DONT_DESTROY calls after asserts
It's not useful to bump the reference count before checking if the object is
NULL. Thanks to d40f5cc498 we can do this ;).

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1576084,
https://bugzilla.redhat.com/show_bug.cgi?id=1575340,
https://bugzilla.redhat.com/show_bug.cgi?id=1575350. I'm not sure why those two
people hit this code path, while most people don't. At least we won't abort.
2018-07-18 12:16:33 +02:00
Yu Watanabe 385b2eb262 sd-bus: make BUS_DEFAULT_TIMEOUT configurable
This adds sd_bus_{get,set}_method_call_timeout().
If the timeout is not set or set to 0, then the timeout value is
parsed from $SYSTEMD_BUS_TIMEOUT= environment variable. If the
environment variable is not set, then built-in timeout is used.
2018-07-16 15:11:50 +02:00
Yu Watanabe 8f5dd8c094 tree-wide: drop empty comments 2018-06-29 11:00:30 +09:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Lennart Poettering fc2d4c89b8 sd-bus: make add match method callback slot "floating"
When we allocate an asynchronous match object we will allocate an
asynchronous bus call object to install the match server side.
Previously the call slot would be created as regular slot, i.e.
non-floating which meant installing the match even if it was itself
floating would result in a non-floating slot to be created internally,
which ultimately would mean the sd_bus object would be referenced by it,
and thus never be freed.

Let's fix that by making the match method callback floating in any case
as we have no interest in leaving the bus allocated beyond the match
slot.

Fixes: #8551
2018-05-30 17:34:34 +02:00
Yu Watanabe 1ab436e314 sd-bus: use free_and_strdup() 2018-05-14 14:09:03 +09:00
Yu Watanabe 130d3d22e9 tree-wide: use strv_free_and_replace() macro 2018-05-10 00:57:34 +09:00
Zbigniew Jędrzejewski-Szmek 9df088f1ea sd-bus: add bus_freep and use _cleanup_ 2018-05-09 09:44:37 +02:00
Zbigniew Jędrzejewski-Szmek 01c4dcaffb sd-bus: use automatic cleanup more 2018-05-09 09:35:01 +02:00
Zbigniew Jędrzejewski-Szmek 0639f1354c sd-bus: trivial simplification 2018-05-09 09:30:58 +02:00
Lennart Poettering 5d13a15b1d tree-wide: drop spurious newlines (#8764)
Double newlines (i.e. one empty lines) are great to structure code. But
let's avoid triple newlines (i.e. two empty lines), quadruple newlines,
quintuple newlines, …, that's just spurious whitespace.

It's an easy way to drop 121 lines of code, and keeps the coding style
of our sources a bit tigther.
2018-04-19 12:13:23 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Zbigniew Jędrzejewski-Szmek 56fbd7187a sd-bus: allow description to be set for system/user busses (#8594)
sd_bus_open/sd_bus_open_system/sd_bus_open_user are convenient, but
don't allow the description to be set. After they return, the bus is
is already started, and sd_bus_set_description() fails with -EBUSY.
It would be possible to allow sd_bus_set_description() to update the
description "live", but messages are already emitted from sd_bus_open
functions, so it's better to allow the description to be set in
sd_bus_open/sd_bus_open_system/sd_bus_open_user.

Fixes message like:
Bus n/a: changing state UNSET → OPENING
2018-03-29 16:14:11 +02:00
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00