From 08efc527139fc04bbb62f18ec3363e83bd1e8532 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Tue, 26 Dec 2006 11:27:44 +0000 Subject: [PATCH] - Unhook usr.bin/uname from boot strap tools building, because it is not used as boot strap tool at all. - Add hw.machin_uname, which is "i386" on pc32(machine)/i386(cpu). It is used by uname(1) -m option and uname(3), since most third party application understand "i386" much better than "pc32". In uname(3), fallback to hw.machine, if hw.machine_uname does not exist, so we can stay compatible with old kernel which does not have hw.machine_uname. Implementation-suggestions-from: dillon@ Approved-by: dillon@ --- Makefile.inc1 | 4 ++-- lib/libc/gen/uname.c | 18 ++++++++++++------ sys/cpu/i386/include/param.h | 6 +++++- sys/kern/kern_mib.c | 6 +++++- sys/sys/sysctl.h | 6 ++++-- usr.bin/uname/uname.c | 4 ++-- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index 4b0166ca2c..afe0bc8b38 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -1,6 +1,6 @@ # # $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $ -# $DragonFly: src/Makefile.inc1,v 1.94 2006/11/15 03:27:10 corecode Exp $ +# $DragonFly: src/Makefile.inc1,v 1.95 2006/12/26 11:27:44 sephe Exp $ # # Build-time options are documented in make.conf(5). # @@ -769,7 +769,7 @@ bootstrap-tools: bin/hostname bin/kill \ usr.bin/yacc usr.bin/colldef usr.bin/uudecode usr.bin/xinstall \ usr.bin/m4 usr.bin/rpcgen usr.bin/make usr.bin/awk usr.bin/stat \ - usr.bin/find usr.bin/lex usr.bin/sed usr.bin/uname usr.bin/touch \ + usr.bin/find usr.bin/lex usr.bin/sed usr.bin/touch \ usr.bin/mkdep usr.bin/mktemp usr.bin/lorder usr.bin/file2c \ usr.bin/tsort usr.bin/tr usr.bin/join usr.bin/wc usr.bin/basename \ usr.bin/gencat usr.bin/chflags usr.bin/expand usr.bin/paste \ diff --git a/lib/libc/gen/uname.c b/lib/libc/gen/uname.c index c38c989d40..31b05b84f8 100644 --- a/lib/libc/gen/uname.c +++ b/lib/libc/gen/uname.c @@ -32,7 +32,7 @@ * * @(#)uname.c 8.1 (Berkeley) 1/4/94 * $FreeBSD: src/lib/libc/gen/uname.c,v 1.7 1999/08/27 23:59:06 peter Exp $ - * $DragonFly: src/lib/libc/gen/uname.c,v 1.3 2005/11/13 00:07:42 swildner Exp $ + * $DragonFly: src/lib/libc/gen/uname.c,v 1.4 2006/12/26 11:27:44 sephe Exp $ */ #include @@ -46,7 +46,7 @@ uname(struct utsname *name) int mib[2], rval; size_t len; char *p; - int oerrno; + int oerrno, noent = 0; rval = 0; @@ -107,15 +107,21 @@ uname(struct utsname *name) } } + oerrno = errno; + mib[1] = HW_MACHINE_UNAME; +again: mib[0] = CTL_HW; - mib[1] = HW_MACHINE; len = sizeof(name->machine); - oerrno = errno; if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) { - if (errno == ENOMEM) + if (errno == ENOMEM) { errno = oerrno; - else + } else if (!noent && errno == ENOENT) { + noent = 1; + mib[1] = HW_MACHINE; + goto again; + } else { rval = -1; + } } name->machine[sizeof(name->machine) - 1] = '\0'; return (rval); diff --git a/sys/cpu/i386/include/param.h b/sys/cpu/i386/include/param.h index 4811dc5793..cc9d6fcb2d 100644 --- a/sys/cpu/i386/include/param.h +++ b/sys/cpu/i386/include/param.h @@ -35,7 +35,7 @@ * * from: @(#)param.h 5.8 (Berkeley) 6/28/91 * $FreeBSD: src/sys/i386/include/param.h,v 1.54.2.8 2002/08/31 21:15:55 dillon Exp $ - * $DragonFly: src/sys/cpu/i386/include/param.h,v 1.11 2006/12/04 18:04:00 dillon Exp $ + * $DragonFly: src/sys/cpu/i386/include/param.h,v 1.12 2006/12/26 11:27:44 sephe Exp $ */ #ifndef _CPU_PARAM_H_ @@ -85,6 +85,10 @@ #define MACHINE_CPU "i386" /* minimum supported cpu rev */ #endif +#ifndef MACHINE_UNAME +#define MACHINE_UNAME "i386" /* for uname(1)/uname(3) */ +#endif + #define MID_MACHINE MID_I386 /* diff --git a/sys/kern/kern_mib.c b/sys/kern/kern_mib.c index b829f75af5..e654a82a85 100644 --- a/sys/kern/kern_mib.c +++ b/sys/kern/kern_mib.c @@ -38,7 +38,7 @@ * * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94 * $FreeBSD: src/sys/kern/kern_mib.c,v 1.29.2.4 2001/07/30 23:28:00 peter Exp $ - * $DragonFly: src/sys/kern/kern_mib.c,v 1.11 2006/11/07 06:43:24 dillon Exp $ + * $DragonFly: src/sys/kern/kern_mib.c,v 1.12 2006/12/26 11:27:44 sephe Exp $ */ #include @@ -156,6 +156,10 @@ static char machine_cpu[] = MACHINE_CPU; SYSCTL_STRING(_hw, HW_MACHINE_CPU, machine_cpu, CTLFLAG_RD, machine_arch, 0, "Cpu architecture"); +static char machine_uname[] = MACHINE_UNAME; +SYSCTL_STRING(_hw, HW_MACHINE_UNAME, machine_uname, CTLFLAG_RD, + machine_uname, 0, "Machine class (for uname)"); + char hostname[MAXHOSTNAMELEN]; static int diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index c85ee18ef9..630fbba289 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -35,7 +35,7 @@ * * @(#)sysctl.h 8.1 (Berkeley) 6/2/93 * $FreeBSD: src/sys/sys/sysctl.h,v 1.81.2.10 2003/05/01 22:48:09 trhodes Exp $ - * $DragonFly: src/sys/sys/sysctl.h,v 1.19 2006/11/07 06:43:25 dillon Exp $ + * $DragonFly: src/sys/sys/sysctl.h,v 1.20 2006/12/26 11:27:44 sephe Exp $ */ #ifndef _SYS_SYSCTL_H_ @@ -459,7 +459,9 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); #define HW_FLOATINGPT 10 /* int: has HW floating point? */ #define HW_MACHINE_ARCH 11 /* string: machine architecture */ #define HW_MACHINE_CPU 12 /* string: cpu architecture */ -#define HW_MAXID 13 /* number of valid hw ids */ +#define HW_MACHINE_UNAME 13 /* string: machine class + * (for uname only) */ +#define HW_MAXID 14 /* number of valid hw ids */ #define CTL_HW_NAMES { \ { 0, 0 }, \ diff --git a/usr.bin/uname/uname.c b/usr.bin/uname/uname.c index 6da8b1027c..7dc1c5ddbe 100644 --- a/usr.bin/uname/uname.c +++ b/usr.bin/uname/uname.c @@ -34,7 +34,7 @@ * @(#) Copyright (c) 1993 The Regents of the University of California. All rights reserved. * @(#)uname.c 8.2 (Berkeley) 5/4/95 * $FreeBSD: src/usr.bin/uname/uname.c,v 1.4.6.2 2002/10/17 07:47:29 jmallett Exp $ - * $DragonFly: src/usr.bin/uname/uname.c,v 1.3 2003/10/24 17:19:16 dillon Exp $ + * $DragonFly: src/usr.bin/uname/uname.c,v 1.4 2006/12/26 11:27:44 sephe Exp $ */ #include @@ -223,7 +223,7 @@ NATIVE_SYSCTL2_GET(version, CTL_KERN, KERN_VERSION) { *p = ' '; } NATIVE_SET; -NATIVE_SYSCTL2_GET(platform, CTL_HW, HW_MACHINE) { +NATIVE_SYSCTL2_GET(platform, CTL_HW, HW_MACHINE_UNAME) { } NATIVE_SET; NATIVE_SYSCTL2_GET(arch, CTL_HW, HW_MACHINE_ARCH) { -- 2.41.0