0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering#pragma once
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering/***
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering This file is part of systemd.
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering Copyright 2013 Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering systemd is free software; you can redistribute it and/or modify it
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering under the terms of the GNU Lesser General Public License as published by
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering (at your option) any later version.
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering systemd is distributed in the hope that it will be useful, but
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering Lesser General Public License for more details.
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering You should have received a copy of the GNU Lesser General Public License
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0c8570287400ba57d3705a2f62dd26039121ea6fLennart Poettering***/
0c8570287400ba57d3705a2f62dd26039121ea6fLennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering#include <stdbool.h>
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#include <stddef.h>
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#include <stdint.h>
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#include <sys/types.h>
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#include "sd-bus-vtable.h"
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#include "sd-bus.h"
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#include "sd-event.h"
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0c8570287400ba57d3705a2f62dd26039121ea6fLennart Poettering#include "hashmap.h"
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#include "install.h"
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#include "macro.h"
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#include "string-util.h"
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering#include "time-util.h"
e7d179acb9f50dec4a16c6c222dd147d7e53c6bbLennart Poettering
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringtypedef enum BusTransport {
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering BUS_TRANSPORT_LOCAL,
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering BUS_TRANSPORT_REMOTE,
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering BUS_TRANSPORT_MACHINE,
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering _BUS_TRANSPORT_MAX,
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering _BUS_TRANSPORT_INVALID = -1
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering} BusTransport;
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poetteringtypedef int (*bus_property_set_t) (sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poetteringstruct bus_properties_map {
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering const char *member;
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering const char *signature;
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering bus_property_set_t set;
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering size_t offset;
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering};
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_message_map_all_properties(sd_bus_message *m, const struct bus_properties_map *map, void *userdata);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_message_map_properties_changed(sd_bus_message *m, const struct bus_properties_map *map, void *userdata);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_map_all_properties(sd_bus *bus, const char *destination, const char *path, const struct bus_properties_map *map, void *userdata);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringtypedef bool (*check_idle_t)(void *userdata);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout, check_idle_t check_idle, void *userdata);
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poetteringint bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error);
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poetteringint bus_check_peercred(sd_bus *c);
86e9cbcaeda647eb4f1db77333f7069d5bf549f1Lennart Poettering
d76f90f1711e55d23ee6c8c0957fa3db17927327Lennart Poetteringint bus_test_polkit(sd_bus_message *call, int capability, const char *action, const char **details, uid_t good_user, bool *_challenge, sd_bus_error *e);
d76f90f1711e55d23ee6c8c0957fa3db17927327Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_verify_polkit_async(sd_bus_message *call, int capability, const char *action, const char **details, bool interactive, uid_t good_user, Hashmap **registry, sd_bus_error *error);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringvoid bus_verify_polkit_async_registry_free(Hashmap *registry);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_connect_system_systemd(sd_bus **_bus);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_connect_user_systemd(sd_bus **_bus);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_print_property(const char *name, sd_bus_message *property, bool all);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringint 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);
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering#define bus_property_get_usec ((sd_bus_property_get_t) NULL)
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering#define bus_property_set_usec ((sd_bus_property_set_t) NULL)
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poetteringassert_cc(sizeof(int) == sizeof(int32_t));
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering#define bus_property_get_int ((sd_bus_property_get_t) NULL)
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poettering
0d2cd47617b423f37d7425be7a56ae2fca8ff9f6Lennart Poetteringassert_cc(sizeof(unsigned) == sizeof(unsigned));
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#define bus_property_get_unsigned ((sd_bus_property_get_t) NULL)
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering/* On 64bit machines we can use the default serializer for size_t and
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering * friends, otherwise we need to cast this manually */
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#if __SIZEOF_SIZE_T__ == 8
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#define bus_property_get_size ((sd_bus_property_get_t) NULL)
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering#else
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringint 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);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#endif
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#if __SIZEOF_LONG__ == 8
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#define bus_property_get_long ((sd_bus_property_get_t) NULL)
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#define bus_property_get_ulong ((sd_bus_property_get_t) NULL)
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#else
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint 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);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint 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);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#endif
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering/* uid_t and friends on Linux 32 bit. This means we can just use the
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering * default serializer for 32bit unsigned, for serializing it, and map
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering * it to NULL here */
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringassert_cc(sizeof(uid_t) == sizeof(uint32_t));
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#define bus_property_get_uid ((sd_bus_property_get_t) NULL)
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringassert_cc(sizeof(gid_t) == sizeof(uint32_t));
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#define bus_property_get_gid ((sd_bus_property_get_t) NULL)
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringassert_cc(sizeof(pid_t) == sizeof(uint32_t));
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#define bus_property_get_pid ((sd_bus_property_get_t) NULL)
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringassert_cc(sizeof(mode_t) == sizeof(uint32_t));
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#define bus_property_get_mode ((sd_bus_property_get_t) NULL)
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_log_parse_error(int r);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_log_create_error(int r);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringtypedef struct UnitInfo {
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *machine;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *id;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *description;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *load_state;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *active_state;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *sub_state;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *following;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *unit_path;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering uint32_t job_id;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *job_type;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *job_path;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering} UnitInfo;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_parse_unit_info(sd_bus_message *message, UnitInfo *u);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type) \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering int function(sd_bus *bus, \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *path, \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *interface, \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *property, \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering sd_bus_message *reply, \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering void *userdata, \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering sd_bus_error *error) { \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering const char *value; \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering type *field = userdata; \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering int r; \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering assert(bus); \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering assert(reply); \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering assert(field); \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering value = strempty(name##_to_string(*field)); \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering r = sd_bus_message_append_basic(reply, 's', value); \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering if (r < 0) \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering return r; \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering return 1; \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering } \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering struct __useless_struct_to_allow_trailing_semicolon__
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering#define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags))
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_append_unit_property_assignment(sd_bus_message *m, const char *assignment);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringtypedef struct BusWaitForJobs BusWaitForJobs;
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringvoid bus_wait_for_jobs_free(BusWaitForJobs *d);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char *extra_args);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_wait_for_jobs_one(BusWaitForJobs *d, const char *path, bool quiet);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(BusWaitForJobs*, bus_wait_for_jobs_free);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poetteringint bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, unsigned *n_changes);
30c778094b90a637c6691c462a66df81eeb865b5Lennart Poettering
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringint bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, const char *external_id, char **ret_path);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringint bus_path_decode_unique(const char *path, const char *prefix, char **ret_sender, char **ret_external);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringbool is_kdbus_wanted(void);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringbool is_kdbus_available(void);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poetteringint 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);
8e54f5d90a6b9dd1ff672fb97ea98de66c49e332Lennart Poettering