From 46d107c270e7d0d00956920c142996ab786ea9a1 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sun, 28 Apr 2024 15:52:38 +0530 Subject: npassd/collection/aliases: init --- src/npassd/collection.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/npassd/collection.c b/src/npassd/collection.c index 6fecf16..97f1e31 100644 --- a/src/npassd/collection.c +++ b/src/npassd/collection.c @@ -46,6 +46,7 @@ static void collection_free(struct collection *c) return; sd_bus_slot_unref(c->slot); + sd_bus_slot_unref(c->slot); free(c->path); free(c->alias); @@ -177,6 +178,7 @@ static int collection_alloc(sd_bus *bus, struct collection **p, uint64_t modified) { struct collection *collection; + char *alias_path; int ret; *p = malloc(sizeof(**p)); @@ -218,7 +220,7 @@ static int collection_alloc(sd_bus *bus, struct collection **p, collection->root); if (ret < 0) { collection_free(collection); - print_err("%s", "Failed to create collection object path"); + print_err("%s", "Failed to build collection object path"); return -ENOMEM; } ret = dbus_objpath_alnumify(collection->path); @@ -231,6 +233,25 @@ static int collection_alloc(sd_bus *bus, struct collection **p, ret = sd_bus_add_object_vtable(bus, &collection->slot, collection->path, COLLECTION_IFACE, collection_vtable, collection); + if (ret < 0) { + collection_free(collection); + print_err("Failed to connect to bus: %s", strerror(-ret)); + return ret; + } else if (alias == NULL) { + return 0; + } + + ret = asprintf(&alias_path, DBUS_OBJECT_PATH "/aliases/%s", alias); + if (ret < 0) { + collection_free(collection); + print_err("%s", "Failed to build collection alias path"); + return -ENOMEM; + } + + ret = sd_bus_add_object_vtable(bus, &collection->slot, alias_path, + COLLECTION_IFACE, collection_vtable, + collection); + free(alias_path); if (ret < 0) { collection_free(collection); print_err("Failed to connect to bus: %s", strerror(-ret)); -- cgit v1.2.3