summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2012-10-01 18:11:21 -0300
committerJasper St. Pierre <jstpierre@mecheye.net>2012-11-14 16:06:50 -0500
commit1f91e62af5b6af027e5e555e490b3ed5a78775a6 (patch)
treec6adc055174a8be17032138767103e7070d77a39
parentfd70689ec5d0ddd116680fb6711449e29b72a725 (diff)
downloadgnome-desktop-wip/thumbnail-resources.tar.gz
thumbnail: Set a resource limit for thumbnailing scriptswip/thumbnail-resources
Thumbnailing scripts may exhaust a lot of memory. We also call them synchronously, which is a bit annoying, but hard to change without breaking the API. Force them to take up to 256MB and take 2 seconds of CPU time at most. Some code based on thumbnailing code from libgsf. Patch written by Jody Goldberg.
-rw-r--r--libgnome-desktop/gnome-desktop-thumbnail.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.c b/libgnome-desktop/gnome-desktop-thumbnail.c
index 89f8636c..ece6bb35 100644
--- a/libgnome-desktop/gnome-desktop-thumbnail.c
+++ b/libgnome-desktop/gnome-desktop-thumbnail.c
@@ -45,6 +45,8 @@
#include <glib/gstdio.h>
#include <libgsystem.h>
+#include <sys/resource.h>
+
#define SECONDS_BETWEEN_STATS 10
struct _GnomeDesktopThumbnailFactoryPrivate {
@@ -1154,6 +1156,23 @@ expand_thumbnailing_script (const char *script,
return NULL;
}
+#define MAX_HELPER_MEMORY (256 * 1024 * 1024) /* 256 MB */
+#define MAX_HELPER_SECONDS (2) /* 2 seconds */
+
+static void
+set_resource_limits (gpointer user_data)
+{
+ struct rlimit limit;
+
+ limit.rlim_cur = MAX_HELPER_MEMORY;
+ limit.rlim_max = MAX_HELPER_MEMORY;
+ setrlimit (RLIMIT_AS, &limit);
+
+ limit.rlim_cur = MAX_HELPER_SECONDS;
+ limit.rlim_max = MAX_HELPER_SECONDS;
+ setrlimit (RLIMIT_CPU, &limit);
+}
+
static GdkPixbuf *
run_script (char *script, const char *uri, int size)
{
@@ -1179,7 +1198,7 @@ run_script (char *script, const char *uri, int size)
goto out;
if (!g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
- NULL, NULL, NULL, NULL,
+ set_resource_limits, NULL, NULL, NULL,
&exit_status, NULL))
goto out;