diff options
Diffstat (limited to 'src/imlib.c')
-rw-r--r-- | src/imlib.c | 42 |
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; |