From ba5dfbfffd6000fa05bf191858d3b2c4fa854070 Mon Sep 17 00:00:00 2001 From: kramm Date: Thu, 8 May 2008 08:13:54 +0000 Subject: [PATCH] if rendering is aborted due to -Q, print out an error message (and some memory info) --- src/pdf2swf.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/pdf2swf.c b/src/pdf2swf.c index 1a5cc37..ea61645 100644 --- a/src/pdf2swf.c +++ b/src/pdf2swf.c @@ -25,9 +25,16 @@ #include #include #include "../config.h" +#ifdef HAVE_SIGNAL_H +#include +#endif #ifdef HAVE_DIRENT_H #include #endif +#ifdef HAVE_MALLOC_H +#include +#endif + #include "../lib/args.h" #include "../lib/os.h" #include "../lib/rfxswf.h" @@ -56,6 +63,8 @@ static int ynup = 1; static int info_only = 0; +static int max_time = 0; + static int flatten = 0; char* fontpaths[256]; @@ -90,6 +99,23 @@ int systemf(const char* format, ...) return ret; } +#ifdef HAVE_SIGNAL_H +void sigalarm(int signal) +{ + msg(" Aborting rendering after %d seconds", max_time); +#if 0 && defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRUSAGE) + struct rusage usage; + getrusage(RUSAGE_CHILDREN, &usage); + msg(" Memory used: %d,%d,%d", usage.ru_maxrss, usage.ru_idrss, usage.ru_isrss); +#endif +#if defined(HAVE_MALLINFO) && defined(HAVE_MALLOC_H) + struct mallinfo info = mallinfo(); + msg(" Memory used: %d Mb (%d bytes)", info.uordblks/1048576, info.uordblks); +#endif + exit(1); +} +#endif + int args_callback_option(char*name,char*val) { if (!strcmp(name, "o")) { @@ -209,8 +235,11 @@ int args_callback_option(char*name,char*val) { #ifndef WIN32 else if (!strcmp(name, "Q")) { - int seconds = atoi(val); - alarm(seconds); + max_time = atoi(val); + alarm(max_time); +# ifdef HAVE_SIGNAL_H + signal(SIGALRM, sigalarm); +# endif return 1; } #endif -- 1.7.10.4