jokkedk/webgrind

Problem with bin/preproccessor

Closed this issue · 9 comments

mavik commented

Webgrind does not work after I did make all
It creates empty file cachegrind.out.xxxx.webgrind
And it works again after make clear.

What happens if you run the binary preprocessor manually?

'/var/www/html/webgrind/bin/preprocessor' '/tmp/cachegrind.out.1234' '/tmp/cachegrind.out.1234.webgrind' 'php::call_user_func' 'php::call_user_func_array'

(Changing paths as applicable to your system.)

What webserver and OS are you using?

Is there anything in the webserver or PHP error logs?

mavik commented
mavik commented

Does the following patch fix the issue?

diff --git a/library/Preprocessor.php b/library/Preprocessor.php
index 29668f2..afdce34 100644
--- a/library/Preprocessor.php
+++ b/library/Preprocessor.php
@@ -44,11 +44,9 @@ class Webgrind_Preprocessor
      */
     static function parse($inFile, $outFile)
     {
-        $in = @fopen($inFile, 'rb');
-        if (!$in)
+        if (!is_readable($inFile))
             throw new Exception('Could not open '.$inFile.' for reading.');
-        $out = @fopen($outFile, 'w+b');
-        if (!$out)
+        if (!touch($outFile) || !is_writeable($outFile))
             throw new Exception('Could not open '.$outFile.' for writing.');
 
         // If possible, use the binary preprocessor
@@ -56,6 +54,13 @@ class Webgrind_Preprocessor
             return;
         }
 
+        $in = @fopen($inFile, 'rb');
+        if (!$in)
+            throw new Exception('Could not open '.$inFile.' for reading.');
+        $out = @fopen($outFile, 'w+b');
+        if (!$out)
+            throw new Exception('Could not open '.$outFile.' for writing.');
+
         $proxyFunctions = array_flip(Webgrind_Config::$proxyFunctions);
         $proxyQueue = array();
         $nextFuncNr = 0;
mavik commented

Looks like a file permissions error. Can you confirm if the user your webserver (serving webgrind) is running under actually has correct permissions to read the cachegrind file?

mavik commented

Very strange that PHP's is_readable() claims the cachegrind file is not readable, when webgrind was able to read it (and that file permissions also say it can be read). Does is_readable() always fail, or does it work on some files (other than cachegrind files).

Is your webserver allowed to call executables; i.e., does a command like exec("touch /tmp/testFile") succeed?

If you simply remove the readable/writable checks, and put self::binaryParse($inFile, $outFile) at the top of the parse() function, does it succeed?

No response, assuming resolved. Please re-open if not.