Merge pull request #8953 from yuwata/bus-macro
core: simplify dbus properties
This commit is contained in:
commit
e4915c2797
|
@ -164,3 +164,6 @@ static inline const char *skip_dev_prefix(const char *p) {
|
|||
}
|
||||
|
||||
bool empty_or_root(const char *root);
|
||||
static inline const char *empty_to_root(const char *path) {
|
||||
return isempty(path) ? "/" : path;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ static inline const char *empty_to_null(const char *p) {
|
|||
return isempty(p) ? NULL : p;
|
||||
}
|
||||
|
||||
static inline const char *strdash_if_empty(const char *str) {
|
||||
static inline const char *empty_to_dash(const char *str) {
|
||||
return isempty(str) ? "-" : str;
|
||||
}
|
||||
|
||||
|
|
|
@ -914,10 +914,6 @@ static int on_property(const char *interface, const char *name, const char *sign
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char *strdash(const char *x) {
|
||||
return isempty(x) ? "-" : x;
|
||||
}
|
||||
|
||||
static int introspect(int argc, char **argv, void *userdata) {
|
||||
static const struct hash_ops member_hash_ops = {
|
||||
.hash = member_hash_func,
|
||||
|
@ -1104,15 +1100,15 @@ static int introspect(int argc, char **argv, void *userdata) {
|
|||
|
||||
rv = ellipsized;
|
||||
} else
|
||||
rv = strdash(m->result);
|
||||
rv = empty_to_dash(m->result);
|
||||
|
||||
printf("%s%s%-*s%s %-*s %-*s %-*s%s%s%s%s%s%s\n",
|
||||
is_interface ? ansi_highlight() : "",
|
||||
is_interface ? "" : ".",
|
||||
- !is_interface + (int) name_width, strdash(streq_ptr(m->type, "interface") ? m->interface : m->name),
|
||||
- !is_interface + (int) name_width, empty_to_dash(streq_ptr(m->type, "interface") ? m->interface : m->name),
|
||||
is_interface ? ansi_normal() : "",
|
||||
(int) type_width, strdash(m->type),
|
||||
(int) signature_width, strdash(m->signature),
|
||||
(int) type_width, empty_to_dash(m->type),
|
||||
(int) signature_width, empty_to_dash(m->signature),
|
||||
(int) result_width, rv,
|
||||
(m->flags & SD_BUS_VTABLE_DEPRECATED) ? " deprecated" : (m->flags || m->writable ? "" : " -"),
|
||||
(m->flags & SD_BUS_VTABLE_METHOD_NO_REPLY) ? " no-reply" : "",
|
||||
|
|
|
@ -149,7 +149,7 @@ static void show_cg_info(const char *controller, const char *path) {
|
|||
if (cg_all_unified() == 0 && controller && !streq(controller, SYSTEMD_CGROUP_CONTROLLER))
|
||||
printf("Controller %s; ", controller);
|
||||
|
||||
printf("Control group %s:\n", isempty(path) ? "/" : path);
|
||||
printf("Control group %s:\n", empty_to_root(path));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
|
|
@ -529,10 +529,6 @@ static int refresh(const char *root, Hashmap *a, Hashmap *b, unsigned iteration)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char *empty_to_slash(const char *p) {
|
||||
return isempty(p) ? "/" : p;
|
||||
}
|
||||
|
||||
static int group_compare(const void*a, const void *b) {
|
||||
const Group *x = *(Group**)a, *y = *(Group**)b;
|
||||
|
||||
|
@ -542,9 +538,9 @@ static int group_compare(const void*a, const void *b) {
|
|||
* recursive summing is off, since that is actually
|
||||
* not accumulative for all children. */
|
||||
|
||||
if (path_startswith(empty_to_slash(y->path), empty_to_slash(x->path)))
|
||||
if (path_startswith(empty_to_root(y->path), empty_to_root(x->path)))
|
||||
return -1;
|
||||
if (path_startswith(empty_to_slash(x->path), empty_to_slash(y->path)))
|
||||
if (path_startswith(empty_to_root(x->path), empty_to_root(y->path)))
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -693,7 +689,7 @@ static void display(Hashmap *a) {
|
|||
|
||||
g = array[j];
|
||||
|
||||
path = empty_to_slash(g->path);
|
||||
path = empty_to_root(g->path);
|
||||
ellipsized = ellipsize(path, path_columns, 33);
|
||||
printf("%-*s", path_columns, ellipsized ?: path);
|
||||
|
||||
|
|
|
@ -51,13 +51,12 @@
|
|||
|
||||
BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_input, exec_input, ExecInput);
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode);
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_home, protect_home, ProtectHome);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_protect_system, protect_system, ProtectSystem);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_home, protect_home, ProtectHome);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system, protect_system, ProtectSystem);
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality, personality, unsigned long);
|
||||
|
||||
static int property_get_environment_files(
|
||||
sd_bus *bus,
|
||||
|
@ -274,10 +273,7 @@ static int property_get_cpu_affinity(
|
|||
assert(reply);
|
||||
assert(c);
|
||||
|
||||
if (c->cpuset)
|
||||
return sd_bus_message_append_array(reply, 'y', c->cpuset, CPU_ALLOC_SIZE(c->cpuset_ncpus));
|
||||
else
|
||||
return sd_bus_message_append_array(reply, 'y', NULL, 0);
|
||||
return sd_bus_message_append_array(reply, 'y', c->cpuset, CPU_ALLOC_SIZE(c->cpuset_ncpus));
|
||||
}
|
||||
|
||||
static int property_get_timer_slack_nsec(
|
||||
|
@ -304,42 +300,6 @@ static int property_get_timer_slack_nsec(
|
|||
return sd_bus_message_append(reply, "t", u);
|
||||
}
|
||||
|
||||
static int property_get_capability_bounding_set(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
ExecContext *c = userdata;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(c);
|
||||
|
||||
return sd_bus_message_append(reply, "t", c->capability_bounding_set);
|
||||
}
|
||||
|
||||
static int property_get_ambient_capabilities(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
ExecContext *c = userdata;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(c);
|
||||
|
||||
return sd_bus_message_append(reply, "t", c->capability_ambient_set);
|
||||
}
|
||||
|
||||
static int property_get_empty_string(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
|
@ -352,7 +312,7 @@ static int property_get_empty_string(
|
|||
assert(bus);
|
||||
assert(reply);
|
||||
|
||||
return sd_bus_message_append(reply, "s", "");
|
||||
return sd_bus_message_append(reply, "s", NULL);
|
||||
}
|
||||
|
||||
static int property_get_syscall_filter(
|
||||
|
@ -470,24 +430,6 @@ static int property_get_syscall_archs(
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int property_get_syscall_errno(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
ExecContext *c = userdata;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(c);
|
||||
|
||||
return sd_bus_message_append(reply, "i", (int32_t) c->syscall_errno);
|
||||
}
|
||||
|
||||
static int property_get_selinux_context(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
|
@ -542,24 +484,6 @@ static int property_get_smack_process_label(
|
|||
return sd_bus_message_append(reply, "(bs)", c->smack_process_label_ignore, c->smack_process_label);
|
||||
}
|
||||
|
||||
static int property_get_personality(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
ExecContext *c = userdata;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(c);
|
||||
|
||||
return sd_bus_message_append(reply, "s", personality_to_string(c->personality));
|
||||
}
|
||||
|
||||
static int property_get_address_families(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
|
@ -644,13 +568,13 @@ static int property_get_syslog_level(
|
|||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
ExecContext *c = userdata;
|
||||
int *s = userdata;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(c);
|
||||
assert(s);
|
||||
|
||||
return sd_bus_message_append(reply, "i", LOG_PRI(c->syslog_priority));
|
||||
return sd_bus_message_append(reply, "i", LOG_PRI(*s));
|
||||
}
|
||||
|
||||
static int property_get_syslog_facility(
|
||||
|
@ -662,13 +586,13 @@ static int property_get_syslog_facility(
|
|||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
ExecContext *c = userdata;
|
||||
int *s = userdata;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(c);
|
||||
assert(s);
|
||||
|
||||
return sd_bus_message_append(reply, "i", LOG_FAC(c->syslog_priority));
|
||||
return sd_bus_message_append(reply, "i", LOG_FAC(*s));
|
||||
}
|
||||
|
||||
static int property_get_stdio_fdname(
|
||||
|
@ -895,13 +819,13 @@ const sd_bus_vtable bus_exec_vtable[] = {
|
|||
SD_BUS_PROPERTY("SyslogPriority", "i", bus_property_get_int, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SyslogIdentifier", "s", NULL, offsetof(ExecContext, syslog_identifier), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("CapabilityBoundingSet", "t", property_get_capability_bounding_set, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("AmbientCapabilities", "t", property_get_ambient_capabilities, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("AmbientCapabilities", "t", NULL, offsetof(ExecContext, capability_ambient_set), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("User", "s", NULL, offsetof(ExecContext, user), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Group", "s", NULL, offsetof(ExecContext, group), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("DynamicUser", "b", bus_property_get_bool, offsetof(ExecContext, dynamic_user), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
|
@ -919,8 +843,8 @@ const sd_bus_vtable bus_exec_vtable[] = {
|
|||
SD_BUS_PROPERTY("ProtectControlGroups", "b", bus_property_get_bool, offsetof(ExecContext, protect_control_groups), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("PrivateNetwork", "b", bus_property_get_bool, offsetof(ExecContext, private_network), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("PrivateUsers", "b", bus_property_get_bool, offsetof(ExecContext, private_users), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("ProtectHome", "s", bus_property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("ProtectSystem", "s", bus_property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("ProtectHome", "s", property_get_protect_home, offsetof(ExecContext, protect_home), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("ProtectSystem", "s", property_get_protect_system, offsetof(ExecContext, protect_system), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SameProcessGroup", "b", bus_property_get_bool, offsetof(ExecContext, same_pgrp), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("UtmpIdentifier", "s", NULL, offsetof(ExecContext, utmp_id), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("UtmpMode", "s", property_get_exec_utmp_mode, offsetof(ExecContext, utmp_mode), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
|
@ -931,8 +855,8 @@ const sd_bus_vtable bus_exec_vtable[] = {
|
|||
SD_BUS_PROPERTY("NoNewPrivileges", "b", bus_property_get_bool, offsetof(ExecContext, no_new_privileges), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SystemCallFilter", "(bas)", property_get_syscall_filter, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SystemCallArchitectures", "as", property_get_syscall_archs, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SystemCallErrorNumber", "i", property_get_syscall_errno, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Personality", "s", property_get_personality, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SystemCallErrorNumber", "i", bus_property_get_int, offsetof(ExecContext, syscall_errno), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Personality", "s", property_get_personality, offsetof(ExecContext, personality), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("LockPersonality", "b", bus_property_get_bool, offsetof(ExecContext, lock_personality), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("RestrictAddressFamilies", "(bas)", property_get_address_families, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("RuntimeDirectoryPreserve", "s", property_get_exec_preserve_mode, offsetof(ExecContext, runtime_directory_preserve_mode), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
|
|
|
@ -99,7 +99,7 @@ static int property_get_virtualization(
|
|||
|
||||
return sd_bus_message_append(
|
||||
reply, "s",
|
||||
v == VIRTUALIZATION_NONE ? "" : virtualization_to_string(v));
|
||||
v == VIRTUALIZATION_NONE ? NULL : virtualization_to_string(v));
|
||||
}
|
||||
|
||||
static int property_get_architecture(
|
||||
|
|
|
@ -102,8 +102,8 @@ const sd_bus_vtable bus_mount_vtable[] = {
|
|||
SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool, offsetof(Mount, lazy_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool, offsetof(Mount, force_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Mount, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("UID", "u", NULL, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("GID", "u", NULL, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
|
|
|
@ -47,29 +47,9 @@ static int property_get_paths(
|
|||
return sd_bus_message_close_container(reply);
|
||||
}
|
||||
|
||||
static int property_get_unit(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
Unit *p = userdata, *trigger;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(p);
|
||||
|
||||
trigger = UNIT_TRIGGER(p);
|
||||
|
||||
return sd_bus_message_append(reply, "s", trigger ? trigger->id : "");
|
||||
}
|
||||
|
||||
const sd_bus_vtable bus_path_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_PROPERTY("Unit", "s", property_get_unit, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Unit", "s", bus_property_get_triggered_unit, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Paths", "a(ss)", property_get_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("MakeDirectory", "b", bus_property_get_bool, offsetof(Path, make_directory), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Path, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
|
|
|
@ -123,12 +123,12 @@ const sd_bus_vtable bus_service_vtable[] = {
|
|||
SD_BUS_PROPERTY("FileDescriptorStoreMax", "u", bus_property_get_unsigned, offsetof(Service, n_fd_store_max), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("NFileDescriptorStore", "u", bus_property_get_unsigned, offsetof(Service, n_fd_store), 0),
|
||||
SD_BUS_PROPERTY("StatusText", "s", NULL, offsetof(Service, status_text), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("StatusErrno", "i", NULL, offsetof(Service, status_errno), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("StatusErrno", "i", bus_property_get_int, offsetof(Service, status_errno), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Service, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("USBFunctionDescriptors", "s", NULL, offsetof(Service, usb_function_descriptors), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("USBFunctionStrings", "s", NULL, offsetof(Service, usb_function_strings), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("UID", "u", NULL, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("GID", "u", NULL, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("NRestarts", "u", bus_property_get_unsigned, offsetof(Service, n_restarts), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
|
||||
BUS_EXEC_STATUS_VTABLE("ExecMain", offsetof(Service, main_exec_status), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
|
|
|
@ -146,8 +146,8 @@ const sd_bus_vtable bus_socket_vtable[] = {
|
|||
SD_BUS_PROPERTY("SocketProtocol", "i", bus_property_get_int, offsetof(Socket, socket_protocol), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("TriggerLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Socket, trigger_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("TriggerLimitBurst", "u", bus_property_get_unsigned, offsetof(Socket, trigger_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("UID", "u", NULL, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("GID", "u", NULL, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPre", offsetof(Socket, exec_command[SOCKET_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPost", offsetof(Socket, exec_command[SOCKET_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStopPre", offsetof(Socket, exec_command[SOCKET_EXEC_STOP_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
|
|
|
@ -72,8 +72,8 @@ const sd_bus_vtable bus_swap_vtable[] = {
|
|||
SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Swap, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Swap, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Swap, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("UID", "u", NULL, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("GID", "u", NULL, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
BUS_EXEC_COMMAND_VTABLE("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
BUS_EXEC_COMMAND_VTABLE("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
SD_BUS_VTABLE_END
|
||||
|
|
|
@ -103,26 +103,6 @@ static int property_get_calendar_timers(
|
|||
return sd_bus_message_close_container(reply);
|
||||
}
|
||||
|
||||
static int property_get_unit(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
Unit *u = userdata, *trigger;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(u);
|
||||
|
||||
trigger = UNIT_TRIGGER(u);
|
||||
|
||||
return sd_bus_message_append(reply, "s", trigger ? trigger->id : "");
|
||||
}
|
||||
|
||||
static int property_get_next_elapse_monotonic(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
|
@ -145,7 +125,7 @@ static int property_get_next_elapse_monotonic(
|
|||
|
||||
const sd_bus_vtable bus_timer_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_PROPERTY("Unit", "s", property_get_unit, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Unit", "s", bus_property_get_triggered_unit, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("TimersMonotonic", "a(stt)", property_get_monotonic_timers, 0, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
SD_BUS_PROPERTY("TimersCalendar", "a(sst)", property_get_calendar_timers, 0, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
SD_BUS_PROPERTY("NextElapseUSecRealtime", "t", bus_property_get_usec, offsetof(Timer, next_elapse_realtime), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
|
|
|
@ -81,7 +81,7 @@ static int property_get_following(
|
|||
assert(u);
|
||||
|
||||
f = unit_following(u);
|
||||
return sd_bus_message_append(reply, "s", f ? f->id : "");
|
||||
return sd_bus_message_append(reply, "s", f ? f->id : NULL);
|
||||
}
|
||||
|
||||
static int property_get_dependencies(
|
||||
|
@ -235,7 +235,7 @@ static int property_get_unit_file_preset(
|
|||
r = unit_get_unit_file_preset(u);
|
||||
|
||||
return sd_bus_message_append(reply, "s",
|
||||
r < 0 ? "":
|
||||
r < 0 ? NULL:
|
||||
r > 0 ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
|
@ -918,7 +918,7 @@ static int property_get_cgroup(
|
|||
sd_bus_error *error) {
|
||||
|
||||
Unit *u = userdata;
|
||||
const char *t;
|
||||
const char *t = NULL;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
|
@ -931,9 +931,7 @@ static int property_get_cgroup(
|
|||
* other cases we report as-is. */
|
||||
|
||||
if (u->cgroup_path)
|
||||
t = isempty(u->cgroup_path) ? "/" : u->cgroup_path;
|
||||
else
|
||||
t = "";
|
||||
t = empty_to_root(u->cgroup_path);
|
||||
|
||||
return sd_bus_message_append(reply, "s", t);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,26 @@
|
|||
#include "user-util.h"
|
||||
#include "unit.h"
|
||||
|
||||
int bus_property_get_triggered_unit(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
Unit *u = userdata, *trigger;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
assert(u);
|
||||
|
||||
trigger = UNIT_TRIGGER(u);
|
||||
|
||||
return sd_bus_message_append(reply, "s", trigger ? trigger->id : NULL);
|
||||
}
|
||||
|
||||
BUS_DEFINE_SET_TRANSIENT(mode_t, "u", uint32_t, mode_t, "%040o");
|
||||
BUS_DEFINE_SET_TRANSIENT(unsigned, "u", uint32_t, unsigned, "%" PRIu32);
|
||||
BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(user, valid_user_group_name_or_id);
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "sd-bus.h"
|
||||
#include "unit.h"
|
||||
|
||||
int bus_property_get_triggered_unit(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_SET_TRANSIENT(function, bus_type, type, cast_type, fmt) \
|
||||
int bus_set_transient_##function( \
|
||||
Unit *u, \
|
||||
|
|
|
@ -777,7 +777,7 @@ static int bus_socket_inotify_setup(sd_bus *b) {
|
|||
if (IN_SET(errno, ENOENT, ELOOP))
|
||||
break; /* This component doesn't exist yet, or the path contains a cyclic symlink right now */
|
||||
|
||||
r = log_debug_errno(errno, "Failed to add inotify watch on %s: %m", isempty(prefix) ? "/" : prefix);
|
||||
r = log_debug_errno(errno, "Failed to add inotify watch on %s: %m", empty_to_root(prefix));
|
||||
goto fail;
|
||||
} else
|
||||
new_watches[n++] = wd;
|
||||
|
|
|
@ -335,10 +335,10 @@ static int list_machines(int argc, char *argv[], void *userdata) {
|
|||
r = table_add_many(table,
|
||||
TABLE_STRING, name,
|
||||
TABLE_STRING, class,
|
||||
TABLE_STRING, strdash_if_empty(service),
|
||||
TABLE_STRING, strdash_if_empty(os),
|
||||
TABLE_STRING, strdash_if_empty(version_id),
|
||||
TABLE_STRING, strdash_if_empty(addresses));
|
||||
TABLE_STRING, empty_to_dash(service),
|
||||
TABLE_STRING, empty_to_dash(os),
|
||||
TABLE_STRING, empty_to_dash(version_id),
|
||||
TABLE_STRING, empty_to_dash(addresses));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add table row: %m");
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ static void test_unit_name_from_path_one(const char *path, const char *suffix, c
|
|||
_cleanup_free_ char *k = NULL;
|
||||
assert_se(unit_name_to_path(t, &k) == 0);
|
||||
puts(strna(k));
|
||||
assert_se(path_equal(k, isempty(path) ? "/" : path));
|
||||
assert_se(path_equal(k, empty_to_root(path)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ static void test_unit_name_from_path_instance_one(const char *pattern, const cha
|
|||
|
||||
assert_se(unit_name_to_instance(t, &k) > 0);
|
||||
assert_se(unit_name_path_unescape(k, &v) == 0);
|
||||
assert_se(path_equal(v, isempty(path) ? "/" : path));
|
||||
assert_se(path_equal(v, empty_to_root(path)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1504,7 +1504,7 @@ static int create_item(Item *i) {
|
|||
|
||||
if (IN_SET(i->type, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA)) {
|
||||
|
||||
if (btrfs_is_subvol(isempty(arg_root) ? "/" : arg_root) <= 0)
|
||||
if (btrfs_is_subvol(empty_to_root(arg_root)) <= 0)
|
||||
|
||||
/* Don't create a subvolume unless the
|
||||
* root directory is one, too. We do
|
||||
|
|
Loading…
Reference in a new issue