diff --git a/src/modules/backlight.c b/src/modules/backlight.c index 9f4686d..a72be33 100644 --- a/src/modules/backlight.c +++ b/src/modules/backlight.c @@ -466,7 +466,7 @@ static int parse_bus_reply(sd_bus_message *reply, const char *member, void *user r = sd_bus_message_read(reply, "sd", &mon_id, pct); if (r >= 0) { char key[PATH_MAX + 1]; - snprintf(key, sizeof(key), "/org/clightd/clightd/Backlight2/%s", mon_id); + make_valid_obj_path(key, sizeof(key), "/org/clightd/clightd/Backlight2", mon_id); map_put(bls, key, pct); } sd_bus_message_exit_container(reply); diff --git a/src/modules/bus.c b/src/modules/bus.c index b64448b..b8b86b1 100644 --- a/src/modules/bus.c +++ b/src/modules/bus.c @@ -1,5 +1,6 @@ #include "bus.h" #include "utils.h" +#include #define GET_BUS(a) sd_bus *tmp = a->bus; if (!tmp) { tmp = a->type == USER_BUS ? userbus : sysbus; } if (!tmp) { return -1; } @@ -206,3 +207,17 @@ static int proxy_async_request(struct sd_bus_message *m, void *userdata, sd_bus_ sd_bus *get_user_bus(void) { return userbus; } + +/* + * Build a valid D-Bus object path from root + basename. + * Replaces any char not in [A-Za-z0-9_] with '_'. + * Mirrors Clightd's make_valid_obj_path in bus_utils.c. + */ +void make_valid_obj_path(char *storage, size_t size, const char *root, const char *name) { + snprintf(storage, size, "%s/%s", root, name); + for (char *p = storage + strlen(root) + 1; *p; p++) { + if (!isalnum((unsigned char)*p) && *p != '_') { + *p = '_'; + } + } +} diff --git a/src/modules/bus.h b/src/modules/bus.h index 0f8c449..cef05ac 100644 --- a/src/modules/bus.h +++ b/src/modules/bus.h @@ -37,7 +37,7 @@ typedef struct { #define USERBUS_ARG(name, ...) USERBUS_ARG_REPLY(name, NULL, NULL, __VA_ARGS__); #define SYSBUS_ARG(name, ...) SYSBUS_ARG_REPLY(name, NULL, NULL, __VA_ARGS__); - +void make_valid_obj_path(char *storage, size_t size, const char *root, const char *name); int call(const bus_args *a, const char *signature, ...); int add_match(const bus_args *a, sd_bus_slot **slot, sd_bus_message_handler_t cb); int set_property(const bus_args *a, const char *type, const uintptr_t value); diff --git a/src/modules/wizard.c b/src/modules/wizard.c index 95a7815..44fea74 100644 --- a/src/modules/wizard.c +++ b/src/modules/wizard.c @@ -229,7 +229,7 @@ static int parse_bus_reply(sd_bus_message *reply, const char *member, void *user r = sd_bus_message_read(reply, "sd", &sysname, NULL); if (r >= 0) { char obj_path[PATH_MAX + 1]; - snprintf(obj_path, sizeof(obj_path), "/org/clightd/clightd/Backlight2/%s", sysname); + make_valid_obj_path(obj_path, sizeof(obj_path), "/org/clightd/clightd/Backlight2", sysname); bl_obj_path = strdup(obj_path); } sd_bus_message_exit_container(reply);