1 |
On Wed, Oct 29, 2008 at 7:51 PM, Andrey Vul <andrey.vul@×××××.com> wrote: |
2 |
<snip> |
3 |
> elif system in ('Linux',): |
4 |
> # Linux based systems |
5 |
> distname,distversion,distid = dist('') |
6 |
> if distname and not terse: |
7 |
> platform = _platform(system,release,machine,processor, |
8 |
> 'with', |
9 |
> distname,distversion,distid) |
10 |
> else: |
11 |
> # If the distribution name is unknown check for libc vs. glibc |
12 |
> libcname,libcversion = libc_ver(sys.executable) |
13 |
> platform = _platform(system,release,machine,processor, |
14 |
> 'with', |
15 |
> libcname+libcversion) |
16 |
<snip> |
17 |
|
18 |
Hrm. I know just enough about python to get myself in trouble here... |
19 |
but it looks like a python bug in magicking up the libc name and |
20 |
version... but the below is WAY outside my level of practice with |
21 |
python (it'll take re-reading and digging elsewhere a good few times |
22 |
if I'm ever to make sense of it... |
23 |
|
24 |
------------------ |
25 |
def libc_ver(executable=sys.executable,lib='',version='', |
26 |
|
27 |
chunksize=2048): |
28 |
|
29 |
""" Tries to determine the libc version that the file executable |
30 |
(which defaults to the Python interpreter) is linked against. |
31 |
|
32 |
Returns a tuple of strings (lib,version) which default to the |
33 |
given parameters in case the lookup fails. |
34 |
|
35 |
Note that the function has intimate knowledge of how different |
36 |
libc versions add symbols to the executable and thus is probably |
37 |
only useable for executables compiled using gcc. |
38 |
|
39 |
The file is read and scanned in chunks of chunksize bytes. |
40 |
|
41 |
""" |
42 |
f = open(executable,'rb') |
43 |
binary = f.read(chunksize) |
44 |
pos = 0 |
45 |
while 1: |
46 |
m = _libc_search.search(binary,pos) |
47 |
if not m: |
48 |
binary = f.read(chunksize) |
49 |
if not binary: |
50 |
break |
51 |
pos = 0 |
52 |
continue |
53 |
libcinit,glibc,glibcversion,so,threads,soversion = m.groups() |
54 |
if libcinit and not lib: |
55 |
lib = 'libc' |
56 |
elif glibc: |
57 |
if lib != 'glibc': |
58 |
lib = 'glibc' |
59 |
version = glibcversion |
60 |
elif glibcversion > version: |
61 |
version = glibcversion |
62 |
elif so: |
63 |
if lib != 'glibc': |
64 |
lib = 'libc' |
65 |
if soversion > version: |
66 |
version = soversion |
67 |
if threads and version[-len(threads):] != threads: |
68 |
version = version + threads |
69 |
pos = m.end() |
70 |
f.close() |
71 |
return lib,version |
72 |
------------------ |
73 |
|
74 |
It parses the header of an executable and guesses, but... the how is |
75 |
too many directions from this that I'm not seeing it with my haphazard |
76 |
abuse of grep. I'd presume anything that might care what platform it's |
77 |
running on (underneath python itself) would be susceptible, so a word |
78 |
thrown in the direction of upstream python would be the main way to |
79 |
go... though it looks like emerge didn't used to use that call... |
80 |
|
81 |
Portage 2.1.4.5 (default/linux/x86/2008.0, gcc-4.1.2, glibc-2.6.1-r0, |
82 |
2.6.25-gentoo-r7-mahain i686) |
83 |
================================================================= |
84 |
System uname: 2.6.25-gentoo-r7-mahain i686 AMD Athlon(tm) MP 2400+ |
85 |
|
86 |
is my output, based on a call in emerge to "uname -mrp" .. not |
87 |
platform.platform() |
88 |
|
89 |
Looks like gentoo-dev aimed to drop that dependency in newer versions after all. |
90 |
|
91 |
-- |
92 |
Poison [BLX] |
93 |
Joshua M. Murphy |