Lines 35-49
Link Here
|
35 |
|
35 |
|
36 |
static void init_Linux_version(void) __attribute__((constructor)); |
36 |
static void init_Linux_version(void) __attribute__((constructor)); |
37 |
static void init_Linux_version(void) { |
37 |
static void init_Linux_version(void) { |
38 |
static struct utsname uts; |
|
|
39 |
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */ |
38 |
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */ |
|
|
39 |
FILE *fp; |
40 |
char buf[256]; |
40 |
|
41 |
|
41 |
if (uname(&uts) == -1) /* failure implies impending death */ |
42 |
if ( (fp=fopen("/proc/version","r")) == NULL) /* failure implies impending death */ |
42 |
exit(1); |
43 |
exit(1); |
43 |
if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3) |
44 |
if (fgets(buf, 256, fp) == NULL) { |
|
|
45 |
fprintf(stderr, "Cannot read kernel version from /proc/version\n"); |
46 |
fclose(fp); |
47 |
exit(1); |
48 |
} |
49 |
fclose(fp); |
50 |
if (sscanf(buf, "Linux version %d.%d.%d", &x, &y, &z) < 3) |
44 |
fprintf(stderr, /* *very* unlikely to happen by accident */ |
51 |
fprintf(stderr, /* *very* unlikely to happen by accident */ |
45 |
"Non-standard uts for running kernel:\n" |
52 |
"Non-standard uts for running kernel:\n" |
46 |
"release %s=%d.%d.%d gives version code %d\n", |
53 |
"release %s=%d.%d.%d gives version code %d\n", |
47 |
uts.release, x, y, z, LINUX_VERSION(x,y,z)); |
54 |
buf, |
|
|
55 |
x, y, z, LINUX_VERSION(x,y,z)); |
48 |
linux_version_code = LINUX_VERSION(x, y, z); |
56 |
linux_version_code = LINUX_VERSION(x, y, z); |
49 |
} |
57 |
} |