From owner-freebsd-audit Mon Oct 29 13:30:26 2001 Delivered-To: freebsd-audit@freebsd.org Received: from heechee.tobez.org (254.adsl0.ryv.worldonline.dk [213.237.10.254]) by hub.freebsd.org (Postfix) with ESMTP id 0F2ED37B407 for ; Mon, 29 Oct 2001 13:30:13 -0800 (PST) Received: by heechee.tobez.org (Postfix, from userid 1001) id 203C15411; Mon, 29 Oct 2001 22:30:04 +0100 (CET) Date: Mon, 29 Oct 2001 22:30:04 +0100 From: Anton Berezin To: audit@freebsd.org Subject: New option to sysctl(8) Message-ID: <20011029223004.B50609@heechee.tobez.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Index: sysctl.8 =================================================================== RCS file: /home/ncvs/src/sbin/sysctl/sysctl.8,v retrieving revision 1.38 diff -u -r1.38 sysctl.8 --- sysctl.8 2 Aug 2001 12:38:23 -0000 1.38 +++ sysctl.8 29 Oct 2001 21:20:44 -0000 @@ -40,11 +40,11 @@ .Nd get or set kernel state .Sh SYNOPSIS .Nm -.Op Fl bNnox +.Op Fl beNnox .Ar name Ns Op = Ns Ar value .Ar ... .Nm -.Op Fl bNnox +.Op Fl beNnox .Fl a .Sh DESCRIPTION The @@ -71,6 +71,16 @@ Force the value of the variable(s) to be output in raw, binary format. No names are printed and no terminating newlines are output. This is mostly useful with a single variable. +.It Fl e +Separate the name and the value of the variable(s) with `='. +This is useful for producing output which can be fed back to the +.Nm +utility. +This option is ignored if either +.Fl N +or +.Fl n +is specified, or a variable is being set. .It Fl N Show only variable names, not their values. This is particularly useful with shells that offer programmable Index: sysctl.c =================================================================== RCS file: /home/ncvs/src/sbin/sysctl/sysctl.c,v retrieving revision 1.37 diff -u -r1.37 sysctl.c --- sysctl.c 18 Jun 2001 21:06:24 -0000 1.37 +++ sysctl.c 29 Oct 2001 21:22:54 -0000 @@ -58,7 +58,7 @@ #include #include -static int aflag, bflag, Nflag, nflag, oflag, xflag; +static int aflag, bflag, eflag, Nflag, nflag, oflag, xflag; static int oidfmt(int *, int, char *, u_int *); static void parse(char *); @@ -71,8 +71,8 @@ { (void)fprintf(stderr, "%s\n%s\n", - "usage: sysctl [-bNnox] variable[=value] ...", - " sysctl [-bNnox] -a"); + "usage: sysctl [-beNnox] variable[=value] ...", + " sysctl [-beNnox] -a"); exit(1); } @@ -83,7 +83,7 @@ setbuf(stdout,0); setbuf(stderr,0); - while ((ch = getopt(argc, argv, "AabNnowxX")) != -1) { + while ((ch = getopt(argc, argv, "AabeNnowxX")) != -1) { switch (ch) { case 'A': /* compatibility */ @@ -95,6 +95,9 @@ case 'b': bflag = 1; break; + case 'e': + eflag = 1; + break; case 'N': Nflag = 1; break; @@ -380,7 +383,7 @@ show_var(int *oid, int nlen) { u_char buf[BUFSIZ], *val, *p; - char name[BUFSIZ], *fmt; + char name[BUFSIZ], *fmt, *sep; int qoid[CTL_MAXNAME+2]; int i; size_t j, len; @@ -401,6 +404,11 @@ return (0); } + if (eflag) + sep = "="; + else + sep = ": "; + /* find an estimate of how much we need for this var */ j = 0; i = sysctl(oid, nlen, 0, &j, 0, 0); @@ -431,13 +439,13 @@ switch (*fmt) { case 'A': if (!nflag) - printf("%s: ", name); + printf("%s%s", name, sep); printf("%s", p); return (0); case 'I': if (!nflag) - printf("%s: ", name); + printf("%s%s", name, sep); fmt++; val = ""; while (len >= sizeof(int)) { @@ -453,7 +461,7 @@ case 'L': if (!nflag) - printf("%s: ", name); + printf("%s%s", name, sep); fmt++; val = ""; while (len >= sizeof(long)) { @@ -469,7 +477,7 @@ case 'P': if (!nflag) - printf("%s: ", name); + printf("%s%s", name, sep); printf("%p", *(void **)p); return (0); @@ -488,7 +496,7 @@ func = NULL; if (func) { if (!nflag) - printf("%s: ", name); + printf("%s%s", name, sep); return ((*func)(len, p)); } /* FALL THROUGH */ @@ -496,7 +504,7 @@ if (!oflag && !xflag) return (1); if (!nflag) - printf("%s: ", name); + printf("%s%s", name, sep); printf("Format:%s Length:%d Dump:0x", fmt, len); while (len-- && (xflag || p < val + 16)) printf("%02x", *p++); =Anton. -- | Anton Berezin | FreeBSD: The power to serve | | catpipe Systems ApS _ _ |_ | http://www.FreeBSD.org | | tobez@catpipe.net (_(_|| | tobez@FreeBSD.org | | +45 7021 0050 | Private: tobez@tobez.org | To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message