From c4d5ed79d58df276311f3f40cf563dd8dda19a79 Mon Sep 17 00:00:00 2001 From: Vitezslav Crhonek Date: Mon, 11 Nov 2013 16:50:04 +0100 Subject: Service: Remove maximum boundary for amount of services. --- src/service-dbus/util/serviceutil.c | 24 +++++++++++++++++++++--- src/service-dbus/util/serviceutil.h | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/service-dbus/util/serviceutil.c b/src/service-dbus/util/serviceutil.c index 2decc62..50b18b9 100644 --- a/src/service-dbus/util/serviceutil.c +++ b/src/service-dbus/util/serviceutil.c @@ -30,7 +30,7 @@ #include "serviceutil.h" -#define MAX_SLIST_CNT 1000 +#define INITIAL_SLIST_NALLOC 100 #define MANAGER_NAME "org.freedesktop.systemd1" #define MANAGER_OP "/org/freedesktop/systemd1" @@ -92,11 +92,16 @@ SList *service_find_all( } slist = malloc(sizeof(SList)); - if (!slist) return NULL; - slist->name = malloc(MAX_SLIST_CNT * sizeof(char *)); + if (!slist) { + strncpy(output, "Insufficient memory", output_len); + return NULL; + } + slist->nalloc = INITIAL_SLIST_NALLOC; + slist->name = malloc(slist->nalloc * sizeof(char *)); if (!slist->name) { free(slist); g_object_unref(manager_proxy); + strncpy(output, "Insufficient memory", output_len); return NULL; } slist->cnt = 0; @@ -105,6 +110,19 @@ SList *service_find_all( while (g_variant_iter_loop(arr, "(ss)", &primary_unit_name, NULL)) { /* Ignore instantiable units (containing '@') until we find out how to properly present them */ if (strstr(primary_unit_name, ".service") && strchr(primary_unit_name, '@') == NULL) { + if (slist->cnt >= slist->nalloc) { + char **tmpp = NULL; + slist->nalloc *= 2; + tmpp = realloc(slist->name, slist->nalloc * sizeof(char *)); + if (!tmpp) { + g_variant_iter_free(arr); + free(slist); + g_object_unref(manager_proxy); + strncpy(output, "Insufficient memory", output_len); + return NULL; + } + slist->name = tmpp; + } tmps = strdup(primary_unit_name); if (!tmps) continue; diff --git a/src/service-dbus/util/serviceutil.h b/src/service-dbus/util/serviceutil.h index 020cfb7..fbdadad 100644 --- a/src/service-dbus/util/serviceutil.h +++ b/src/service-dbus/util/serviceutil.h @@ -49,6 +49,7 @@ struct _Service { struct _SList { char **name; int cnt; + int nalloc; }; typedef struct _Service Service; -- cgit