2
* Copyright (C) 2007 Bastien Nocera <hadess@hadess.net>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
* The Totem project hereby grant permission for non-gpl compatible GStreamer
19
* plugins to be used and distributed together with GStreamer and Totem. This
20
* permission are above and beyond the permissions granted by the GPL license
21
* Totem is covered by.
23
* Monday 7th February 2005: Christian Schaller: Add exception clause.
24
* See license_change file for details.
31
#include <glib/gstdio.h>
35
#include <sys/types.h>
37
#include <sys/resource.h>
39
#include "totem-resources.h"
41
#define MAX_HELPER_MEMORY (256 * 1024 * 1024) /* 256 MB */
42
#define MAX_HELPER_SECONDS (15) /* 15 seconds */
43
#define DEFAULT_SLEEP_TIME (30 * G_USEC_PER_SEC) /* 30 seconds */
45
static guint sleep_time = DEFAULT_SLEEP_TIME;
46
static gboolean finished = TRUE;
49
set_resource_limits (const char *input)
55
max = MAX_HELPER_MEMORY;
57
/* Set the maximum virtual size depending on the size
58
* of the file to process, as we wouldn't be able to
59
* mmap it otherwise */
61
max = MAX_HELPER_MEMORY;
62
} else if (g_stat (input, &buf) == 0) {
63
max = MAX_HELPER_MEMORY + buf.st_size;
64
} else if (g_str_has_prefix (input, "file://") != FALSE) {
66
file = g_filename_from_uri (input, NULL, NULL);
67
if (file != NULL && g_stat (file, &buf) == 0)
68
max = MAX_HELPER_MEMORY + buf.st_size;
75
setrlimit (RLIMIT_DATA, &limit);
77
limit.rlim_cur = MAX_HELPER_SECONDS;
78
limit.rlim_max = MAX_HELPER_SECONDS;
79
setrlimit (RLIMIT_CPU, &limit);
82
G_GNUC_NORETURN static gpointer
83
time_monitor (gpointer data)
87
g_usleep (sleep_time);
89
if (finished != FALSE)
92
app_name = g_get_application_name ();
94
app_name = g_get_prgname ();
95
g_print ("%s couldn't process file: '%s'\n"
96
"Reason: Took too much time to process.\n",
104
totem_resources_monitor_start (const char *input, gint wall_clock_time)
106
set_resource_limits (input);
108
if (wall_clock_time < 0)
111
if (wall_clock_time > 0)
112
sleep_time = wall_clock_time;
115
g_thread_create (time_monitor, (gpointer) input, FALSE, NULL);
119
totem_resources_monitor_stop (void)