Commit graph

129 commits

Author SHA1 Message Date
Lennart Poettering 6203e07a83 event: rework sd-event exit logic
With this change a failing event source handler will not cause the
entire event loop to fail. Instead, we just disable the specific event
source, log a message at debug level and go on.

This also introduces a new concept of "exit code" which can be stored in
the event loop and is returned by sd_event_loop(). We also rename "quit"
to "exit" everywhere else.

Altogether this should make things more robus and keep errors local
while still providing a way to return event loop errors in a clear way.
2013-12-13 04:06:43 +01:00
Lennart Poettering 3df7a7e610 bus: always pass valid timeout to kdbus 2013-12-12 20:00:45 +01:00
Lennart Poettering 0f437184b6 bus: enforce endianess and marshalling for messages we send 2013-12-12 20:00:45 +01:00
Lennart Poettering f8e11cda53 bus: properly return an error when we detect a method call timeout 2013-12-12 05:40:05 +01:00
Lennart Poettering 9e5548644f bus: connect directly via kdbus in sd_bus_open_system_container()
kdbus fortunately exposes the container's busses in the host fs, hence
we can access it directly instead of doing the namespacing dance.
2013-12-12 00:07:49 +01:00
Lennart Poettering b6741478e7 journal: add ability to browse journals of running OS containers
This adds the new library call sd_journal_open_container() and a new
"-M" switch to journalctl. Particular care is taken that journalctl's
"-b" switch resolves to the current boot ID of the container, not the
host.
2013-12-11 22:04:03 +01:00
Lennart Poettering a82cafb97b bus: don't generate assert warnings when we detach a detached bus from an event 2013-12-10 23:06:50 +00:00
Lennart Poettering 5b1bc83f81 bus: when we _unref() a NULL pointer, don't use assert_return()
We support unreffing NULL pointers just fine and we shouldn't pay the
_unlikely_() price for it, not get a debug message if we do, hence let's
not use assert_return() here.
2013-12-10 20:38:04 +00:00
Lennart Poettering adacb9575a bus: introduce "trusted" bus concept and encode access control in object vtables
Introduces a new concept of "trusted" vs. "untrusted" busses. For the
latter libsystemd-bus will automatically do per-method access control,
for the former all access is automatically granted. Per-method access
control is encoded in the vtables: by default all methods are only
accessible to privileged clients. If the SD_BUS_VTABLE_UNPRIVILEGED flag
is set for a method it is accessible to unprivileged clients too. By
default whether a client is privileged is determined via checking for
its CAP_SYS_ADMIN capability, but this can be altered via the
SD_BUS_VTABLE_CAPABILITY() macro that can be ORed into the flags field
of the method.

Writable properties are also subject to SD_BUS_VTABLE_UNPRIVILEGED and
SD_BUS_VTABLE_CAPABILITY() for controlling write access to them. Note
however that read access is unrestricted, as PropertiesChanged messages
might send out the values anyway as an unrestricted broadcast.

By default the system bus is set to "untrusted" and the user bus is
"trusted" since per-method access control on the latter is unnecessary.

On dbus1 busses we check the UID of the caller rather than the
configured capability since the capability cannot be determined without
race. On kdbus the capability is checked if possible from the attached
meta-data of a message and otherwise queried from the sending peer.

This also decorates the vtables of the various daemons we ship with
these flags.
2013-12-10 16:52:49 +00:00
Lennart Poettering 0461f8cdc1 bus: internalize a lot of protocol definitions
We shouldn export what isn't necessary or useful to clients, so let's
add the protocol definitions we only need internally into a private
header.
2013-12-03 18:14:50 +01:00
Lennart Poettering 95c4fe8271 busctl: add command to dump creds of a peer or pid
(also, rename _SD_BUS_CREDS_MAX to _SD_BUX_CRED_ALL, since "MAX" so far
was used to indicate one higher than the highest valid value, and this
is not correct here.)
2013-12-02 18:40:43 +01:00
Zbigniew Jędrzejewski-Szmek 75be4e6445 bus: remove unused variable 2013-11-30 20:10:18 -05:00
Lennart Poettering 626851be97 bus: do kdbus only if this is enabled on the configure switch
Since we want to retain the ability to break kernel ←→ userspace ABI
after the next release, let's not make use by default of kdbus, so that
people with future kernels will not suddenly break with current systemd
versions.

kdbus support is left in all builds but must now be explicitly requested
at runtime (for example via setting $DBUS_SESSION_BUS). Via a configure
switch the old behaviour can be restored. In fact, we change autogen.sh
to do this, so that git builds (which run autogen.sh) get kdbus by
default, but tarball builds (which ue the configure defaults) do not get
it, and hence this stays out of the distros by default.
2013-11-30 20:18:48 +01:00
Lennart Poettering 3310dfd5bd bus: append unique and well known names to all messages unconditionally 2013-11-30 16:08:11 +01:00
Lennart Poettering 49b832c5b8 bus: include unique and well known names in credentials object 2013-11-30 14:46:14 +01:00
Daniel Mack 1d0e3c9884 libsystemd-bus: catch up with latest kdbus changes
The name list and query functions now work differently in kdbus, as the
result is stored in the connection's pool, rather than being copied back
through the ioctl buffer. That also safes us some logic, as we don't
have to resize the communication buffer in a loop with growing buffer
sizes.

Due to this, KDBUS_CMD_MSG_RELEASE was renamed to KDBUS_CMD_FREE, as it
is now used outside the message logic as well.
2013-11-30 13:31:04 +01:00
Lennart Poettering e3dd987cfc core: allocate a kdbus bus for each systemd instance, if we can 2013-11-30 03:53:42 +01:00
Lennart Poettering 32f464809e bus: whenever we notice the connection is terminated enter CLOSING state 2013-11-30 01:49:40 +01:00
Lennart Poettering a43b9ca304 bus: synthesize local error reply when we cannot deliver a message to kdbus because the destination is unavailable 2013-11-30 01:02:51 +01:00
Lennart Poettering 7adc46fcce bus: don't generate NameAcquired/NameLost messages in the library
The signals appear entirely redundant due to NameOwnerChange, hence
don't do them in the new library, instead leave them for the
compatibility bridge only.

Also, set the serial number for synthesized messages to (uint32_t) -1.
2013-11-30 00:21:06 +01:00
Lennart Poettering 7d22c71732 bus: add the ability for backends to queue to input messages at the same time
We need this so that one incoming kernel message can result in two
high-level bus messages, for the case where we synthesize NameAcquired
and NameOwnerChanged in the same instance.
2013-11-29 22:03:55 +01:00
Daniel Mack 87b522ae19 libsystemd-bus: add sd_bus_translate_attach_flags()
Factor out code from sd_bus_negotiate_attach_creds() to a generic
translate function, so it can be used from other places.
2013-11-29 22:01:34 +01:00
Lennart Poettering 34a2c9e841 bus: when synthesizing messages locally, fill in a sender 2013-11-29 20:14:11 +01:00
Lennart Poettering 777d7a6123 kdbus: synthesize NameOwnerChange signals from kernel messages and support matches against NameOwnerChange 2013-11-29 20:14:11 +01:00
Daniel Mack d21a7bb1a9 libsystemd-bus: catch up with latest kdbus changes
kdbus_cmd_hello now has a new uint64_t flags field for the requested
attachments. Follow that change in libsystemd-bus.
2013-11-29 15:36:40 +01:00
Lennart Poettering 5b12334d35 bus: add new sd_bus_creds object to encapsulate process credentials
This way we can unify handling of credentials that are attached to
messages, or can be queried for bus name owners or connection peers.

This also adds the ability to extend incomplete credential information
with data from /proc,

Also, provide a convenience call that will automatically determine the
most appropriate credential object for an incoming message, by using the
the attached information if possible, the sending name information if
available and otherwise the peer's credentials.
2013-11-28 18:42:18 +01:00
Kay Sievers dd971bd2ce bus: update kdbus.h and always subscribe to KDBUS_HELLO_ATTACH_NAMES 2013-11-28 02:26:03 +01:00
Lennart Poettering c99c09a2dc bus: properly handle if we get disconnected during HELLO phase 2013-11-27 20:28:48 +01:00
Lennart Poettering 0e586eae02 bus: when closing a bus, drop all refs to queued messages, so that the bus can be freed 2013-11-22 16:31:40 +01:00
Lennart Poettering 2be441769f bus: add calls to query attached objects 2013-11-22 01:42:15 +01:00
Lennart Poettering 969987ea93 bus: restore selinux access control to PID 1 for properties 2013-11-21 23:36:51 +01:00
Lennart Poettering ebcf1f97de bus: rework message handlers to always take an error argument
Message handler callbacks can be simplified drastically if the
dispatcher automatically replies to method calls if errors are returned.

Thus: add an sd_bus_error argument to all message handlers. When we
dispatch a message handler and it returns negative or a set sd_bus_error
we send this as message error back to the client. This means errors
returned by handlers by default are given back to clients instead of
rippling all the way up to the event loop, which is desirable to make
things robust.

As a side-effect we can now easily turn the SELinux checks into normal
function calls, since the method call dispatcher will generate the right
error replies automatically now.

Also, make sure we always pass the error structure to all property and
method handlers as last argument to follow the usual style of passing
variables for return values as last argument.
2013-11-21 21:12:36 +01:00
Lennart Poettering 14c24659cd bus: rename SD_BUS_ERROR_MAKE to SD_BUS_ERROR_MAKE_CONST to indicate it only works for const strings 2013-11-21 02:11:06 +01:00
Lennart Poettering df2d202e6e bus: let's simplify things by getting rid of unnecessary bus parameters 2013-11-21 02:07:35 +01:00
Lennart Poettering 28383ba189 bus: add API calls to escape string components of objects paths 2013-11-21 01:03:26 +01:00
Lennart Poettering 86befb4098 bus: make sure an additional ref to a busevent source doesn't cause the event source to be triggered again 2013-11-20 20:58:17 +01:00
Lennart Poettering 718db96199 core: convert PID 1 to libsystemd-bus
This patch converts PID 1 to libsystemd-bus and thus drops the
dependency on libdbus. The only remaining code using libdbus is a test
case that validates our bus marshalling against libdbus' marshalling,
and this dependency can be turned off.

This patch also adds a couple of things to libsystem-bus, that are
necessary to make the port work:

- Synthesizing of "Disconnected" messages when bus connections are
  severed.

- Support for attaching multiple vtables for the same interface on the
  same path.

This patch also fixes the SetDefaultTarget() and GetDefaultTarget() bus
calls which used an inappropriate signature.

As a side effect we will now generate PropertiesChanged messages which
carry property contents, rather than just invalidation information.
2013-11-20 20:52:36 +01:00
Lennart Poettering 911121a7c8 bus: add sd_bus_send_to() API call 2013-11-20 19:37:02 +01:00
Lennart Poettering aea93debfa bus: bump serial number counter when sending already sealed messages 2013-11-20 19:36:14 +01:00
Kay Sievers f21326e604 bus: TIMESTAMP is optional kdbus metadata now, NAMES are always added 2013-11-18 01:30:57 +01:00
Kay Sievers 16be43684f bus: CREDS and NAMES are optional kdbus metadata now 2013-11-17 22:35:58 +01:00
Tom Gundersen 0927756b8d bus: typo
Fix a couple of 'void' that should have been 'sd_bus'.
2013-11-14 22:19:48 +01:00
Lennart Poettering a8a07f892c bus: detect blocking message calls to our own connection and return ELOOP early 2013-11-12 00:12:44 +01:00
Lennart Poettering 76b543756e bus: introduce concept of a default bus for each thread and make use of it everywhere
We want to emphasize bus connections as per-thread communication
primitives, hence introduce a concept of a per-thread default bus, and
make use of it everywhere.
2013-11-12 00:12:43 +01:00
Lennart Poettering c49b30a235 bus: rename sd_bus_send_with_reply_and_block() to sd_bus_call()
The call is one of the most important ones we expose, where we place
major emphasis on. We should make sure to give it a short, memorable
name.
2013-11-12 00:12:43 +01:00
Zbigniew Jędrzejewski-Szmek d9f644e2cd bus: export libsystemd-bus as a public library
Old static libsystemd-bus.la becomes libsystemd-bus-internal.la.
memfd functions are also exported in the same library.

(Best viewed with --color-words -U0).
2013-11-06 14:56:47 -05:00
Lennart Poettering affff0b6f2 bus: add sd_bus_get_current() bus call to determine message that is currently being dispatched 2013-11-05 20:51:49 +01:00
Lennart Poettering 9d6c7c821c bus: make use of assert_return() in all API calls that don't use it yet 2013-11-05 19:14:58 +01:00
Lennart Poettering a7893c6b28 bus: add API call to create bus connection to the system bus of local containers
Also, add support for this to machinectl, so that we can enumerate the
machines that run inside a container. We must go deeper!
2013-10-30 15:37:02 +01:00
Lennart Poettering 0f8bd8debb bus: move ssh support into public API of libsystem-bus 2013-10-30 15:35:49 +01:00