summaryrefslogtreecommitdiff
path: root/src/imlib.c
diff options
context:
space:
mode:
authorDennis Real <github@tildepipe.org>2012-03-16 19:13:47 +0100
committerDennis Real <github@tildepipe.org>2012-03-16 19:13:47 +0100
commit8e96382805eb77a82209df9d71dbf9c0dd1c4cdb (patch)
tree48c54b9715d88cb6e9f8455d689364b73b842f8f /src/imlib.c
parent77fa5aca182435f2771511832ea198d027393ceb (diff)
parent29cd868898660c58b1925bf3647c4c63b7bd3151 (diff)
Merge branch 'master' of git://github.com/derf/feh
Diffstat (limited to 'src/imlib.c')
-rw-r--r--src/imlib.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/imlib.c b/src/imlib.c
index c0252c3..eda3e2a 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 = 0;
+
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,27 +282,52 @@ 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, 0);
dup2(devnull, 1);
dup2(devnull, 2);
+ /*
+ * convert only accepts SIGINT via killpg, a normal kill doesn't work
+ */
+ 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);
+ }
+
+ /*
+ * Reap child. The previous waitpid call was interrupted by
+ * alarm, but convert doesn't terminate immediately.
+ * XXX
+ * normally, if (WIFSIGNALED(status)) waitpid(childpid, &status, 0);
+ * would suffice. However, as soon as feh has its own window,
+ * this doesn't work anymore and the following workaround is
+ * required. Hm.
+ */
+ waitpid(-1, &status, 0);
}
+ childpid = 0;
}
return sfn;