1#!/bin/sh
2
3SYSCTL="/proc/sys"
4TARGET="${SYSCTL}/kernel/domainname"
5ORIG=$(cat "${TARGET}")
6TEST_STR="Testing sysctl"
7
8. ./common_tests
9
10# Only string sysctls support seeking/appending.
11MAXLEN=65
12
13echo -n "Writing entire sysctl in short writes ... "
14set_orig
15dd if="${TEST_FILE}" of="${TARGET}" bs=1 2>/dev/null
16if ! verify "${TARGET}"; then
17	echo "FAIL" >&2
18	rc=1
19else
20	echo "ok"
21fi
22
23echo -n "Writing middle of sysctl after unsynchronized seek ... "
24set_test
25dd if="${TEST_FILE}" of="${TARGET}" bs=1 seek=1 2>/dev/null
26if verify "${TARGET}"; then
27	echo "FAIL" >&2
28	rc=1
29else
30	echo "ok"
31fi
32
33echo -n "Checking sysctl maxlen is at least $MAXLEN ... "
34set_orig
35perl -e 'print "A" x ('"${MAXLEN}"'-2), "B";' | \
36	dd of="${TARGET}" bs="${MAXLEN}" 2>/dev/null
37if ! grep -q B "${TARGET}"; then
38	echo "FAIL" >&2
39	rc=1
40else
41	echo "ok"
42fi
43
44echo -n "Checking sysctl keeps original string on overflow append ... "
45set_orig
46perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
47	dd of="${TARGET}" bs=$(( MAXLEN - 1 )) 2>/dev/null
48if grep -q B "${TARGET}"; then
49	echo "FAIL" >&2
50	rc=1
51else
52	echo "ok"
53fi
54
55echo -n "Checking sysctl stays NULL terminated on write ... "
56set_orig
57perl -e 'print "A" x ('"${MAXLEN}"'-1), "B";' | \
58	dd of="${TARGET}" bs="${MAXLEN}" 2>/dev/null
59if grep -q B "${TARGET}"; then
60	echo "FAIL" >&2
61	rc=1
62else
63	echo "ok"
64fi
65
66echo -n "Checking sysctl stays NULL terminated on overwrite ... "
67set_orig
68perl -e 'print "A" x ('"${MAXLEN}"'-1), "BB";' | \
69	dd of="${TARGET}" bs=$(( $MAXLEN + 1 )) 2>/dev/null
70if grep -q B "${TARGET}"; then
71	echo "FAIL" >&2
72	rc=1
73else
74	echo "ok"
75fi
76
77exit $rc
78