[PATCH] kern.ident + uname -i

Juli Mallett jmallett at FreeBSD.org
Sun Jun 8 01:30:32 PDT 2003


Greetings,

I send you this diff in order that I may gather some concensus on
whether it should be committed and if it seems useful.

Basically, rwatson@ mentioned on IRC at some point that the ability
to get the KERN_IDENT value of the running kernel would be useful,
I admit that I've found it useful before, in the context of doing
something like:
	env KERCONF=`uname -i` make buildworld

But FreeBSD had no such facility, so I tossed this together and
have had it in my personal tree for some months now.  It uses
make -V to get the ident value at kernel build time.  I am a
little hesitant to invoke make directly like that, but I do not
see a real scenario which it would break under.  I did consider
passing in the ident as an argument to newvers.sh, but I don't
really like heading down that road.

Anyway, here's the diff, some time tomorrow if I don't hear any
objections I'll probably commit it, since it's not a major thing,
and certainly is useful.

%%%
? _
Index: sys/conf/newvers.sh
===================================================================
RCS file: /home/ncvs/src/sys/conf/newvers.sh,v
retrieving revision 1.51
diff -d -u -r1.51 newvers.sh
--- sys/conf/newvers.sh	2 Jun 2003 04:58:43 -0000	1.51
+++ sys/conf/newvers.sh	8 Jun 2003 07:58:06 -0000
@@ -86,6 +86,7 @@
 
 touch version
 v=`cat version` u=${USER-root} d=`pwd` h=`hostname` t=`date`
+i=`make -V KERN_IDENT`
 cat << EOF > vers.c
 $COPYRIGHT
 char sccspad[32 - 4 /* sizeof(sccs) */] = { '\\0' };
@@ -94,6 +95,7 @@
 char ostype[] = "${TYPE}";
 char osrelease[] = "${RELEASE}";
 int osreldate = ${RELDATE};
+char ident[] = "${i}";
 EOF
 
 echo `expr ${v} + 1` > version
Index: sys/sys/sysctl.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/sysctl.h,v
retrieving revision 1.113
diff -d -u -r1.113 sysctl.h
--- sys/sys/sysctl.h	28 Mar 2003 14:17:17 -0000	1.113
+++ sys/sys/sysctl.h	8 Jun 2003 07:58:07 -0000
@@ -354,7 +354,8 @@
 #define	KERN_USRSTACK		33	/* int: address of USRSTACK */
 #define	KERN_LOGSIGEXIT		34	/* int: do we log sigexit procs? */
 #define	KERN_IOV_MAX		35	/* int: value of UIO_MAXIOV */
-#define KERN_MAXID		36      /* number of valid kern ids */
+#define	KERN_IDENT		36	/* string: kernel ident */
+#define KERN_MAXID		37      /* number of valid kern ids */
 
 #define CTL_KERN_NAMES { \
 	{ 0, 0 }, \
@@ -392,6 +393,7 @@
 	{ "usrstack", CTLTYPE_INT }, \
 	{ "logsigexit", CTLTYPE_INT }, \
 	{ "iov_max", CTLTYPE_INT }, \
+	{ "ident", CTLTYPE_STRING }, \
 }
 
 /*
@@ -581,6 +583,7 @@
 extern char	machine[];
 extern char	osrelease[];
 extern char	ostype[];
+extern char	ident[];
 
 /* Dynamic oid handling */
 struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist,
Index: usr.bin/uname/uname.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/uname/uname.1,v
retrieving revision 1.14
diff -d -u -r1.14 uname.1
--- usr.bin/uname/uname.1	18 Sep 2002 04:33:10 -0000	1.14
+++ usr.bin/uname/uname.1	8 Jun 2003 07:58:07 -0000
@@ -32,7 +32,7 @@
 .\"	@(#)uname.1	8.3 (Berkeley) 4/8/94
 .\" $FreeBSD: src/usr.bin/uname/uname.1,v 1.14 2002/09/18 04:33:10 jmallett Exp $
 .\"
-.Dd September 18, 2002
+.Dd April 02, 2003
 .Dt UNAME 1
 .Os
 .Sh NAME
@@ -40,7 +40,7 @@
 .Nd display information about the system
 .Sh SYNOPSIS
 .Nm
-.Op Fl amnprsv
+.Op Fl aimnprsv
 .Sh DESCRIPTION
 The
 .Nm
@@ -57,6 +57,8 @@
 and
 .Fl v
 were specified.
+.It Fl i
+Write the kernel ident to standard output.
 .It Fl m
 Write the type of the current hardware platform to standard output.
 .It Fl n
Index: usr.bin/uname/uname.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/uname/uname.c,v
retrieving revision 1.11
diff -d -u -r1.11 uname.c
--- usr.bin/uname/uname.c	23 Sep 2002 06:47:39 -0000	1.11
+++ usr.bin/uname/uname.c	8 Jun 2003 07:58:07 -0000
@@ -60,10 +60,12 @@
 #define	RFLAG	0x08
 #define	SFLAG	0x10
 #define	VFLAG	0x20
+#define	IFLAG	0x40
 
 typedef void (*get_t)(void);
-get_t get_platform, get_hostname, get_arch, get_release, get_sysname, get_version;
+get_t get_ident, get_platform, get_hostname, get_arch, get_release, get_sysname, get_version;
 
+void native_ident(void);
 void native_platform(void);
 void native_hostname(void);
 void native_arch(void);
@@ -74,7 +76,7 @@
 void setup_get(void);
 void usage(void);
 
-char *platform, *hostname, *arch, *release, *sysname, *version;
+char *ident, *platform, *hostname, *arch, *release, *sysname, *version;
 int space;
 
 int
@@ -86,11 +88,14 @@
 	setup_get();
 	flags = 0;
 
-	while ((ch = getopt(argc, argv, "amnprsv")) != -1)
+	while ((ch = getopt(argc, argv, "aimnprsv")) != -1)
 		switch(ch) {
 		case 'a':
 			flags |= (MFLAG | NFLAG | RFLAG | SFLAG | VFLAG);
 			break;
+		case 'i':
+			flags |= IFLAG;
+			break;
 		case 'm':
 			flags |= MFLAG;
 			break;
@@ -145,6 +150,7 @@
 	CHECK_ENV("v", version);
 	CHECK_ENV("m", platform);
 	CHECK_ENV("p", arch);
+	CHECK_ENV("i", ident);
 }
 
 #define	PRINT_FLAG(flags,flag,var)		\
@@ -167,6 +173,7 @@
 	PRINT_FLAG(flags, VFLAG, version);
 	PRINT_FLAG(flags, MFLAG, platform);
 	PRINT_FLAG(flags, PFLAG, arch);
+	PRINT_FLAG(flags, IFLAG, ident);
 	printf("\n");
 }
 
@@ -218,9 +225,12 @@
 NATIVE_SYSCTL2_GET(arch, CTL_HW, HW_MACHINE_ARCH) {
 } NATIVE_SET;
 
+NATIVE_SYSCTL2_GET(ident, CTL_KERN, KERN_IDENT) {
+} NATIVE_SET;
+
 void
 usage(void)
 {
-	fprintf(stderr, "usage: uname [-amnprsv]\n");
+	fprintf(stderr, "usage: uname [-aimnprsv]\n");
 	exit(1);
 }
%%%

Thanx,
juli.
-- 
juli mallett. email: jmallett at freebsd.org; efnet: juli;


More information about the freebsd-hackers mailing list