DragonFly BSD
DragonFly submit List (threaded) for 2003-10
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

kern.ident and uname -i


From: Skip Ford <skip.ford@xxxxxxxxxxx>
Date: Fri, 24 Oct 2003 04:42:36 -0400

This is FreeBSD current's code to dump the kernel's identifier through
either the 'kern.ident' oid or with uname -i.  It's not much code
and it's very useful IMO.

Index: sys/conf/newvers.sh
===================================================================
RCS file: /home/dcvs/src/sys/conf/newvers.sh,v
retrieving revision 1.2
diff -u -r1.2 newvers.sh
--- sys/conf/newvers.sh	17 Jun 2003 04:28:20 -0000	1.2
+++ sys/conf/newvers.sh	24 Oct 2003 05:53:53 -0000
@@ -87,6 +87,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' };
@@ -95,6 +96,7 @@
 char ostype[] = "${TYPE}";
 char osrelease[] = "${RELEASE}";
 int osreldate = ${RELDATE};
+char kern_ident[] = "${i}";
 EOF
 
 echo `expr ${v} + 1` > version
Index: sys/kern/kern_mib.c
===================================================================
RCS file: /home/dcvs/src/sys/kern/kern_mib.c,v
retrieving revision 1.6
diff -u -r1.6 kern_mib.c
--- sys/kern/kern_mib.c	4 Jul 2003 00:32:30 -0000	1.6
+++ sys/kern/kern_mib.c	24 Oct 2003 06:29:01 -0000
@@ -77,6 +77,9 @@
 SYSCTL_NODE(, OID_AUTO,  compat, CTLFLAG_RW, 0,
 	"Compatibility code");
 
+SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD,
+    kern_ident, 0, "Kernel identifier");
+
 SYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD, 
     osrelease, 0, "Operating system type");
 
Index: sys/sys/sysctl.h
===================================================================
RCS file: /home/dcvs/src/sys/sys/sysctl.h,v
retrieving revision 1.7
diff -u -r1.7 sysctl.h
--- sys/sys/sysctl.h	20 Aug 2003 23:54:36 -0000	1.7
+++ sys/sys/sysctl.h	24 Oct 2003 07:47:18 -0000
@@ -570,6 +570,7 @@
 extern char	machine[];
 extern char	osrelease[];
 extern char	ostype[];
+extern char	kern_ident[];
 
 struct linker_set;
 
Index: usr.bin/uname/uname.1
===================================================================
RCS file: /home/dcvs/src/usr.bin/uname/uname.1,v
retrieving revision 1.2
diff -u -r1.2 uname.1
--- usr.bin/uname/uname.1	17 Jun 2003 04:29:33 -0000	1.2
+++ usr.bin/uname/uname.1	24 Oct 2003 02:03:10 -0000
@@ -33,7 +33,7 @@
 .\" $FreeBSD: src/usr.bin/uname/uname.1,v 1.8.2.4 2002/10/17 07:47:29 jmallett Exp $
 .\" $DragonFly: src/usr.bin/uname/uname.1,v 1.2 2003/06/17 04:29:33 dillon Exp $
 .\"
-.Dd September 18, 2002
+.Dd October 24, 2003
 .Dt UNAME 1
 .Os
 .Sh NAME
@@ -41,7 +41,7 @@
 .Nd display information about the system
 .Sh SYNOPSIS
 .Nm
-.Op Fl amnprsv
+.Op Fl aimnprsv
 .Sh DESCRIPTION
 The
 .Nm
@@ -58,6 +58,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/dcvs/src/usr.bin/uname/uname.c,v
retrieving revision 1.2
diff -u -r1.2 uname.c
--- usr.bin/uname/uname.c	17 Jun 2003 04:29:33 -0000	1.2
+++ usr.bin/uname/uname.c	24 Oct 2003 07:09:43 -0000
@@ -51,10 +51,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);
@@ -65,7 +67,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
@@ -77,11 +79,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;
@@ -136,6 +141,7 @@
 	CHECK_ENV("v", version);
 	CHECK_ENV("m", platform);
 	CHECK_ENV("p", arch);
+	CHECK_ENV("i", ident);
 }
 
 #define	PRINT_FLAG(flags,flag,var)		\
@@ -158,6 +164,7 @@
 	PRINT_FLAG(flags, VFLAG, version);
 	PRINT_FLAG(flags, MFLAG, platform);
 	PRINT_FLAG(flags, PFLAG, arch);
+	PRINT_FLAG(flags, IFLAG, ident);
 	printf("\n");
 }
 
@@ -175,6 +182,19 @@
 	   &buf, &len, NULL, 0) == -1)		\
 		err(1, "sysctl");
 
+#define	NATIVE_SYSCTLNAME_GET(var,name)		\
+void						\
+native_##var(void)				\
+{						\
+	size_t len;				\
+	static char buf[1024];			\
+	char **varp = &(var);			\
+						\
+	len = sizeof buf;			\
+	if (sysctlbyname(name, &buf, &len, NULL,\
+	    0) == -1)				\
+		err(1, "sysctlbyname");
+
 #define	NATIVE_SET				\
 	*varp = buf;				\
 	return;					\
@@ -209,9 +229,12 @@
 NATIVE_SYSCTL2_GET(arch, CTL_HW, HW_MACHINE_ARCH) {
 } NATIVE_SET;
 
+NATIVE_SYSCTLNAME_GET(ident, "kern.ident") {
+} NATIVE_SET;
+
 void
 usage(void)
 {
-	fprintf(stderr, "usage: uname [-amnprsv]\n");
+	fprintf(stderr, "usage: uname [-aimnprsv]\n");
 	exit(1);
 }

-- 
Skip



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]