summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-07 13:35:00 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-07 13:35:00 +0200
commit0ab80c977898493d0f0f1d4962bf867601127a65 (patch)
tree52e3d9553cb9eaa1f1889865014539bf60c537c4 /src
parentcbd686eb63dd2f37f2d53641fcd565ff4ac6900e (diff)
downloadabrt-0ab80c977898493d0f0f1d4962bf867601127a65.tar.gz
abrt-0ab80c977898493d0f0f1d4962bf867601127a65.tar.xz
abrt-0ab80c977898493d0f0f1d4962bf867601127a65.zip
run_main_loop: allocate GPollFD array dynamically
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/daemon/Daemon.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp
index 7c7fed2b..e99ce22c 100644
--- a/src/daemon/Daemon.cpp
+++ b/src/daemon/Daemon.cpp
@@ -629,23 +629,28 @@ static void run_main_loop(GMainLoop* loop)
GMainContext *context = g_main_loop_get_context(loop);
time_t old_time = 0;
time_t dns_conf_hash = 0;
+ int fds_size = 0;
+ GPollFD *fds = NULL;
while (!s_exiting)
{
- /* we have just a handful of sources, 32 should be ample */
- const unsigned NUM_POLLFDS = 32;
- GPollFD fds[NUM_POLLFDS];
gboolean some_ready;
gint max_priority;
gint timeout;
+ gint nfds;
some_ready = g_main_context_prepare(context, &max_priority);
if (some_ready)
g_main_context_dispatch(context);
- gint nfds = g_main_context_query(context, max_priority, &timeout, fds, NUM_POLLFDS);
- if (nfds > NUM_POLLFDS)
- error_msg_and_die("Internal error");
+ while (1)
+ {
+ nfds = g_main_context_query(context, max_priority, &timeout, fds, fds_size);
+ if (nfds <= fds_size)
+ break;
+ fds_size = nfds + 16; /* +16: optimizing realloc frequency */
+ fds = (GPollFD *)xrealloc(fds, fds_size * sizeof(fds[0]));
+ }
if (s_timeout)
alarm(s_timeout);
@@ -685,6 +690,7 @@ static void run_main_loop(GMainLoop* loop)
g_main_context_dispatch(context);
}
+ free(fds);
g_main_context_unref(context);
}