diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-04-26 22:48:10 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-04-27 10:59:14 +0530 |
commit | 06e3f1885fc112093f867cd5d7a8b163ef28650c (patch) | |
tree | e60eb7e80f76d45f294131ab8de2d9ce1f0c1657 /src/npassd/service.c | |
parent | 8ce5f52567f486dbad1eb3f91383f62395df7581 (diff) |
npassd/session: refactor
- mak use of list(3)
Diffstat (limited to 'src/npassd/service.c')
-rw-r--r-- | src/npassd/service.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/npassd/service.c b/src/npassd/service.c index b294cf0..b179735 100644 --- a/src/npassd/service.c +++ b/src/npassd/service.c @@ -1,5 +1,6 @@ #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <systemd/sd-bus.h> #include "npassd/common.h" @@ -33,9 +34,10 @@ static int handle_open_session(sd_bus_message *msg, void *data, sd_bus_error *ret_error) { struct service *service = data; - int ret, session_slot_no; + struct session *session; const char *sender; char *algo; + int ret; ret = sd_bus_message_read(msg, "s", &algo); if (ret < 0) @@ -48,27 +50,21 @@ static int handle_open_session(sd_bus_message *msg, void *data, return -ENOTSUP; } - session_slot_no = session_slot_available(service->session, MAX_SESSION); - if (session_slot_no < 0) { - print_err("No free slot available: %s", - strerror(-session_slot_no)); - return ret; - } - sender = sd_bus_message_get_sender(msg); - ret = session_new(service->bus, &service->session[session_slot_no], - session_slot_no, sender); + ret = session_new(service->bus, &session, sender); if (ret < 0) return ret; - return sd_bus_reply_method_return( - msg, "vo", "s", NULL, service->session[session_slot_no].path); + LIST_INSERT_HEAD(&service->sessions, session, dlist); + return sd_bus_reply_method_return(msg, "vo", "s", NULL, session->path); } void service_free(struct service *service) { - for (int i = 0; i < MAX_SESSION; i++) - session_free(&service->session[i]); + struct session *p; + + LIST_FOREACH(p, &service->sessions, dlist) + session_free(p); sd_bus_slot_unref(service->slot); } @@ -78,7 +74,7 @@ int service_init(sd_bus *bus, struct service *service) int ret; service->bus = bus; - session_init(service->session, MAX_SESSION); + LIST_INIT(&service->sessions); ret = sd_bus_add_object_vtable(service->bus, &service->slot, DBUS_OBJECT_PATH, SERVICE_IFACE, |