can i simply "re-version" the kernel down to 2.x?

Josh Cartwright joshc at linux.com
Fri Aug 5 23:52:03 EDT 2011


On Fri, Aug 05, 2011 at 10:36:00AM -0400, Robert P. J. Day wrote:
> 
>   for reasons that don't need explaining, i need to rebuild my current
> 3.0.0... kernel so that it returns a "uname" version number of
> "2.whatever".  i simply have an app i want to run that checks the
> output of "uname" and if it doesn't see a major number of "2", it goes
> a bit squirrelly.

If it is just one poorly written app you are trying to deal with, it
might just be easier to create a wrapper dll that traps the glibc uname
wrapper and hijacks the returned version.  Something like this:

--- /dev/null	2011-08-02 20:23:03.358999850 -0500
+++ b/trapuname.c	2011-08-05 22:45:02.000000000 -0500
@@ -0,0 +1,43 @@
+/* trapuname: tool to fake uname release
+ * Copyright (C) 2011 Josh Cartwright <joshc at linux.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/utsname.h>
+
+int uname(struct utsname *u)
+{
+	const char *err;
+	int ret;
+	int (*old_uname)(struct utsname *u);
+
+	dlerror();
+	old_uname = dlsym(RTLD_NEXT, "uname");
+
+	if ((err = dlerror())) {
+		fprintf(stderr, "Unable to load uname: %s\n", err);
+		exit(EXIT_FAILURE);
+	}
+
+	if (!(ret = old_uname(u)))
+		strcpy(u->release, "2.6.40");
+
+	return ret;
+}

Build it into a dynamic library, the use LD_PRELOAD to load it before
your application is run:

    $ gcc -shared -fPIC trapuname.c -ldl -o libtrapuname.so
    $ LD_PRELOAD=./libtrapuname.so stupidapp

At least this way, you won't be carting around a local kernel patch just
for a version change :\.

-- 
                                        joshc



More information about the Kernelnewbies mailing list