37 lines
1.4 KiB
Diff
37 lines
1.4 KiB
Diff
Author: <csmall@debian.org>
|
|
Description: Rework version parsing so its ok with other OSes
|
|
Index: b/proc/version.c
|
|
===================================================================
|
|
--- a/proc/version.c 2009-11-24 20:53:02.000000000 +1100
|
|
+++ b/proc/version.c 2009-11-24 21:00:44.000000000 +1100
|
|
@@ -35,15 +35,23 @@
|
|
|
|
static void init_Linux_version(void) __attribute__((constructor));
|
|
static void init_Linux_version(void) {
|
|
- static struct utsname uts;
|
|
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
|
|
+ FILE *fp;
|
|
+ char buf[256];
|
|
|
|
- if (uname(&uts) == -1) /* failure implies impending death */
|
|
- exit(1);
|
|
- if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3)
|
|
+ if ( (fp=fopen("/proc/version","r")) == NULL) /* failure implies impending death */
|
|
+ exit(1);
|
|
+ if (fgets(buf, 256, fp) == NULL) {
|
|
+ fprintf(stderr, "Cannot read kernel version from /proc/version\n");
|
|
+ fclose(fp);
|
|
+ exit(1);
|
|
+ }
|
|
+ fclose(fp);
|
|
+ if (sscanf(buf, "Linux version %d.%d.%d", &x, &y, &z) < 3)
|
|
fprintf(stderr, /* *very* unlikely to happen by accident */
|
|
"Non-standard uts for running kernel:\n"
|
|
- "release %s=%d.%d.%d gives version code %d\n",
|
|
- uts.release, x, y, z, LINUX_VERSION(x,y,z));
|
|
+ "release %s=%d.%d.%d gives version code %d\n",
|
|
+ buf,
|
|
+ x, y, z, LINUX_VERSION(x,y,z));
|
|
linux_version_code = LINUX_VERSION(x, y, z);
|
|
}
|