summaryrefslogtreecommitdiffstats
path: root/src/service-dbus
diff options
context:
space:
mode:
authorVitezslav Crhonek <vcrhonek@redhat.com>2013-11-11 16:50:04 +0100
committerVitezslav Crhonek <vcrhonek@redhat.com>2013-11-11 16:50:04 +0100
commitc4d5ed79d58df276311f3f40cf563dd8dda19a79 (patch)
tree8bf96da4a1c82aac8fd1360f4ece8cd7dff02df4 /src/service-dbus
parent2d81fdc4583e4b4c6d7a0c220ff14ad1b0defc34 (diff)
downloadopenlmi-providers-c4d5ed79d58df276311f3f40cf563dd8dda19a79.tar.gz
openlmi-providers-c4d5ed79d58df276311f3f40cf563dd8dda19a79.tar.xz
openlmi-providers-c4d5ed79d58df276311f3f40cf563dd8dda19a79.zip
Service: Remove maximum boundary for amount of services.
Diffstat (limited to 'src/service-dbus')
-rw-r--r--src/service-dbus/util/serviceutil.c24
-rw-r--r--src/service-dbus/util/serviceutil.h1
2 files changed, 22 insertions, 3 deletions
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;