From 2f1f92d1c2ed75915d8b0aac0043d121cc89420f Mon Sep 17 00:00:00 2001 From: bluhm Date: Thu, 8 Jun 2017 17:29:33 +0000 Subject: [PATCH] Start with a clean /var/account/acct accounting file and turn on process accounting with accton(8). Each test executes a command with a unique name and checks the flags in the lastcomm(1) output. Run tests with fork, su, core, xsig, pledge, trap accounting. --- regress/usr.bin/lastcomm/LICENSE | 13 +++++ regress/usr.bin/lastcomm/Makefile | 82 +++++++++++++++++++++++++++++++ regress/usr.bin/lastcomm/crash.c | 26 ++++++++++ 3 files changed, 121 insertions(+) create mode 100644 regress/usr.bin/lastcomm/LICENSE create mode 100644 regress/usr.bin/lastcomm/Makefile create mode 100644 regress/usr.bin/lastcomm/crash.c diff --git a/regress/usr.bin/lastcomm/LICENSE b/regress/usr.bin/lastcomm/LICENSE new file mode 100644 index 00000000000..fc86159c7c6 --- /dev/null +++ b/regress/usr.bin/lastcomm/LICENSE @@ -0,0 +1,13 @@ +# Copyright (c) 2017 Alexander Bluhm +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/regress/usr.bin/lastcomm/Makefile b/regress/usr.bin/lastcomm/Makefile new file mode 100644 index 00000000000..a04efa8cc79 --- /dev/null +++ b/regress/usr.bin/lastcomm/Makefile @@ -0,0 +1,82 @@ +# $OpenBSD: Makefile,v 1.1.1.1 2017/06/08 17:29:33 bluhm Exp $ + +# Start with a clean /var/account/acct accounting file and turn on +# process accounting with accton(8). Each test executes a command +# with a unique name and checks the flags in the lastcomm(1) output. +# Run tests with fork, su, core, xsig, pledge, trap accounting. + +PROG= crash +CLEANFILES= bin-* stamp-* + +.if make (regress) || make (all) +.BEGIN: + @echo + rm -f stamp-rotate +.endif + +# Rotate accouting files and keep statistics, from /etc/daily. +stamp-rotate: + @echo '\n======== $@ ========' + ${SUDO} touch /var/account/acct + -${SUDO} mv -f /var/account/acct.2 /var/account/acct.3 + -${SUDO} mv -f /var/account/acct.1 /var/account/acct.2 + -${SUDO} mv -f /var/account/acct.0 /var/account/acct.1 + ${SUDO} cp -f /var/account/acct /var/account/acct.0 + ${SUDO} sa -sq + ${SUDO} accton /var/account/acct + date >$@ + +TARGETS+= fork +run-regress-fork: + @echo '\n======== $@ ========' + # Create shell program, fork a sub shell, and check the -F flag. + cp -f /bin/sh bin-fork + ./bin-fork -c '( : ) &' + lastcomm bin-fork | grep -q ' -F ' + +TARGETS+= su +run-regress-su: + @echo '\n======== $@ ========' + # Create shell program, run as super user, and check the -S flag. + cp -f /bin/sh bin-su + ${SUDO} ./bin-su -c ':' + lastcomm bin-su | grep -q ' -S ' + +TARGETS+= core +run-regress-core: + @echo '\n======== $@ ========' + # Create shell program, abort sub shell, and check the -DX flag. + cp -f /bin/sh bin-core + rm -f bin-core.core + ulimit -c 100000; ./bin-core -c '( : ) & kill -SEGV $$!' + lastcomm bin-core | grep -q ' -FDX ' + +TARGETS+= xsig +run-regress-xsig: + @echo '\n======== $@ ========' + # Create shell program, kill sub shell, and check the -X flag. + cp -f /bin/sh bin-xsig + ./bin-xsig -c '( : ) & kill -KILL $$!' + lastcomm bin-xsig | grep -q ' -FX ' + +TARGETS+= pledge +run-regress-pledge: + @echo '\n======== $@ ========' + # Create perl program, kill sub shell, and check the -X flag. + cp -f /usr/bin/perl bin-pledge + ulimit -c 0; ! ./bin-pledge -MOpenBSD::Pledge -e\ + 'pledge("stdio") or die $$!; chdir("/")' + lastcomm bin-pledge | grep -q ' -S*XP ' + +TARGETS+= trap +run-regress-trap: ${PROG} + @echo '\n======== $@ ========' + # Create perl program, kill sub shell, and check the -X flag. + cp -f ${PROG} bin-trap + ./bin-trap + lastcomm bin-trap | grep -q ' -S*T ' + +REGRESS_TARGETS= ${TARGETS:S/^/run-regress-/} +${REGRESS_TARGETS}: stamp-rotate + +.include diff --git a/regress/usr.bin/lastcomm/crash.c b/regress/usr.bin/lastcomm/crash.c new file mode 100644 index 00000000000..31e7df63d99 --- /dev/null +++ b/regress/usr.bin/lastcomm/crash.c @@ -0,0 +1,26 @@ +/* $OpenBSD: crash.c,v 1.1.1.1 2017/06/08 17:29:33 bluhm Exp $ */ + +#include +#include +#include + +void handler(int); + +int +main(int argc, char *argv[]) +{ + int *i; + + if (signal(SIGSEGV, handler) == SIG_ERR) + err(1, "signal"); + + i = (void *)0x10UL; + (*i)++; + return *i; +} + +void +handler(int signum) +{ + exit(0); +} -- 2.20.1