summaryrefslogtreecommitdiff
path: root/src/imlib.c
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2012-03-13 00:45:13 +0100
committerDaniel Friesel <derf@finalrewind.org>2012-03-13 00:45:13 +0100
commit8f5bf736a9d3f8084c644dbf6ceefc4142715c4e (patch)
treecc912d82821c91b48f248a0dc6fe69d31e400861 /src/imlib.c
parentcbab594f051b5c21a76d0ad389a25d6449e0b839 (diff)
Experimental code to limit imagemagick convert runtime (see #82)
Problems so far: * leaks zombie processes * does not work when terminating feh with a signal (since the convert process is no longer in feh's process group)
Diffstat (limited to 'src/imlib.c')
-rw-r--r--src/imlib.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/imlib.c b/src/imlib.c
index c0252c3..1e4eb3f 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -59,6 +59,8 @@ int xinerama_screen;
int num_xinerama_screens;
#endif /* HAVE_LIBXINERAMA */
+int childpid;
+
static char *feh_http_load_image(char *url);
static char *feh_magick_load_image(char *filename);
@@ -253,7 +255,10 @@ static char *feh_magick_load_image(char *filename)
char *tmpname;
char *sfn;
int fd = -1, devnull = -1;
- int pid, status;
+ int status;
+
+ if (opt.magick_timeout < 0)
+ return NULL;
basename = strrchr(filename, '/');
@@ -277,26 +282,39 @@ static char *feh_magick_load_image(char *filename)
snprintf(argv_fd, sizeof(argv_fd), "png:fd:%d", fd);
-
- if ((pid = fork()) == 0) {
+ if ((childpid = fork()) == 0) {
/* discard convert output */
devnull = open("/dev/null", O_WRONLY);
dup2(devnull, 1);
dup2(devnull, 2);
+ /*
+ * convert only accepts SIGINT via killpg, a normal kill doesn't work
+ */
+ if (opt.magick_timeout)
+ setpgid(0, 0);
+
execlp("convert", "convert", filename, argv_fd, NULL);
exit(1);
}
else {
- waitpid(pid, &status, 0);
+ alarm(opt.magick_timeout);
+ waitpid(childpid, &status, 0);
+ alarm(0);
if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
close(fd);
unlink(sfn);
sfn = NULL;
- if (!opt.quiet)
- weprintf("%s - No loader for that file format", filename);
+ if (!opt.quiet) {
+ if (WIFSIGNALED(status))
+ weprintf("%s - Conversion took too long, skipping",
+ filename);
+ else
+ weprintf("%s - No loader for that file format",
+ filename);
+ }
}
}