Commit Graph

230 Commits

Author SHA1 Message Date
Thomas Hindoe Paaboel Andersen 0a6f50c0af include <poll.h> instead of <sys/poll.h>
include-what-you-use automatically does this and it makes finding
unnecessary harder to spot. The only content of poll.h is a include
of sys/poll.h so should be harmless.
2015-02-12 20:47:38 +01:00
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01:00
Lennart Poettering 997eadb553 sd-bus: even if we need a cookie when sending a message there's no need to needlessly send it if we don't actually need it 2015-01-09 21:25:23 +01:00
Lennart Poettering 52cd587789 sd-bus: when we synthesize messages, initialize timestamps ourselves 2015-01-07 20:36:23 +01:00
Lennart Poettering d29ae2914e sd-bus: unify how we set the sender of synthetic messages 2015-01-07 20:25:30 +01:00
Lennart Poettering 146d477367 machined,bus-proxy: fix connecting to containers 2015-01-05 01:40:51 +01:00
Lennart Poettering de33fc6257 sd-bus: rename sd_bus_open_system_container() to sd_bus_open_system_machine()
Pretty much everywhere else we use the generic term "machine" when
referring to containers in API, so let's do though in sd-bus too. In
particular, since the concept of a "container" exists in sd-bus too, but
as part of the marshalling system.
2014-12-24 16:53:04 +01:00
Lennart Poettering ee502e0c28 sd-bus: teach x-container-unix: bus protoocol to connect to the namespace of a PID instead of a container name 2014-12-23 19:15:27 +01:00
Torstein Husebø ad67ef274e sd-bus: correct spacing near eol in code comments 2014-12-11 15:04:56 +01:00
Thomas Hindoe Paaboel Andersen d2df88ffba sd-bus: avoid a null dereference 2014-12-04 00:24:44 +01:00
Lennart Poettering 224b378767 sd-bus: make more connection properties readable 2014-11-28 20:29:43 +01:00
Lennart Poettering 5b820358cf sd-bus: add new sd_bus_get_address() for querying the current bus address
Also, update "busctl" to show this in its output.
2014-11-28 20:29:43 +01:00
Lennart Poettering 5c3026927d sd-bus: rename sd_bus_get_owner_id() → sd_bus_get_bus_id()
The ID returned really doesn't identify the owner, but the bus instance,
hence fix this misnaming.

Also, update "busctl status" to show the ID in its output.
2014-11-28 20:29:43 +01:00
Lennart Poettering e3afaf6b8e sd-bus: rename default bus address constants, they aren't "paths" but "addresses" 2014-11-28 16:17:33 +01:00
Lennart Poettering 3acc1dafd1 sd-bus: add new call sd_bus_get_scope() for querying whether one is connected to a system or a user bus 2014-11-28 16:17:33 +01:00
Lennart Poettering fb6d9b77a7 sd-bus: set creds info for "org.freedesktop.DBus.Local" generated messages, too 2014-11-27 22:05:23 +01:00
Lennart Poettering cf226cfc24 sd-bus: make sure that when we connect to the system bus we have enough creds to make security decisions 2014-11-26 18:59:31 +01:00
Lennart Poettering b5dae4c7f7 sd-bus: add suppot for renegotiating message credential attach flags 2014-11-26 02:20:55 +01:00
Lennart Poettering 705a415f68 sd-bus: update to current kernel version, by splitting off the extended KDBUS_ITEM_PIDS structure from KDBUS_ITEM_CREDS
Also:

- adds support for euid, suid, fsuid, egid, sgid, fsgid fields.

- makes augmentation of creds with data from /proc explicitly
  controllable to give apps better control over this, given that this is
  racy.

- enables augmentation for kdbus connections (previously we only did it
  for dbus1). This is useful since with recent kdbus versions it is
  possible for clients to control the metadata they want to send.

- changes sd_bus_query_sender_privilege() to take the euid of the client
  into consideration, if known

- when we don't have permissions to read augmentation data from /proc,
  don't fail, just don't add the data in
2014-11-25 14:28:34 +01:00
Daniel Mack 63cc4c3138 sd-bus: sync with kdbus upstream (ABI break)
kdbus has seen a larger update than expected lately, most notably with
kdbusfs, a file system to expose the kdbus control files:

 * Each time a file system of this type is mounted, a new kdbus
   domain is created.

 * The layout inside each mount point is the same as before, except
   that domains are not hierarchically nested anymore.

 * Domains are therefore also unnamed now.

 * Unmounting a kdbusfs will automatically also detroy the
   associated domain.

 * Hence, the action of creating a kdbus domain is now as
   privileged as mounting a filesystem.

 * This way, we can get around creating dev nodes for everything,
   which is last but not least something that is not limited by
   20-bit minor numbers.

The kdbus specific bits in nspawn have all been dropped now, as nspawn
can rely on the container OS to set up its own kdbus domain, simply by
mounting a new instance.

A new set of mounts has been added to mount things *after* the kernel
modules have been loaded. For now, only kdbus is in this set, which is
invoked with mount_setup_late().
2014-11-13 20:41:52 +01:00
Lennart Poettering f7fce3454c sd-bus: rename sd_bus_get_server_id() to sd_bus_get_owner_id()
In kdbus a "server id" is mostly a misnomer, as there isn't any "server"
involved anymore. Let's rename this to "owner" id hence, since it is an
ID that is picked by the owner of a bus or direct connection. This
matches nicely the sd_bus_get_owner_creds() call we already have.
2014-11-04 18:09:19 +01:00
Lennart Poettering f4b2933ee7 sd-bus,sd-event: unify error handling of object descriptions
a) When getting the description return ENXIO if none is set

b) Allow setting a description to NULL

c) return ECHILD on fork() like for other calls
2014-11-04 18:09:19 +01:00
Lennart Poettering d1b91c99d9 sd-bus: make use of free_and_strdup() where it makes sense 2014-11-04 18:09:19 +01:00
Lennart Poettering 356779df90 sd-event: rename sd_event_source_set_name() to sd_event_source_get_name()
To mirror the recent name change of the concept for sd_bus objects,
follow the same logic for sd_event_source objects, too.
2014-11-04 18:09:19 +01:00
Lennart Poettering 455971c149 sd-bus: rename "connection name" to "description" for the sd-bus API too
kdbus recently renamed this concept, and so should we in what we expose
in userspace.
2014-11-04 16:13:49 +01:00
Lennart Poettering 24f6fc22c1 sd-bus: explicitly cast asprintf() return value away we are not interested in
Let's give coverity a hint what's going on here.
2014-10-27 13:06:20 +01:00
Lennart Poettering 54ad51e3e9 Revert "sd-bus: check return value of asprintf()"
This reverts commit b1543c4c93.

We check b->address anyway, no need to check the return value,
especially given that the other #ifdef branch don't get the same
treatment.
2014-10-27 13:04:17 +01:00
Michal Schmidt c9fe4af70d sd-bus: make sd_bus::reply_callbacks a OrderedHashmap
The way process_closing() picks the first entry from reply_callbacks
and works with it makes it likely that it cares about the order.
2014-10-23 17:38:02 +02:00
Lennart Poettering affcf18915 machine: validate machine names using machine_name_is_valid() instead of string_is_safe()
After all, we know have this as generic validator, so let's be correct
and use it wherver applicable.
2014-10-22 23:22:47 +02:00
Daniel Mack 8f44e3ea3e sd-bus: implement sd_bus_get_owner_creds() for kdbus
kdbus learned a new ioctl to tell userspace about a bus creator's
credentials, which is what we need to implement sd_bus_get_owner_creds() for
kdbus.

Move the function from sd-bus.c to bus-control.c to be able to reuse
the bus_populate_creds_from_items() helper.
2014-10-22 19:45:07 +02:00
Daniel Mack 056f95d0a7 sd-bus: rename sd_bus_get_owner_uid(), sd_bus_get_owner_machine_id() and sd_bus_get_peer_creds()
Clean up the function namespace by renaming the following:

  sd_bus_get_owner_uid()        → sd_bus_get_name_creds_uid()
  sd_bus_get_owner_machine_id() → sd_bus_get_name_machine_id()
  sd_bus_get_peer_creds()       → sd_bus_get_owner_creds()
2014-10-22 19:45:07 +02:00
Kay Sievers c32195e057 Revert "sd-bus: sync kdbus.h (ABI break)"
This reverts commit 1a2409e262.

Support from the kdbus interface was removed. We require
memfds to be supported by all clients.
2014-10-17 10:12:44 +02:00
Daniel Mack 1a2409e262 sd-bus: sync kdbus.h (ABI break)
kdbus learned KDBUS_HELLO_ACCEPT_MEMFD as new connection negotiation
flag. Set it by default in systemd for now.
2014-10-14 20:03:06 +02:00
Daniel Mack b1543c4c93 sd-bus: check return value of asprintf()
Check for OOM conditions of asprintf() in bus_set_address_user().
2014-10-09 11:26:09 +02:00
Zbigniew Jędrzejewski-Szmek 75a0da952f bus: add assert to check that we're not freeing a static structure
CID #996315.
2014-10-05 15:29:41 -04:00
Thomas Hindoe Paaboel Andersen b49ffb29ed sd-bus: sd_bus_message_get_errno should only return positive errno
sd_bus_message_get_errno can currently return either a number of
different poitive errno values (from bus-error-mapping), or a negative
EINVAL if passed null as parameter.

The check for null parameter was introduced in 40ca29a137
at the same as the function was renamed from bus_message_to_errno and
made public API. Before becoming public the function used to return
only negative values.

It is weird to have a function return both positive and negative errno
and it generally looks like a mistake. The function is guarded by the
--enable-kdbus flags so I wonder if we still have time to fix it up?
It does not have any documentation yet. However, except for a few details
it is just a convenient way to call sd_bus_error_get_errno which is documented
to return only positive errno.

This patch makes it return only positive errno and fixes up the two
calls to the function that tried to cope with both positive and negative
values.
2014-09-16 21:31:15 +02:00
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00
Philippe De Swert 2b347169b9 bus: unref buscreds on failure
Actually unref the buscreds when we are not going to return a
pointer to them. As when bus_creds_add_more fails we immediately
return the error code otherwise and leak the new buscreds.
Found with coverity. Fixes: CID#1237761
2014-09-11 17:29:19 +02:00
Tom Gundersen 9021bb9f93 sd-event: name event sources used in libraries
This should help in debugging failing event sources.
2014-08-28 21:19:17 +02:00
David Herrmann d974ad0524 bus: fix use-after-free in slot-release
We must not access slot->floating after we possible dropped the last
reference to it. Fix all callback-invocations to first check
slot->floating and possible disconnect the slot, then release the last
reference.
2014-08-28 12:45:51 +02:00
Denis Kenzior fe3f22d116 bus-control: Fix cgroup handling
On systems without properly setup systemd, cg_get_root_path returns
-ENOENT.  This means that busctl doesn't display much information.

busctl monitor also fails whenever it intercepts messages.

This fix fakes creates a fake "/" root cgroup which lets busctl work
on such systems.
2014-08-18 21:01:57 +02:00
Lennart Poettering caa829849d sd-bus: add API to query which handler/callback is currently being dispatched 2014-08-18 17:49:53 +02:00
Kay Sievers 3a43da2832 time-util: add and use USEC/NSEC_INFINIY 2014-07-29 13:20:20 +02:00
Lennart Poettering db9bb83fa5 bus: close a bus that failed to connect 2014-07-03 01:19:21 +02:00
Lennart Poettering 7f0d207d2c sd-bus: support connecting to remote hosts, directly into containers
systemctl -H root@foobar:waldi

will now show a list of services running on container "waldi" on host
"foobar", using "root" for authenticating at "foobar".

Since entereing a container requires priviliges, this will only work
correctly for root logins.
2014-07-03 01:17:26 +02:00
Lennart Poettering 7bb4d371af sd-bus: when an event loop terminates, explicitly close the bus
This makes sure we actually release the bus and all the messages it
references.
2014-07-02 17:36:47 +02:00
Lennart Poettering b5eca3a205 bus: drop bus/message GC logic
When a caller drops all references to a bus and its messages while the
messages where still queue, this causes the bus to reference the
messages, and the messages to reference the bus, without anybody else
keeping a reference, which is something we so far considered a leak, and
tried to fix with a GC logic that would recognize cases like this, and
drop the reference.

This GC logic has been broken sofar, and remained unfixed. This commit
removes it altogther, replacing it with nothing. The rationale is that
simply because all refs to the bus have been dropped its queued messages
should *still* be written to the bus, even if the caller doesn't retain
any reference to either bus nor message. This means it was actually
wrong to attempt to clean up the bus in this case.

The proper way how applications should handle this is by explicitly
invoking sd_bus_close(), when they want busses to go away. This is
probably want they want to do anyway to avoid getting spurious
callbacks after they stopped using a bus.
2014-07-02 17:29:09 +02:00
Zbigniew Jędrzejewski-Szmek 2915234da0 bus: fix unitialized variable access in error path 2014-05-16 18:03:00 -04:00
Lennart Poettering 1b64f83829 sd-bus: always keep slot reference while dispatching callback
Also, make sure we automatically destroy reply callbacks that are
floating.
2014-05-15 17:13:05 +02:00
Zbigniew Jędrzejewski-Szmek de0671ee7f Remove unnecessary casts in printfs
No functional change expected :)
2014-05-15 15:29:58 +02:00
Lennart Poettering 19befb2d5f sd-bus: introduce sd_bus_slot objects encapsulating callbacks or vtables attached to a bus connection
This makes callback behaviour more like sd-event or sd-resolve, and
creates proper object for unregistering callbacks.

Taking the refernce to the slot is optional. If not taken life time of
the slot will be bound to the underlying bus object (or in the case of
an async call until the reply has been recieved).
2014-05-15 01:15:30 +02:00
Lennart Poettering 93f1bcf400 sd-resolve: rework sd-resolve to be callback based, similar in style to sd-bus and sd-event 2014-04-29 15:45:16 +02:00
Daniel Mack e955c45881 sd-bus: invert bus->is_kernel check in sd_bus_get_peer_creds()
The bug was introducted in a3d59cd1 ("sd-bus: don't use assert_return()
to check for disconnected bus connections")
2014-03-24 14:45:34 +01:00
Lennart Poettering 6a0f1f6d5a sd-event: rework API to support CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM, too 2014-03-24 02:58:41 +01:00
David Herrmann 374c356979 sd-bus: mark sd_bus_unref() as broken regarding self-refs
If you allocate a message with bus==NULL and then unref the main bus,
it will free your message underneath and your program will go boom!

To fix that, we really need to figure out what the semantics for
self-references (m->bus) should be and when/where/what accesses are
actually allowed.

Same is true for the pseudo-thread-safety we employ..
2014-03-22 19:35:25 +01:00
David Herrmann eb33a6f858 sd-bus: add note about sd_bus_unref() recursion
In sd_bus_unref() we check for self-reference loops and destruct our
queues in case we're the only reference holders. However, we do _not_
modify our own ref-count, thus effectively causing the
message-destructions to enter with the same reference count as we did.

The only reason this doesn't cause an endless recursion (or trigger
assert(m->n_ref > 0) in sd_bus_message_unref()) is the fact that we
decrease queue-counters _before_ calling _unref(). That's not obvious at
all, so add a big fat note in bus_reset_queues() to everyone touching that
code.
2014-03-22 18:06:38 +01:00
Lennart Poettering a3d59cd1b0 sd-bus: don't use assert_return() to check for disconnected bus connections
A terminated connection is a runtime error and not a developer mistake,
hence don't use assert_return() to check for it.
2014-03-19 21:41:21 +01:00
Lennart Poettering ae439c9f9b sd-bus: properly translate high-level attach flags into kdbus attach flags 2014-03-19 19:09:00 +01:00
Lennart Poettering 0936559234 sd-bus: add proper monitoring API 2014-03-19 04:17:00 +01:00
Lennart Poettering 2ce97e2b04 sd-bus: if we got a message with fds attached even though we didn't negotiate it, refuse to take it
This makes sure we don't mishandle if developers specificy a different
AcceptFileDescriptors= setting in .busname units then they set for the
bus connection in the activated program.
2014-03-18 21:03:37 +01:00
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Miklos Vajna 6f285378aa core, libsystemd, systemd, timedate, udev: spelling fixes 2014-03-17 02:35:35 -04:00
Lennart Poettering 42c4ebcbd4 sd-bus: don't look for a 64bit value when we only have 32bit value on reply cookie hash table access
This broke hashtable lookups for the message cookies on s390x, which is
a 64bit BE machine where accessing 32bit values as 64bit and vice versa
will explode.

Also, while we are at it, be a bit more careful when dealing with the
64bit cookies we expose and the 32bit serial numbers dbus uses in its
payload.

Problem identified by Fridrich Strba.
2014-03-13 20:33:22 +01:00
Lennart Poettering 82923adfe5 bus: fix memory leak when kdbus is not enabled 2014-03-13 20:01:17 +01:00
Lennart Poettering a6278b8830 bus: replace sd_bus_label_{escape,unescape}() by new sd_bus_path_{encode,decode}()
The new calls work similarly, but enforce a that a common, fixed bus
path prefix is used.

This follows discussions with Simon McVittie on IRC that it should be a
good idea to make sure that people don't use the escaping applied here
too wildly as anything other than the last label of a bus path.
2014-03-11 19:03:50 +01:00
Lennart Poettering 8f8f05a919 bus: add sd_bus_track object for tracking peers, and port core over to it
This is primarily useful for services that need to track clients which
reference certain objects they maintain, or which explicitly want to
subscribe to certain events. Something like this is done in a large
number of services, and not trivial to do. Hence, let's unify this at
one place.

This also ports over PID 1 to use this to ensure that subscriptions to
job and manager events are correctly tracked. As a side-effect this
makes sure we properly serialize and restore the track list across
daemon reexec/reload, which didn't work correctly before.

This also simplifies how we distribute messages to broadcast to the
direct busses: we only track subscriptions for the API bus and
implicitly assume that all direct busses are subscribed. This should be
a pretty OK simplification since clients connected via direct bus
connections are shortlived anyway.
2014-03-03 02:34:13 +01:00
Lennart Poettering df1e020461 Revert back to /var/run at a couple of problems
This partially reverts 41a55c46ab

Some specifications we want to stay compatibility actually document
/var/run, not /run, and we should stay compatible with that. In order to
make sure our D-Bus implementation works on any system, regardless if
running systemd or not, we should always use /var/run which is the
only path mandated by the D-Bus spec.

Similar, glibc hardcodes the utmp location to /var/run, and this is
exposed in _UTMP_PATH in limits.h, hence let's stay in sync with this
public API, too.

We simply do not support systems where /var/run is not a symlink → /run.
Hence both are equivalent. Staying compatible with upstream
specifications hence weighs more than cleaning up superficial
appearance.
2014-02-26 02:47:43 +01:00
Zbigniew Jędrzejewski-Szmek 41a55c46ab Replace /var/run with /run in remaining places
/run was already used almost everywhere, fix the remaining places
for consistency.
2014-02-25 20:41:24 -05:00
Kay Sievers f01de9656d src/shared/ cannot reference symbols from libraries
../src/shared/unit-name.c:462: error: undefined reference to 'sd_bus_label_escape'
../src/shared/unit-name.c:477: error: undefined reference to 'sd_bus_label_unescape'
collect2: error: ld returned 1 exit status
2014-02-23 01:53:40 +01:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Jason A. Donenfeld 3db729cb8e sd-bus: the bus returned should be the first arg
This matches the API of previous headers, such as sd-journal.h.
2014-02-20 00:03:09 +01:00
Lennart Poettering 23abf5d582 bus: fix unreffing logic 2014-02-19 20:36:17 +01:00
Lennart Poettering f4d140e9a6 bus: properly unset default bus pointer when destroying last reference 2014-02-05 23:06:13 +01:00
Lennart Poettering f389bf15d0 bus: when closing the bus don't end up in a recursive destruction deadlock 2014-02-03 19:59:18 +01:00
Lennart Poettering af08d2f9cd bus: add API calls for connecting to starter bus
Add new calls sd_bus_open() and sd_bus_default() for connecting to the
starter bus a service was invoked for, or -- if the process is not a
bus-activated service -- the appropriate bus for the scope the process
has been started in.
2014-01-27 21:34:54 +01:00
Lennart Poettering 766c580959 bus: add sd_bus_process_priority() to support prioq mode of kdbus 2014-01-22 20:26:58 +01:00
Lennart Poettering 5972fe953e bus: add support for attaching name to bus connections for debugging purposes 2014-01-22 16:09:59 +01:00
Lennart Poettering 4fc319887e bus: simplify naming of feature negotation calls
Two verbs in a function name suck, so let's simplify this a bit.
2014-01-22 11:21:51 +01:00
Lennart Poettering 069f5e61eb bus: implement synchronous message calls via kernel ioctl 2014-01-21 21:42:49 +01:00
Tom Gundersen 607553f930 libsystemd: split up into subdirs
We still only produce on .so, but let's keep the sources separate to make things a bit
less messy.
2014-01-21 14:41:35 +01:00
Renamed from src/libsystemd/sd-bus.c (Browse further)