Compare commits

...

12 Commits

Author SHA1 Message Date
Daan De Meyer e8c47f7370 sd-bus: Add sd_bus_message_at_end docs 2020-04-22 23:42:03 +02:00
Zbigniew Jędrzejewski-Szmek bbdeb2b5e9
Merge pull request #15517 from DaanDeMeyer/sd-bus-monitor-docs
sd-bus: Add sd_bus_set/is_monitor docs
2020-04-22 23:38:37 +02:00
Zbigniew Jędrzejewski-Szmek 1943d50e4e
Merge pull request #15507 from poettering/bus-log-api
add generic bus interface for setting log level that can be implemented by any daemon
2020-04-22 23:30:09 +02:00
Lennart Poettering e8cf09b2a2 core: make sure we don't get confused when setting TERM for a tty fd
Fixes: #15344
2020-04-22 22:59:41 +02:00
Lennart Poettering 60e16d20a3 man: document that VirtualEthernetExtra= has nothing to do with Bridge=
Fixes: #15402
2020-04-22 22:34:52 +02:00
Daan De Meyer 0eb5b641c5 sd-bus: Add sd_bus_set/is_monitor docs 2020-04-21 19:33:25 +02:00
Daan De Meyer 7fffaafaf2 sd-bus: Rewrap sd_bus_set_server docs at 109 columns 2020-04-21 19:08:25 +02:00
Lennart Poettering 893f801d67 core: implement generic log control API in PID1 too
It has slightly different setters in place, so it needs some special
love, which is easy enough though.
2020-04-21 17:08:23 +02:00
Lennart Poettering 25141692e9 core: use generic implementations of log level/target bus propertier getters
The setters are slightly different, hence keep them as they are for now.
2020-04-21 17:08:23 +02:00
Lennart Poettering ac9f55ed40 tree-wide: implement new log control API dbus interface in all our daemons 2020-04-21 17:08:16 +02:00
Lennart Poettering 4c4520789d resolved: replace private log level control API with generic one
The property was just added, let's replace it again. Given that it was
never released this should not be an API breakage.
2020-04-21 17:08:02 +02:00
Lennart Poettering 052740e2e3 log-control-api: add generic D-Bus interface for querying/setting log level/target
Let's define a new, generic bus interface that any daemon can implement
for querying/setting the log level.

We can turn this into something more powerful later on, but for now,
only expose three properties: the log level, log target and the syslog
identifier (with the former two being writable).

This is supposed to be generic, so that it can be implemented by 3rd
party daemons too, eventually.
2020-04-21 17:07:43 +02:00
24 changed files with 387 additions and 134 deletions

View File

@ -277,6 +277,7 @@ manpages = [
['sd_bus_message_append_string_iovec', 'sd_bus_message_append_string_space'],
''],
['sd_bus_message_append_strv', '3', [], ''],
['sd_bus_message_at_end', '3', [], ''],
['sd_bus_message_copy', '3', [], ''],
['sd_bus_message_dump', '3', [], ''],
['sd_bus_message_get_cookie', '3', ['sd_bus_message_get_reply_cookie'], ''],
@ -409,8 +410,10 @@ manpages = [
'3',
['sd_bus_get_bus_id',
'sd_bus_is_bus_client',
'sd_bus_is_monitor',
'sd_bus_is_server',
'sd_bus_set_bus_client'],
'sd_bus_set_bus_client',
'sd_bus_set_monitor'],
''],
['sd_bus_set_watch_bind', '3', ['sd_bus_get_watch_bind'], ''],
['sd_bus_slot_get_bus',

View File

@ -84,6 +84,7 @@
<citerefentry><refentrytitle>sd_bus_get_scope</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_tid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_get_unique_name</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_is_monitor</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_is_bus_client</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_is_server</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_list_names</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
@ -92,6 +93,7 @@
<citerefentry><refentrytitle>sd_bus_message_append_basic</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_append_string_memfd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_append_strv</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_at_end</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_copy</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_dump</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_get_cookie</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
@ -133,6 +135,7 @@
<citerefentry><refentrytitle>sd_bus_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_set_exit_on_disconnect</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_set_method_call_timeout</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_set_monitor</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_set_property</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_set_propertyv</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_set_sender</refentrytitle><manvolnum>3</manvolnum></citerefentry>,

View File

@ -0,0 +1,86 @@
<?xml version='1.0'?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1+ -->
<refentry id="sd_bus_message_at_end" xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo>
<title>sd_bus_message_at_end</title>
<productname>systemd</productname>
</refentryinfo>
<refmeta>
<refentrytitle>sd_bus_message_at_end</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>
<refnamediv>
<refname>sd_bus_message_at_end</refname>
<refpurpose>Check if a message has been fully read</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
<funcprototype>
<funcdef>int <function>sd_bus_message_at_end</function></funcdef>
<paramdef>sd_bus_message *<parameter>m</parameter></paramdef>
<paramdef>int <parameter>complete</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para><function>sd_bus_message_at_end()</function> returns whether all data from the currently opened
container in <parameter>m</parameter> or all data from all containers in <parameter>m</parameter> has
been read. If <parameter>complete</parameter> is zero, this function returns whether all data from the
currently opened container has been read. If <parameter>complete</parameter> is non-zero, this function
returns whether all data from all containers in <parameter>m</parameter> has been read.</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<para>If all data from all containers or the current container (depending on the value of
<parameter>complete</parameter>) has been read, <function>sd_bus_message_at_end()</function> returns a
positive integer. If there is still data left to be read, it returns zero. On failure, it returns a
negative errno-style error code.</para>
<refsect2>
<title>Errors</title>
<para>Returned errors may indicate the following problems:</para>
<variablelist>
<varlistentry>
<term><constant>-EINVAL</constant></term>
<listitem><para>The <parameter>m</parameter> parameter is <constant>NULL</constant>.
</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-EPERM</constant></term>
<listitem><para>The message is not sealed.</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
</refsect1>
<xi:include href="libsystemd-pkgconfig.xml" />
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_bus_message_read</refentrytitle><manvolnum>3</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>

View File

@ -22,8 +22,10 @@
<refname>sd_bus_get_bus_id</refname>
<refname>sd_bus_set_bus_client</refname>
<refname>sd_bus_is_bus_client</refname>
<refname>sd_bus_set_monitor</refname>
<refname>sd_bus_is_monitor</refname>
<refpurpose>Configure direct connection mode for a bus object</refpurpose>
<refpurpose>Configure connection mode for a bus object</refpurpose>
</refnamediv>
<refsynopsisdiv>
@ -58,61 +60,83 @@
<funcdef>int <function>sd_bus_is_bus_client</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_bus_set_monitor</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
<paramdef>int <parameter>b</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_bus_is_monitor</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para><function>sd_bus_set_server()</function> configures the bus object as a server for direct
D-Bus connections. <parameter>b</parameter> enables/disables the server mode. If zero, the
server mode is disabled. Otherwise, the server mode is enabled. Configuring a bus object as a
server is required to allow establishing direct connections between two peers without going via
the D-Bus daemon. <parameter>id</parameter> must contain a 128-bit integer id for the server. If
clients add a guid field to their D-Bus address string, the server id must match this guid or
the D-Bus authentication handshake will fail. If no specific id is defined for the server,
<para><function>sd_bus_set_server()</function> configures the bus object as a server for direct D-Bus
connections. <parameter>b</parameter> enables/disables the server mode. If zero, the server mode is
disabled. Otherwise, the server mode is enabled. Configuring a bus object as a server is required to
allow establishing direct connections between two peers without going via the D-Bus daemon.
<parameter>id</parameter> must contain a 128-bit integer id for the server. If clients add a guid field
to their D-Bus address string, the server id must match this guid or the D-Bus authentication handshake
will fail. If no specific id is defined for the server,
<citerefentry><refentrytitle>sd_id128_randomize</refentrytitle><manvolnum>3</manvolnum></citerefentry>
can be used to generate a random id instead.</para>
<para><function>sd_bus_is_server()</function> returns whether the server mode is enabled for
the given bus object.</para>
<para><function>sd_bus_is_server()</function> returns whether the server mode is enabled for the given
bus object.</para>
<para><function>sd_bus_get_bus_id()</function> stores the D-Bus server id configured using
<function>sd_bus_set_server()</function> (for server bus objects) or received during
D-Bus authentication (for client bus objects) in <parameter>id</parameter>.</para>
<function>sd_bus_set_server()</function> (for server bus objects) or received during D-Bus authentication
(for client bus objects) in <parameter>id</parameter>.</para>
<para><function>sd_bus_set_bus_client()</function> configures the bus object as a D-Bus daemon
client. <parameter>b</parameter> enables/disables the client mode. If zero, the client mode is
disabled and the bus object should connect directly to a D-Bus server. Otherwise, the client
mode is enabled and the bus object should connect to a D-Bus daemon. When connecting to an
existing bus using any of the functions in the
<citerefentry><refentrytitle>sd_bus_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>
<para><function>sd_bus_set_bus_client()</function> configures the bus object as a D-Bus daemon client.
<parameter>b</parameter> enables/disables the client mode. If zero, the client mode is disabled and the
bus object should connect directly to a D-Bus server. Otherwise, the client mode is enabled and the bus
object should connect to a D-Bus daemon. When connecting to an existing bus using any of the functions in
the <citerefentry><refentrytitle>sd_bus_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>
family of functions or any of the functions in the
<citerefentry><refentrytitle>sd_bus_default</refentrytitle><manvolnum>3</manvolnum></citerefentry>
family of functions, the bus object is automatically configured as a bus client. However, when
connecting to a D-Bus daemon by calling
<citerefentry><refentrytitle>sd_bus_default</refentrytitle><manvolnum>3</manvolnum></citerefentry> family
of functions, the bus object is automatically configured as a bus client. However, when connecting to a
D-Bus daemon by calling
<citerefentry><refentrytitle>sd_bus_set_address</refentrytitle><manvolnum>3</manvolnum></citerefentry>
followed by
<citerefentry><refentrytitle>sd_bus_start</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
the bus object should be manually configured as a bus client using
<function>sd_bus_set_bus_client()</function>. By default, a bus object is not configured as a
D-Bus daemon client.</para>
<citerefentry><refentrytitle>sd_bus_start</refentrytitle><manvolnum>3</manvolnum></citerefentry>, the bus
object should be manually configured as a bus client using <function>sd_bus_set_bus_client()</function>.
By default, a bus object is not configured as a D-Bus daemon client.</para>
<para><function>sd_bus_is_bus_client()</function> returns whether the client mode is enabled/disabled for
the given bus object.</para>
<para><function>sd_bus_set_monitor()</function> configures the bus object as a D-Bus monitor object.
<parameter>b</parameter> enables/disables the monitor mode. If zero, the monitor mode is disabled. If
non-zero, the monitor mode is enabled. When the monitor mode is enabled, no messages may be sent via the
bus object and it may not expose any objects on the bus. To start monitoring messages, call the
<function>org.freedesktop.DBus.Monitoring.BecomeMonitor</function> method of the D-Bus daemon and pass
a list of matches indicating which messages to intercept. See
<ulink url="https://dbus.freedesktop.org/doc/dbus-specification.html#bus-messages-become-monitor">
The D-Bus specification</ulink> for more information.</para>
<para><function>sd_bus_is_monitor()</function> returns whether the monitor mode is enabled/disabled for
the given bus object.</para>
<para><function>sd_bus_is_bus_client()</function> returns whether the client mode is
enabled/disabled for the given bus object.</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<para>On success, <function>sd_bus_set_server()</function>,
<function>sd_bus_get_bus_id()</function> and <function>sd_bus_set_bus_client()</function> return
a non-negative integer. On failure, they return a negative errno-style error code.</para>
<function>sd_bus_get_bus_id()</function>, <function>sd_bus_set_bus_client()</function> and
<function>sd_bus_set_monitor()</function> return a non-negative integer. On failure, they return a
negative errno-style error code.</para>
<para><function>sd_bus_is_server()</function> and <function>sd_bus_is_bus_client()</function>
return a positive integer when the server or client mode is enabled, respectively. Otherwise,
they return zero.
</para>
<para><function>sd_bus_is_server()</function>, <function>sd_bus_is_bus_client()</function> and
<function>sd_bus_is_monitor()</function> return a positive integer when the server or client mode is
enabled, respectively. Otherwise, they return zero.</para>
<refsect2>
<title>Errors</title>

View File

@ -469,18 +469,16 @@
<varlistentry>
<term><varname>VirtualEthernetExtra=</varname></term>
<listitem><para>Takes a colon-separated pair of interface
names. Configures an additional virtual Ethernet connection
(<literal>veth</literal>) between host and the container. The
first specified name is the interface name on the host, the
second the interface name in the container. The latter may be
omitted in which case it is set to the same name as the host
side interface. This setting implies
<varname>Private=yes</varname>. This setting corresponds to
the <option>--network-veth-extra=</option> command line
switch, and maybe be used multiple times. It is independent of
<varname>VirtualEthernet=</varname>. This option is privileged
(see above).</para></listitem>
<listitem><para>Takes a colon-separated pair of interface names. Configures an additional virtual
Ethernet connection (<literal>veth</literal>) between host and the container. The first specified
name is the interface name on the host, the second the interface name in the container. The latter
may be omitted in which case it is set to the same name as the host side interface. This setting
implies <varname>Private=yes</varname>. This setting corresponds to the
<option>--network-veth-extra=</option> command line switch, and maybe be used multiple times. It is
independent of <varname>VirtualEthernet=</varname>. Note that this option is unrelated to the
<varname>Bridge=</varname> setting below, and thus any connections created this way are not
automatically added to any bridge device on the host side. This option is privileged (see
above).</para></listitem>
</varlistentry>
<varlistentry>

View File

@ -9,6 +9,7 @@
#include "architecture.h"
#include "build.h"
#include "bus-common-errors.h"
#include "bus-log-control-api.h"
#include "bus-util.h"
#include "dbus-cgroup.h"
#include "dbus-execute.h"
@ -50,7 +51,6 @@ BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_oom_policy, oom_policy, OOMPolicy)
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_version, "s", GIT_VERSION);
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_features, "s", SYSTEMD_FEATURES);
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_architecture, "s", architecture_to_string(uname_architecture()));
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_log_target, "s", log_target_to_string(log_get_target()));
static BUS_DEFINE_PROPERTY_GET2(property_get_system_state, "s", Manager, manager_state, manager_state_to_string);
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_timer_slack_nsec, "t", (uint64_t) prctl(PR_GET_TIMERSLACK));
static BUS_DEFINE_PROPERTY_GET_REF(property_get_hashmap_size, "u", Hashmap *, hashmap_size);
@ -141,28 +141,6 @@ static int property_set_log_target(
return 0;
}
static int property_get_log_level(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
_cleanup_free_ char *t = NULL;
int r;
assert(bus);
assert(reply);
r = log_level_to_string_alloc(log_get_max_level(), &t);
if (r < 0)
return r;
return sd_bus_message_append(reply, "s", t);
}
static int property_set_log_level(
sd_bus *bus,
const char *path,
@ -2404,8 +2382,8 @@ const sd_bus_vtable bus_manager_vtable[] = {
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDGeneratorsFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_GENERATORS_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST),
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadStartTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_START]), SD_BUS_VTABLE_PROPERTY_CONST),
BUS_PROPERTY_DUAL_TIMESTAMP("InitRDUnitsLoadFinishTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_INITRD_UNITS_LOAD_FINISH]), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level, property_set_log_level, 0, 0),
SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", property_get_log_target, property_set_log_target, 0, 0),
SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0),
SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0),
SD_BUS_PROPERTY("NNames", "u", property_get_hashmap_size, offsetof(Manager, units), 0),
SD_BUS_PROPERTY("NFailedUnits", "u", property_get_set_size, offsetof(Manager, failed_units), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("NJobs", "u", property_get_hashmap_size, offsetof(Manager, jobs), 0),
@ -3044,6 +3022,21 @@ const sd_bus_vtable bus_manager_vtable[] = {
SD_BUS_VTABLE_END
};
const sd_bus_vtable bus_manager_log_control_vtable[] = {
SD_BUS_VTABLE_START(0),
/* We define a private version of this interface here, since we want slightly different
* implementations for the setters. We'll still use the generic getters however, and we share the
* setters with the implementations for the Manager interface above (which pre-dates the generic
* service API interface). */
SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, property_set_log_level, 0, 0),
SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, property_set_log_target, 0, 0),
SD_BUS_PROPERTY("SyslogIdentifier", "s", bus_property_get_syslog_identifier, 0, 0),
SD_BUS_VTABLE_END,
};
static int send_finished(sd_bus *bus, void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL;
usec_t *times = userdata;

View File

@ -6,6 +6,7 @@
#include "manager.h"
extern const sd_bus_vtable bus_manager_vtable[];
extern const sd_bus_vtable bus_manager_log_control_vtable[];
void bus_manager_send_finished(Manager *m, usec_t firmware_usec, usec_t loader_usec, usec_t kernel_usec, usec_t initrd_usec, usec_t userspace_usec, usec_t total_usec);
void bus_manager_send_reloading(Manager *m, bool active);

View File

@ -539,6 +539,10 @@ static int bus_setup_api_vtables(Manager *m, sd_bus *bus) {
if (r < 0)
return log_error_errno(r, "Failed to register Manager vtable: %m");
r = sd_bus_add_object_vtable(bus, NULL, "/org/freedesktop/LogControl1", "org.freedesktop.LogControl1", bus_manager_log_control_vtable, m);
if (r < 0)
return log_error_errno(r, "Failed to register service API vtable: %m");
r = sd_bus_add_fallback_vtable(bus, NULL, "/org/freedesktop/systemd1/job", "org.freedesktop.systemd1.Job", bus_job_vtable, bus_job_find, m);
if (r < 0)
return log_error_errno(r, "Failed to register Job vtable: %m");

View File

@ -1820,12 +1820,13 @@ static int build_environment(
tty_path = exec_context_tty_path(c);
/* If we are forked off PID 1 and we are supposed to operate on /dev/console, then let's try to inherit
* the $TERM set for PID 1. This is useful for containers so that the $TERM the container manager
* passes to PID 1 ends up all the way in the console login shown. */
/* If we are forked off PID 1 and we are supposed to operate on /dev/console, then let's try
* to inherit the $TERM set for PID 1. This is useful for containers so that the $TERM the
* container manager passes to PID 1 ends up all the way in the console login shown. */
if (path_equal(tty_path, "/dev/console") && getppid() == 1)
if (path_equal_ptr(tty_path, "/dev/console") && getppid() == 1)
term = getenv("TERM");
if (!term)
term = default_term_for_tty(tty_path);

View File

@ -12,6 +12,7 @@
#include "btrfs-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "clean-ipc.h"
#include "conf-files.h"
@ -894,6 +895,10 @@ static int manager_connect_bus(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to add object manager: %m");
r = bus_log_control_api_register(m->bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(m->bus, NULL, "org.freedesktop.home1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -8,6 +8,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "def.h"
#include "env-file-label.h"
@ -754,6 +755,10 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
if (r < 0)
return log_error_errno(r, "Failed to register object: %m");
r = bus_log_control_api_register(bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(bus, NULL, "org.freedesktop.hostname1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -7,6 +7,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "def.h"
#include "fd-util.h"
@ -1308,6 +1309,10 @@ static int manager_add_bus_objects(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to add transfer enumerator: %m");
r = bus_log_control_api_register(m->bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(m->bus, NULL, "org.freedesktop.import1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -14,6 +14,7 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-log-control-api.h"
#include "bus-message.h"
#include "bus-polkit.h"
#include "def.h"
@ -724,6 +725,10 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
if (r < 0)
return log_error_errno(r, "Failed to register object: %m");
r = bus_log_control_api_register(bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(bus, NULL, "org.freedesktop.locale1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -9,6 +9,7 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "cgroup-util.h"
#include "def.h"
@ -706,6 +707,10 @@ static int manager_connect_bus(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to enable subscription: %m");
r = bus_log_control_api_register(m->bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(m->bus, NULL, "org.freedesktop.login1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -10,6 +10,7 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "cgroup-util.h"
#include "dirent-util.h"
@ -263,6 +264,10 @@ static int manager_connect_bus(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to enable subscription: %m");
r = bus_log_control_api_register(m->bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(m->bus, NULL, "org.freedesktop.machine1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -11,6 +11,7 @@
#include "sd-netlink.h"
#include "alloc-util.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "conf-parser.h"
@ -165,6 +166,10 @@ int manager_connect_bus(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to add network enumerator: %m");
r = bus_log_control_api_register(m->bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(m->bus, NULL, "org.freedesktop.network1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -7,6 +7,7 @@
#include "sd-daemon.h"
#include "alloc-util.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "def.h"
#include "main-func.h"
@ -84,6 +85,10 @@ static int manager_connect_bus(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to add image enumerator: %m");
r = bus_log_control_api_register(m->bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(m->bus, NULL, "org.freedesktop.portable1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -2529,8 +2529,8 @@ static int verb_log_level(int argc, char *argv[], void *userdata) {
r = sd_bus_get_property_string(
bus,
"org.freedesktop.resolve1",
"/org/freedesktop/resolve1",
"org.freedesktop.resolve1.Manager",
"/org/freedesktop/LogControl1",
"org.freedesktop.LogControl1",
"LogLevel",
&error,
&level);
@ -2545,8 +2545,8 @@ static int verb_log_level(int argc, char *argv[], void *userdata) {
r = sd_bus_set_property(
bus,
"org.freedesktop.resolve1",
"/org/freedesktop/resolve1",
"org.freedesktop.resolve1.Manager",
"/org/freedesktop/LogControl1",
"org.freedesktop.LogControl1",
"LogLevel",
&error,
"s",

View File

@ -2,6 +2,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "dns-domain.h"
@ -1836,57 +1837,6 @@ static int bus_method_unregister_service(sd_bus_message *message, void *userdata
return call_dnssd_method(m, message, bus_dnssd_method_unregister, error);
}
static int property_get_log_level(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
_cleanup_free_ char *t = NULL;
int r;
assert(bus);
assert(reply);
r = log_level_to_string_alloc(log_get_max_level(), &t);
if (r < 0)
return r;
return sd_bus_message_append(reply, "s", t);
}
static int property_set_log_level(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *value,
void *userdata,
sd_bus_error *error) {
const char *t;
int r;
assert(bus);
assert(value);
r = sd_bus_message_read(value, "s", &t);
if (r < 0)
return r;
r = log_level_from_string(t);
if (r < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log level '%s'", t);
log_info("Setting log level to %s.", t);
log_set_max_level(r);
return 0;
}
static const sd_bus_vtable resolve_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("LLMNRHostname", "s", NULL, offsetof(Manager, llmnr_hostname), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
@ -1905,8 +1855,6 @@ static const sd_bus_vtable resolve_vtable[] = {
SD_BUS_PROPERTY("DNSSECNegativeTrustAnchors", "as", bus_property_get_ntas, 0, 0),
SD_BUS_PROPERTY("DNSStubListener", "s", bus_property_get_dns_stub_listener_mode, offsetof(Manager, dns_stub_listener_mode), 0),
SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level, property_set_log_level, 0, 0),
SD_BUS_METHOD_WITH_NAMES("ResolveHostname",
"isit",
SD_BUS_PARAM(ifindex)
@ -2121,6 +2069,10 @@ int manager_connect_bus(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to register dnssd enumerator: %m");
r = bus_log_control_api_register(m->bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(m->bus, NULL, "org.freedesktop.resolve1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -0,0 +1,123 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "alloc-util.h"
#include "bus-log-control-api.h"
#include "bus-util.h"
#include "log.h"
#include "sd-bus.h"
#include "syslog-util.h"
int bus_property_get_log_level(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
_cleanup_free_ char *t = NULL;
int r;
assert(bus);
assert(reply);
r = log_level_to_string_alloc(log_get_max_level(), &t);
if (r < 0)
return r;
return sd_bus_message_append(reply, "s", t);
}
int bus_property_set_log_level(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *value,
void *userdata,
sd_bus_error *error) {
const char *t;
int r;
assert(bus);
assert(value);
r = sd_bus_message_read(value, "s", &t);
if (r < 0)
return r;
r = log_level_from_string(t);
if (r < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log level '%s'", t);
log_info("Setting log level to %s.", t);
log_set_max_level(r);
return 0;
}
BUS_DEFINE_PROPERTY_GET_GLOBAL(bus_property_get_log_target, "s", log_target_to_string(log_get_target()));
int bus_property_set_log_target(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *value,
void *userdata,
sd_bus_error *error) {
LogTarget target;
const char *t;
int r;
assert(bus);
assert(value);
r = sd_bus_message_read(value, "s", &t);
if (r < 0)
return r;
target = log_target_from_string(t);
if (target < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log target '%s'", t);
log_info("Setting log target to %s.", log_target_to_string(target));
log_set_target(target);
log_open();
return 0;
}
BUS_DEFINE_PROPERTY_GET_GLOBAL(bus_property_get_syslog_identifier, "s", program_invocation_short_name);
static const sd_bus_vtable log_control_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", bus_property_get_log_level, bus_property_set_log_level, 0, 0),
SD_BUS_WRITABLE_PROPERTY("LogTarget", "s", bus_property_get_log_target, bus_property_set_log_target, 0, 0),
SD_BUS_PROPERTY("SyslogIdentifier", "s", bus_property_get_syslog_identifier, 0, 0),
/* One of those days we might want to add a similar, second interface to cover common service
* operations such as Reload(), Reexecute(), Exit() and maybe some properties exposing version
* number and other meta-data of the service. */
SD_BUS_VTABLE_END,
};
int bus_log_control_api_register(sd_bus *bus) {
int r;
r = sd_bus_add_object_vtable(
bus,
NULL,
"/org/freedesktop/LogControl1",
"org.freedesktop.LogControl1",
log_control_vtable, NULL);
if (r < 0)
return log_error_errno(r, "Failed to register service API object: %m");
return 0;
}

View File

@ -0,0 +1,13 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "sd-bus.h"
int bus_log_control_api_register(sd_bus *bus);
int bus_property_get_log_level(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
int bus_property_set_log_level(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error);
int bus_property_get_log_target(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
int bus_property_set_log_target(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
int bus_property_get_syslog_identifier(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);

View File

@ -23,14 +23,16 @@ shared_sources = files('''
bpf-program.h
bridge-util.c
bridge-util.h
bus-log-control-api.c
bus-log-control-api.h
bus-polkit.c
bus-polkit.h
bus-unit-procs.c
bus-unit-procs.h
bus-unit-util.c
bus-unit-util.h
bus-util.c
bus-util.h
bus-polkit.c
bus-polkit.h
bus-wait-for-jobs.c
bus-wait-for-jobs.h
bus-wait-for-units.c

View File

@ -12,6 +12,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "clock-util.h"
#include "conf-files.h"
@ -1100,6 +1101,10 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
if (r < 0)
return log_error_errno(r, "Failed to register object: %m");
r = bus_log_control_api_register(bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(bus, NULL, "org.freedesktop.timedate1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");

View File

@ -4,6 +4,7 @@
#include "alloc-util.h"
#include "bus-internal.h"
#include "bus-log-control-api.h"
#include "bus-protocol.h"
#include "bus-util.h"
#include "in-addr-util.h"
@ -189,6 +190,10 @@ int manager_connect_bus(Manager *m) {
if (r < 0)
return log_error_errno(r, "Failed to add manager object vtable: %m");
r = bus_log_control_api_register(m->bus);
if (r < 0)
return r;
r = sd_bus_request_name_async(m->bus, NULL, "org.freedesktop.timesync1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");