Page MenuHomeFreeBSD

D34012.id101834.diff
No OneTemporary

D34012.id101834.diff

Index: sbin/sysctl/sysctl.c
===================================================================
--- sbin/sysctl/sysctl.c
+++ sbin/sysctl/sysctl.c
@@ -949,6 +949,41 @@
return (0);
}
+/*
+ * This displays information aout a sysctl
+ *
+ * Returns zero if anything was actually output.
+ * Returns one if didn't know what to do with this.
+ * Return minus one if we had errors.
+ */
+static void
+show_info(char *name, const char *sep, int ctltype, int *qoid, int nlen)
+{
+ u_char buf[BUFSIZ];
+ const char *prntype;
+ int i;
+ size_t j;
+
+ 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;
+ }
+
+ qoid[1] = CTL_SYSCTL_OIDDESCR;
+ bzero(buf, BUFSIZ);
+ j = sizeof(buf);
+ i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
+ printf("%s", buf);
+}
+
/*
* This formats and outputs the value of one variable
*
@@ -960,9 +995,9 @@
show_var(int *oid, int nlen, bool honor_skip)
{
static int skip_len = 0, skip_oid[CTL_MAXNAME];
- u_char buf[BUFSIZ], *val, *oval, *p;
+ u_char *val, *oval, *p;
char name[BUFSIZ], fmt[BUFSIZ];
- const char *sep, *sep1, *prntype;
+ const char *sep, *sep1;
int qoid[CTL_MAXNAME+2];
uintmax_t umv;
intmax_t mv;
@@ -977,7 +1012,6 @@
/* Silence GCC. */
umv = mv = intlen = 0;
- bzero(buf, BUFSIZ);
bzero(fmt, BUFSIZ);
bzero(name, BUFSIZ);
qoid[0] = CTL_SYSCTL;
@@ -1009,22 +1043,7 @@
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] = CTL_SYSCTL_OIDDESCR;
- j = sizeof(buf);
- i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
- printf("%s", buf);
+ show_info(name, sep, ctltype, qoid, nlen);
return (0);
}
Index: sbin/sysctl/tests/Makefile
===================================================================
--- /dev/null
+++ sbin/sysctl/tests/Makefile
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+ATF_TESTS_SH= sysctl_test
+
+.include <bsd.test.mk>
Index: sbin/sysctl/tests/Makefile.depend
===================================================================
--- /dev/null
+++ sbin/sysctl/tests/Makefile.depend
@@ -0,0 +1,11 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
Index: sbin/sysctl/tests/sysctl_test.sh
===================================================================
--- /dev/null
+++ sbin/sysctl/tests/sysctl_test.sh
@@ -0,0 +1,119 @@
+# Copyright (c) 2022 Yoshihiro Ota <ota@j.email.ne.jp>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+sysctl_name="kern.ostype"
+sysctl_value="FreeBSD"
+sysctl_type="string"
+sysctl_description="Operating system type"
+
+atf_test_case sysctl_by_name
+sysctl_by_name_head()
+{
+ atf_set "descr" "Verify name without any arguments"
+}
+sysctl_by_name_body()
+{
+ atf_check -o "inline:${sysctl_name}: ${sysctl_value}\n" sysctl ${sysctl_name}
+}
+
+
+atf_test_case sysctl_nflag
+sysctl_nflag()
+{
+ atf_set "descr" "Verify -n argument"
+}
+sysctl_nflag_body()
+{
+ atf_check -o "inline:${sysctl_value}\n" sysctl -n ${sysctl_name}
+}
+
+
+atf_test_case sysctl_eflag
+sysctl_eflag()
+{
+ atf_set "descr" "Verify -e argument"
+}
+sysctl_eflag_body()
+{
+ atf_check -o "inline:${sysctl_name}=${sysctl_value}\n" sysctl -e ${sysctl_name}
+}
+
+
+atf_test_case sysctl_tflag
+sysctl_tflag()
+{
+ atf_set "descr" "Verify -t argument"
+}
+sysctl_tflag_body()
+{
+ atf_check -o "inline:${sysctl_name}: ${sysctl_type}\n" sysctl -t ${sysctl_name}
+}
+
+
+atf_test_case sysctl_dflag
+sysctl_dflag()
+{
+ atf_set "descr" "Verify -d argument"
+}
+sysctl_dflag_body()
+{
+ atf_check -o "inline:${sysctl_name}: ${sysctl_description}\n" sysctl -d ${sysctl_name}
+}
+
+
+atf_test_case sysctl_tflag_dflag
+sysctl_tflag_dflag()
+{
+ atf_set "descr" "Verify -t -d arguments"
+}
+sysctl_tflag_dflag_body()
+{
+ atf_check -o "inline:${sysctl_name}: ${sysctl_type}: ${sysctl_description}\n" sysctl -t -d ${sysctl_name}
+ atf_check -o "inline:${sysctl_name}: ${sysctl_type}: ${sysctl_description}\n" sysctl -d -t ${sysctl_name}
+}
+
+
+atf_test_case sysctl_nflag_tflag_dflag
+sysctl_nflag_tflag_dflag()
+{
+ atf_set "descr" "Verify -n -t -d arguments"
+}
+sysctl_nflag_tflag_dflag_body()
+{
+ atf_check -o "inline:${sysctl_type}: ${sysctl_description}\n" sysctl -n -t -d ${sysctl_name}
+}
+
+
+atf_init_test_cases()
+{
+ atf_add_test_case sysctl_by_name
+ atf_add_test_case sysctl_nflag
+ atf_add_test_case sysctl_eflag
+ atf_add_test_case sysctl_tflag
+ atf_add_test_case sysctl_dflag
+ atf_add_test_case sysctl_tflag_dflag
+ atf_add_test_case sysctl_nflag_tflag_dflag
+}

File Metadata

Mime Type
text/plain
Expires
Sat, May 23, 4:53 AM (2 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33440936
Default Alt Text
D34012.id101834.diff (6 KB)

Event Timeline