svn commit: r292045 - head/sbin/sysctl

Steven Hartland steven.hartland at multiplay.co.uk
Thu Dec 10 02:33:53 UTC 2015


Nice Marcelo, I always thought it was odd there was no way to easily get 
this info :)

On 10/12/2015 02:11, Marcelo Araujo wrote:
> Author: araujo
> Date: Thu Dec 10 02:11:42 2015
> New Revision: 292045
> URL: https://svnweb.freebsd.org/changeset/base/292045
>
> Log:
>    Add -t option to display field types.
>    
>    PR:		bin/203918
>    Submitted by:	ota <ota at j.email.ne.jp>
>    Reviewed by:	cem
>    Approved by:	bapt (mentor)
>    Differential Revision:	https://reviews.freebsd.org/D4451
>
> Modified:
>    head/sbin/sysctl/sysctl.8
>    head/sbin/sysctl/sysctl.c
>
> Modified: head/sbin/sysctl/sysctl.8
> ==============================================================================
> --- head/sbin/sysctl/sysctl.8	Thu Dec 10 02:05:35 2015	(r292044)
> +++ head/sbin/sysctl/sysctl.8	Thu Dec 10 02:11:42 2015	(r292045)
> @@ -28,7 +28,7 @@
>   .\"	From: @(#)sysctl.8	8.1 (Berkeley) 6/6/93
>   .\" $FreeBSD$
>   .\"
> -.Dd February 12, 2015
> +.Dd December 10, 2015
>   .Dt SYSCTL 8
>   .Os
>   .Sh NAME
> @@ -36,13 +36,13 @@
>   .Nd get or set kernel state
>   .Sh SYNOPSIS
>   .Nm
> -.Op Fl bdehiNnoRTqx
> +.Op Fl bdehiNnoRTtqx
>   .Op Fl B Ar bufsize
>   .Op Fl f Ar filename
>   .Ar name Ns Op = Ns Ar value
>   .Ar ...
>   .Nm
> -.Op Fl bdehNnoRTqx
> +.Op Fl bdehNnoRTtqx
>   .Op Fl B Ar bufsize
>   .Fl a
>   .Sh DESCRIPTION
> @@ -140,6 +140,8 @@ Suppress some warnings generated by
>   to standard error.
>   .It Fl T
>   Display only variables that are settable via loader (CTLFLAG_TUN).
> +.It Fl t
> +Print the type of the variable.
>   .It Fl W
>   Display only writable variables that are not statistical.
>   Useful for determining the set of runtime tunable sysctls.
>
> Modified: head/sbin/sysctl/sysctl.c
> ==============================================================================
> --- head/sbin/sysctl/sysctl.c	Thu Dec 10 02:05:35 2015	(r292044)
> +++ head/sbin/sysctl/sysctl.c	Thu Dec 10 02:11:42 2015	(r292045)
> @@ -72,7 +72,7 @@ static const char rcsid[] =
>   static const char *conffile;
>   
>   static int	aflag, bflag, Bflag, dflag, eflag, hflag, iflag;
> -static int	Nflag, nflag, oflag, qflag, Tflag, Wflag, xflag;
> +static int	Nflag, nflag, oflag, qflag, tflag, Tflag, Wflag, xflag;
>   
>   static int	oidfmt(int *, int, char *, u_int *);
>   static int	parsefile(const char *);
> @@ -120,6 +120,9 @@ static const char *ctl_typename[CTLTYPE+
>   	[CTLTYPE_S16] = "int16_t",
>   	[CTLTYPE_S32] = "int32_t",
>   	[CTLTYPE_S64] = "int64_t",
> +	[CTLTYPE_NODE] = "node",
> +	[CTLTYPE_STRING] = "string",
> +	[CTLTYPE_OPAQUE] = "opaque",
>   };
>   
>   static void
> @@ -127,8 +130,8 @@ usage(void)
>   {
>   
>   	(void)fprintf(stderr, "%s\n%s\n",
> -	    "usage: sysctl [-bdehiNnoqTWx] [ -B <bufsize> ] [-f filename] name[=value] ...",
> -	    "       sysctl [-bdehNnoqTWx] [ -B <bufsize> ] -a");
> +	    "usage: sysctl [-bdehiNnoqTtWx] [ -B <bufsize> ] [-f filename] name[=value] ...",
> +	    "       sysctl [-bdehNnoqTtWx] [ -B <bufsize> ] -a");
>   	exit(1);
>   }
>   
> @@ -142,7 +145,7 @@ main(int argc, char **argv)
>   	setbuf(stdout,0);
>   	setbuf(stderr,0);
>   
> -	while ((ch = getopt(argc, argv, "AabB:def:hiNnoqTwWxX")) != -1) {
> +	while ((ch = getopt(argc, argv, "AabB:def:hiNnoqtTwWxX")) != -1) {
>   		switch (ch) {
>   		case 'A':
>   			/* compatibility */
> @@ -184,6 +187,9 @@ main(int argc, char **argv)
>   		case 'q':
>   			qflag = 1;
>   			break;
> +		case 't':
> +			tflag = 1;
> +			break;
>   		case 'T':
>   			Tflag = 1;
>   			break;
> @@ -856,7 +862,7 @@ show_var(int *oid, int nlen)
>   {
>   	u_char buf[BUFSIZ], *val, *oval, *p;
>   	char name[BUFSIZ], fmt[BUFSIZ];
> -	const char *sep, *sep1;
> +	const char *sep, *sep1, *prntype;
>   	int qoid[CTL_MAXNAME+2];
>   	uintmax_t umv;
>   	intmax_t mv;
> @@ -902,12 +908,23 @@ show_var(int *oid, int nlen)
>   	else
>   		sep = ": ";
>   
> -	if (dflag) {	/* just print description */
> +	ctltype = (kind & CTLTYPE);
> +	if (tflag || dflag) {
> +		if (!nflag)
> +			printf("%s%s", name, sep);
> +        	if (ctl_typename[ctltype] != NULL)
> +            		prntype = ctl_typename[ctltype];
> +        	else
> +            		prntype = "unknown";
> +		if (tflag && dflag)
> +			printf("%s%s", prntype, sep);
> +		else if (tflag) {
> +			printf("%s", prntype);
> +			return (0);
> +		}
>   		qoid[1] = 5;
>   		j = sizeof(buf);
>   		i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
> -		if (!nflag)
> -			printf("%s%s", name, sep);
>   		printf("%s", buf);
>   		return (0);
>   	}
> @@ -925,7 +942,6 @@ show_var(int *oid, int nlen)
>   		warnx("malloc failed");
>   		return (1);
>   	}
> -	ctltype = (kind & CTLTYPE);
>   	len = j;
>   	i = sysctl(oid, nlen, val, &len, 0, 0);
>   	if (i != 0 || (len == 0 && ctltype != CTLTYPE_STRING)) {
>



More information about the svn-src-head mailing list