From: Stig Bakken Date: Sat, 25 Jan 2003 00:44:41 +0000 (+0000) Subject: * add glibc version detection for Linux X-Git-Tag: PHP_5_0_dev_before_13561_fix~45 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d19bd6f12c2cec7335829cfebd362cd1a83e5349;p=php * add glibc version detection for Linux --- diff --git a/pear/OS/Guess.php b/pear/OS/Guess.php index 8e28e4f3be..97e665818e 100644 --- a/pear/OS/Guess.php +++ b/pear/OS/Guess.php @@ -106,13 +106,14 @@ class OS_Guess if ($uname === null) { $uname = php_uname(); } - $parts = preg_split('/\s+/', trim($uname)); + $parts = split('[[:space:]]+', trim($uname)); $n = count($parts); $release = $machine = $cpu = ''; $sysname = $parts[0]; $nodename = $parts[1]; $cpu = $parts[$n-1]; + $extra = ''; if ($cpu == 'unknown') { $cpu = $parts[$n-2]; } @@ -124,8 +125,13 @@ class OS_Guess case 'Windows': $release = $parts[3]; break; + case 'Linux': + $extra = $this->_detectGlibcVersion(); + // use only the first two digits from the kernel version + $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]); + break; default: - $release = preg_replace('/-.*/', '', $parts[2]); + $release = ereg_replace('-.*', '', $parts[2]); break; } @@ -138,13 +144,48 @@ class OS_Guess if (isset($cpumap[$cpu])) { $cpu = $cpumap[$cpu]; } - $extra = ''; return array($sysname, $release, $cpu, $extra, $nodename); } + function _detectGlibcVersion() + { + // Use glibc's header file to + // get major and minor version number: + include_once "System.php"; + $tmpfile = System::mktemp("glibctest"); + $fp = fopen($tmpfile, "w"); + fwrite($fp, "#include \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} == '#') { + continue; + } + if (list($major, $minor) = explode(' ', trim($line))) { + break; + } + } + pclose($cpp); + unlink($tmpfile); + if (!($major && $minor) && file_exists('/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 (!($major && $minor)) { + return ''; + } + return "glibc{$major}.{$minor}"; + } + function getSignature() { - return "{$this->sysname}-{$this->release}-{$this->cpu}"; + if (empty($this->extra)) { + return "{$this->sysname}-{$this->release}-{$this->cpu}"; + } + return "{$this->sysname}-{$this->release}-{$this->cpu}-{$this->extra}"; } function getSysname() @@ -199,8 +240,8 @@ class OS_Guess function _matchFragment($fragment, $value) { if (strcspn($fragment, '*?') < strlen($fragment)) { - $preg = '/^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$/i'; - return preg_match($preg, $value); + $reg = '^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$'; + return eregi($preg, $value); } return ($fragment == '*' || !strcasecmp($fragment, $value)); }