Compare commits

...

12 Commits

Author SHA1 Message Date
Yu Watanabe 9457b6bb21
Merge pull request #16303 from poettering/dbus-util-split
shared: split src/shared/bus-util.c into multiple files
2020-07-01 14:15:40 +09:00
Marc Kleine-Budde b46d8c1c70 udev: spi: include chip select number in ID_PATH
All devices behind a SPI controller have the same udev ID_PATH property.
This is a problem for predicable network names for CAN controllers.

CAN controllers, in contrast to Ethernet controllers, don't have a MAC
Address, so there's no way to tell two CAN controllers on the same SPI
host controller apart:

$ udevadm info /sys/class/net/can0
P: /devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.1/net/can0
L: 0
E: DEVPATH=/devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.1/net/can0
E: INTERFACE=can0
E: IFINDEX=3
E: SUBSYSTEM=net
E: USEC_INITIALIZED=11187199
E: ID_PATH=platform-fe204000.spi
E: ID_PATH_TAG=platform-fe204000_spi
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/can0
E: TAGS=:systemd:

$ udevadm info /sys/class/net/can1
P: /devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.0/net/can1
L: 0
E: DEVPATH=/devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.0/net/can1
E: INTERFACE=can1
E: IFINDEX=4
E: SUBSYSTEM=net
E: USEC_INITIALIZED=11192211
E: ID_PATH=platform-fe204000.spi
E: ID_PATH_TAG=platform-fe204000_spi
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/can1
E: TAGS=:systemd:

With this the chip select number is added to the ID_PATH, to make
predictable network names possible.

$ sudo udevadm info /sys/class/net/can0
P: /devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.1/net/can0
L: 0
E: DEVPATH=/devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.1/net/can0
E: INTERFACE=can0
E: IFINDEX=3
E: SUBSYSTEM=net
E: USEC_INITIALIZED=11187199
E: ID_PATH=platform-fe204000.spi-cs-1
E: ID_PATH_TAG=platform-fe204000_spi-cs-1
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/can0
E: TAGS=:systemd:

$ sudo udevadm info /sys/class/net/can1
P: /devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.0/net/can1
L: 0
E: DEVPATH=/devices/platform/soc/fe204000.spi/spi_master/spi0/spi0.0/net/can1
E: INTERFACE=can1
E: IFINDEX=4
E: SUBSYSTEM=net
E: USEC_INITIALIZED=11192211
E: ID_PATH=platform-fe204000.spi-cs-0
E: ID_PATH_TAG=platform-fe204000_spi-cs-0
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/can1
E: TAGS=:systemd:
2020-07-01 13:12:11 +09:00
Zbigniew Jędrzejewski-Szmek d17eabb105 Fix build with µhttpd 0.9.71
The return type of callbacks was changed from int to an enum.
2020-07-01 13:10:48 +09:00
Yu Watanabe 116739cfb6
Merge pull request #16316 from yuwata/backlight-use-actual-brightness
backlight: use actual_brightness attribute to get current backlight level
2020-07-01 13:10:15 +09:00
Yu Watanabe 437b9a7f75 backlight: read current backlight brightness from 'actual_brightness' attribute
Closes #16302.
2020-06-30 22:19:21 +09:00
Yu Watanabe daa227a320 backlight: call log_setup_service() before logging 2020-06-30 22:19:21 +09:00
Yu Watanabe 74f1bb5c9f backlight: use SYNTHETIC_ERRNO() macro 2020-06-30 22:19:21 +09:00
Lennart Poettering 40af3d020f shared: split out property get helpers
No code changes, just some refactoring.
2020-06-30 15:10:17 +02:00
Lennart Poettering 9176326ba2 shared: split out code for printing properties
No code changes, just some refactoring.
2020-06-30 15:09:56 +02:00
Lennart Poettering 807542bece shared: split out code that maps properties to local structs
Just some refactoring, no code changes.
2020-06-30 15:09:35 +02:00
Lennart Poettering 9b71e4ab90 shared: actually move all BusLocator related calls to bus-locator.c 2020-06-30 15:09:19 +02:00
Lennart Poettering c664cf5607 shared: split out BusObjectImplementor APIs
Just some refactoring, no code changes
2020-06-30 15:08:35 +02:00
80 changed files with 1514 additions and 1397 deletions

View File

@ -4,6 +4,7 @@
#include "analyze-security.h"
#include "bus-error.h"
#include "bus-map-properties.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "env-util.h"

View File

@ -17,8 +17,9 @@
#include "analyze-verify.h"
#include "build.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "calendarspec.h"
#include "conf-files.h"
#include "copy.h"

View File

@ -224,10 +224,8 @@ static int get_max_brightness(sd_device *device, unsigned *ret) {
if (r < 0)
return log_device_warning_errno(device, r, "Failed to parse 'max_brightness' \"%s\": %m", max_brightness_str);
if (max_brightness <= 0) {
log_device_warning(device, "Maximum brightness is 0, ignoring device.");
return -EINVAL;
}
if (max_brightness <= 0)
return log_device_warning_errno(device, SYNTHETIC_ERRNO(EINVAL), "Maximum brightness is 0, ignoring device.");
*ret = max_brightness;
return 0;
@ -299,6 +297,34 @@ static bool shall_clamp(sd_device *d) {
return r;
}
static int read_brightness(sd_device *device, const char **ret) {
const char *subsystem;
int r;
assert(device);
assert(ret);
r = sd_device_get_subsystem(device, &subsystem);
if (r < 0)
return log_device_debug_errno(device, r, "Failed to get subsystem: %m");
if (streq(subsystem, "backlight")) {
r = sd_device_get_sysattr_value(device, "actual_brightness", ret);
if (r >= 0)
return 0;
if (r != -ENOENT)
return log_device_debug_errno(device, r, "Failed to read 'actual_brightness' attribute: %m");
log_device_debug_errno(device, r, "Failed to read 'actual_brightness' attribute, fall back to use 'brightness' attribute: %m");
}
r = sd_device_get_sysattr_value(device, "brightness", ret);
if (r < 0)
return log_device_debug_errno(device, r, "Failed to read 'brightness' attribute: %m");
return 0;
}
static int run(int argc, char *argv[]) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
_cleanup_free_ char *escaped_ss = NULL, *escaped_sysname = NULL, *escaped_path_id = NULL;
@ -306,13 +332,11 @@ static int run(int argc, char *argv[]) {
unsigned max_brightness;
int r;
if (argc != 3) {
log_error("This program requires two arguments.");
return -EINVAL;
}
log_setup_service();
if (argc != 3)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program requires two arguments.");
umask(0022);
r = mkdir_p("/var/lib/systemd/backlight", 0755);
@ -320,19 +344,15 @@ static int run(int argc, char *argv[]) {
return log_error_errno(r, "Failed to create backlight directory /var/lib/systemd/backlight: %m");
sysname = strchr(argv[2], ':');
if (!sysname) {
log_error("Requires a subsystem and sysname pair specifying a backlight device.");
return -EINVAL;
}
if (!sysname)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Requires a subsystem and sysname pair specifying a backlight device.");
ss = strndupa(argv[2], sysname - argv[2]);
sysname++;
if (!STR_IN_SET(ss, "backlight", "leds")) {
log_error("Not a backlight or LED device: '%s:%s'", ss, sysname);
return -EINVAL;
}
if (!STR_IN_SET(ss, "backlight", "leds"))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Not a backlight or LED device: '%s:%s'", ss, sysname);
r = sd_device_new_from_subsystem_sysname(&device, ss, sysname);
if (r < 0)
@ -391,9 +411,9 @@ static int run(int argc, char *argv[]) {
if (!clamp)
return 0;
r = sd_device_get_sysattr_value(device, "brightness", &curval);
r = read_brightness(device, &curval);
if (r < 0)
return log_device_warning_errno(device, r, "Failed to read 'brightness' attribute: %m");
return log_device_error_errno(device, r, "Failed to read current brightness: %m");
value = strdup(curval);
if (!value)
@ -416,18 +436,16 @@ static int run(int argc, char *argv[]) {
return 0;
}
r = sd_device_get_sysattr_value(device, "brightness", &value);
r = read_brightness(device, &value);
if (r < 0)
return log_device_error_errno(device, r, "Failed to read system 'brightness' attribute: %m");
return log_device_error_errno(device, r, "Failed to read current brightness: %m");
r = write_string_file(saved, value, WRITE_STRING_FILE_CREATE);
if (r < 0)
return log_device_error_errno(device, r, "Failed to write %s: %m", saved);
} else {
log_error("Unknown verb %s.", argv[1]);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown verb %s.", argv[1]);
return 0;
}

View File

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "automount.h"
#include "bus-util.h"
#include "bus-get-properties.h"
#include "dbus-automount.h"
#include "dbus-util.h"
#include "string-util.h"

View File

@ -5,7 +5,7 @@
#include "af-list.h"
#include "alloc-util.h"
#include "bpf-firewall.h"
#include "bus-util.h"
#include "bus-get-properties.h"
#include "cgroup-util.h"
#include "cgroup.h"
#include "dbus-cgroup.h"

View File

@ -9,7 +9,7 @@
#include "af-list.h"
#include "alloc-util.h"
#include "bus-util.h"
#include "bus-get-properties.h"
#include "cap-list.h"
#include "capability-util.h"
#include "cpu-set-util.h"

View File

@ -3,6 +3,7 @@
#include "sd-bus.h"
#include "alloc-util.h"
#include "bus-get-properties.h"
#include "bus-util.h"
#include "dbus-job.h"
#include "dbus-unit.h"

View File

@ -4,7 +4,7 @@
#include "sd-bus.h"
#include "unit.h"
#include "bus-util.h"
#include "bus-object.h"
extern const sd_bus_vtable bus_job_vtable[];
extern const BusObjectImplementation job_object;

View File

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "bus-util.h"
#include "bus-get-properties.h"
#include "dbus-kill.h"
#include "dbus-util.h"
#include "kill.h"

View File

@ -9,8 +9,8 @@
#include "architecture.h"
#include "build.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-log-control-api.h"
#include "bus-util.h"
#include "dbus-cgroup.h"
#include "dbus-execute.h"
#include "dbus-job.h"

View File

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "bus-util.h"
#include "bus-get-properties.h"
#include "dbus-cgroup.h"
#include "dbus-execute.h"
#include "dbus-kill.h"

View File

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "alloc-util.h"
#include "bus-util.h"
#include "bus-get-properties.h"
#include "dbus-path.h"
#include "dbus-util.h"
#include "list.h"

View File

@ -2,7 +2,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-util.h"
#include "bus-get-properties.h"
#include "dbus-cgroup.h"
#include "dbus-kill.h"
#include "dbus-scope.h"

View File

@ -4,7 +4,7 @@
#include "alloc-util.h"
#include "async.h"
#include "bus-util.h"
#include "bus-get-properties.h"
#include "dbus-cgroup.h"
#include "dbus-execute.h"
#include "dbus-kill.h"

View File

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "alloc-util.h"
#include "bus-util.h"
#include "bus-get-properties.h"
#include "dbus-cgroup.h"
#include "dbus-execute.h"
#include "dbus-kill.h"

View File

@ -3,7 +3,7 @@
Copyright © 2010 Maarten Lankhorst
***/
#include "bus-util.h"
#include "bus-get-properties.h"
#include "dbus-cgroup.h"
#include "dbus-execute.h"
#include "dbus-swap.h"

View File

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "alloc-util.h"
#include "bus-util.h"
#include "bus-get-properties.h"
#include "dbus-timer.h"
#include "dbus-util.h"
#include "strv.h"

View File

@ -5,8 +5,8 @@
#include "alloc-util.h"
#include "bpf-firewall.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "cgroup-util.h"
#include "condition.h"
#include "dbus-job.h"

View File

@ -8,7 +8,7 @@
#include "ask-password-api.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-util.h"
#include "bus-locator.h"
#include "cgroup-util.h"
#include "dns-domain.h"
#include "env-util.h"

View File

@ -3,7 +3,7 @@
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-object.h"
#include "homed-home.h"
int bus_home_client_is_trusted(Home *h, sd_bus_message *message);

View File

@ -6,7 +6,7 @@
#include "sd-bus.h"
#include "bus-common-errors.h"
#include "bus-util.h"
#include "bus-locator.h"
#include "errno-util.h"
#include "fd-util.h"
#include "home-util.h"

View File

@ -12,7 +12,7 @@
#include "alloc-util.h"
#include "architecture.h"
#include "bus-error.h"
#include "bus-util.h"
#include "bus-map-properties.h"
#include "hostname-util.h"
#include "main-func.h"
#include "pretty-print.h"

View File

@ -7,8 +7,8 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-log-control-api.h"
#include "bus-util.h"
#include "bus-polkit.h"
#include "def.h"
#include "fd-util.h"
@ -22,8 +22,8 @@
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
#include "signal-util.h"
#include "service-util.h"
#include "signal-util.h"
#include "socket-util.h"
#include "stat-util.h"
#include "string-table.h"

View File

@ -349,7 +349,7 @@ static int request_parse_range(
return 0;
}
static int request_parse_arguments_iterator(
static mhd_result request_parse_arguments_iterator(
void *cls,
enum MHD_ValueKind kind,
const char *key,
@ -796,7 +796,7 @@ static int request_handler_machine(
return MHD_queue_response(connection, MHD_HTTP_OK, response);
}
static int request_handler(
static mhd_result request_handler(
void *cls,
struct MHD_Connection *connection,
const char *url,

View File

@ -253,7 +253,7 @@ static int process_http_upload(
return mhd_respond(connection, MHD_HTTP_ACCEPTED, "OK.");
};
static int request_handler(
static mhd_result request_handler(
void *cls,
struct MHD_Connection *connection,
const char *url,

View File

@ -47,6 +47,12 @@
# define MHD_create_response_from_fd_at_offset64 MHD_create_response_from_fd_at_offset
#endif
#if MHD_VERSION >= 0x00097002
# define mhd_result enum MHD_Result
#else
# define mhd_result int
#endif
void microhttpd_logger(void *arg, const char *fmt, va_list ap) _printf_(2, 0);
/* respond_oom() must be usable with return, hence this form. */

View File

@ -6,6 +6,7 @@
#include "bus-internal.h"
#include "bus-track.h"
#include "bus-util.h"
#include "string-util.h"
struct track_item {
unsigned n_ref;

View File

@ -8,7 +8,8 @@
#include "sd-bus.h"
#include "bus-error.h"
#include "bus-util.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
#include "fd-util.h"
#include "fileio.h"
#include "kbd-util.h"

View File

@ -9,8 +9,10 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
#include "bus-print-properties.h"
#include "bus-unit-procs.h"
#include "bus-util.h"
#include "cgroup-show.h"
#include "cgroup-util.h"
#include "format-table.h"

View File

@ -12,6 +12,8 @@
#include "bootspec.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-get-properties.h"
#include "bus-locator.h"
#include "bus-polkit.h"
#include "bus-unit-util.h"
#include "bus-util.h"

View File

@ -3,10 +3,10 @@
#include "sd-bus.h"
#include "bus-util.h"
#include "logind.h"
#include "bus-object.h"
#include "logind-session.h"
#include "logind-user.h"
#include "logind.h"
int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret);
int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret);

View File

@ -4,6 +4,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-label.h"
#include "bus-polkit.h"
#include "bus-util.h"

View File

@ -3,8 +3,8 @@
#include "sd-bus.h"
#include "bus-object.h"
#include "logind-seat.h"
#include "bus-util.h"
extern const BusObjectImplementation seat_object;

View File

@ -4,6 +4,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-label.h"
#include "bus-polkit.h"
#include "bus-util.h"

View File

@ -3,6 +3,7 @@
#include "sd-bus.h"
#include "bus-object.h"
#include "logind-session.h"
extern const BusObjectImplementation session_object;

View File

@ -3,6 +3,7 @@
#include <errno.h>
#include "alloc-util.h"
#include "bus-get-properties.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "format-util.h"

View File

@ -10,9 +10,9 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "cgroup-util.h"
#include "def.h"
#include "device-util.h"

View File

@ -20,7 +20,7 @@
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-internal.h"
#include "bus-util.h"
#include "bus-locator.h"
#include "cgroup-setup.h"
#include "errno-util.h"
#include "fd-util.h"

View File

@ -4,9 +4,9 @@
#include <sys/mount.h>
#include "alloc-util.h"
#include "bus-get-properties.h"
#include "bus-label.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "copy.h"
#include "dissect-image.h"
#include "fd-util.h"

View File

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include "bus-util.h"
#include "bus-object.h"
#include "machined.h"
extern const BusObjectImplementation image_object;

View File

@ -12,10 +12,11 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-internal.h"
#include "bus-label.h"
#include "bus-locator.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "copy.h"
#include "env-file.h"
#include "env-util.h"

View File

@ -16,9 +16,11 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
#include "bus-print-properties.h"
#include "bus-unit-procs.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "bus-wait-for-jobs.h"
#include "cgroup-show.h"
#include "cgroup-util.h"

View File

@ -8,8 +8,9 @@
#include "alloc-util.h"
#include "btrfs-util.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-locator.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "cgroup-util.h"
#include "errno-util.h"
#include "fd-util.h"

View File

@ -10,9 +10,9 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "cgroup-util.h"
#include "dirent-util.h"
#include "fd-util.h"

View File

@ -6,8 +6,8 @@
#include "sd-device.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "bus-wait-for-jobs.h"
#include "device-util.h"
#include "dirent-util.h"

View File

@ -21,10 +21,10 @@
#include "alloc-util.h"
#include "bond-util.h"
#include "bridge-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-util.h"
#include "bridge-util.h"
#include "bus-locator.h"
#include "device-util.h"
#include "escape.h"
#include "ether-addr-util.h"

View File

@ -6,8 +6,8 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "dns-domain.h"
#include "networkd-link-bus.h"
#include "networkd-link.h"

View File

@ -3,6 +3,7 @@
#include "sd-bus.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "bus-wait-for-jobs.h"

View File

@ -8,7 +8,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-util.h"
#include "bus-locator.h"
#include "env-util.h"
#include "errno-util.h"
#include "format-util.h"

View File

@ -10,7 +10,7 @@
#include "sd-bus.h"
#include "bus-common-errors.h"
#include "bus-util.h"
#include "bus-locator.h"
#include "errno-util.h"
#include "in-addr-util.h"
#include "macro.h"

View File

@ -7,8 +7,8 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "bus-wait-for-jobs.h"
#include "def.h"
#include "dirent-util.h"

View File

@ -7,6 +7,7 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-label.h"
#include "bus-polkit.h"
#include "bus-util.h"

View File

@ -11,7 +11,8 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-util.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
#include "dns-domain.h"
#include "escape.h"
#include "format-table.h"

View File

@ -2,9 +2,9 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "dns-domain.h"
#include "memory-util.h"
#include "missing_capability.h"

View File

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include "bus-util.h"
#include "bus-object.h"
#include "resolved-manager.h"
extern const BusObjectImplementation manager_object;

View File

@ -2,7 +2,7 @@
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-object.h"
extern const BusObjectImplementation dnssd_object;

View File

@ -6,8 +6,8 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-get-properties.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "parse-util.h"
#include "resolve-util.h"
#include "resolved-bus.h"

View File

@ -11,8 +11,9 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "bus-wait-for-jobs.h"
#include "calendarspec.h"
#include "env-util.h"

View File

@ -0,0 +1,149 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "bus-get-properties.h"
#include "rlimit-util.h"
#include "string-util.h"
int bus_property_get_bool(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
int b = *(bool*) userdata;
return sd_bus_message_append_basic(reply, 'b', &b);
}
int bus_property_set_bool(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *value,
void *userdata,
sd_bus_error *error) {
int b, r;
r = sd_bus_message_read(value, "b", &b);
if (r < 0)
return r;
*(bool*) userdata = b;
return 0;
}
int bus_property_get_id128(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
sd_id128_t *id = userdata;
if (sd_id128_is_null(*id)) /* Add an empty array if the ID is zero */
return sd_bus_message_append(reply, "ay", 0);
else
return sd_bus_message_append_array(reply, 'y', id->bytes, 16);
}
#if __SIZEOF_SIZE_T__ != 8
int bus_property_get_size(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
uint64_t sz = *(size_t*) userdata;
return sd_bus_message_append_basic(reply, 't', &sz);
}
#endif
#if __SIZEOF_LONG__ != 8
int bus_property_get_long(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
int64_t l = *(long*) userdata;
return sd_bus_message_append_basic(reply, 'x', &l);
}
int bus_property_get_ulong(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
uint64_t ul = *(unsigned long*) userdata;
return sd_bus_message_append_basic(reply, 't', &ul);
}
#endif
int bus_property_get_rlimit(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
const char *is_soft;
struct rlimit *rl;
uint64_t u;
rlim_t x;
assert(bus);
assert(reply);
assert(userdata);
is_soft = endswith(property, "Soft");
rl = *(struct rlimit**) userdata;
if (rl)
x = is_soft ? rl->rlim_cur : rl->rlim_max;
else {
struct rlimit buf = {};
const char *s, *p;
int z;
/* Chop off "Soft" suffix */
s = is_soft ? strndupa(property, is_soft - property) : property;
/* Skip over any prefix, such as "Default" */
assert_se(p = strstr(s, "Limit"));
z = rlimit_from_string(p + 5);
assert(z >= 0);
(void) getrlimit(z, &buf);
x = is_soft ? buf.rlim_cur : buf.rlim_max;
}
/* rlim_t might have different sizes, let's map RLIMIT_INFINITY to (uint64_t) -1, so that it is the same on all
* archs */
u = x == RLIM_INFINITY ? (uint64_t) -1 : (uint64_t) x;
return sd_bus_message_append(reply, "t", u);
}

View File

@ -0,0 +1,103 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include "sd-bus.h"
#include "sd-bus.h"
#include "macro.h"
int bus_property_get_bool(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_bool(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_id128(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#define bus_property_get_usec ((sd_bus_property_get_t) NULL)
#define bus_property_set_usec ((sd_bus_property_set_t) NULL)
assert_cc(sizeof(int) == sizeof(int32_t));
#define bus_property_get_int ((sd_bus_property_get_t) NULL)
assert_cc(sizeof(unsigned) == sizeof(uint32_t));
#define bus_property_get_unsigned ((sd_bus_property_get_t) NULL)
/* On 64bit machines we can use the default serializer for size_t and
* friends, otherwise we need to cast this manually */
#if __SIZEOF_SIZE_T__ == 8
#define bus_property_get_size ((sd_bus_property_get_t) NULL)
#else
int bus_property_get_size(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#endif
#if __SIZEOF_LONG__ == 8
#define bus_property_get_long ((sd_bus_property_get_t) NULL)
#define bus_property_get_ulong ((sd_bus_property_get_t) NULL)
#else
int bus_property_get_long(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_ulong(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#endif
/* uid_t and friends on Linux 32 bit. This means we can just use the
* default serializer for 32bit unsigned, for serializing it, and map
* it to NULL here */
assert_cc(sizeof(uid_t) == sizeof(uint32_t));
#define bus_property_get_uid ((sd_bus_property_get_t) NULL)
assert_cc(sizeof(gid_t) == sizeof(uint32_t));
#define bus_property_get_gid ((sd_bus_property_get_t) NULL)
assert_cc(sizeof(pid_t) == sizeof(uint32_t));
#define bus_property_get_pid ((sd_bus_property_get_t) NULL)
assert_cc(sizeof(mode_t) == sizeof(uint32_t));
#define bus_property_get_mode ((sd_bus_property_get_t) NULL)
int bus_property_get_rlimit(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#define BUS_DEFINE_PROPERTY_GET_GLOBAL(function, bus_type, val) \
int function(sd_bus *bus, \
const char *path, \
const char *interface, \
const char *property, \
sd_bus_message *reply, \
void *userdata, \
sd_bus_error *error) { \
\
assert(bus); \
assert(reply); \
\
return sd_bus_message_append(reply, bus_type, val); \
}
#define BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, get2) \
int function(sd_bus *bus, \
const char *path, \
const char *interface, \
const char *property, \
sd_bus_message *reply, \
void *userdata, \
sd_bus_error *error) { \
\
data_type *data = userdata; \
\
assert(bus); \
assert(reply); \
assert(data); \
\
return sd_bus_message_append(reply, bus_type, \
get2(get1(data))); \
}
#define ident(x) (x)
#define BUS_DEFINE_PROPERTY_GET(function, bus_type, data_type, get1) \
BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, ident)
#define ref(x) (*(x))
#define BUS_DEFINE_PROPERTY_GET_REF(function, bus_type, data_type, get) \
BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, ref, get)
#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type) \
BUS_DEFINE_PROPERTY_GET_REF(function, "s", type, name##_to_string)
#define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \
SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \
SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags))

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "bus-locator.h"
#include "macro.h"
const BusLocator* const bus_home_mgr = &(BusLocator){
.destination = "org.freedesktop.home1",
@ -61,3 +62,152 @@ const BusLocator* const bus_timedate = &(BusLocator){
.path = "/org/freedesktop/timedate1",
.interface = "org.freedesktop.timedate1"
};
/* Shorthand flavors of the sd-bus convenience helpers with destination,path,interface strings encapsulated
* within a single struct. */
int bus_call_method_async(
sd_bus *bus,
sd_bus_slot **slot,
const BusLocator *locator,
const char *member,
sd_bus_message_handler_t callback,
void *userdata,
const char *types, ...) {
va_list ap;
int r;
assert(locator);
va_start(ap, types);
r = sd_bus_call_method_asyncv(bus, slot, locator->destination, locator->path, locator->interface, member, callback, userdata, types, ap);
va_end(ap);
return r;
}
int bus_call_method(
sd_bus *bus,
const BusLocator *locator,
const char *member,
sd_bus_error *error,
sd_bus_message **reply,
const char *types, ...) {
va_list ap;
int r;
assert(locator);
va_start(ap, types);
r = sd_bus_call_methodv(bus, locator->destination, locator->path, locator->interface, member, error, reply, types, ap);
va_end(ap);
return r;
}
int bus_get_property(
sd_bus *bus,
const BusLocator *locator,
const char *member,
sd_bus_error *error,
sd_bus_message **reply,
const char *type) {
assert(locator);
return sd_bus_get_property(bus, locator->destination, locator->path, locator->interface, member, error, reply, type);
}
int bus_get_property_trivial(
sd_bus *bus,
const BusLocator *locator,
const char *member,
sd_bus_error *error,
char type, void *ptr) {
assert(locator);
return sd_bus_get_property_trivial(bus, locator->destination, locator->path, locator->interface, member, error, type, ptr);
}
int bus_get_property_string(
sd_bus *bus,
const BusLocator *locator,
const char *member,
sd_bus_error *error,
char **ret) {
assert(locator);
return sd_bus_get_property_string(bus, locator->destination, locator->path, locator->interface, member, error, ret);
}
int bus_get_property_strv(
sd_bus *bus,
const BusLocator *locator,
const char *member,
sd_bus_error *error,
char ***ret) {
assert(locator);
return sd_bus_get_property_strv(bus, locator->destination, locator->path, locator->interface, member, error, ret);
}
int bus_set_property(
sd_bus *bus,
const BusLocator *locator,
const char *member,
sd_bus_error *error,
const char *type, ...) {
va_list ap;
int r;
assert(locator);
va_start(ap, type);
r = sd_bus_set_propertyv(bus, locator->destination, locator->path, locator->interface, member, error, type, ap);
va_end(ap);
return r;
}
int bus_match_signal(
sd_bus *bus,
sd_bus_slot **ret,
const BusLocator *locator,
const char *member,
sd_bus_message_handler_t callback,
void *userdata) {
assert(locator);
return sd_bus_match_signal(bus, ret, locator->destination, locator->path, locator->interface, member, callback, userdata);
}
int bus_match_signal_async(
sd_bus *bus,
sd_bus_slot **ret,
const BusLocator *locator,
const char *member,
sd_bus_message_handler_t callback,
sd_bus_message_handler_t install_callback,
void *userdata) {
assert(locator);
return sd_bus_match_signal_async(bus, ret, locator->destination, locator->path, locator->interface, member, callback, install_callback, userdata);
}
int bus_message_new_method_call(
sd_bus *bus,
sd_bus_message **m,
const BusLocator *locator,
const char *member) {
assert(locator);
return sd_bus_message_new_method_call(bus, m, locator->destination, locator->path, locator->interface, member);
}

View File

@ -1,10 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include "sd-bus.h"
typedef struct BusLocator {
const char *destination;
const char *path;
const char *interface;
const char *destination;
const char *path;
const char *interface;
} BusLocator;
extern const BusLocator* const bus_home_mgr;
@ -17,3 +19,16 @@ extern const BusLocator* const bus_portable_mgr;
extern const BusLocator* const bus_resolve_mgr;
extern const BusLocator* const bus_systemd_mgr;
extern const BusLocator* const bus_timedate;
/* Shorthand flavors of the sd-bus convenience helpers with destination,path,interface strings encapsulated
* within a single struct. */
int bus_call_method_async(sd_bus *bus, sd_bus_slot **slot, const BusLocator *locator, const char *member, sd_bus_message_handler_t callback, void *userdata, const char *types, ...);
int bus_call_method(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...);
int bus_get_property(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *type);
int bus_get_property_trivial(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, char type, void *ptr);
int bus_get_property_string(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, char **ret);
int bus_get_property_strv(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, char ***ret);
int bus_set_property(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, const char *type, ...);
int bus_match_signal(sd_bus *bus, sd_bus_slot **ret, const BusLocator *locator, const char *member, sd_bus_message_handler_t callback, void *userdata);
int bus_match_signal_async(sd_bus *bus, sd_bus_slot **ret, const BusLocator *locator, const char *member, sd_bus_message_handler_t callback, sd_bus_message_handler_t install_callback, void *userdata);
int bus_message_new_method_call(sd_bus *bus, sd_bus_message **m, const BusLocator *locator, const char *member);

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "alloc-util.h"
#include "bus-get-properties.h"
#include "bus-log-control-api.h"
#include "bus-util.h"
#include "log.h"

View File

@ -3,7 +3,7 @@
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-object.h"
extern const BusObjectImplementation log_control_object;
static inline int bus_log_control_api_register(sd_bus *bus) {

View File

@ -0,0 +1,229 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "bus-map-properties.h"
#include "alloc-util.h"
#include "strv.h"
#include "bus-message.h"
int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
sd_id128_t *p = userdata;
const void *v;
size_t n;
int r;
r = sd_bus_message_read_array(m, SD_BUS_TYPE_BYTE, &v, &n);
if (r < 0)
return r;
if (n == 0)
*p = SD_ID128_NULL;
else if (n == 16)
memcpy((*p).bytes, v, n);
else
return -EINVAL;
return 0;
}
static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, unsigned flags, sd_bus_error *error, void *userdata) {
char type;
int r;
r = sd_bus_message_peek_type(m, &type, NULL);
if (r < 0)
return r;
switch (type) {
case SD_BUS_TYPE_STRING:
case SD_BUS_TYPE_OBJECT_PATH: {
const char **p = userdata;
const char *s;
r = sd_bus_message_read_basic(m, type, &s);
if (r < 0)
return r;
if (isempty(s))
s = NULL;
if (flags & BUS_MAP_STRDUP)
return free_and_strdup((char **) userdata, s);
*p = s;
return 0;
}
case SD_BUS_TYPE_ARRAY: {
_cleanup_strv_free_ char **l = NULL;
char ***p = userdata;
r = bus_message_read_strv_extend(m, &l);
if (r < 0)
return r;
return strv_extend_strv(p, l, false);
}
case SD_BUS_TYPE_BOOLEAN: {
int b;
r = sd_bus_message_read_basic(m, type, &b);
if (r < 0)
return r;
if (flags & BUS_MAP_BOOLEAN_AS_BOOL)
*(bool*) userdata = b;
else
*(int*) userdata = b;
return 0;
}
case SD_BUS_TYPE_INT32:
case SD_BUS_TYPE_UINT32: {
uint32_t u, *p = userdata;
r = sd_bus_message_read_basic(m, type, &u);
if (r < 0)
return r;
*p = u;
return 0;
}
case SD_BUS_TYPE_INT64:
case SD_BUS_TYPE_UINT64: {
uint64_t t, *p = userdata;
r = sd_bus_message_read_basic(m, type, &t);
if (r < 0)
return r;
*p = t;
return 0;
}
case SD_BUS_TYPE_DOUBLE: {
double d, *p = userdata;
r = sd_bus_message_read_basic(m, type, &d);
if (r < 0)
return r;
*p = d;
return 0;
}}
return -EOPNOTSUPP;
}
int bus_message_map_all_properties(
sd_bus_message *m,
const struct bus_properties_map *map,
unsigned flags,
sd_bus_error *error,
void *userdata) {
int r;
assert(m);
assert(map);
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
if (r < 0)
return r;
while ((r = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
const struct bus_properties_map *prop;
const char *member;
const char *contents;
void *v;
unsigned i;
r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &member);
if (r < 0)
return r;
for (i = 0, prop = NULL; map[i].member; i++)
if (streq(map[i].member, member)) {
prop = &map[i];
break;
}
if (prop) {
r = sd_bus_message_peek_type(m, NULL, &contents);
if (r < 0)
return r;
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, contents);
if (r < 0)
return r;
v = (uint8_t *)userdata + prop->offset;
if (map[i].set)
r = prop->set(sd_bus_message_get_bus(m), member, m, error, v);
else
r = map_basic(sd_bus_message_get_bus(m), member, m, flags, error, v);
if (r < 0)
return r;
r = sd_bus_message_exit_container(m);
if (r < 0)
return r;
} else {
r = sd_bus_message_skip(m, "v");
if (r < 0)
return r;
}
r = sd_bus_message_exit_container(m);
if (r < 0)
return r;
}
if (r < 0)
return r;
return sd_bus_message_exit_container(m);
}
int bus_map_all_properties(
sd_bus *bus,
const char *destination,
const char *path,
const struct bus_properties_map *map,
unsigned flags,
sd_bus_error *error,
sd_bus_message **reply,
void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
int r;
assert(bus);
assert(destination);
assert(path);
assert(map);
assert(reply || (flags & BUS_MAP_STRDUP));
r = sd_bus_call_method(
bus,
destination,
path,
"org.freedesktop.DBus.Properties",
"GetAll",
error,
&m,
"s", "");
if (r < 0)
return r;
r = bus_message_map_all_properties(m, map, flags, error, userdata);
if (r < 0)
return r;
if (reply)
*reply = sd_bus_message_ref(m);
return r;
}

View File

@ -0,0 +1,24 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include "sd-bus.h"
typedef int (*bus_property_set_t) (sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
struct bus_properties_map {
const char *member;
const char *signature;
bus_property_set_t set;
size_t offset;
};
enum {
BUS_MAP_STRDUP = 1 << 0, /* If set, each "s" message is duplicated. Thus, each pointer needs to be freed. */
BUS_MAP_BOOLEAN_AS_BOOL = 1 << 1, /* If set, each "b" message is written to a bool pointer. If not set, "b" is written to a int pointer. */
};
int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
int bus_message_map_all_properties(sd_bus_message *m, const struct bus_properties_map *map, unsigned flags, sd_bus_error *error, void *userdata);
int bus_map_all_properties(sd_bus *bus, const char *destination, const char *path, const struct bus_properties_map *map,
unsigned flags, sd_bus_error *error, sd_bus_message **reply, void *userdata);

177
src/shared/bus-object.c Normal file
View File

@ -0,0 +1,177 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "bus-introspect.h"
#include "bus-object.h"
#include "macro.h"
#include "string-util.h"
#include "strv.h"
int bus_add_implementation(sd_bus *bus, const BusObjectImplementation *impl, void *userdata) {
int r;
log_debug("Registering bus object implementation for path=%s iface=%s", impl->path, impl->interface);
for (const sd_bus_vtable **p = impl->vtables; p && *p; p++) {
r = sd_bus_add_object_vtable(bus, NULL,
impl->path,
impl->interface,
*p,
userdata);
if (r < 0)
return log_error_errno(r, "Failed to register bus path %s with interface %s: %m",
impl->path,
impl->interface);
}
for (const BusObjectVtablePair *p = impl->fallback_vtables; p && p->vtable; p++) {
r = sd_bus_add_fallback_vtable(bus, NULL,
impl->path,
impl->interface,
p->vtable,
p->object_find,
userdata);
if (r < 0)
return log_error_errno(r, "Failed to register bus path %s with interface %s: %m",
impl->path,
impl->interface);
}
if (impl->node_enumerator) {
r = sd_bus_add_node_enumerator(bus, NULL,
impl->path,
impl->node_enumerator,
userdata);
if (r < 0)
return log_error_errno(r, "Failed to add node enumerator for %s: %m",
impl->path);
}
if (impl->manager) {
r = sd_bus_add_object_manager(bus, NULL, impl->path);
if (r < 0)
return log_error_errno(r, "Failed to add object manager for %s: %m", impl->path);
}
for (size_t i = 0; impl->children && impl->children[i]; i++) {
r = bus_add_implementation(bus, impl->children[i], userdata);
if (r < 0)
return r;
}
return 0;
}
static const BusObjectImplementation* find_implementation(
const char *pattern,
const BusObjectImplementation* const* bus_objects) {
for (size_t i = 0; bus_objects && bus_objects[i]; i++) {
const BusObjectImplementation *impl = bus_objects[i];
if (STR_IN_SET(pattern, impl->path, impl->interface))
return impl;
impl = find_implementation(pattern, impl->children);
if (impl)
return impl;
}
return NULL;
}
static int bus_introspect_implementation(
struct introspect *intro,
const BusObjectImplementation *impl) {
int r;
for (const sd_bus_vtable **p = impl->vtables; p && *p; p++) {
r = introspect_write_interface(intro, impl->interface, *p);
if (r < 0)
return log_error_errno(r, "Failed to write introspection data: %m");
}
for (const BusObjectVtablePair *p = impl->fallback_vtables; p && p->vtable; p++) {
r = introspect_write_interface(intro, impl->interface, p->vtable);
if (r < 0)
return log_error_errno(r, "Failed to write introspection data: %m");
}
return 0;
}
static void list_paths(
FILE *out,
const BusObjectImplementation* const* bus_objects) {
for (size_t i = 0; bus_objects[i]; i++) {
fprintf(out, "%s\t%s\n", bus_objects[i]->path, bus_objects[i]->interface);
if (bus_objects[i]->children)
list_paths(out, bus_objects[i]->children);
}
}
int bus_introspect_implementations(
FILE *out,
const char *pattern,
const BusObjectImplementation* const* bus_objects) {
const BusObjectImplementation *impl, *main_impl = NULL;
_cleanup_free_ char *s = NULL;
int r;
if (streq(pattern, "list")) {
list_paths(out, bus_objects);
return 0;
}
struct introspect intro = {};
bool is_interface = sd_bus_interface_name_is_valid(pattern);
impl = find_implementation(pattern, bus_objects);
if (!impl)
return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
"%s %s not found",
is_interface ? "Interface" : "Object path",
pattern);
/* We use trusted=false here to get all the @org.freedesktop.systemd1.Privileged annotations. */
r = introspect_begin(&intro, false);
if (r < 0)
return log_error_errno(r, "Failed to write introspection data: %m");
r = introspect_write_default_interfaces(&intro, impl->manager);
if (r < 0)
return log_error_errno(r, "Failed to write introspection data: %m");
/* Check if there is a non-fallback path that applies to the given interface, also
* print it. This is useful in the case of units: o.fd.systemd1.Service is declared
* as a fallback vtable for o/fd/systemd1/unit, and we also want to print
* o.fd.systemd1.Unit, which is the non-fallback implementation. */
if (impl->fallback_vtables && is_interface)
main_impl = find_implementation(impl->path, bus_objects);
if (main_impl)
bus_introspect_implementation(&intro, main_impl);
if (impl != main_impl)
bus_introspect_implementation(&intro, impl);
_cleanup_set_free_ Set *nodes = NULL;
for (size_t i = 0; impl->children && impl->children[i]; i++) {
r = set_put_strdup(&nodes, impl->children[i]->path);
if (r < 0)
return log_oom();
}
r = introspect_write_child_nodes(&intro, nodes, impl->path);
if (r < 0)
return r;
r = introspect_finish(&intro, &s);
if (r < 0)
return log_error_errno(r, "Failed to write introspection data: %m");
fputs(s, out);
return 0;
}

34
src/shared/bus-object.h Normal file
View File

@ -0,0 +1,34 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <stdbool.h>
#include <stdio.h>
#include "sd-bus.h"
typedef struct BusObjectImplementation BusObjectImplementation;
typedef struct BusObjectVtablePair {
const sd_bus_vtable *vtable;
sd_bus_object_find_t object_find;
} BusObjectVtablePair;
struct BusObjectImplementation {
const char *path;
const char *interface;
const sd_bus_vtable **vtables;
const BusObjectVtablePair *fallback_vtables;
sd_bus_node_enumerator_t node_enumerator;
bool manager;
const BusObjectImplementation **children;
};
#define BUS_VTABLES(...) ((const sd_bus_vtable* []){ __VA_ARGS__, NULL })
#define BUS_FALLBACK_VTABLES(...) ((const BusObjectVtablePair[]) { __VA_ARGS__, {} })
#define BUS_IMPLEMENTATIONS(...) ((const BusObjectImplementation* []) { __VA_ARGS__, NULL })
int bus_add_implementation(sd_bus *bus, const BusObjectImplementation *impl, void *userdata);
int bus_introspect_implementations(
FILE *out,
const char *pattern,
const BusObjectImplementation* const* bus_objects);

View File

@ -0,0 +1,462 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "bus-print-properties.h"
#include "cap-list.h"
#include "cgroup-util.h"
#include "escape.h"
#include "mountpoint-util.h"
#include "nsflags.h"
#include "parse-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
#include "user-util.h"
int bus_print_property_value(const char *name, const char *expected_value, bool only_value, const char *value) {
assert(name);
if (expected_value && !streq_ptr(expected_value, value))
return 0;
if (only_value)
puts(value);
else
printf("%s=%s\n", name, value);
return 0;
}
int bus_print_property_valuef(const char *name, const char *expected_value, bool only_value, const char *fmt, ...) {
va_list ap;
int r;
assert(name);
assert(fmt);
if (expected_value) {
_cleanup_free_ char *s = NULL;
va_start(ap, fmt);
r = vasprintf(&s, fmt, ap);
va_end(ap);
if (r < 0)
return -ENOMEM;
if (streq_ptr(expected_value, s)) {
if (only_value)
puts(s);
else
printf("%s=%s\n", name, s);
}
return 0;
}
if (!only_value)
printf("%s=", name);
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
puts("");
return 0;
}
static int bus_print_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) {
char type;
const char *contents;
int r;
assert(name);
assert(m);
r = sd_bus_message_peek_type(m, &type, &contents);
if (r < 0)
return r;
switch (type) {
case SD_BUS_TYPE_STRING: {
const char *s;
r = sd_bus_message_read_basic(m, type, &s);
if (r < 0)
return r;
if (all || !isempty(s)) {
bool good;
/* This property has a single value, so we need to take
* care not to print a new line, everything else is OK. */
good = !strchr(s, '\n');
bus_print_property_value(name, expected_value, value, good ? s : "[unprintable]");
}
return 1;
}
case SD_BUS_TYPE_BOOLEAN: {
int b;
r = sd_bus_message_read_basic(m, type, &b);
if (r < 0)
return r;
if (expected_value && parse_boolean(expected_value) != b)
return 1;
bus_print_property_value(name, NULL, value, yes_no(b));
return 1;
}
case SD_BUS_TYPE_UINT64: {
uint64_t u;
r = sd_bus_message_read_basic(m, type, &u);
if (r < 0)
return r;
/* Yes, heuristics! But we can change this check
* should it turn out to not be sufficient */
if (endswith(name, "Timestamp") ||
STR_IN_SET(name, "NextElapseUSecRealtime", "LastTriggerUSec", "TimeUSec", "RTCTimeUSec")) {
char timestamp[FORMAT_TIMESTAMP_MAX];
const char *t;
t = format_timestamp(timestamp, sizeof(timestamp), u);
if (t || all)
bus_print_property_value(name, expected_value, value, strempty(t));
} else if (strstr(name, "USec")) {
char timespan[FORMAT_TIMESPAN_MAX];
(void) format_timespan(timespan, sizeof(timespan), u, 0);
bus_print_property_value(name, expected_value, value, timespan);
} else if (streq(name, "CoredumpFilter")) {
char buf[STRLEN("0xFFFFFFFF")];
xsprintf(buf, "0x%"PRIx64, u);
bus_print_property_value(name, expected_value, value, buf);
} else if (streq(name, "RestrictNamespaces")) {
_cleanup_free_ char *s = NULL;
const char *result;
if ((u & NAMESPACE_FLAGS_ALL) == 0)
result = "yes";
else if (FLAGS_SET(u, NAMESPACE_FLAGS_ALL))
result = "no";
else {
r = namespace_flags_to_string(u, &s);
if (r < 0)
return r;
result = strempty(s);
}
bus_print_property_value(name, expected_value, value, result);
} else if (streq(name, "MountFlags")) {
const char *result;
result = mount_propagation_flags_to_string(u);
if (!result)
return -EINVAL;
bus_print_property_value(name, expected_value, value, result);
} else if (STR_IN_SET(name, "CapabilityBoundingSet", "AmbientCapabilities")) {
_cleanup_free_ char *s = NULL;
r = capability_set_to_string_alloc(u, &s);
if (r < 0)
return r;
bus_print_property_value(name, expected_value, value, s);
} else if ((STR_IN_SET(name, "CPUWeight", "StartupCPUWeight", "IOWeight", "StartupIOWeight") && u == CGROUP_WEIGHT_INVALID) ||
(STR_IN_SET(name, "CPUShares", "StartupCPUShares") && u == CGROUP_CPU_SHARES_INVALID) ||
(STR_IN_SET(name, "BlockIOWeight", "StartupBlockIOWeight") && u == CGROUP_BLKIO_WEIGHT_INVALID) ||
(STR_IN_SET(name, "MemoryCurrent", "TasksCurrent") && u == (uint64_t) -1) ||
(endswith(name, "NSec") && u == (uint64_t) -1))
bus_print_property_value(name, expected_value, value, "[not set]");
else if ((STR_IN_SET(name, "DefaultMemoryLow", "DefaultMemoryMin", "MemoryLow", "MemoryHigh", "MemoryMax", "MemorySwapMax", "MemoryLimit") && u == CGROUP_LIMIT_MAX) ||
(STR_IN_SET(name, "TasksMax", "DefaultTasksMax") && u == (uint64_t) -1) ||
(startswith(name, "Limit") && u == (uint64_t) -1) ||
(startswith(name, "DefaultLimit") && u == (uint64_t) -1))
bus_print_property_value(name, expected_value, value, "infinity");
else if (STR_IN_SET(name, "IPIngressBytes", "IPIngressPackets", "IPEgressBytes", "IPEgressPackets") && u == (uint64_t) -1)
bus_print_property_value(name, expected_value, value, "[no data]");
else
bus_print_property_valuef(name, expected_value, value, "%"PRIu64, u);
return 1;
}
case SD_BUS_TYPE_INT64: {
int64_t i;
r = sd_bus_message_read_basic(m, type, &i);
if (r < 0)
return r;
bus_print_property_valuef(name, expected_value, value, "%"PRIi64, i);
return 1;
}
case SD_BUS_TYPE_UINT32: {
uint32_t u;
r = sd_bus_message_read_basic(m, type, &u);
if (r < 0)
return r;
if (strstr(name, "UMask") || strstr(name, "Mode"))
bus_print_property_valuef(name, expected_value, value, "%04o", u);
else if (streq(name, "UID")) {
if (u == UID_INVALID)
bus_print_property_value(name, expected_value, value, "[not set]");
else
bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
} else if (streq(name, "GID")) {
if (u == GID_INVALID)
bus_print_property_value(name, expected_value, value, "[not set]");
else
bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
} else
bus_print_property_valuef(name, expected_value, value, "%"PRIu32, u);
return 1;
}
case SD_BUS_TYPE_INT32: {
int32_t i;
r = sd_bus_message_read_basic(m, type, &i);
if (r < 0)
return r;
bus_print_property_valuef(name, expected_value, value, "%"PRIi32, i);
return 1;
}
case SD_BUS_TYPE_DOUBLE: {
double d;
r = sd_bus_message_read_basic(m, type, &d);
if (r < 0)
return r;
bus_print_property_valuef(name, expected_value, value, "%g", d);
return 1;
}
case SD_BUS_TYPE_ARRAY:
if (streq(contents, "s")) {
bool first = true;
const char *str;
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, contents);
if (r < 0)
return r;
while ((r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &str)) > 0) {
_cleanup_free_ char *e = NULL;
e = shell_maybe_quote(str, ESCAPE_BACKSLASH_ONELINE);
if (!e)
return -ENOMEM;
if (first) {
if (!value)
printf("%s=", name);
first = false;
} else
fputs(" ", stdout);
fputs(e, stdout);
}
if (r < 0)
return r;
if (first && all && !value)
printf("%s=", name);
if (!first || all)
puts("");
r = sd_bus_message_exit_container(m);
if (r < 0)
return r;
return 1;
} else if (streq(contents, "y")) {
const uint8_t *u;
size_t n;
r = sd_bus_message_read_array(m, SD_BUS_TYPE_BYTE, (const void**) &u, &n);
if (r < 0)
return r;
if (all || n > 0) {
unsigned i;
if (!value)
printf("%s=", name);
for (i = 0; i < n; i++)
printf("%02x", u[i]);
puts("");
}
return 1;
} else if (streq(contents, "u")) {
uint32_t *u;
size_t n;
r = sd_bus_message_read_array(m, SD_BUS_TYPE_UINT32, (const void**) &u, &n);
if (r < 0)
return r;
if (all || n > 0) {
unsigned i;
if (!value)
printf("%s=", name);
for (i = 0; i < n; i++)
printf("%08x", u[i]);
puts("");
}
return 1;
}
break;
}
return 0;
}
int bus_message_print_all_properties(
sd_bus_message *m,
bus_message_print_t func,
char **filter,
bool value,
bool all,
Set **found_properties) {
int r;
assert(m);
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
if (r < 0)
return r;
while ((r = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
_cleanup_free_ char *name_with_equal = NULL;
const char *name, *contents, *expected_value = NULL;
r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &name);
if (r < 0)
return r;
if (found_properties) {
r = set_ensure_put(found_properties, &string_hash_ops, name);
if (r < 0)
return log_oom();
}
name_with_equal = strjoin(name, "=");
if (!name_with_equal)
return log_oom();
if (!filter || strv_find(filter, name) ||
(expected_value = strv_find_startswith(filter, name_with_equal))) {
r = sd_bus_message_peek_type(m, NULL, &contents);
if (r < 0)
return r;
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, contents);
if (r < 0)
return r;
if (func)
r = func(name, expected_value, m, value, all);
if (!func || r == 0)
r = bus_print_property(name, expected_value, m, value, all);
if (r < 0)
return r;
if (r == 0) {
if (all && !expected_value)
printf("%s=[unprintable]\n", name);
/* skip what we didn't read */
r = sd_bus_message_skip(m, contents);
if (r < 0)
return r;
}
r = sd_bus_message_exit_container(m);
if (r < 0)
return r;
} else {
r = sd_bus_message_skip(m, "v");
if (r < 0)
return r;
}
r = sd_bus_message_exit_container(m);
if (r < 0)
return r;
}
if (r < 0)
return r;
r = sd_bus_message_exit_container(m);
if (r < 0)
return r;
return 0;
}
int bus_print_all_properties(
sd_bus *bus,
const char *dest,
const char *path,
bus_message_print_t func,
char **filter,
bool value,
bool all,
Set **found_properties) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
assert(bus);
assert(path);
r = sd_bus_call_method(bus,
dest,
path,
"org.freedesktop.DBus.Properties",
"GetAll",
&error,
&reply,
"s", "");
if (r < 0)
return r;
return bus_message_print_all_properties(reply, func, filter, value, all, found_properties);
}

View File

@ -0,0 +1,16 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <stdbool.h>
#include "sd-bus.h"
#include "macro.h"
#include "set.h"
typedef int (*bus_message_print_t) (const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all);
int bus_print_property_value(const char *name, const char *expected_value, bool only_value, const char *value);
int bus_print_property_valuef(const char *name, const char *expected_value, bool only_value, const char *fmt, ...) _printf_(4,5);
int bus_message_print_all_properties(sd_bus_message *m, bus_message_print_t func, char **filter, bool value, bool all, Set **found_properties);
int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, bus_message_print_t func, char **filter, bool value, bool all, Set **found_properties);

File diff suppressed because it is too large Load Diff

View File

@ -9,9 +9,7 @@
#include "sd-bus.h"
#include "sd-event.h"
#include "bus-locator.h"
#include "macro.h"
#include "set.h"
#include "string-util.h"
#include "time-util.h"
@ -23,47 +21,6 @@ typedef enum BusTransport {
_BUS_TRANSPORT_INVALID = -1
} BusTransport;
typedef struct BusObjectImplementation BusObjectImplementation;
typedef struct BusObjectVtablePair {
const sd_bus_vtable *vtable;
sd_bus_object_find_t object_find;
} BusObjectVtablePair;
struct BusObjectImplementation {
const char *path;
const char *interface;
const sd_bus_vtable **vtables;
const BusObjectVtablePair *fallback_vtables;
sd_bus_node_enumerator_t node_enumerator;
bool manager;
const BusObjectImplementation **children;
};
#define BUS_VTABLES(...) ((const sd_bus_vtable* []){ __VA_ARGS__, NULL })
#define BUS_FALLBACK_VTABLES(...) ((const BusObjectVtablePair[]) { __VA_ARGS__, {} })
#define BUS_IMPLEMENTATIONS(...) ((const BusObjectImplementation* []) { __VA_ARGS__, NULL })
typedef int (*bus_property_set_t) (sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
struct bus_properties_map {
const char *member;
const char *signature;
bus_property_set_t set;
size_t offset;
};
enum {
BUS_MAP_STRDUP = 1 << 0, /* If set, each "s" message is duplicated. Thus, each pointer needs to be freed. */
BUS_MAP_BOOLEAN_AS_BOOL = 1 << 1, /* If set, each "b" message is written to a bool pointer. If not set, "b" is written to a int pointer. */
};
int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
int bus_message_map_all_properties(sd_bus_message *m, const struct bus_properties_map *map, unsigned flags, sd_bus_error *error, void *userdata);
int bus_map_all_properties(sd_bus *bus, const char *destination, const char *path, const struct bus_properties_map *map,
unsigned flags, sd_bus_error *error, sd_bus_message **reply, void *userdata);
int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name);
typedef bool (*check_idle_t)(void *userdata);
@ -80,117 +37,15 @@ int bus_connect_user_systemd(sd_bus **_bus);
int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
typedef int (*bus_message_print_t) (const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all);
int bus_print_property_value(const char *name, const char *expected_value, bool only_value, const char *value);
int bus_print_property_valuef(const char *name, const char *expected_value, bool only_value, const char *fmt, ...) _printf_(4,5);
int bus_message_print_all_properties(sd_bus_message *m, bus_message_print_t func, char **filter, bool value, bool all, Set **found_properties);
int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, bus_message_print_t func, char **filter, bool value, bool all, Set **found_properties);
int bus_property_get_bool(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_bool(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_id128(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#define bus_property_get_usec ((sd_bus_property_get_t) NULL)
#define bus_property_set_usec ((sd_bus_property_set_t) NULL)
assert_cc(sizeof(int) == sizeof(int32_t));
#define bus_property_get_int ((sd_bus_property_get_t) NULL)
assert_cc(sizeof(unsigned) == sizeof(uint32_t));
#define bus_property_get_unsigned ((sd_bus_property_get_t) NULL)
/* On 64bit machines we can use the default serializer for size_t and
* friends, otherwise we need to cast this manually */
#if __SIZEOF_SIZE_T__ == 8
#define bus_property_get_size ((sd_bus_property_get_t) NULL)
#else
int bus_property_get_size(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#endif
#if __SIZEOF_LONG__ == 8
#define bus_property_get_long ((sd_bus_property_get_t) NULL)
#define bus_property_get_ulong ((sd_bus_property_get_t) NULL)
#else
int bus_property_get_long(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_ulong(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
#endif
/* uid_t and friends on Linux 32 bit. This means we can just use the
* default serializer for 32bit unsigned, for serializing it, and map
* it to NULL here */
assert_cc(sizeof(uid_t) == sizeof(uint32_t));
#define bus_property_get_uid ((sd_bus_property_get_t) NULL)
assert_cc(sizeof(gid_t) == sizeof(uint32_t));
#define bus_property_get_gid ((sd_bus_property_get_t) NULL)
assert_cc(sizeof(pid_t) == sizeof(uint32_t));
#define bus_property_get_pid ((sd_bus_property_get_t) NULL)
assert_cc(sizeof(mode_t) == sizeof(uint32_t));
#define bus_property_get_mode ((sd_bus_property_get_t) NULL)
#define bus_log_parse_error(r) \
log_error_errno(r, "Failed to parse bus message: %m")
#define bus_log_create_error(r) \
log_error_errno(r, "Failed to create bus message: %m")
#define BUS_DEFINE_PROPERTY_GET_GLOBAL(function, bus_type, val) \
int function(sd_bus *bus, \
const char *path, \
const char *interface, \
const char *property, \
sd_bus_message *reply, \
void *userdata, \
sd_bus_error *error) { \
\
assert(bus); \
assert(reply); \
\
return sd_bus_message_append(reply, bus_type, val); \
}
#define BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, get2) \
int function(sd_bus *bus, \
const char *path, \
const char *interface, \
const char *property, \
sd_bus_message *reply, \
void *userdata, \
sd_bus_error *error) { \
\
data_type *data = userdata; \
\
assert(bus); \
assert(reply); \
assert(data); \
\
return sd_bus_message_append(reply, bus_type, \
get2(get1(data))); \
}
#define ident(x) (x)
#define BUS_DEFINE_PROPERTY_GET(function, bus_type, data_type, get1) \
BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, get1, ident)
#define ref(x) (*(x))
#define BUS_DEFINE_PROPERTY_GET_REF(function, bus_type, data_type, get) \
BUS_DEFINE_PROPERTY_GET2(function, bus_type, data_type, ref, get)
#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type) \
BUS_DEFINE_PROPERTY_GET_REF(function, "s", type, name##_to_string)
#define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \
SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \
SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags))
int bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, const char *external_id, char **ret_path);
int bus_path_decode_unique(const char *path, const char *prefix, char **ret_sender, char **ret_external);
int bus_property_get_rlimit(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error);
int bus_track_add_name_many(sd_bus_track *t, char **l);
int bus_open_system_watch_bind_with_description(sd_bus **ret, const char *description);
@ -201,23 +56,3 @@ static inline int bus_open_system_watch_bind(sd_bus **ret) {
int bus_reply_pair_array(sd_bus_message *m, char **l);
extern const struct hash_ops bus_message_hash_ops;
/* Shorthand flavors of the sd-bus convenience helpers with destination,path,interface
* strings encapsulated within a single struct.
*/
int bus_call_method_async(sd_bus *bus, sd_bus_slot **slot, const BusLocator *locator, const char *member, sd_bus_message_handler_t callback, void *userdata, const char *types, ...);
int bus_call_method(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...);
int bus_get_property(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *type);
int bus_get_property_trivial(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, char type, void *ptr);
int bus_get_property_string(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, char **ret);
int bus_get_property_strv(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, char ***ret);
int bus_set_property(sd_bus *bus, const BusLocator *locator, const char *member, sd_bus_error *error, const char *type, ...);
int bus_match_signal(sd_bus *bus, sd_bus_slot **ret, const BusLocator *locator, const char *member, sd_bus_message_handler_t callback, void *userdata);
int bus_match_signal_async(sd_bus *bus, sd_bus_slot **ret, const BusLocator *locator, const char *member, sd_bus_message_handler_t callback, sd_bus_message_handler_t install_callback, void *userdata);
int bus_message_new_method_call(sd_bus *bus, sd_bus_message **m, const BusLocator *locator, const char *member);
int bus_add_implementation(sd_bus *bus, const BusObjectImplementation *impl, void *userdata);
int bus_introspect_implementations(
FILE *out,
const char *pattern,
const BusObjectImplementation* const* bus_objects);

View File

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "bus-util.h"
#include "bus-map-properties.h"
#include "bus-wait-for-units.h"
#include "hashmap.h"
#include "string-util.h"

View File

@ -27,12 +27,20 @@ shared_sources = files('''
bpf-program.h
bridge-util.c
bridge-util.h
bus-get-properties.c
bus-get-properties.h
bus-locator.c
bus-locator.h
bus-log-control-api.c
bus-log-control-api.h
bus-map-properties.c
bus-map-properties.h
bus-object.c
bus-object.h
bus-polkit.c
bus-polkit.h
bus-print-properties.c
bus-print-properties.h
bus-unit-procs.c
bus-unit-procs.h
bus-unit-util.c

View File

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include "bus-util.h"
#include "bus-object.h"
int service_parse_argv(
const char *service,

View File

@ -20,10 +20,12 @@
#include "bootspec.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
#include "bus-message.h"
#include "bus-print-properties.h"
#include "bus-unit-procs.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "bus-wait-for-jobs.h"
#include "bus-wait-for-units.h"
#include "cgroup-show.h"

View File

@ -9,15 +9,17 @@
#include "sd-bus.h"
#include "bus-error.h"
#include "bus-util.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
#include "bus-print-properties.h"
#include "format-table.h"
#include "in-addr-util.h"
#include "main-func.h"
#include "pager.h"
#include "parse-util.h"
#include "pretty-print.h"
#include "spawn-polkit-agent.h"
#include "sparse-endian.h"
#include "spawn-polkit-agent.h"
#include "string-table.h"
#include "strv.h"
#include "terminal-util.h"

View File

@ -12,9 +12,11 @@
#include "alloc-util.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-get-properties.h"
#include "bus-locator.h"
#include "bus-log-control-api.h"
#include "bus-map-properties.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "clock-util.h"
#include "conf-files.h"
#include "def.h"

View File

@ -3,6 +3,7 @@
#include "sd-bus.h"
#include "alloc-util.h"
#include "bus-get-properties.h"
#include "bus-internal.h"
#include "bus-log-control-api.h"
#include "bus-protocol.h"

View File

@ -643,6 +643,13 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) {
supported_parent = true;
supported_transport = true;
}
} else if (streq(subsys, "spi")) {
const char *sysnum;
if (sd_device_get_sysnum(parent, &sysnum) >= 0 && sysnum) {
path_prepend(&path, "cs-%s", sysnum);
parent = skip_subsystem(parent, "spi");
}
}
if (!parent)