Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.10.9

Bug #9355 Bug in GLIBC detection (OS/Guess.php), patch proposal
Submitted: 2006-11-16 17:47 UTC
From: Fedora at FamilleCollet dot com Assigned: cellog
Status: Closed Package: PEAR (version 1.4.11)
PHP Version: 5.2.0 OS: Linux (Fedora)
Roadmaps: (Not assigned)    
Subscription  


 [2006-11-16 17:47 UTC] Fedora at FamilleCollet dot com (Remi Collet)
Description: ------------ GLIBC version is detected in OS/Guess.php This require "cpp" and "/usr/include/features.h" (glibc-headers) If "cpp" is available, the script compile a small piece of code which include "features.h" without testing if it is installed. And finaly the failback (reading the link /lib/libc.so.6) seems broken (regex problem). Test script: --------------- php -r 'require("OS/Guess.php"); print_r(new OS_Guess());' Expected result: ---------------- OS_Guess Object ( [sysname] => linux [nodename] => remi [cpu] => x86_64 [release] => 2.6 [extra] => glibc2.5 ) Actual result: -------------- /tmp/glibctest3HeaAL:1:22: erreur: features.h : Aucun fichier ou répertoire de ce type OS_Guess Object ( [sysname] => linux [nodename] => remi [cpu] => x86_64 [release] => 2.6 [extra] => glibc__GLIBC__.__GLIBC_MINOR__ )

Comments

 [2006-11-16 17:49 UTC] Fedora at FamilleCollet dot com
Here is a patch : --- OS/Guess.php.orig 2006-11-01 08:26:23.000000000 +0100 +++ OS/Guess.php 2006-11-01 08:42:32.000000000 +0100 @@ -202,11 +202,11 @@ return $glibc; // no need to run this multiple times } include_once "System.php"; - if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) { - // Use glibc's <features.h> header file to - // get major and minor version number: - if (@file_exists('/usr/include/features.h') && - @is_readable('/usr/include/features.h')) { + // Use glibc's <features.h> header file to + // get major and minor version number: + if (@file_exists('/usr/include/features.h') && + @is_readable('/usr/include/features.h')) { + if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) { $features_file = fopen('/usr/include/features.h', 'rb'); while (!feof($features_file)) { $line = fgets($features_file, 8192); @@ -238,29 +238,31 @@ return $glibc = ''; } return $glibc = 'glibc' . trim($glibc_major) . "." . trim($glibc_minor) ; + } // No cpp + $tmpfile = System::mktemp("glibctest"); + $fp = fopen($tmpfile, "w"); + fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n"); + fclose($fp); + $cpp = popen("/usr/bin/cpp $tmpfile", "r"); + $major = $minor = 0; + while ($line = fgets($cpp, 1024)) { + if ($line{0} == '#' || trim($line) == '') { + continue; + } + if (list($major, $minor) = explode(' ', trim($line))) { + break; + } } - return $glibc = ''; - } - $tmpfile = System::mktemp("glibctest"); - $fp = fopen($tmpfile, "w"); - fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n"); - fclose($fp); - $cpp = popen("/usr/bin/cpp $tmpfile", "r"); - $major = $minor = 0; - while ($line = fgets($cpp, 1024)) { - if ($line{0} == '#' || trim($line) == '') { - continue; - } - if (list($major, $minor) = explode(' ', trim($line))) { - break; + pclose($cpp); + unlink($tmpfile); + if (!($major && $minor)) { + return $glibc = "glibc{$major}.{$minor}"; } - } - pclose($cpp); - unlink($tmpfile); - if (!($major && $minor) && is_link('/lib/libc.so.6')) { + } // features.h + if (is_link('/lib/libc.so.6')) { // Let's try reading the libc.so.6 symlink - if (ereg('^libc-([.*])\.so$', basename(readlink('/lib/libc.so.6')), $matches)) { - list($major, $minor) = explode('.', $matches); + if (ereg('^libc-(.*)\.so$', basename(readlink('/lib/libc.so.6')), $matches)) { + list($major, $minor) = explode('.', $matches[1]); } } if (!($major && $minor)) {
 [2006-11-16 17:50 UTC] Fedora at FamilleCollet dot com
Change summary.
 [2006-11-21 03:33 UTC] cellog (Greg Beaver)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. the patch is not quite correct, but I have corrected it in the source
 [2006-11-21 06:34 UTC] Fedora at FamilleCollet dot com
Thank's for fixing this bug. It seems to me there still a problem with the "ereg" command as it return an array : array(2) { [0]=> string(11) "libc-2.5.so" [1]=> string(3) "2.5" } From php doc : If matches are found for parenthesized substrings of pattern and the function is called with the third argument regs, the matches will be stored in the elements of the array regs. $regs[1] will contain the substring which starts at the first left parenthesis; $regs[2] will contain the substring starting at the second, and so on. $regs[0] will contain a copy of the complete string matched. So, you should use (line 262) : list($major, $minor) = explode('.', $matches[1]);
 [2006-12-09 18:12 UTC] Fedora at FamilleCollet dot com
What about fixing the last problem with ereg ?
 [2006-12-14 00:24 UTC] cellog (Greg Beaver)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.