From nobody Fri Oct 08 16:29:40 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id B603E17F42D7; Fri, 8 Oct 2021 16:29:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HQtv84mDFz3F99; Fri, 8 Oct 2021 16:29:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 853AA270A; Fri, 8 Oct 2021 16:29:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 198GTeqS029672; Fri, 8 Oct 2021 16:29:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 198GTels029671; Fri, 8 Oct 2021 16:29:40 GMT (envelope-from git) Date: Fri, 8 Oct 2021 16:29:40 GMT Message-Id: <202110081629.198GTels029671@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: cae3560307ec - stable/13 - freebsd-version(1): Add -j flag to support jails List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: cae3560307ec593cf35211536e8deb5c99def561 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=cae3560307ec593cf35211536e8deb5c99def561 commit cae3560307ec593cf35211536e8deb5c99def561 Author: Faraz Vahedi AuthorDate: 2021-10-01 18:46:23 +0000 Commit: Kyle Evans CommitDate: 2021-10-08 16:29:07 +0000 freebsd-version(1): Add -j flag to support jails Make freebsd-version(1) support jails by adding the -j flag which takes a jail jid or name as an argument. As with other options, -j flags stack and display in the order requested. Reviewed by: bcr (manpages), kevans MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25705 (cherry picked from commit f54b18fc4d72c566912b9a41601ed87a852960e7) --- bin/freebsd-version/freebsd-version.1 | 13 +++++++++++-- bin/freebsd-version/freebsd-version.sh.in | 29 ++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/bin/freebsd-version/freebsd-version.1 b/bin/freebsd-version/freebsd-version.1 index 710bb23ac4c3..b580c580fcbc 100644 --- a/bin/freebsd-version/freebsd-version.1 +++ b/bin/freebsd-version/freebsd-version.1 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 14, 2017 +.Dd October 1, 2021 .Dt FREEBSD-VERSION 1 .Os .Sh NAME @@ -34,6 +34,7 @@ .Sh SYNOPSIS .Nm .Op Fl kru +.Op Fl j Ar jail .Sh DESCRIPTION The .Nm @@ -60,12 +61,20 @@ Print the version and patch level of the installed userland. These are hardcoded into .Nm during the build. +.It Fl j Ar jail +Print the version and patch level of the installed userland in the +given jail specified by +.Va jid +or +.Va name . +This option can be specified multiple times. .El .Pp If several of the above options are specified, .Nm will print the installed kernel version first, then the running kernel -version, and finally the userland version, on separate lines. +version, next the userland version, and finally the userland version +of the specified jails, on separate lines. If neither is specified, it will print the userland version only. .Sh IMPLEMENTATION NOTES The diff --git a/bin/freebsd-version/freebsd-version.sh.in b/bin/freebsd-version/freebsd-version.sh.in index 9541b86a2636..be1be366f652 100644 --- a/bin/freebsd-version/freebsd-version.sh.in +++ b/bin/freebsd-version/freebsd-version.sh.in @@ -84,11 +84,20 @@ userland_version() { echo $USERLAND_VERSION } +# +# Print the hardcoded userland version of a jail. +# +jail_version() { + for i in $jail; do + jexec -- $i freebsd-version + done +} + # # Print a usage string and exit. # usage() { - echo "usage: $progname [-kru]" >&2 + echo "usage: $progname [-kru] [-j jail]" >&2 exit 1 } @@ -97,7 +106,8 @@ usage() { # main() { # parse command-line arguments - while getopts "kru" option ; do + local OPTIND=1 OPTARG option + while getopts "kruj:" option ; do case $option in k) opt_k=1 @@ -108,6 +118,14 @@ main() { u) opt_u=1 ;; + j) + if [ $opt_j ] ; then + jail="$jail $OPTARG" + else + opt_j=1 + jail="$OPTARG" + fi + ;; *) usage ;; @@ -118,7 +136,7 @@ main() { fi # default is -u - if [ $((opt_k + opt_r + opt_u)) -eq 0 ] ; then + if [ $((opt_k + opt_r + opt_u + opt_j)) -eq 0 ] ; then opt_u=1 fi @@ -136,6 +154,11 @@ main() { if [ $opt_u ] ; then userland_version fi + + # print jail version + if [ $opt_j ] ; then + jail_version + fi } main "$@"