From 394517d1c66783c4e1d044f79df9ef1703a6f5db Mon Sep 17 00:00:00 2001 From: ulteq Date: Sat, 20 Jan 2018 11:25:09 +0100 Subject: Fix the --magick-timeout handling * Prevents nasty loading loops * Prevents zombie subprocesses * Fixes the conversion timeout detection routine --- src/imlib.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/imlib.c b/src/imlib.c index 73b7039..6de6bdb 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -231,7 +231,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file) if ((image_source != SRC_IMLIB) && tmpname) { *im = imlib_load_image_with_error_return(tmpname, &err); - if (im) { + if (!err && im) { real_filename = file->filename; file->filename = tmpname; feh_file_info_load(file, *im); @@ -240,7 +240,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file) file->ed = exif_get_data(tmpname); #endif } - if ((image_source == SRC_MAGICK) || !opt.keep_http) + if ((image_source != SRC_HTTP) || !opt.keep_http) unlink(tmpname); free(tmpname); @@ -357,30 +357,17 @@ static char *feh_magick_load_image(char *filename) else { alarm(opt.magick_timeout); waitpid(childpid, &status, 0); - alarm(0); - if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) { - close(fd); + kill(childpid, SIGKILL); + if (opt.magick_timeout > 0 && !alarm(0)) { unlink(sfn); free(sfn); sfn = NULL; if (!opt.quiet) { - if (WIFSIGNALED(status)) - weprintf("%s - Conversion took too long, skipping", - filename); + weprintf("%s - Conversion took too long, skipping", 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); } + close(fd); childpid = 0; } -- cgit v1.2.3