Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modules/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/modules/bus.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "bus.h"
#include "utils.h"
#include <ctype.h>

#define GET_BUS(a) sd_bus *tmp = a->bus; if (!tmp) { tmp = a->type == USER_BUS ? userbus : sysbus; } if (!tmp) { return -1; }

Expand Down Expand Up @@ -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 = '_';
}
}
}
2 changes: 1 addition & 1 deletion src/modules/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/wizard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading