Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/sysctl add -e flag to set the separator to '=' where th...



details:   https://anonhg.NetBSD.org/src/rev/9be838d6fdc6
branches:  trunk
changeset: 552163:9be838d6fdc6
user:      grant <grant%NetBSD.org@localhost>
date:      Sat Sep 20 17:02:17 2003 +0000

description:
add -e flag to set the separator to '=' where the default is ' = '.
this allows sysctl output to fed back into itself. inspired by
FreeBSD's sysctl(8).

ok'd by atatat.

diffstat:

 sbin/sysctl/sysctl.8 |  16 ++++++++++++++--
 sbin/sysctl/sysctl.c |  39 ++++++++++++++++++++++++---------------
 2 files changed, 38 insertions(+), 17 deletions(-)

diffs (194 lines):

diff -r a4eba406a548 -r 9be838d6fdc6 sbin/sysctl/sysctl.8
--- a/sbin/sysctl/sysctl.8      Sat Sep 20 15:40:41 2003 +0000
+++ b/sbin/sysctl/sysctl.8      Sat Sep 20 17:02:17 2003 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sysctl.8,v 1.98 2003/09/17 18:24:47 grant Exp $
+.\"    $NetBSD: sysctl.8,v 1.99 2003/09/20 17:02:17 grant Exp $
 .\"
 .\" Copyright (c) 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"    @(#)sysctl.8    8.1 (Berkeley) 6/6/93
 .\"
-.Dd August 7, 2003
+.Dd September 21, 2003
 .Dt SYSCTL 8
 .Os
 .Sh NAME
@@ -38,6 +38,7 @@
 .Sh SYNOPSIS
 .Nm sysctl
 .Op Fl n
+.Op Fl e
 .Ar name ...
 .Nm sysctl
 .Op Fl n
@@ -46,9 +47,11 @@
 .Ar name Ns Li = Ns Ar value ...
 .Nm sysctl
 .Op Fl n
+.Op Fl e
 .Fl a
 .Nm sysctl
 .Op Fl n
+.Op Fl e
 .Fl A
 .Nm sysctl
 .Op Fl n
@@ -74,6 +77,15 @@
 .Fl a
 flag; for the table values,
 the name of the utility to retrieve them is given.
+.It Fl e
+Separate the name and the value of the variable(s) with
+.Ql = .
+This is useful for producing output which can be fed back to the
+.Nm
+utility.
+This option is ignored if
+.Fl n
+is specified or a variable is being set.
 .It Fl f
 Specifies the name of a file to read and process.
 Blank lines and comments (beginning with
diff -r a4eba406a548 -r 9be838d6fdc6 sbin/sysctl/sysctl.c
--- a/sbin/sysctl/sysctl.c      Sat Sep 20 15:40:41 2003 +0000
+++ b/sbin/sysctl/sysctl.c      Sat Sep 20 17:02:17 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysctl.c,v 1.71 2003/08/07 10:04:40 agc Exp $  */
+/*     $NetBSD: sysctl.c,v 1.72 2003/09/20 17:02:19 grant Exp $        */
 
 /*
  * Copyright (c) 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)sysctl.c   8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: sysctl.c,v 1.71 2003/08/07 10:04:40 agc Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.72 2003/09/20 17:02:19 grant Exp $");
 #endif
 #endif /* not lint */
 
@@ -157,7 +157,7 @@
        { 0, 0},
 };
 
-int    Aflag, aflag, nflag, qflag, wflag;
+int    Aflag, aflag, eflag, nflag, qflag, wflag;
 FILE   *warnfp = stderr;
 
 /*
@@ -217,7 +217,7 @@
        char *fn = NULL;
        int ch, lvl1;
 
-       while ((ch = getopt(argc, argv, "Aaf:nqw")) != -1) {
+       while ((ch = getopt(argc, argv, "Aaef:nqw")) != -1) {
                switch (ch) {
 
                case 'A':
@@ -228,6 +228,10 @@
                        aflag = 1;
                        break;
 
+               case 'e':
+                       eflag = 1;
+                       break;
+
                case 'f':
                        fn = optarg;
                        wflag = 1;
@@ -327,9 +331,14 @@
        size_t size;
        struct list *lp;
        int mib[CTL_MAXNAME];
-       char *cp, *bufp, buf[BUFSIZ];
+       char *cp, *bufp, buf[BUFSIZ], *eq;
        double loads[3];
 
+       if (eflag)
+               eq = "=";
+       else
+               eq = " = ";
+
        bufp = buf;
        snprintf(buf, BUFSIZ, "%s", string);
        if ((cp = strchr(string, '=')) != NULL) {
@@ -634,7 +643,7 @@
                if (!nflag) {
                        boottime = btp->tv_sec;
                        /* ctime() provides the trailing newline */
-                       printf("%s = %s", string, ctime(&boottime));
+                       printf("%s%s%s", string, eq, ctime(&boottime));
                } else
                        printf("%ld\n", (long) btp->tv_sec);
                return;
@@ -643,7 +652,7 @@
                dev_t dev = *(dev_t *)buf;
 
                if (!nflag)
-                       printf("%s = %s\n", string, devname(dev, S_IFCHR));
+                       printf("%s%s%s\n", string, eq, devname(dev, S_IFCHR));
                else
                        printf("0x%x\n", dev);
                return;
@@ -702,7 +711,7 @@
                int i;
 
                if (!nflag)
-                       printf("%s%s ", string, newsize ? ":" : " =");
+                       printf("%s%s", string, eq);
                for (i = 0; i < size - 1; i++)
                        printf("\\x%2.2x", buf[i]);
                if (newsize != 0) {
@@ -718,7 +727,7 @@
        case CTLTYPE_INT:
                if (newsize == 0) {
                        if (!nflag)
-                               printf("%s = ", string);
+                               printf("%s%s", string, eq);
                        printf("%d\n", *(int *)buf);
                } else {
                        if (!nflag)
@@ -733,7 +742,7 @@
                        buf[0] = '\0';
                if (newsize == 0) {
                        if (!nflag)
-                               printf("%s = ", string);
+                               printf("%s%s", string, eq);
                        printf("%s\n", buf);
                } else {
                        if (!nflag)
@@ -752,7 +761,7 @@
 
                if (newsize == 0) {
                        if (!nflag)
-                               printf("%s = ", string);
+                               printf("%s%s", string, eq);
                        PRINTF_LIMIT((long long)(*(quad_t *)buf));
                } else {
                        if (!nflag) {
@@ -769,7 +778,7 @@
        case CTLTYPE_QUAD:
                if (newsize == 0) {
                        if (!nflag)
-                               printf("%s = ", string);
+                               printf("%s%s", string, eq);
                        printf("%lld\n", (long long)(*(quad_t *)buf));
                } else {
                        if (!nflag)
@@ -1257,10 +1266,10 @@
 
        (void)fprintf(stderr,
            "Usage:\t%s %s\n\t%s %s\n\t%s %s\n\t%s %s\n\t%s %s\n",
-           progname, "[-n] variable ...",
+           progname, "[-n] [-e] variable ...",
            progname, "[-n] [-q] -w variable=value ...",
-           progname, "[-n] -a",
-           progname, "[-n] -A",
+           progname, "[-n] [-e] -a",
+           progname, "[-n] [-e] -A",
            progname, "[-n] [-q] -f file");
        exit(1);
 }



Home | Main Index | Thread Index | Old Index