From b3480596e29138bd7f3a063404d4eb6e3c9c5ef5 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Feb 2014 17:07:28 +0000 Subject: [PATCH] MFC r256557 - kernel and userland osreldate helpers. git-svn-id: svn://svn.freebsd.org/base/stable/8@261775 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.bin/uname/uname.1 | 30 ++++++++++++++++++++++++++++-- usr.bin/uname/uname.c | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/usr.bin/uname/uname.1 b/usr.bin/uname/uname.1 index f78e437c7..74c1cc4b1 100644 --- a/usr.bin/uname/uname.1 +++ b/usr.bin/uname/uname.1 @@ -32,7 +32,7 @@ .\" @(#)uname.1 8.3 (Berkeley) 4/8/94 .\" $FreeBSD$ .\" -.Dd January 26, 2010 +.Dd February 11, 2014 .Dt UNAME 1 .Os .Sh NAME @@ -40,7 +40,7 @@ .Nd display information about the system .Sh SYNOPSIS .Nm -.Op Fl aimnoprsv +.Op Fl aiKmnoprsUv .Sh DESCRIPTION The .Nm @@ -59,6 +59,10 @@ and were specified. .It Fl i Write the kernel ident to standard output. +.It Fl K +Write the +.Fx +version of the kernel. .It Fl m Write the type of the current hardware platform to standard output. .It Fl n @@ -74,6 +78,10 @@ Write the current release level of the operating system to standard output. .It Fl s Write the name of the operating system implementation to standard output. +.It Fl U +Write the +.Fx +version of the user environment. .It Fl v Write the version level of this release of the operating system to standard output. @@ -83,6 +91,14 @@ If the .Fl a flag is specified, or multiple flags are specified, all output is written on a single line, separated by spaces. +.Pp +The +.Fl K +and +.Fl U +flags are intended to be used for fine grain differentiation of incremental +.Fx +development and user visible changes. .Sh ENVIRONMENT An environment variable composed of the string .Ev UNAME_ @@ -95,6 +111,8 @@ of the environment variable. .Sh EXIT STATUS .Ex -std .Sh SEE ALSO +.Xr feature_present 3 , +.Xr getosreldate 3 , .Xr sysctl 3 , .Xr uname 3 , .Xr sysctl 8 @@ -108,3 +126,11 @@ specification. The .Nm command appeared in PWB UNIX. +.Pp +The +.Fl K +and +.Fl U +extension flags were first released in +.Fx 10.0 +and then ported back to older stable branches. diff --git a/usr.bin/uname/uname.c b/usr.bin/uname/uname.c index 0e120b9b5..6b4503e2d 100644 --- a/usr.bin/uname/uname.c +++ b/usr.bin/uname/uname.c @@ -54,6 +54,8 @@ static const char sccsid[] = "@(#)uname.c 8.2 (Berkeley) 5/4/95"; #include #include +#include + #define MFLAG 0x01 #define NFLAG 0x02 #define PFLAG 0x04 @@ -61,9 +63,12 @@ static const char sccsid[] = "@(#)uname.c 8.2 (Berkeley) 5/4/95"; #define SFLAG 0x10 #define VFLAG 0x20 #define IFLAG 0x40 +#define UFLAG 0x80 +#define KFLAG 0x100 typedef void (*get_t)(void); -get_t get_ident, 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_kernvers, get_uservers, get_version; void native_ident(void); void native_platform(void); @@ -72,11 +77,13 @@ void native_arch(void); void native_release(void); void native_sysname(void); void native_version(void); +void native_kernvers(void); +void native_uservers(void); void print_uname(u_int); void setup_get(void); void usage(void); -char *ident, *platform, *hostname, *arch, *release, *sysname, *version; +char *ident, *platform, *hostname, *arch, *release, *sysname, *version, *kernvers, *uservers; int space; int @@ -88,7 +95,7 @@ main(int argc, char *argv[]) setup_get(); flags = 0; - while ((ch = getopt(argc, argv, "aimnoprsv")) != -1) + while ((ch = getopt(argc, argv, "aiKmnoprsUv")) != -1) switch(ch) { case 'a': flags |= (MFLAG | NFLAG | RFLAG | SFLAG | VFLAG); @@ -96,6 +103,9 @@ main(int argc, char *argv[]) case 'i': flags |= IFLAG; break; + case 'K': + flags |= KFLAG; + break; case 'm': flags |= MFLAG; break; @@ -112,6 +122,9 @@ main(int argc, char *argv[]) case 'o': flags |= SFLAG; break; + case 'U': + flags |= UFLAG; + break; case 'v': flags |= VFLAG; break; @@ -152,6 +165,8 @@ setup_get(void) CHECK_ENV("m", platform); CHECK_ENV("p", arch); CHECK_ENV("i", ident); + CHECK_ENV("K", kernvers); + CHECK_ENV("U", uservers); } #define PRINT_FLAG(flags,flag,var) \ @@ -175,6 +190,8 @@ print_uname(u_int flags) PRINT_FLAG(flags, MFLAG, platform); PRINT_FLAG(flags, PFLAG, arch); PRINT_FLAG(flags, IFLAG, ident); + PRINT_FLAG(flags, KFLAG, kernvers); + PRINT_FLAG(flags, UFLAG, uservers); printf("\n"); } @@ -242,9 +259,27 @@ NATIVE_SYSCTL2_GET(arch, CTL_HW, HW_MACHINE_ARCH) { NATIVE_SYSCTLNAME_GET(ident, "kern.ident") { } NATIVE_SET; +void +native_uservers(void) +{ + static char buf[128]; + + snprintf(buf, sizeof(buf), "%d", __FreeBSD_version); + uservers = buf; +} + +void +native_kernvers(void) +{ + static char buf[128]; + + snprintf(buf, sizeof(buf), "%d", getosreldate()); + kernvers = buf; +} + void usage(void) { - fprintf(stderr, "usage: uname [-aimnoprsv]\n"); + fprintf(stderr, "usage: uname [-aiKmnoprsUv]\n"); exit(1); } -- 2.45.0