1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 01:27:11 +03:00

bus-unit-util: use struct __useless_struct_to_allow_trailing_semicolon__ in DEFINE_BUS_APPEND_PARSE{,_PTR} macro

This commit is contained in:
Yu Watanabe 2018-01-02 00:50:19 +09:00
parent f76e92af1c
commit 0cf6628e54

View File

@ -72,62 +72,71 @@ int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u) {
&u->job_path); &u->job_path);
} }
#define DEFINE_BUS_APPEND_PARSE_PTR(bus_type, cast_type, type, parse_func) \ #define DEFINE_BUS_APPEND_PARSE_PTR(bus_type, cast_type, type, parse_func) \
static int bus_append_##parse_func(sd_bus_message *m, const char *field, const char *eq) { \ static int bus_append_##parse_func( \
type val; \ sd_bus_message *m, \
int r; \ const char *field, \
\ const char *eq) { \
r = parse_func(eq, &val); \ type val; \
if (r < 0) \ int r; \
return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq); \ \
\ r = parse_func(eq, &val); \
r = sd_bus_message_append(m, "(sv)", field, bus_type, (cast_type) val); \ if (r < 0) \
if (r < 0) \ return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq); \
return bus_log_create_error(r); \ \
\ r = sd_bus_message_append(m, "(sv)", field, \
return 1; \ bus_type, (cast_type) val); \
} if (r < 0) \
return bus_log_create_error(r); \
\
return 1; \
} \
struct __useless_struct_to_allow_trailing_semicolon__
#define DEFINE_BUS_APPEND_PARSE(bus_type, parse_func) \ #define DEFINE_BUS_APPEND_PARSE(bus_type, parse_func) \
static int bus_append_##parse_func(sd_bus_message *m, const char *field, const char *eq) { \ static int bus_append_##parse_func( \
int r; \ sd_bus_message *m, \
\ const char *field, \
r = parse_func(eq); \ const char *eq) { \
if (r < 0) { \ int r; \
log_error("Failed to parse %s: %s", field, eq); \ \
return -EINVAL; \ r = parse_func(eq); \
} \ if (r < 0) { \
\ log_error("Failed to parse %s: %s", field, eq); \
r = sd_bus_message_append(m, "(sv)", field, bus_type, (int32_t) r); \ return -EINVAL; \
if (r < 0) \ } \
return bus_log_create_error(r); \ \
\ r = sd_bus_message_append(m, "(sv)", field, \
return 1; \ bus_type, (int32_t) r); \
} if (r < 0) \
return bus_log_create_error(r); \
\
return 1; \
} \
struct __useless_struct_to_allow_trailing_semicolon__
DEFINE_BUS_APPEND_PARSE("b", parse_boolean) DEFINE_BUS_APPEND_PARSE("b", parse_boolean);
DEFINE_BUS_APPEND_PARSE("i", ioprio_class_from_string) DEFINE_BUS_APPEND_PARSE("i", ioprio_class_from_string);
DEFINE_BUS_APPEND_PARSE("i", ip_tos_from_string) DEFINE_BUS_APPEND_PARSE("i", ip_tos_from_string);
DEFINE_BUS_APPEND_PARSE("i", log_facility_unshifted_from_string) DEFINE_BUS_APPEND_PARSE("i", log_facility_unshifted_from_string);
DEFINE_BUS_APPEND_PARSE("i", log_level_from_string) DEFINE_BUS_APPEND_PARSE("i", log_level_from_string);
DEFINE_BUS_APPEND_PARSE("i", parse_errno) DEFINE_BUS_APPEND_PARSE("i", parse_errno);
DEFINE_BUS_APPEND_PARSE("i", sched_policy_from_string) DEFINE_BUS_APPEND_PARSE("i", sched_policy_from_string);
DEFINE_BUS_APPEND_PARSE("i", secure_bits_from_string) DEFINE_BUS_APPEND_PARSE("i", secure_bits_from_string);
DEFINE_BUS_APPEND_PARSE("i", signal_from_string_try_harder) DEFINE_BUS_APPEND_PARSE("i", signal_from_string_try_harder);
DEFINE_BUS_APPEND_PARSE("i", socket_protocol_from_name) DEFINE_BUS_APPEND_PARSE("i", socket_protocol_from_name);
DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, ioprio_parse_priority) DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, ioprio_parse_priority);
DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, parse_nice) DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, parse_nice);
DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, safe_atoi) DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, safe_atoi);
DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, nsec_t, parse_nsec) DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, nsec_t, parse_nsec);
DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_blkio_weight_parse) DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_blkio_weight_parse);
DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_cpu_shares_parse) DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_cpu_shares_parse);
DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_weight_parse) DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_weight_parse);
DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, unsigned long, mount_propagation_flags_from_string) DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, unsigned long, mount_propagation_flags_from_string);
DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, usec_t, parse_sec) DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, safe_atou64);
DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, safe_atou64) DEFINE_BUS_APPEND_PARSE_PTR("u", uint32_t, mode_t, parse_mode);
DEFINE_BUS_APPEND_PARSE_PTR("u", uint32_t, mode_t, parse_mode) DEFINE_BUS_APPEND_PARSE_PTR("u", uint32_t, unsigned, safe_atou);
DEFINE_BUS_APPEND_PARSE_PTR("u", uint32_t, unsigned, safe_atou) DEFINE_BUS_APPEND_PARSE_PTR("x", int64_t, int64_t, safe_atoi64);
DEFINE_BUS_APPEND_PARSE_PTR("x", int64_t, int64_t, safe_atoi64)
static inline int bus_append_string(sd_bus_message *m, const char *field, const char *eq) { static inline int bus_append_string(sd_bus_message *m, const char *field, const char *eq) {
int r; int r;