Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Nov 2017 10:15:17 +0000 (UTC)
From:      =?UTF-8?Q?Dag-Erling_Sm=c3=b8rgrav?= <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325800 - head/bin/freebsd-version
Message-ID:  <201711141015.vAEAFH5f072066@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Tue Nov 14 10:15:17 2017
New Revision: 325800
URL: https://svnweb.freebsd.org/changeset/base/325800

Log:
  Add a -r option to print the running kernel version.
  
  MFC after:	1 week

Modified:
  head/bin/freebsd-version/freebsd-version.1
  head/bin/freebsd-version/freebsd-version.sh.in

Modified: head/bin/freebsd-version/freebsd-version.1
==============================================================================
--- head/bin/freebsd-version/freebsd-version.1	Tue Nov 14 09:31:56 2017	(r325799)
+++ head/bin/freebsd-version/freebsd-version.1	Tue Nov 14 10:15:17 2017	(r325800)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd October 5, 2013
+.Dd November 14, 2017
 .Dt FREEBSD-VERSION 1
 .Os
 .Sh NAME
@@ -33,7 +33,7 @@
 .Nd print the version and patch level of the installed system
 .Sh SYNOPSIS
 .Nm
-.Op Fl ku
+.Op Fl kru
 .Sh DESCRIPTION
 The
 .Nm
@@ -50,6 +50,11 @@ if a new kernel has been installed but the system has 
 rebooted,
 .Nm
 will print the version and patch level of the new kernel.
+.It Fl r
+Print the version and patch level of the running kernel.
+Unlike
+.Xr uname 1 ,
+this is unaffected by environment variables.
 .It Fl u
 Print the version and patch level of the installed userland.
 These are hardcoded into
@@ -57,14 +62,10 @@ These are hardcoded into
 during the build.
 .El
 .Pp
-If both
-.Fl k
-and
-.Fl u
-are specified,
+If several of the above options are specified,
 .Nm
-will print the kernel version first, then the userland version, on
-separate lines.
+will print the installed kernel version first, then the running kernel
+version, and finally the userland version, on separate lines.
 If neither is specified, it will print the userland version only.
 .Sh IMPLEMENTATION NOTES
 The

Modified: head/bin/freebsd-version/freebsd-version.sh.in
==============================================================================
--- head/bin/freebsd-version/freebsd-version.sh.in	Tue Nov 14 09:31:56 2017	(r325799)
+++ head/bin/freebsd-version/freebsd-version.sh.in	Tue Nov 14 10:15:17 2017	(r325800)
@@ -38,7 +38,7 @@ LOADER_RE1='^\([A-Z_a-z][0-9A-Z_a-z]*=[-./0-9A-Z_a-z]\
 LOADER_RE2='^\([A-Z_a-z][0-9A-Z_a-z]*="[-./0-9A-Z_a-z]\{1,\}"\).*$'
 KERNEL_RE='^@@TYPE@@ \([-.0-9A-Za-z]\{1,\}\) .*$'
 
-progname=$(basename $0)
+progname=${0##*/}
 
 #
 # Print an error message and exit.
@@ -71,6 +71,13 @@ kernel_version() {
 }
 
 #
+# Print the version of the currently running kernel.
+#
+running_version() {
+	sysctl -n kern.osrelease
+}
+
+#
 # Print the hardcoded userland version.
 #
 userland_version() {
@@ -81,7 +88,7 @@ userland_version() {
 # Print a usage string and exit.
 #
 usage() {
-	echo "usage: $progname [-ku]" >&2
+	echo "usage: $progname [-kru]" >&2
 	exit 1
 }
 
@@ -90,11 +97,14 @@ usage() {
 #
 main() {
 	# parse command-line arguments
-	while getopts "ku" option ; do
+	while getopts "kru" option ; do
 		case $option in
 		k)
 			opt_k=1
 			;;
+		r)
+			opt_r=1
+			;;
 		u)
 			opt_u=1
 			;;
@@ -108,13 +118,18 @@ main() {
 	fi
 
 	# default is -u
-	if [ $((opt_k + opt_u)) -eq 0 ] ; then
+	if [ $((opt_k + opt_r + opt_u)) -eq 0 ] ; then
 		opt_u=1
 	fi
 
-	# print kernel version
+	# print installed kernel version
 	if [ $opt_k ] ; then
 		kernel_version
+	fi
+
+	# print running kernel version
+	if [ $opt_r ] ; then
+		running_version
 	fi
 
 	# print userland version



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711141015.vAEAFH5f072066>