From: Brion Vibber Date: Fri, 26 May 2006 02:41:20 +0000 (+0000) Subject: * wfShellexec() now accepts an optional parameter to receive the exit code X-Git-Tag: 1.31.0-rc.0~57026 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=cf91714d580463b0c38b654b084415475835473f;p=lhc%2Fweb%2Fwiklou.git * wfShellexec() now accepts an optional parameter to receive the exit code * Failed, but not zero-length, thumbnail renderings are now removed. Should help clean up when rsvg fails in weird ways. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a0fa2652da..af71e5305d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -339,6 +339,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 6086) Remove vestigial attempt to call Article::validate() * wfHostname() function for consistent server hostname use in debug messages * Send thumbnailing error messages to 'thumbnail' log group +* wfShellexec() now accepts an optional parameter to receive the exit code +* Failed, but not zero-length, thumbnail renderings are now removed. + Should help clean up when rsvg fails in weird ways. == Compatibility == diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index e76b41d606..cbd58214de 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1666,12 +1666,21 @@ function wfUrlProtocols() { } /** - * shell_exec() with time and memory limits mirrored from the PHP configuration, - * if supported. - */ -function wfShellExec( $cmd ) -{ + * Execute a shell command, with time and memory limits mirrored from the PHP + * configuration if supported. + * @param $cmd Command line, properly escaped for shell. + * @param &$retval optional, will receive the program's exit code. + * (non-zero is usually failure) + * @return collected stdout as a string (trailing newlines stripped) + */ +function wfShellExec( $cmd, &$retval=null ) { global $IP; + + if( ini_get( 'safe_mode' ) ) { + wfDebug( "wfShellExec can't run in safe_mode, PHP's exec functions are too broken.\n" ); + $retval = 1; + return "Unable to run external programs in safe mode."; + } if ( php_uname( 's' ) == 'Linux' ) { $time = ini_get( 'max_execution_time' ); @@ -1692,7 +1701,12 @@ function wfShellExec( $cmd ) $cmd = '"' . $cmd . '"'; } wfDebug( "wfShellExec: $cmd\n" ); - return shell_exec( $cmd ); + + $output = array(); + $retval = 1; // error by default? + $lastline = exec( $cmd, $output, $retval ); + return implode( "\n", $output ); + } /** diff --git a/includes/Image.php b/includes/Image.php index fd2ce63fac..1ba084eb8f 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -1050,6 +1050,9 @@ class Image $this->load(); $err = false; + $cmd = ""; + $retval = 0; + if( $this->mime === "image/svg" ) { #Right now we have only SVG @@ -1066,7 +1069,7 @@ class Image $wgSVGConverters[$wgSVGConverter] ); wfProfileIn( 'rsvg' ); wfDebug( "reallyRenderThumb SVG: $cmd\n" ); - $err = wfShellExec( $cmd ); + $err = wfShellExec( $cmd, $retval ); wfProfileOut( 'rsvg' ); } } elseif ( $wgUseImageMagick ) { @@ -1098,7 +1101,7 @@ class Image wfEscapeShellArg($thumbPath) . " 2>&1"; wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n"); wfProfileIn( 'convert' ); - $err = wfShellExec( $cmd ); + $err = wfShellExec( $cmd, $retval ); wfProfileOut( 'convert' ); } elseif( $wgCustomConvertCommand ) { # Use a custom convert command @@ -1110,7 +1113,7 @@ class Image $cmd = str_replace( '%h', $height, str_replace( '%w', $width, $cmd ) ); # Size wfDebug( "reallyRenderThumb: Running custom convert command $cmd\n" ); wfProfileIn( 'convert' ); - $err = wfShellExec( $cmd ); + $err = wfShellExec( $cmd, $retval ); wfProfileOut( 'convert' ); } else { # Use PHP's builtin GD library functions. @@ -1165,17 +1168,17 @@ class Image # if( file_exists( $thumbPath ) ) { $thumbstat = stat( $thumbPath ); - if( $thumbstat['size'] == 0 ) { + if( $thumbstat['size'] == 0 || $retval != 0 ) { + wfDebugLog( 'thumbnail', + sprintf( 'Removing bad %d-byte thumbnail "%s"', + $thumbstat['size'], $thumbPath ) ); unlink( $thumbPath ); - } else { - // All good - $err = true; } } - if ( $err !== true ) { + if ( $retval != 0 ) { wfDebugLog( 'thumbnail', - sprintf( 'thumbnail failed on %s: "%s" from "%s"', - wfHostname(), trim($err), $cmd ) ); + sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"', + wfHostname(), $retval, trim($err), $cmd ) ); return wfMsg( 'thumbnail_error', $err ); } else { return true;