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];
}
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;
}
if (isset($cpumap[$cpu])) {
$cpu = $cpumap[$cpu];
}
- $extra = '';
return array($sysname, $release, $cpu, $extra, $nodename);
}
+ function _detectGlibcVersion()
+ {
+ // Use glibc's <features.h> header file to
+ // get major and minor version number:
+ include_once "System.php";
+ $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} == '#') {
+ 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()
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));
}