summaryrefslogtreecommitdiff
path: root/thumbnailer/atril-thumbnailer.c
diff options
context:
space:
mode:
authorCarlos Garcia Campos <[email protected]>2011-06-26 11:00:30 +0000
committerStefano Karapetsas <[email protected]>2013-04-11 13:09:00 +0200
commit360c4652feef85e15c936d9da9d3c49b081cd502 (patch)
tree88f475a2babc2370c7eb78ce499ebdc73aa36b5f /thumbnailer/atril-thumbnailer.c
parent818c7bfe6a4a177a42bc29ae1f96dd19330b379c (diff)
downloadatril-360c4652feef85e15c936d9da9d3c49b081cd502.tar.bz2
atril-360c4652feef85e15c936d9da9d3c49b081cd502.tar.xz
thumbnailer: limit thumbnailing time to 15 seconds by default
The limit can be disabled with no-limit command line option. Fixes bug #651655.
Diffstat (limited to 'thumbnailer/atril-thumbnailer.c')
-rw-r--r--thumbnailer/atril-thumbnailer.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/thumbnailer/atril-thumbnailer.c b/thumbnailer/atril-thumbnailer.c
index 7dfc79a5..e5c214a1 100644
--- a/thumbnailer/atril-thumbnailer.c
+++ b/thumbnailer/atril-thumbnailer.c
@@ -35,12 +35,17 @@
#endif
#define THUMBNAIL_SIZE 128
+#define DEFAULT_SLEEP_TIME (15 * G_USEC_PER_SEC) /* 15 seconds */
+
+static gboolean finished = TRUE;
static gint size = THUMBNAIL_SIZE;
+static gboolean time_limit = TRUE;
static const gchar **file_arguments;
static const GOptionEntry goption_options[] = {
{ "size", 's', 0, G_OPTION_ARG_INT, &size, NULL, "SIZE" },
+ { "no-limit", 'l', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &time_limit, "Don't limit the thumbnailing time to 15 seconds", NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file_arguments, NULL, "<input> <ouput>" },
{ NULL }
};
@@ -52,6 +57,41 @@ struct AsyncData {
gboolean success;
};
+/* Time monitor: copied from totem */
+G_GNUC_NORETURN static gpointer
+time_monitor (gpointer data)
+{
+ const gchar *app_name;
+
+ g_usleep (DEFAULT_SLEEP_TIME);
+
+ if (finished)
+ g_thread_exit (NULL);
+
+ app_name = g_get_application_name ();
+ if (app_name == NULL)
+ app_name = g_get_prgname ();
+ g_print ("%s couldn't process file: '%s'\n"
+ "Reason: Took too much time to process.\n",
+ app_name,
+ (const char *) data);
+
+ exit (0);
+}
+
+static void
+time_monitor_start (const char *input)
+{
+ finished = FALSE;
+ g_thread_create (time_monitor, (gpointer) input, FALSE, NULL);
+}
+
+static void
+time_monitor_stop (void)
+{
+ finished = TRUE;
+}
+
static void
delete_temp_file (GFile *file)
{
@@ -276,6 +316,9 @@ main (int argc, char *argv[])
return -2;
}
+ if (time_limit)
+ time_monitor_start (input);
+
if (EV_IS_ASYNC_RENDERER (document)) {
struct AsyncData data;
@@ -302,6 +345,7 @@ main (int argc, char *argv[])
return -2;
}
+ time_monitor_stop ();
g_object_unref (document);
ev_shutdown ();