Skip to content

Commit

Permalink
Merge some additional freebsd 13 stable oct28 code
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Nov 10, 2024
1 parent 2d7c0b6 commit 75470dc
Show file tree
Hide file tree
Showing 1,508 changed files with 406,203 additions and 0 deletions.
73 changes: 73 additions & 0 deletions bin/cp/tests/sparse.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*-
* Copyright (c) 2023 Klara, Inc.
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <err.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <unistd.h>

static bool verbose;

/*
* Returns true if the file named by its argument is sparse, i.e. if
* seeking to SEEK_HOLE returns a different value than seeking to
* SEEK_END.
*/
static bool
sparse(const char *filename)
{
off_t hole, end;
int fd;

if ((fd = open(filename, O_RDONLY)) < 0 ||
(hole = lseek(fd, 0, SEEK_HOLE)) < 0 ||
(end = lseek(fd, 0, SEEK_END)) < 0)
err(1, "%s", filename);
close(fd);
if (end > hole) {
if (verbose)
printf("%s: hole at %zu\n", filename, (size_t)hole);
return (true);
}
return (false);
}

static void
usage(void)
{

fprintf(stderr, "usage: sparse [-v] file [...]\n");
exit(EX_USAGE);
}

int
main(int argc, char *argv[])
{
int opt, rv;

while ((opt = getopt(argc, argv, "v")) != -1) {
switch (opt) {
case 'v':
verbose = true;
break;
default:
usage();
break;
}
}
argc -= optind;
argv += optind;
if (argc == 0)
usage();
rv = EXIT_SUCCESS;
while (argc-- > 0)
if (!sparse(*argv++))
rv = EXIT_FAILURE;
exit(rv);
}
6 changes: 6 additions & 0 deletions bin/hostname/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PACKAGE= tests

ATF_TESTS_SH= hostname_test
BINDIR= ${TESTSDIR}

.include <bsd.test.mk>
87 changes: 87 additions & 0 deletions bin/hostname/tests/hostname_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#-
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2024 Lin Lee <[email protected]>
#
# 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.
#

#
# These tests need to run in a multibyte locale with non-localized
# error messages.
#
export LC_CTYPE=C.UTF-8
export LC_MESSAGES=C

test_jail_name="test-hostname-jail"

test_jail_conf='%%test_jail_name%% {
host.hostname = "test-hostname.example.org";
path = "/";
persist;
}'

init()
{
echo "${test_jail_conf}" | \
sed -e "s/%%test_jail_name%%/${test_jail_name}/" > "./jail.conf"
jail -f "./jail.conf" -c ${test_jail_name}
}

recycle()
{
jail -f "./jail.conf" -r ${test_jail_name}
rm "./jail.conf"
}

atf_test_case basic cleanup
basic_head()
{
atf_set require.user root
atf_set "descr" "basic test for getting hostname"
}
basic_body()
{
init

result=$(jexec ${test_jail_name} "hostname")
atf_check_equal "test-hostname.example.org" "${result}"

result=$(jexec ${test_jail_name} "hostname" -s)
atf_check_equal "test-hostname" "${result}"

result=$(jexec ${test_jail_name} "hostname" -d)
atf_check_equal "example.org" "${result}"

jexec ${test_jail_name} "hostname" "test-bsd2"
result=$(jexec ${test_jail_name} "hostname")
atf_check_equal "test-bsd2" "${result}"
}
basic_cleanup()
{
recycle
}

atf_init_test_cases()
{
atf_add_test_case basic
}
23 changes: 23 additions & 0 deletions bin/pkill/tests/pgrep-_f_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

base=`basename $0`

echo "1..1"

name="pgrep -F <pidfile>"
pidfile=$(pwd)/pidfile.txt
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
echo $chpid > $pidfile
pid=`pgrep -f -F $pidfile $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
kill "$chpid"
rm -f $pidfile
rm -f $sleep
40 changes: 40 additions & 0 deletions bin/pkill/tests/pgrep-_lf_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

base=`basename $0`

echo "1..2"

name="pgrep -LF <pidfile>"
pidfile=$(pwd)/pidfile.txt
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
daemon -p $pidfile $sleep 5
sleep 0.3
chpid=`cat $pidfile`
pid=`pgrep -f -L -F $pidfile $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
kill "$chpid"

# Be sure we cannot find process which pidfile is not locked.
$sleep 5 &
sleep 0.3
chpid=$!
echo $chpid > $pidfile
pgrep -f -L -F $pidfile $sleep 2>/dev/null
ec=$?
case $ec in
0)
echo "not ok 2 - $name"
;;
*)
echo "ok 2 - $name"
;;
esac

kill "$chpid"
rm -f $pidfile
rm -f $sleep
21 changes: 21 additions & 0 deletions bin/pkill/tests/pgrep-_p_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

base=`basename $0`

echo "1..1"

name="pgrep -P <ppid>"
ppid=$$
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -P $ppid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
kill $chpid
rm -f $sleep
37 changes: 37 additions & 0 deletions bin/pkill/tests/pgrep-_u_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

base=`basename $0`

echo "1..2"

name="pgrep -U <uid>"
ruid=`id -ur`
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -U $ruid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
kill $chpid
rm -f $sleep

name="pgrep -U <user>"
ruid=`id -urn`
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -U $ruid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
kill $chpid
rm -f $sleep
57 changes: 57 additions & 0 deletions bin/pkill/tests/pgrep-f_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

: ${ARG_MAX:=524288}
base=$(dirname $(realpath "$0"))

echo "1..2"

waitfor() {
flagfile=$1

iter=0

while [ ! -f ${flagfile} ] && [ ${iter} -lt 50 ]; do
sleep 0.10
iter=$((iter + 1))
done

if [ ! -f ${flagfile} ]; then
return 1
fi
}

sentinel="findme=test-$$"
sentinelsz=$(printf "${sentinel}" | wc -c | tr -d '[[:space:]]')
name="pgrep -f"
spin="${base}/spin_helper"
flagfile="pgrep_f_short.flag"

${spin} --short ${flagfile} ${sentinel} &
chpid=$!
if ! waitfor ${flagfile}; then
echo "not ok - $name"
else
pid=$(pgrep -f ${sentinel})
if [ "$pid" = "$chpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
fi
kill $chpid

name="pgrep -f long args"
flagfile="pgrep_f_long.flag"
${spin} --long ${flagfile} ${sentinel} &
chpid=$!
if ! waitfor ${flagfile}; then
echo "not ok - $name"
else
pid=$(pgrep -f ${sentinel})
if [ "$pid" = "$chpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
fi
kill $chpid
26 changes: 26 additions & 0 deletions bin/pkill/tests/pkill-_f_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

base=`basename $0`

echo "1..1"

name="pkill -F <pidfile>"
pidfile=$(pwd)/pidfile.txt
sleep=$(pwd)/sleep.txt
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
echo $! > $pidfile
pkill -f -F $pidfile $sleep
ec=$?
case $ec in
0)
echo "ok - $name"
;;
*)
echo "not ok - $name"
;;
esac

rm -f $pidfile
rm -f $sleep
Loading

0 comments on commit 75470dc

Please sign in to comment.