summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--COPYRIGHT2
-rw-r--r--Makefile.inc122
-rw-r--r--UPDATING5
-rw-r--r--bin/csh/config_p.h2
-rw-r--r--bin/pax/pat_rep.c2
-rw-r--r--cddl/lib/libnvpair/Makefile6
-rw-r--r--contrib/bmake/ChangeLog6
-rw-r--r--contrib/bmake/Makefile4
-rw-r--r--contrib/bmake/mk/ChangeLog6
-rw-r--r--contrib/bmake/mk/auto.obj.mk11
-rw-r--r--contrib/bmake/mk/install-mk4
-rwxr-xr-xcontrib/bmake/os.sh48
-rw-r--r--contrib/bmake/suff.c37
-rw-r--r--contrib/bsnmp/snmpd/action.c23
-rw-r--r--contrib/bsnmp/snmpd/main.c16
-rw-r--r--contrib/bsnmp/snmpd/trap.c6
-rw-r--r--contrib/mdocml/lib.in1
-rw-r--r--contrib/openbsm/.travis.yml18
-rw-r--r--contrib/openbsm/INSTALL4
-rw-r--r--contrib/openbsm/LICENSE2
-rw-r--r--contrib/openbsm/Makefile.am4
-rw-r--r--contrib/openbsm/Makefile.in6
-rw-r--r--contrib/openbsm/NEWS13
-rw-r--r--contrib/openbsm/README6
-rw-r--r--contrib/openbsm/TODO4
-rw-r--r--contrib/openbsm/VERSION2
-rw-r--r--contrib/openbsm/autogen.sh3
-rw-r--r--contrib/openbsm/bin/Makefile.am4
-rw-r--r--contrib/openbsm/bin/audit/Makefile.am4
-rw-r--r--contrib/openbsm/bin/audit/audit.86
-rw-r--r--contrib/openbsm/bin/audit/audit.c2
-rw-r--r--contrib/openbsm/bin/auditd/Makefile.am4
-rw-r--r--contrib/openbsm/bin/auditd/audit_triggers.defs4
-rw-r--r--contrib/openbsm/bin/auditd/audit_warn.c2
-rw-r--r--contrib/openbsm/bin/auditd/auditd.86
-rw-r--r--contrib/openbsm/bin/auditd/auditd.c2
-rw-r--r--contrib/openbsm/bin/auditd/auditd.h2
-rw-r--r--contrib/openbsm/bin/auditd/auditd_control.defs2
-rw-r--r--contrib/openbsm/bin/auditd/auditd_darwin.c2
-rw-r--r--contrib/openbsm/bin/auditd/auditd_fbsd.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/Makefile.am4
-rw-r--r--contrib/openbsm/bin/auditdistd/auditdistd.86
-rw-r--r--contrib/openbsm/bin/auditdistd/auditdistd.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/auditdistd.conf.597
-rw-r--r--contrib/openbsm/bin/auditdistd/auditdistd.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/faccessat.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/fstatat.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/openat.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/parse.y2
-rw-r--r--contrib/openbsm/bin/auditdistd/pjdlog.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/pjdlog.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/proto.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/proto.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/proto_common.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/proto_impl.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/proto_socketpair.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/proto_tcp.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/proto_tls.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/proto_uds.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/receiver.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/renameat.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/sandbox.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/sandbox.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/sender.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/sigtimedwait.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/strndup.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/subr.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/subr.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/synch.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/token.l2
-rw-r--r--contrib/openbsm/bin/auditdistd/trail.c2
-rw-r--r--contrib/openbsm/bin/auditdistd/trail.h2
-rw-r--r--contrib/openbsm/bin/auditdistd/unlinkat.h2
-rw-r--r--contrib/openbsm/bin/auditfilterd/Makefile.am4
-rw-r--r--contrib/openbsm/bin/auditfilterd/auditfilterd.82
-rw-r--r--contrib/openbsm/bin/auditfilterd/auditfilterd.c4
-rw-r--r--contrib/openbsm/bin/auditfilterd/auditfilterd.h2
-rw-r--r--contrib/openbsm/bin/auditfilterd/auditfilterd_conf.c2
-rw-r--r--contrib/openbsm/bin/auditreduce/Makefile.am4
-rw-r--r--contrib/openbsm/bin/auditreduce/auditreduce.12
-rw-r--r--contrib/openbsm/bin/auditreduce/auditreduce.c2
-rw-r--r--contrib/openbsm/bin/auditreduce/auditreduce.h2
-rw-r--r--contrib/openbsm/bin/praudit/Makefile.am4
-rw-r--r--contrib/openbsm/bin/praudit/praudit.12
-rw-r--r--contrib/openbsm/bin/praudit/praudit.c2
-rw-r--r--contrib/openbsm/bsm/Makefile.am4
-rw-r--r--contrib/openbsm/bsm/audit_filter.h2
-rw-r--r--contrib/openbsm/bsm/audit_uevents.h2
-rw-r--r--contrib/openbsm/bsm/auditd_lib.h2
-rw-r--r--contrib/openbsm/bsm/libbsm.h2
-rw-r--r--contrib/openbsm/compat/clock_gettime.h2
-rw-r--r--contrib/openbsm/compat/closefrom.h2
-rw-r--r--contrib/openbsm/compat/compat.h2
-rw-r--r--contrib/openbsm/compat/endian.h1
-rw-r--r--contrib/openbsm/compat/endian_enc.h1
-rw-r--r--contrib/openbsm/compat/flopen.h1
-rw-r--r--contrib/openbsm/compat/pidfile.h1
-rw-r--r--contrib/openbsm/compat/queue.h1
-rw-r--r--contrib/openbsm/compat/strlcat.h1
-rw-r--r--contrib/openbsm/compat/strlcpy.h1
-rw-r--r--contrib/openbsm/config/config.h8
-rwxr-xr-xcontrib/openbsm/configure49
-rw-r--r--contrib/openbsm/configure.ac4
-rw-r--r--contrib/openbsm/etc/audit_class1
-rw-r--r--contrib/openbsm/etc/audit_control1
-rw-r--r--contrib/openbsm/etc/audit_event1
-rw-r--r--contrib/openbsm/etc/audit_filter2
-rw-r--r--contrib/openbsm/etc/audit_user1
-rw-r--r--contrib/openbsm/etc/audit_warn2
-rw-r--r--contrib/openbsm/libauditd/Makefile.am4
-rw-r--r--contrib/openbsm/libauditd/auditd_lib.c11
-rw-r--r--contrib/openbsm/libauditd/libauditd.34
-rw-r--r--contrib/openbsm/libbsm/Makefile.am116
-rw-r--r--contrib/openbsm/libbsm/Makefile.in122
-rw-r--r--contrib/openbsm/libbsm/au_class.32
-rw-r--r--contrib/openbsm/libbsm/au_control.34
-rw-r--r--contrib/openbsm/libbsm/au_domain.32
-rw-r--r--contrib/openbsm/libbsm/au_errno.34
-rw-r--r--contrib/openbsm/libbsm/au_event.32
-rw-r--r--contrib/openbsm/libbsm/au_fcntl_cmd.34
-rw-r--r--contrib/openbsm/libbsm/au_free_token.34
-rw-r--r--contrib/openbsm/libbsm/au_io.32
-rw-r--r--contrib/openbsm/libbsm/au_mask.32
-rw-r--r--contrib/openbsm/libbsm/au_notify.3118
-rw-r--r--contrib/openbsm/libbsm/au_open.32
-rw-r--r--contrib/openbsm/libbsm/au_socket_type.32
-rw-r--r--contrib/openbsm/libbsm/au_token.32
-rw-r--r--contrib/openbsm/libbsm/au_user.32
-rw-r--r--contrib/openbsm/libbsm/audit_submit.32
-rw-r--r--contrib/openbsm/libbsm/bsm_audit.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_class.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_control.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_domain.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_errno.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_event.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_fcntl.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_flags.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_io.c9
-rw-r--r--contrib/openbsm/libbsm/bsm_mask.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_notify.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_socket_type.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_token.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_user.c2
-rw-r--r--contrib/openbsm/libbsm/bsm_wrappers.c2
-rw-r--r--contrib/openbsm/libbsm/libbsm.32
-rw-r--r--contrib/openbsm/man/Makefile.am11
-rw-r--r--contrib/openbsm/man/Makefile.in32
-rw-r--r--contrib/openbsm/man/audit.22
-rw-r--r--contrib/openbsm/man/audit.log.52
-rw-r--r--contrib/openbsm/man/audit_class.52
-rw-r--r--contrib/openbsm/man/audit_control.52
-rw-r--r--contrib/openbsm/man/audit_event.52
-rw-r--r--contrib/openbsm/man/audit_user.52
-rw-r--r--contrib/openbsm/man/audit_warn.52
-rw-r--r--contrib/openbsm/man/auditctl.22
-rw-r--r--contrib/openbsm/man/auditon.22
-rw-r--r--contrib/openbsm/man/getaudit.22
-rw-r--r--contrib/openbsm/man/getauid.22
-rw-r--r--contrib/openbsm/man/setaudit.22
-rw-r--r--contrib/openbsm/man/setauid.22
-rw-r--r--contrib/openbsm/modules/Makefile.am4
-rw-r--r--contrib/openbsm/modules/auditfilter_noop/Makefile.am4
-rw-r--r--contrib/openbsm/modules/auditfilter_noop/auditfilter_noop.c2
-rw-r--r--contrib/openbsm/sys/Makefile.am4
-rw-r--r--contrib/openbsm/sys/bsm/Makefile.am5
-rw-r--r--contrib/openbsm/sys/bsm/audit.h2
-rw-r--r--contrib/openbsm/sys/bsm/audit_domain.h2
-rw-r--r--contrib/openbsm/sys/bsm/audit_errno.h2
-rw-r--r--contrib/openbsm/sys/bsm/audit_fcntl.h2
-rw-r--r--contrib/openbsm/sys/bsm/audit_internal.h2
-rw-r--r--contrib/openbsm/sys/bsm/audit_kevents.h19
-rw-r--r--contrib/openbsm/sys/bsm/audit_record.h2
-rw-r--r--contrib/openbsm/sys/bsm/audit_socket_type.h2
-rw-r--r--contrib/openbsm/test/Makefile.am4
-rw-r--r--contrib/openbsm/test/bsm/Makefile.am4
-rw-r--r--contrib/openbsm/test/bsm/generate.c2
-rw-r--r--contrib/openbsm/tools/Makefile.am4
-rw-r--r--contrib/openbsm/tools/audump.c2
-rw-r--r--contrib/pf/pflogd/pflogd.c2
-rw-r--r--etc/mtree/BSD.tests.dist8
-rwxr-xr-xetc/rc.d/jail128
-rw-r--r--lib/Makefile1
-rw-r--r--lib/libbsm/Makefile4
-rw-r--r--lib/libc/net/gethostbynis.c55
-rw-r--r--lib/libc/net/netdb_private.h2
-rw-r--r--lib/libnv/Makefile92
-rw-r--r--lib/libnv/common_impl.h37
-rw-r--r--lib/libnv/msgio.c469
-rw-r--r--lib/libnv/msgio.h (renamed from sys/boot/i386/efi/i386_copy.c)53
-rw-r--r--lib/libnv/nv.3653
-rw-r--r--lib/libnv/tests/Makefile21
-rw-r--r--lib/libnv/tests/dnv_tests.cc567
-rw-r--r--lib/libnv/tests/nv_tests.cc1240
-rw-r--r--lib/libnv/tests/nvlist_add_test.c196
-rw-r--r--lib/libnv/tests/nvlist_exists_test.c321
-rw-r--r--lib/libnv/tests/nvlist_free_test.c221
-rw-r--r--lib/libnv/tests/nvlist_get_test.c182
-rw-r--r--lib/libnv/tests/nvlist_move_test.c161
-rw-r--r--lib/libnv/tests/nvlist_send_recv_test.c342
-rw-r--r--lib/msun/tests/Makefile22
-rw-r--r--lib/msun/tests/cexp_test.c322
-rw-r--r--lib/msun/tests/conj_test.c139
-rw-r--r--lib/msun/tests/csqrt_test.c295
-rw-r--r--lib/msun/tests/fenv_test.c (renamed from tools/regression/lib/msun/test-fenv.c)0
-rw-r--r--lib/msun/tests/fmaxmin_test.c (renamed from tools/regression/lib/msun/test-fmaxmin.c)0
-rw-r--r--lib/msun/tests/ilogb_test.c (renamed from tools/regression/lib/msun/test-ilogb.c)0
-rw-r--r--lib/msun/tests/invctrig_test.c (renamed from tools/regression/lib/msun/test-invctrig.c)0
-rw-r--r--lib/msun/tests/logarithm_test.c (renamed from tools/regression/lib/msun/test-logarithm.c)0
-rw-r--r--lib/msun/tests/lrint_test.c (renamed from tools/regression/lib/msun/test-lrint.c)0
-rw-r--r--lib/msun/tests/nan_test.c (renamed from tools/regression/lib/msun/test-nan.c)0
-rw-r--r--lib/msun/tests/nearbyint_test.c (renamed from tools/regression/lib/msun/test-nearbyint.c)0
-rw-r--r--lib/msun/tests/next_test.c (renamed from tools/regression/lib/msun/test-next.c)0
-rw-r--r--lib/msun/tests/rem_test.c (renamed from tools/regression/lib/msun/test-rem.c)0
-rw-r--r--lib/msun/tests/trig_test.c280
-rw-r--r--libexec/rtld-elf/rtld.c1
-rw-r--r--sbin/devd/devd.cc2
-rw-r--r--sbin/fsck_ffs/fsck.h2
-rw-r--r--sbin/fsck_ffs/globs.c2
-rw-r--r--sbin/natd/natd.c2
-rw-r--r--sbin/newfs_nandfs/newfs_nandfs.c2
-rw-r--r--sbin/rcorder/rcorder.c4
-rw-r--r--sbin/reboot/reboot.819
-rw-r--r--sbin/reboot/reboot.c12
-rw-r--r--sbin/route/route.c3
-rw-r--r--share/mk/bsd.compiler.mk2
-rw-r--r--share/mk/bsd.libnames.mk1
-rw-r--r--sys/boot/amd64/Makefile7
-rw-r--r--sys/boot/amd64/Makefile.inc12
-rw-r--r--sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu22
-rw-r--r--sys/boot/efi/Makefile4
-rw-r--r--sys/boot/efi/Makefile.inc3
-rw-r--r--sys/boot/efi/boot1/Makefile (renamed from sys/boot/amd64/boot1.efi/Makefile)12
-rw-r--r--sys/boot/efi/boot1/Makefile.fat (renamed from sys/boot/amd64/boot1.efi/Makefile.fat)0
-rw-r--r--sys/boot/efi/boot1/boot1.c (renamed from sys/boot/amd64/boot1.efi/boot1.c)9
-rw-r--r--sys/boot/efi/boot1/fat.tmpl.bz2.uu20
-rwxr-xr-xsys/boot/efi/boot1/generate-fat.sh (renamed from sys/boot/amd64/boot1.efi/generate-fat.sh)22
-rw-r--r--sys/boot/efi/loader/Makefile (renamed from sys/boot/amd64/efi/Makefile)35
-rw-r--r--sys/boot/efi/loader/arch/amd64/Makefile.inc11
-rw-r--r--sys/boot/efi/loader/arch/amd64/amd64_tramp.S (renamed from sys/boot/amd64/efi/amd64_tramp.S)0
-rw-r--r--sys/boot/efi/loader/arch/amd64/elf64_freebsd.c (renamed from sys/boot/amd64/efi/elf64_freebsd.c)21
-rw-r--r--sys/boot/efi/loader/arch/amd64/framebuffer.c (renamed from sys/boot/amd64/efi/framebuffer.c)0
-rw-r--r--sys/boot/efi/loader/arch/amd64/framebuffer.h (renamed from sys/boot/amd64/efi/framebuffer.h)0
-rw-r--r--sys/boot/efi/loader/arch/amd64/ldscript.amd64 (renamed from sys/boot/amd64/efi/ldscript.amd64)0
-rw-r--r--sys/boot/efi/loader/arch/amd64/reloc.c (renamed from sys/boot/amd64/efi/reloc.c)0
-rw-r--r--sys/boot/efi/loader/arch/amd64/start.S (renamed from sys/boot/amd64/efi/start.S)0
-rw-r--r--sys/boot/efi/loader/autoload.c (renamed from sys/boot/amd64/efi/autoload.c)2
-rw-r--r--sys/boot/efi/loader/bootinfo.c (renamed from sys/boot/amd64/efi/bootinfo.c)145
-rw-r--r--sys/boot/efi/loader/conf.c (renamed from sys/boot/amd64/efi/conf.c)9
-rw-r--r--sys/boot/efi/loader/copy.c (renamed from sys/boot/amd64/efi/copy.c)10
-rw-r--r--sys/boot/efi/loader/devicename.c (renamed from sys/boot/amd64/efi/devicename.c)16
-rw-r--r--sys/boot/efi/loader/loader_efi.h (renamed from sys/boot/amd64/efi/x86_efi.h)26
-rw-r--r--sys/boot/efi/loader/main.c (renamed from sys/boot/amd64/efi/main.c)21
-rw-r--r--sys/boot/efi/loader/version (renamed from sys/boot/amd64/efi/version)0
-rw-r--r--sys/boot/forth/loader.conf15
-rw-r--r--sys/boot/forth/loader.rc3
-rw-r--r--sys/boot/forth/menu.rc3
-rw-r--r--sys/boot/forth/support.4th19
-rw-r--r--sys/boot/i386/efi/bootinfo.c275
-rw-r--r--sys/boot/i386/efi/efimd.c139
-rw-r--r--sys/boot/i386/efi/elf32_freebsd.c87
-rw-r--r--sys/boot/i386/efi/ldscript.i38672
-rw-r--r--sys/boot/i386/efi/reloc.c107
-rw-r--r--sys/boot/i386/efi/start.S70
-rw-r--r--sys/boot/i386/loader/Makefile7
-rw-r--r--sys/boot/pc98/loader/Makefile7
-rw-r--r--sys/boot/powerpc/ofw/Makefile8
-rw-r--r--sys/boot/powerpc/ps3/Makefile8
-rw-r--r--sys/boot/sparc64/loader/Makefile8
-rw-r--r--sys/bsm/audit.h1
-rw-r--r--sys/bsm/audit_domain.h1
-rw-r--r--sys/bsm/audit_errno.h1
-rw-r--r--sys/bsm/audit_fcntl.h1
-rw-r--r--sys/bsm/audit_internal.h1
-rw-r--r--sys/bsm/audit_kevents.h3
-rw-r--r--sys/bsm/audit_record.h1
-rw-r--r--sys/bsm/audit_socket_type.h1
-rw-r--r--sys/cddl/compat/opensolaris/sys/nvpair.h263
-rw-r--r--sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_fnvpair.c (renamed from sys/cddl/contrib/opensolaris/common/nvpair/fnvpair.c)0
-rw-r--r--sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c (renamed from sys/cddl/contrib/opensolaris/common/nvpair/nvpair.c)0
-rw-r--r--sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair_alloc_fixed.c (renamed from sys/cddl/contrib/opensolaris/common/nvpair/nvpair_alloc_fixed.c)0
-rw-r--r--sys/conf/files9
-rw-r--r--sys/conf/newvers.sh10
-rw-r--r--sys/contrib/ipfilter/netinet/ip_nat.c2
-rw-r--r--sys/dev/mlx5/device.h33
-rw-r--r--sys/dev/mlx5/mlx5_en/en.h7
-rw-r--r--sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c174
-rw-r--r--sys/dev/mlx5/mlx5_en/mlx5_en_main.c91
-rw-r--r--sys/dev/mlx5/mlx5_en/mlx5_en_rx.c68
-rw-r--r--sys/dev/mlx5/mlx5_en/mlx5_en_tx.c2
-rw-r--r--sys/dev/mlx5/mlx5_en/mlx5_en_txrx.c2
-rw-r--r--sys/dev/pci/pci.c2
-rw-r--r--sys/dev/usb/controller/uhci.h2
-rw-r--r--sys/dev/usb/serial/uftdi.c2
-rw-r--r--sys/fs/ext2fs/ext2fs.h3
-rw-r--r--sys/fs/nullfs/null_vnops.c8
-rw-r--r--sys/kern/imgact_elf.c5
-rw-r--r--sys/kern/kern_proc.c1
-rw-r--r--sys/kern/link_elf.c10
-rw-r--r--sys/kern/subr_dnvlist.c128
-rw-r--r--sys/kern/subr_nvlist.c1475
-rw-r--r--sys/kern/subr_nvpair.c1111
-rw-r--r--sys/modules/zfs/Makefile6
-rw-r--r--sys/ofed/include/linux/compiler.h26
-rw-r--r--sys/ofed/include/linux/file.h17
-rw-r--r--sys/ofed/include/linux/kobject.h24
-rw-r--r--sys/ofed/include/linux/linux_compat.c91
-rw-r--r--sys/ofed/include/linux/srcu.h (renamed from sys/boot/i386/efi/exec.c)57
-rw-r--r--sys/ofed/include/linux/types.h2
-rw-r--r--sys/ofed/include/linux/workqueue.h121
-rw-r--r--sys/security/audit/bsm_domain.c2
-rw-r--r--sys/security/audit/bsm_errno.c2
-rw-r--r--sys/security/audit/bsm_fcntl.c2
-rw-r--r--sys/security/audit/bsm_socket_type.c2
-rw-r--r--sys/security/audit/bsm_token.c2
-rw-r--r--sys/sys/copyright.h4
-rw-r--r--sys/sys/dnv.h116
-rw-r--r--sys/sys/nv.h200
-rw-r--r--sys/sys/nv_impl.h131
-rw-r--r--sys/sys/nvlist_impl.h49
-rw-r--r--sys/sys/nvpair_impl.h94
-rw-r--r--sys/sys/proc.h3
-rw-r--r--sys/x86/include/specialreg.h1
-rw-r--r--sys/x86/x86/identcpu.c2
-rw-r--r--tests/sys/Makefile1
-rw-r--r--tests/sys/aio/aio_kqueue_test.c37
-rw-r--r--tests/sys/aio/lio_kqueue_test.c101
-rw-r--r--tests/sys/kern/Makefile1
-rw-r--r--tests/sys/kern/pipe/pipe_overcommit1_test.c7
-rw-r--r--tests/sys/kern/ptrace_test.c6
-rw-r--r--tests/sys/kern/unix_passfd_test.c396
-rw-r--r--tests/sys/kern/unix_seqpacket_test.c93
-rw-r--r--tests/sys/mac/Makefile8
-rw-r--r--tests/sys/mac/bsdextended/Makefile14
-rw-r--r--tests/sys/mac/bsdextended/matches_test.sh353
-rw-r--r--tests/sys/mac/bsdextended/ugidfw_test.c252
-rw-r--r--tests/sys/mac/portacl/LICENSE27
-rw-r--r--tests/sys/mac/portacl/Makefile16
-rwxr-xr-xtests/sys/mac/portacl/misc.sh106
-rwxr-xr-xtests/sys/mac/portacl/nobody_test.sh67
-rwxr-xr-xtests/sys/mac/portacl/root_test.sh51
-rw-r--r--tools/regression/lib/msun/Makefile8
-rw-r--r--tools/regression/lib/msun/test-cexp.t10
-rw-r--r--tools/regression/lib/msun/test-conj.t10
-rw-r--r--tools/regression/lib/msun/test-csqrt.t10
-rw-r--r--tools/regression/lib/msun/test-fenv.t10
-rw-r--r--tools/regression/lib/msun/test-fmaxmin.t10
-rw-r--r--tools/regression/lib/msun/test-ilogb.t10
-rw-r--r--tools/regression/lib/msun/test-logarithm.t10
-rw-r--r--tools/regression/lib/msun/test-lrint.t10
-rw-r--r--tools/regression/lib/msun/test-nan.t10
-rw-r--r--tools/regression/lib/msun/test-nearbyint.t10
-rw-r--r--tools/regression/lib/msun/test-next.t10
-rw-r--r--tools/regression/lib/msun/test-rem.t10
-rw-r--r--tools/regression/lib/msun/test-trig.t10
-rw-r--r--tools/regression/mac/mac_bsdextended/test_matches.sh328
-rw-r--r--tools/regression/mac/mac_bsdextended/test_ugidfw.c91
-rw-r--r--tools/regression/sockets/unix_passfd/Makefile7
-rw-r--r--tools/regression/sockets/unix_passfd/unix_passfd.c389
-rw-r--r--usr.bin/bmake/Makefile4
-rw-r--r--usr.bin/calendar/parsedata.c2
-rw-r--r--usr.bin/colldef/parse.y12
-rw-r--r--usr.bin/dtc/dtb.hh2
-rw-r--r--usr.bin/indent/indent.12
-rw-r--r--usr.bin/locale/locale.c4
-rw-r--r--usr.bin/mkimg/mkimg.12
-rw-r--r--usr.bin/mt/mt.c4
-rw-r--r--usr.bin/netstat/flowtable.c13
-rw-r--r--usr.bin/netstat/if.c20
-rw-r--r--usr.bin/netstat/inet.c162
-rw-r--r--usr.bin/netstat/inet6.c77
-rw-r--r--usr.bin/netstat/ipsec.c25
-rw-r--r--usr.bin/netstat/main.c34
-rw-r--r--usr.bin/netstat/mbuf.c33
-rw-r--r--usr.bin/netstat/mroute.c12
-rw-r--r--usr.bin/netstat/mroute6.c13
-rw-r--r--usr.bin/netstat/netstat.h2
-rw-r--r--usr.bin/netstat/sctp.c19
-rw-r--r--usr.bin/patch/pch.c2
-rw-r--r--usr.bin/pr/egetopt.c2
-rw-r--r--usr.bin/sed/compile.c2
-rw-r--r--usr.bin/sockstat/sockstat.c6
-rw-r--r--usr.bin/vgrind/regexp.c2
-rw-r--r--usr.sbin/bhyve/pci_emul.c2
-rwxr-xr-xusr.sbin/bsdconfig/bsdconfig2
-rw-r--r--usr.sbin/bsdconfig/console/INDEX7
-rw-r--r--usr.sbin/bsdconfig/share/sysrc.subr96
-rw-r--r--usr.sbin/config/config.h2
-rw-r--r--usr.sbin/cron/cron/do_command.c6
-rw-r--r--usr.sbin/cron/cron/popen.c3
-rw-r--r--usr.sbin/cron/crontab/crontab.c2
-rw-r--r--usr.sbin/ctld/ctld.c2
-rw-r--r--usr.sbin/fwcontrol/fwmpegts.c2
-rw-r--r--usr.sbin/jail/command.c2
-rw-r--r--usr.sbin/jail/jailp.h2
-rw-r--r--usr.sbin/jail/jailparse.y2
-rw-r--r--usr.sbin/jls/jls.c2
-rw-r--r--usr.sbin/kbdmap/kbdmap.c18
-rw-r--r--usr.sbin/mailwrapper/mailwrapper.86
-rw-r--r--usr.sbin/mailwrapper/mailwrapper.c19
-rw-r--r--usr.sbin/makefs/cd9660.c2
-rw-r--r--usr.sbin/makefs/makefs.c2
-rw-r--r--usr.sbin/mfiutil/mfiutil.88
-rw-r--r--usr.sbin/nandsim/nandsim.82
-rw-r--r--usr.sbin/nandsim/nandsim.c2
-rw-r--r--usr.sbin/nandsim/nandsim_cfgparse.c4
-rw-r--r--usr.sbin/ndp/ndp.c2
-rw-r--r--usr.sbin/newsyslog/newsyslog.c2
-rw-r--r--usr.sbin/pmcstudy/eval_expr.c2
-rw-r--r--usr.sbin/ppp/ip.c2
-rw-r--r--usr.sbin/ppp/ppp.84
-rw-r--r--usr.sbin/pw/pw_conf.c2
-rw-r--r--usr.sbin/pw/pw_group.c5
-rw-r--r--usr.sbin/pw/pw_vpw.c2
-rw-r--r--usr.sbin/rtsold/rtsold.h2
-rw-r--r--usr.sbin/uefisign/magic.h2
-rw-r--r--usr.sbin/uefisign/pe.c2
-rw-r--r--usr.sbin/ypbind/ypbind.c2
-rw-r--r--usr.sbin/ypserv/ypinit.sh2
418 files changed, 12809 insertions, 3019 deletions
diff --git a/COPYRIGHT b/COPYRIGHT
index 1d7198f..94046dd 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -4,7 +4,7 @@
The compilation of software known as FreeBSD is distributed under the
following terms:
-Copyright (c) 1992-2015 The FreeBSD Project. All rights reserved.
+Copyright (c) 1992-2016 The FreeBSD Project. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
diff --git a/Makefile.inc1 b/Makefile.inc1
index de4b434..beea132 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -1102,6 +1102,16 @@ reinstallkernel reinstallkernel.debug: _installcheck_kernel
cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
${CROSSENV} PATH=${TMPPATH} \
${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//}
+.if ${BUILDKERNELS:[#]} > 1
+.for _kernel in ${BUILDKERNELS:[2..-1]}
+ @echo "--------------------------------------------------------------"
+ @echo ">>> Installing kernel ${_kernel}"
+ @echo "--------------------------------------------------------------"
+ cd ${KRNLOBJDIR}/${_kernel}; \
+ ${CROSSENV} PATH=${TMPPATH} \
+ ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//}
+.endfor
+.endif
distributekernel distributekernel.debug:
.if empty(INSTALLKERNEL)
@@ -1121,7 +1131,8 @@ distributekernel distributekernel.debug:
sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
${DESTDIR}/${DISTDIR}/kernel.meta
.endif
-.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
+.if ${BUILDKERNELS:[#]} > 1
+.for _kernel in ${BUILDKERNELS:[2..-1]}
.if defined(NO_ROOT)
echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
.endif
@@ -1137,27 +1148,32 @@ distributekernel distributekernel.debug:
${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
.endif
.endfor
+.endif
packagekernel:
.if defined(NO_ROOT)
cd ${DESTDIR}/${DISTDIR}/kernel; \
tar cvf - @${DESTDIR}/${DISTDIR}/kernel.meta | \
${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.txz
-.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
+.if ${BUILDKERNELS:[#]} > 1
+.for _kernel in ${BUILDKERNELS:[2..-1]}
cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
tar cvf - @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \
${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz
.endfor
+.endif
.else
cd ${DESTDIR}/${DISTDIR}/kernel; \
tar cvf - . | \
${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.txz
-.for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//}
+.if ${BUILDKERNELS:[#]} > 1
+.for _kernel in ${BUILDKERNELS:[2..-1]}
cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \
tar cvf - . | \
${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz
.endfor
.endif
+.endif
#
# doxygen
diff --git a/UPDATING b/UPDATING
index 4daf9c7..c737b71 100644
--- a/UPDATING
+++ b/UPDATING
@@ -26,6 +26,11 @@ older version of current is a bit fragile.
Kernel modules isp_2400_multi and isp_2500_multi were removed and
should be replaced with isp_2400 and isp_2500 modules respectively.
+20150806:
+ The menu.rc and loader.rc files will now be replaced during
+ upgrades. Please migrate local changes to menu.rc.local and
+ loader.rc.local instead.
+
20151026:
NTP has been upgraded to 4.2.8p4.
diff --git a/bin/csh/config_p.h b/bin/csh/config_p.h
index a1bbea6..0006fe0 100644
--- a/bin/csh/config_p.h
+++ b/bin/csh/config_p.h
@@ -9,7 +9,7 @@
#ifndef _h_config
#define _h_config
-/****************** System dependant compilation flags ****************/
+/****************** System dependent compilation flags ****************/
/*
* POSIX This system supports IEEE Std 1003.1-1988 (POSIX).
*/
diff --git a/bin/pax/pat_rep.c b/bin/pax/pat_rep.c
index e8d17db..516519e 100644
--- a/bin/pax/pat_rep.c
+++ b/bin/pax/pat_rep.c
@@ -878,7 +878,7 @@ rep_name(char *name, int *nlen, int prnt)
* (the user already saw that substitution go by)
*/
pt = rephead;
- (void)strcpy(buf1, name);
+ (void)strlcpy(buf1, name, sizeof(buf1));
inpt = buf1;
outpt = nname;
endpt = outpt + PAXPATHLEN;
diff --git a/cddl/lib/libnvpair/Makefile b/cddl/lib/libnvpair/Makefile
index d605a7f..695b371 100644
--- a/cddl/lib/libnvpair/Makefile
+++ b/cddl/lib/libnvpair/Makefile
@@ -7,10 +7,10 @@ LIB= nvpair
SRCS= libnvpair.c \
nvpair_alloc_system.c \
- nvpair_alloc_fixed.c \
- nvpair.c \
nvpair_json.c \
- fnvpair.c
+ opensolaris_fnvpair.c \
+ opensolaris_nvpair.c \
+ opensolaris_nvpair_alloc_fixed.c
WARNS?= 0
CFLAGS+= -I${.CURDIR}/../../../cddl/compat/opensolaris/include
diff --git a/contrib/bmake/ChangeLog b/contrib/bmake/ChangeLog
index c620c84..c3a4241 100644
--- a/contrib/bmake/ChangeLog
+++ b/contrib/bmake/ChangeLog
@@ -1,3 +1,9 @@
+2015-12-20 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * Makefile (MAKE_VERSION): 20151220
+ Merge with NetBSD make, pick up
+ o suff.c: re-initialize suffNull when clearing suffixes.
+
2015-12-01 Simon J. Gerraty <sjg@bad.crufty.net>
* Makefile (MAKE_VERSION): 20151201
diff --git a/contrib/bmake/Makefile b/contrib/bmake/Makefile
index 861e8f5..625c254 100644
--- a/contrib/bmake/Makefile
+++ b/contrib/bmake/Makefile
@@ -1,7 +1,7 @@
-# $Id: Makefile,v 1.48 2015/12/02 00:36:42 sjg Exp $
+# $Id: Makefile,v 1.49 2015/12/20 22:54:40 sjg Exp $
# Base version on src date
-MAKE_VERSION= 20151201
+MAKE_VERSION= 20151220
PROG= bmake
diff --git a/contrib/bmake/mk/ChangeLog b/contrib/bmake/mk/ChangeLog
index 965ff4d..3c728c8 100644
--- a/contrib/bmake/mk/ChangeLog
+++ b/contrib/bmake/mk/ChangeLog
@@ -1,3 +1,9 @@
+2015-12-12 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): 20151212
+ * auto.obj.mk: do not require MAKEOBJDIRPREFIX to exist.
+ only apply :tA to __objdir when comparing to .OBJDIR
+
2015-11-14 Simon J. Gerraty <sjg@bad.crufty.net>
* install-mk (MK_VERSION): 20151111
diff --git a/contrib/bmake/mk/auto.obj.mk b/contrib/bmake/mk/auto.obj.mk
index fee3de2..2395f64 100644
--- a/contrib/bmake/mk/auto.obj.mk
+++ b/contrib/bmake/mk/auto.obj.mk
@@ -1,4 +1,4 @@
-# $Id: auto.obj.mk,v 1.11 2015/06/16 06:28:21 sjg Exp $
+# $Id: auto.obj.mk,v 1.12 2015/12/16 01:57:06 sjg Exp $
#
# @(#) Copyright (c) 2004, Simon J. Gerraty
#
@@ -40,12 +40,12 @@ MKOBJDIRS= auto
.if !defined(NOOBJ) && !defined(NO_OBJ) && ${MKOBJDIRS:Uno} == auto
# Use __objdir here so it is easier to tweak without impacting
# the logic.
-.if !empty(MAKEOBJDIRPREFIX) && exists(${MAKEOBJDIRPREFIX})
+.if !empty(MAKEOBJDIRPREFIX)
__objdir?= ${MAKEOBJDIRPREFIX}${.CURDIR}
.endif
__objdir?= ${MAKEOBJDIR:Uobj}
-__objdir:= ${__objdir:tA}
-.if ${.OBJDIR} != ${__objdir}
+__objdir:= ${__objdir}
+.if ${.OBJDIR:tA} != ${__objdir:tA}
# We need to chdir, make the directory if needed
.if !exists(${__objdir}/) && \
(${.TARGETS} == "" || ${.TARGETS:Nclean*:N*clean:Ndestroy*} != "")
@@ -53,11 +53,10 @@ __objdir:= ${__objdir:tA}
__objdir_made != echo ${__objdir}/; umask ${OBJDIR_UMASK:U002}; \
${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \
${Mkdirs}; Mkdirs ${__objdir}
-__objdir:= ${__objdir:tA}
.endif
# This causes make to use the specified directory as .OBJDIR
.OBJDIR: ${__objdir}
-.if ${.OBJDIR} != ${__objdir} && ${__objdir_made:Uno:M${__objdir}/*} != ""
+.if ${.OBJDIR:tA} != ${__objdir:tA} && ${__objdir_made:Uno:M${__objdir}/*} != ""
.error could not use ${__objdir}: .OBJDIR=${.OBJDIR}
.endif
.endif
diff --git a/contrib/bmake/mk/install-mk b/contrib/bmake/mk/install-mk
index d2500da..0c3db00 100644
--- a/contrib/bmake/mk/install-mk
+++ b/contrib/bmake/mk/install-mk
@@ -55,7 +55,7 @@
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
-# $Id: install-mk,v 1.117 2015/11/14 18:09:57 sjg Exp $
+# $Id: install-mk,v 1.118 2015/12/16 01:57:06 sjg Exp $
#
# @(#) Copyright (c) 1994 Simon J. Gerraty
#
@@ -70,7 +70,7 @@
# sjg@crufty.net
#
-MK_VERSION=20151111
+MK_VERSION=20151212
OWNER=
GROUP=
MODE=444
diff --git a/contrib/bmake/os.sh b/contrib/bmake/os.sh
index 93d4387..1dd394f 100755
--- a/contrib/bmake/os.sh
+++ b/contrib/bmake/os.sh
@@ -17,7 +17,7 @@
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
-# $Id: os.sh,v 1.49 2015/10/25 00:05:40 sjg Exp $
+# $Id: os.sh,v 1.50 2015/12/17 17:06:29 sjg Exp $
#
# @(#) Copyright (c) 1994 Simon J. Gerraty
#
@@ -56,10 +56,10 @@ Which() {
case "$1" in
/*) test $t $1 && echo $1;;
*)
- # some shells cannot correctly handle `IFS`
- # in conjunction with the for loop.
- _dirs=`IFS=:; echo ${2:-$PATH}`
- for d in $_dirs
+ # some shells cannot correctly handle `IFS`
+ # in conjunction with the for loop.
+ _dirs=`IFS=:; echo ${2:-$PATH}`
+ for d in $_dirs
do
test $t $d/$1 && { echo $d/$1; break; }
done
@@ -70,11 +70,11 @@ Which() {
# tr is insanely non-portable wrt char classes, so we need to
# spell out the alphabet. sed y/// would work too.
toUpper() {
- ${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
+ ${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
}
toLower() {
- ${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
+ ${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
}
K=
@@ -91,7 +91,7 @@ SunOS)
export CHOWN
# Great! Solaris keeps moving arch(1)
- # should just bite the bullet and use uname -p
+ # should just bite the bullet and use uname -p
arch=`Which arch /usr/bin:/usr/ucb`
MAILER=/usr/ucb/Mail
@@ -105,8 +105,8 @@ SunOS)
MACHINE=$MACHINE_ARCH
;;
4*)
- MACHINE_ARCH=`arch`
- ;;
+ MACHINE_ARCH=`arch`
+ ;;
5*)
K=-k
LOCAL_FS=ufs
@@ -116,8 +116,8 @@ SunOS)
# overwriting an existing file!!!!! We want one that works!
test -x /usr/xpg4/bin/ln && LN=${LN:-/usr/xpg4/bin/ln}
# wonderful, 5.8's tr again require's []'s
- # but /usr/xpg4/bin/tr causes problems if LC_COLLATE is set!
- # use toUpper/toLower instead.
+ # but /usr/xpg4/bin/tr causes problems if LC_COLLATE is set!
+ # use toUpper/toLower instead.
;;
esac
case "$OS/$MACHINE_ARCH" in
@@ -142,9 +142,9 @@ SunOS)
SHARE_ARCH=$OS/$HOST
;;
OpenBSD)
- arch=`Which arch /usr/bin:/usr/ucb:$PATH`
- MACHINE_ARCH=`$arch -s`
- ;;
+ arch=`Which arch /usr/bin:/usr/ucb:$PATH`
+ MACHINE_ARCH=`$arch -s`
+ ;;
esac
NAWK=awk
export NAWK
@@ -218,17 +218,25 @@ export HOST_TARGET
case `echo -n .` in -n*) N=; C="\c";; *) N=-n; C=;; esac
-export HOSTNAME HOST
+Echo() {
+ case "$1" in
+ -n) _n=$N _c=$C; shift;;
+ *) _n= _c=;;
+ esac
+ echo $_n "$@" $_c
+}
+
+export HOSTNAME HOST
export OS MACHINE MACHINE_ARCH OSREL OSMAJOR LOCAL_FS TMP_DIRS MAILER N C K PS_AXC
export LN SHARE_ARCH TR
case /$0 in
*/os.sh)
- for v in $*
+ for v in $*
do
- eval vv=\$$v
- echo "$v='$vv'"
+ eval vv=\$$v
+ echo "$v='$vv'"
done
- ;;
+ ;;
esac
diff --git a/contrib/bmake/suff.c b/contrib/bmake/suff.c
index 15a3cc8..db69643 100644
--- a/contrib/bmake/suff.c
+++ b/contrib/bmake/suff.c
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.74 2015/10/11 04:51:24 sjg Exp $ */
+/* $NetBSD: suff.c,v 1.75 2015/12/20 22:44:10 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.74 2015/10/11 04:51:24 sjg Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.75 2015/12/20 22:44:10 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
#else
-__RCSID("$NetBSD: suff.c,v 1.74 2015/10/11 04:51:24 sjg Exp $");
+__RCSID("$NetBSD: suff.c,v 1.75 2015/12/20 22:44:10 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -553,7 +553,20 @@ Suff_ClearSuffixes(void)
#endif
sufflist = Lst_Init(FALSE);
sNum = 0;
- suffNull = emptySuff;
+ if (suffNull)
+ SuffFree(suffNull);
+ emptySuff = suffNull = bmake_malloc(sizeof(Suff));
+
+ suffNull->name = bmake_strdup("");
+ suffNull->nameLen = 0;
+ suffNull->searchPath = Lst_Init(FALSE);
+ Dir_Concat(suffNull->searchPath, dirSearchPath);
+ suffNull->children = Lst_Init(FALSE);
+ suffNull->parents = Lst_Init(FALSE);
+ suffNull->ref = Lst_Init(FALSE);
+ suffNull->sNum = sNum++;
+ suffNull->flags = SUFF_NULL;
+ suffNull->refCount = 1;
}
/*-
@@ -2524,32 +2537,18 @@ Suff_SetNull(char *name)
void
Suff_Init(void)
{
- sufflist = Lst_Init(FALSE);
#ifdef CLEANUP
suffClean = Lst_Init(FALSE);
#endif
srclist = Lst_Init(FALSE);
transforms = Lst_Init(FALSE);
- sNum = 0;
/*
* Create null suffix for single-suffix rules (POSIX). The thing doesn't
* actually go on the suffix list or everyone will think that's its
* suffix.
*/
- emptySuff = suffNull = bmake_malloc(sizeof(Suff));
-
- suffNull->name = bmake_strdup("");
- suffNull->nameLen = 0;
- suffNull->searchPath = Lst_Init(FALSE);
- Dir_Concat(suffNull->searchPath, dirSearchPath);
- suffNull->children = Lst_Init(FALSE);
- suffNull->parents = Lst_Init(FALSE);
- suffNull->ref = Lst_Init(FALSE);
- suffNull->sNum = sNum++;
- suffNull->flags = SUFF_NULL;
- suffNull->refCount = 1;
-
+ Suff_ClearSuffixes();
}
diff --git a/contrib/bsnmp/snmpd/action.c b/contrib/bsnmp/snmpd/action.c
index ebba0f5..e8fd715 100644
--- a/contrib/bsnmp/snmpd/action.c
+++ b/contrib/bsnmp/snmpd/action.c
@@ -60,29 +60,6 @@ static const struct asn_oid
#endif
/*
- * Get a string value from the KERN sysctl subtree.
- */
-static char *
-act_getkernstring(int id)
-{
- int mib[2];
- size_t len;
- char *string;
-
- mib[0] = CTL_KERN;
- mib[1] = id;
- if (sysctl(mib, 2, NULL, &len, NULL, 0) != 0)
- return (NULL);
- if ((string = malloc(len)) == NULL)
- return (NULL);
- if (sysctl(mib, 2, string, &len, NULL, 0) != 0) {
- free(string);
- return (NULL);
- }
- return (string);
-}
-
-/*
* Get an integer value from the KERN sysctl subtree.
*/
static char *
diff --git a/contrib/bsnmp/snmpd/main.c b/contrib/bsnmp/snmpd/main.c
index e7257b5..cbd1893 100644
--- a/contrib/bsnmp/snmpd/main.c
+++ b/contrib/bsnmp/snmpd/main.c
@@ -119,26 +119,30 @@ static struct lmodules modules_start = TAILQ_HEAD_INITIALIZER(modules_start);
struct community_list community_list = TAILQ_HEAD_INITIALIZER(community_list);
/* list of all known USM users */
-struct usm_userlist usm_userlist = SLIST_HEAD_INITIALIZER(usm_userlist);
+static struct usm_userlist usm_userlist = SLIST_HEAD_INITIALIZER(usm_userlist);
/* A list of all VACM users configured, including v1, v2c and v3 */
-struct vacm_userlist vacm_userlist = SLIST_HEAD_INITIALIZER(vacm_userlist);
+static struct vacm_userlist vacm_userlist =
+ SLIST_HEAD_INITIALIZER(vacm_userlist);
/* A list of all VACM groups */
-struct vacm_grouplist vacm_grouplist = SLIST_HEAD_INITIALIZER(vacm_grouplist);
+static struct vacm_grouplist vacm_grouplist =
+ SLIST_HEAD_INITIALIZER(vacm_grouplist);
static struct vacm_group vacm_default_group = {
.groupname = "",
};
/* The list of configured access entries */
-struct vacm_accesslist vacm_accesslist = TAILQ_HEAD_INITIALIZER(vacm_accesslist);
+static struct vacm_accesslist vacm_accesslist =
+ TAILQ_HEAD_INITIALIZER(vacm_accesslist);
/* The list of configured views */
-struct vacm_viewlist vacm_viewlist = SLIST_HEAD_INITIALIZER(vacm_viewlist);
+static struct vacm_viewlist vacm_viewlist =
+ SLIST_HEAD_INITIALIZER(vacm_viewlist);
/* The list of configured contexts */
-struct vacm_contextlist vacm_contextlist =
+static struct vacm_contextlist vacm_contextlist =
SLIST_HEAD_INITIALIZER(vacm_contextlist);
/* list of all installed object resources */
diff --git a/contrib/bsnmp/snmpd/trap.c b/contrib/bsnmp/snmpd/trap.c
index bf02708..aa9dd93 100644
--- a/contrib/bsnmp/snmpd/trap.c
+++ b/contrib/bsnmp/snmpd/trap.c
@@ -60,15 +60,15 @@
struct trapsink_list trapsink_list = TAILQ_HEAD_INITIALIZER(trapsink_list);
/* List of target addresses */
-struct target_addresslist target_addresslist =
+static struct target_addresslist target_addresslist =
SLIST_HEAD_INITIALIZER(target_addresslist);
/* List of target parameters */
-struct target_paramlist target_paramlist =
+static struct target_paramlist target_paramlist =
SLIST_HEAD_INITIALIZER(target_paramlist);
/* List of notification targets */
-struct target_notifylist target_notifylist =
+static struct target_notifylist target_notifylist =
SLIST_HEAD_INITIALIZER(target_notifylist);
static const struct asn_oid oid_begemotTrapSinkTable =
diff --git a/contrib/mdocml/lib.in b/contrib/mdocml/lib.in
index 7198a79..0e3162f 100644
--- a/contrib/mdocml/lib.in
+++ b/contrib/mdocml/lib.in
@@ -67,6 +67,7 @@ LINE("libmemstat", "Kernel Memory Allocator Statistics Library (libmemstat, \\-l
LINE("libmenu", "Curses Menu Library (libmenu, \\-lmenu)")
LINE("libnetgraph", "Netgraph User Library (libnetgraph, \\-lnetgraph)")
LINE("libnetpgp", "Netpgp signing, verification, encryption and decryption (libnetpgp, \\-lnetpgp)")
+LINE("libnv", "Name/value pairs library (libnv, \\-lnv)")
LINE("libossaudio", "OSS Audio Emulation Library (libossaudio, \\-lossaudio)")
LINE("libpam", "Pluggable Authentication Module Library (libpam, \\-lpam)")
LINE("libpcap", "Packet Capture Library (libpcap, \\-lpcap)")
diff --git a/contrib/openbsm/.travis.yml b/contrib/openbsm/.travis.yml
new file mode 100644
index 0000000..5540774
--- /dev/null
+++ b/contrib/openbsm/.travis.yml
@@ -0,0 +1,18 @@
+language: c
+
+compiler:
+ - clang
+ - gcc
+
+os:
+ - linux
+ - osx
+
+before_install:
+ - if [ $TRAVIS_OS_NAME == "linux" ]; then
+ sudo apt-get -qq update;
+ sudo apt-get -qq install byacc flex;
+ elif [ $TRAVIS_OS_NAME == "osx" ]; then
+ brew update;
+ brew install byacc flex;
+ fi
diff --git a/contrib/openbsm/INSTALL b/contrib/openbsm/INSTALL
index 9e52b0d..307a3bb 100644
--- a/contrib/openbsm/INSTALL
+++ b/contrib/openbsm/INSTALL
@@ -3,7 +3,7 @@ OpenBSM Build and Installation Instructions
OpenBSM is currently built using autoconf and automake, which should allow
for building on a range of operating systems, including FreeBSD, Mac OS X,
and Linux. Some components are built only if appropriate kernel audit
-suppport is found. Typical builds will be performed using:
+support is found. Typical builds will be performed using:
./configure
make
@@ -31,7 +31,7 @@ not configurable.
You may wish to specify that the OpenBSM components not be installed in the
base system, rather in a specific directory. This may be done using the
--prefix argument to configure. If installing to a specific directory,
-remember to update your library path so that running tools from that
+remember to update your library path so that when running tools from that
directory the correct libbsm is used:
./configure --prefix=/home/rwatson/openbsm
diff --git a/contrib/openbsm/LICENSE b/contrib/openbsm/LICENSE
index e053584..58bd5fa 100644
--- a/contrib/openbsm/LICENSE
+++ b/contrib/openbsm/LICENSE
@@ -34,5 +34,3 @@ as a whole:
The TrustedBSD Project would appreciate the contribution of fixes and
enhancements under an identical license in order to avoid potentially
confusing license proliferation.
-
-$P4: //depot/projects/trustedbsd/openbsm/LICENSE#6 $
diff --git a/contrib/openbsm/Makefile.am b/contrib/openbsm/Makefile.am
index 5073133..b58c170 100644
--- a/contrib/openbsm/Makefile.am
+++ b/contrib/openbsm/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/Makefile.am#5 $
-##
-
SUBDIRS = \
bsm
diff --git a/contrib/openbsm/Makefile.in b/contrib/openbsm/Makefile.in
index 9f90493..4e0a8a8 100644
--- a/contrib/openbsm/Makefile.in
+++ b/contrib/openbsm/Makefile.in
@@ -59,9 +59,9 @@ DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
$(top_srcdir)/config/config.sub \
$(top_srcdir)/config/install-sh $(top_srcdir)/config/ltmain.sh \
$(top_srcdir)/config/missing $(top_srcdir)/configure INSTALL \
- NEWS TODO config/config.guess config/config.sub config/depcomp \
- config/install-sh config/ltmain.sh config/missing \
- config/ylwrap
+ NEWS TODO config/compile config/config.guess config/config.sub \
+ config/depcomp config/install-sh config/ltmain.sh \
+ config/missing config/ylwrap
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
diff --git a/contrib/openbsm/NEWS b/contrib/openbsm/NEWS
index a55fabb..dc49117 100644
--- a/contrib/openbsm/NEWS
+++ b/contrib/openbsm/NEWS
@@ -1,5 +1,16 @@
OpenBSM Version History
+OpenBSM 1.2 alpha 4
+
+- Fix praudit to emit correct XML.
+- Fix auditdistd bugs related to IPv6 support, locking, and a kqueue-related
+ descriptor leak.
+- Add audit event definitions for Capsicum-related syscalls, as well as
+ AUE_BINDAT and AUE_CONNECTAT.
+- Manpage symlinks for all libbsm functions are installed again after the
+ move to autotools in OpenBSM 1.0 Alpha 5.
+- A variety of minor documentation cleanups.
+
OpenBSM 1.2 alpha 3
- Various minor tweaks to the auditdistd build to make it fit the FreeBSD
@@ -494,5 +505,3 @@ OpenBSM 1.0 alpha 1
- auditd(8), audit(8) added to the OpenBSM distribution. auditd extended
to support reloading of kernel event table.
- Allow comments in /etc/security configuration files.
-
-$P4: //depot/projects/trustedbsd/openbsm/NEWS#55 $
diff --git a/contrib/openbsm/README b/contrib/openbsm/README
index 17446af..e60c502 100644
--- a/contrib/openbsm/README
+++ b/contrib/openbsm/README
@@ -1,4 +1,4 @@
-OpenBSM 1.2a2
+OpenBSM
Introduction
@@ -10,7 +10,7 @@ of several organizations.
OpenBSM includes several command line tools, including auditreduce(8) and
praudit(8) for reducing and printing audit trails, as well as the libbsm(3)
library to manage configuration files, generate audit records, and parse and
-print audit trils.
+print audit trails.
Coupled with a kernel audit implementation, OpenBSM can be used to maintain
system audit streams, and is a foundation for a full audit-enabled system.
@@ -64,5 +64,3 @@ Information on OpenBSM may be found on the OpenBSM home page:
Information on TrustedBSD may be found on the TrustedBSD home page:
http://www.TrustedBSD.org/
-
-$P4: //depot/projects/trustedbsd/openbsm/README#41 $
diff --git a/contrib/openbsm/TODO b/contrib/openbsm/TODO
index 7b8f403..5928aed 100644
--- a/contrib/openbsm/TODO
+++ b/contrib/openbsm/TODO
@@ -7,8 +7,6 @@ OpenBSM TODO
- Document contents of libbsm "public" data structures in libbsm man pages.
- The audit.log.5 man page is incomplete, as it does not describe all
token types.
-- With the move to autoconf/automake, man page symlinks are no longer
- installed. This needs to be fixed.
- It might be desirable to be able to provide EOPNOTSUPP system call stubs
on systems that don't have the necessary audit system calls; that would
allow the full libbsm and tool set to build, just not run.
@@ -23,5 +21,3 @@ OpenBSM TODO
not available on the local OS platform.
- Support for client certificates in auditdistd, to include certificate chain
validation.
-
-$P4: //depot/projects/trustedbsd/openbsm/TODO#14 $
diff --git a/contrib/openbsm/VERSION b/contrib/openbsm/VERSION
index b3ea4dc..da1fd62 100644
--- a/contrib/openbsm/VERSION
+++ b/contrib/openbsm/VERSION
@@ -1 +1 @@
-OPENBSM_1_2_alpha3
+OPENBSM_1_2_alpha4
diff --git a/contrib/openbsm/autogen.sh b/contrib/openbsm/autogen.sh
index 41fbc31..afa8a03 100644
--- a/contrib/openbsm/autogen.sh
+++ b/contrib/openbsm/autogen.sh
@@ -1,7 +1,4 @@
#!/bin/sh
-#
-# $P4: //depot/projects/trustedbsd/openbsm/autogen.sh#2 $
-#
libtoolize --copy --force
aclocal
diff --git a/contrib/openbsm/bin/Makefile.am b/contrib/openbsm/bin/Makefile.am
index 16073e9..15a3dbc 100644
--- a/contrib/openbsm/bin/Makefile.am
+++ b/contrib/openbsm/bin/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/bin/Makefile.am#4 $
-##
-
SUBDIRS = \
auditdistd \
auditfilterd \
diff --git a/contrib/openbsm/bin/audit/Makefile.am b/contrib/openbsm/bin/audit/Makefile.am
index e797783..d0af56c 100644
--- a/contrib/openbsm/bin/audit/Makefile.am
+++ b/contrib/openbsm/bin/audit/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/bin/audit/Makefile.am#7 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/bin/audit/audit.8 b/contrib/openbsm/bin/audit/audit.8
index d5b2960..b9f98b3 100644
--- a/contrib/openbsm/bin/audit/audit.8
+++ b/contrib/openbsm/bin/audit/audit.8
@@ -25,9 +25,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/bin/audit/audit.8#16 $
-.\"
-.Dd January 29, 2009
+.Dd July 25, 2015
.Dt AUDIT 8
.Os
.Sh NAME
@@ -88,7 +86,7 @@ Audit policy file used to configure the auditing system.
.Xr audit 4 ,
.Xr audit_control 5 ,
.Xr auditd 8 ,
-.Xr launchd 8
+.Xr launchd 8 (Mac OS X)
.Sh HISTORY
The OpenBSM implementation was created by McAfee Research, the security
division of McAfee Inc., under contract to Apple Computer Inc.\& in 2004.
diff --git a/contrib/openbsm/bin/audit/audit.c b/contrib/openbsm/bin/audit/audit.c
index 95ac3bc..dfe956f 100644
--- a/contrib/openbsm/bin/audit/audit.c
+++ b/contrib/openbsm/bin/audit/audit.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/audit/audit.c#15 $
*/
/*
* Program to trigger the audit daemon with a message that is either:
diff --git a/contrib/openbsm/bin/auditd/Makefile.am b/contrib/openbsm/bin/auditd/Makefile.am
index 2a187db..8a2a9df 100644
--- a/contrib/openbsm/bin/auditd/Makefile.am
+++ b/contrib/openbsm/bin/auditd/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/Makefile.am#6 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/bin/auditd/audit_triggers.defs b/contrib/openbsm/bin/auditd/audit_triggers.defs
index f5b394d..9fe2c35 100644
--- a/contrib/openbsm/bin/auditd/audit_triggers.defs
+++ b/contrib/openbsm/bin/auditd/audit_triggers.defs
@@ -1,5 +1 @@
-/*
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/audit_triggers.defs#1 $
- */
-
#include <mach/audit_triggers.defs>
diff --git a/contrib/openbsm/bin/auditd/audit_warn.c b/contrib/openbsm/bin/auditd/audit_warn.c
index 22806e2..6bd2b84 100644
--- a/contrib/openbsm/bin/auditd/audit_warn.c
+++ b/contrib/openbsm/bin/auditd/audit_warn.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/audit_warn.c#11 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/bin/auditd/auditd.8 b/contrib/openbsm/bin/auditd/auditd.8
index b437524..c76dfca 100644
--- a/contrib/openbsm/bin/auditd/auditd.8
+++ b/contrib/openbsm/bin/auditd/auditd.8
@@ -25,9 +25,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/auditd.8#19 $
-.\"
-.Dd December 11, 2008
+.Dd July 25, 2015
.Dt AUDITD 8
.Os
.Sh NAME
@@ -123,7 +121,7 @@ and are no longer available as arguments to
.Xr audit_warn 5 ,
.Xr audit 8 ,
.Xr auditdistd 8 ,
-.Xr launchd 8
+.Xr launchd 8 (Mac OS X)
.Sh HISTORY
The OpenBSM implementation was created by McAfee Research, the security
division of McAfee Inc., under contract to Apple Computer Inc.\& in 2004.
diff --git a/contrib/openbsm/bin/auditd/auditd.c b/contrib/openbsm/bin/auditd/auditd.c
index 26a0d07..a4357bd 100644
--- a/contrib/openbsm/bin/auditd/auditd.c
+++ b/contrib/openbsm/bin/auditd/auditd.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/auditd.c#50 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/bin/auditd/auditd.h b/contrib/openbsm/bin/auditd/auditd.h
index f952181..20afd75 100644
--- a/contrib/openbsm/bin/auditd/auditd.h
+++ b/contrib/openbsm/bin/auditd/auditd.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/auditd.h#13 $
*/
#ifndef _AUDITD_H_
diff --git a/contrib/openbsm/bin/auditd/auditd_control.defs b/contrib/openbsm/bin/auditd/auditd_control.defs
index f06fe01..84f37df 100644
--- a/contrib/openbsm/bin/auditd/auditd_control.defs
+++ b/contrib/openbsm/bin/auditd/auditd_control.defs
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/auditd_control.defs#2 $
*/
/*
diff --git a/contrib/openbsm/bin/auditd/auditd_darwin.c b/contrib/openbsm/bin/auditd/auditd_darwin.c
index 8530185..702eb94 100644
--- a/contrib/openbsm/bin/auditd/auditd_darwin.c
+++ b/contrib/openbsm/bin/auditd/auditd_darwin.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/auditd_darwin.c#5 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/bin/auditd/auditd_fbsd.c b/contrib/openbsm/bin/auditd/auditd_fbsd.c
index 2da9875..d8f040f 100644
--- a/contrib/openbsm/bin/auditd/auditd_fbsd.c
+++ b/contrib/openbsm/bin/auditd/auditd_fbsd.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditd/auditd_fbsd.c#4 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/bin/auditdistd/Makefile.am b/contrib/openbsm/bin/auditdistd/Makefile.am
index 88f2584..263cb2d 100644
--- a/contrib/openbsm/bin/auditdistd/Makefile.am
+++ b/contrib/openbsm/bin/auditdistd/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/Makefile.am#1 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/bin/auditdistd/auditdistd.8 b/contrib/openbsm/bin/auditdistd/auditdistd.8
index 299cde4..71a6575 100644
--- a/contrib/openbsm/bin/auditdistd/auditdistd.8
+++ b/contrib/openbsm/bin/auditdistd/auditdistd.8
@@ -41,7 +41,7 @@
.Sh DESCRIPTION
The
.Nm
-daemon is responsible for distributing audit trail files over TCP/IP network in
+daemon is responsible for distributing audit trail files over a TCP/IP network in
a secure and reliable way.
.Pp
The
@@ -49,7 +49,7 @@ The
daemon can be started with the following command line arguments:
.Bl -tag -width ".Fl P Ar pidfile"
.It Fl c Ar config
-Specify alternative location of the configuration file.
+Specify an alternative location of the configuration file.
The default location is
.Pa /etc/security/auditdistd.conf .
Note: the configuration file may contain passwords.
@@ -74,7 +74,7 @@ usage message.
Start in a launchd-friendly mode, ie. do not use
.Xr daemon 3 .
.It Fl P Ar pidfile
-Specify alternative location of a file where main process PID will be
+Specify an alternative location of a file where main process PID will be
stored.
The default location is
.Pa /var/run/auditdistd.pid .
diff --git a/contrib/openbsm/bin/auditdistd/auditdistd.c b/contrib/openbsm/bin/auditdistd/auditdistd.c
index 436531d..696f048 100644
--- a/contrib/openbsm/bin/auditdistd/auditdistd.c
+++ b/contrib/openbsm/bin/auditdistd/auditdistd.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/auditdistd.c#3 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/auditdistd.conf.5 b/contrib/openbsm/bin/auditdistd/auditdistd.conf.5
index 13abb5a..c6ed2b5 100644
--- a/contrib/openbsm/bin/auditdistd/auditdistd.conf.5
+++ b/contrib/openbsm/bin/auditdistd/auditdistd.conf.5
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 22, 2011
+.Dd July 1, 2015
.Dt AUDITDISTD.CONF 5
.Os
.Sh NAME
@@ -37,19 +37,21 @@
daemon.
.Sh DESCRIPTION
Note: the configuration file may contain passwords.
-Care should be taken to configure proper permissions on this file
-.Li ( eg. 0600 ) .
+Care should be taken to configure proper permissions for this file
+.Li ( e.g., 0600 ) .
.Pp
-Every line starting with # is treated as comment and ignored.
+Every line starting with
+.Li #
+gets treated as a comment and is ignored.
.Sh CONFIGURATION FILE SYNTAX
-General syntax of the
+The general syntax of the
.Nm
-file is following:
-.Bd -literal -offset
+file is as follows:
+.Bd -literal
## Global section.
# Our name.
-# The default is first part of the hostname.
+# The default is the first part of the hostname.
name "<name>"
# Connection timeout.
@@ -71,11 +73,11 @@ sender {
# The default is /var/audit/dist.
directory "<dir>"
.\"
-.\" # Checksum algorithm for data send over the wire.
+.\" # Checksum algorithm for data sent over the wire.
.\" # The default is none.
.\" checksum "<algorithm>"
.\"
-.\" # Compression algorithm for data send over the wire.
+.\" # Compression algorithm for data sent over the wire.
.\" # The default is none.
.\" compression "<algorithm>"
@@ -86,7 +88,7 @@ sender {
# Optional.
source "<addr>"
- # Address of auditdistd receiver.
+ # Address of the auditdistd receiver.
# No default. Obligatory.
remote "<addr>"
@@ -95,7 +97,7 @@ sender {
directory "<dir>"
# Fingerprint of the receiver's public key when using TLS
- # for connection.
+ # for connections.
# Example fingerprint:
# SHA256=8F:0A:FC:8A:3D:09:80:AF:D9:AA:38:CC:8A:86:53:E6:8F:B6:1C:55:30:14:D7:F9:AA:8B:3E:73:CD:F5:76:2B
fingerprint "<algorithm=hash>"
@@ -103,37 +105,37 @@ sender {
# Password used to authenticate in front of the receiver.
password "<password>"
.\"
-.\" # Checksum algorithm for data send over the wire.
+.\" # Checksum algorithm for data sent over the wire.
.\" # The default is none.
.\" checksum "<algorithm>"
.\"
-.\" # Compression algorithm for data send over the wire.
+.\" # Compression algorithm for data sent over the wire.
.\" # The default is none.
.\" compression "<algorithm>"
}
- # Currently local audit trail files can be send only to one remote
+ # Currently local audit trail files can be sent only to one remote
# auditdistd receiver, but this can change in the future.
}
receiver {
## Receiver section.
- # Address to listen on. Multiple listen addresses might be specified.
+ # Address to listen on. Multiple listen addresses may be specified.
# The defaults are "tcp4://0.0.0.0:7878" and "tcp6://[::]:7878".
listen "<addr>"
# Base directory.
- # If directory in host section is no absolute, it will be concatenated
- # with this base directory.
+ # If the directory in the host section is not absolute, it will be
+ # concatenated with this base directory.
# The default is "/var/audit/remote".
directory "<basedir>"
- # Path to receiver's certificate file.
+ # Path to the receiver's certificate file.
# The default is "/etc/security/auditdistd.cert.pem".
certfile "<path>"
- # Path to receiver's private key file.
+ # Path to the receiver's private key file.
# The default is "/etc/security/auditdistd.key.pem".
keyfile "<path>"
@@ -158,7 +160,7 @@ receiver {
.Ed
.Pp
Most of the various available configuration parameters are optional.
-If parameter is not defined in the particular section, it will be
+If a parameter is not defined in the particular section, it will be
inherited from the parent section if possible.
For example, if the
.Ic source
@@ -172,14 +174,14 @@ In case the
section does not define the
.Ic source
parameter at all, the default value will be used.
-.Sh CONFIGURATION FILE DESCRIPTION
+.Sh CONFIGURATION OPTION DESCRIPTION
The following statements are available:
.Bl -tag -width ".Ic xxxx"
.It Ic name Aq name
.Pp
This host's name.
-It is send to the receiver, so it can properly recognize us if there are
-more than one sender coming from the same IP address.
+It is sent to the receiver, so it can properly recognize us if there are
+multiple senders coming from the same IP address.
.It Ic timeout Aq seconds
.Pp
Connection timeout in seconds.
@@ -198,17 +200,17 @@ The default value is
Local address to bind to before connecting to the remote
.Nm auditdistd
daemon.
-Format is the same as for the
+The format is the same as for the
.Ic listen
statement.
.It Ic directory Aq path
.Pp
-Directory where to look for audit trail files in case of sender mode or
-directory where to store received audit trail files.
+The directory where to look for audit trail files in case of sender mode, or
+the directory where to store received audit trail files.
The provided path has to be an absolute path.
-The only exception is when directory is provided in the
+The only exception is when the directory is provided in the
.Ic receiver
-section, then path provided in the
+section; then the path provided in the
.Ic host
subsections can be relative to the directory in the
.Ic receiver
@@ -229,13 +231,13 @@ subsections in the
.Ic receiver
section where
.Aq name
-is host's name.
+is the host's name.
.\".It Ic checksum Aq algorithm
.\".Pp
.\"Checksum algorithm should be one of the following:
.\".Bl -tag -width ".Ic sha256"
.\".It Ic none
-.\"No checksum will be calculated for the data being send over the network.
+.\"No checksum will be calculated for the data being sent over the network.
.\"This is the default setting.
.\".It Ic crc32
.\"CRC32 checksum will be calculated.
@@ -247,30 +249,30 @@ is host's name.
.\"Compression algorithm should be one of the following:
.\".Bl -tag -width ".Ic none"
.\".It Ic none
-.\"Data send over the network will not be compressed.
+.\"Data sent over the network will not be compressed.
.\"This is the default setting.
.\".It Ic lzf
.\"The
.\".Nm LZF
.\"algorithm by
.\".An Marc Alexander Lehmann
-.\"will be used to compress the data send over the network.
+.\"will be used to compress the data sent over the network.
.\".Nm LZF
-.\"is very fast, general purpose compression algorithm.
+.\"is a very fast, general purpose compression algorithm.
.\".El
.It Ic remote Aq addr
.Pp
Address of the remote
.Nm auditdistd
daemon.
-Format is the same as for the
+The format is the same as for the
.Ic listen
statement.
-When operating in the
+When operating in
.Ic sender
mode this address will be used to connect to the
.Ic receiver .
-When operating in the
+When operating in
.Ic receiver
mode only connections from this address will be accepted.
.It Ic listen Aq addr
@@ -296,21 +298,22 @@ By default
listens on
.Pa tcp4://0.0.0.0:7878
and
-.Pa tcp6://[::]:7878
-if kernel supports IPv4 and IPv6 respectively.
+.Pa tcp6://[::]:7878 ,
+if the kernel supports IPv4 and IPv6 respectively.
.It Ic keyfile Aq path
.Pp
-Path to a file that contains private key for TLS communication.
+Path to a file that contains the private key for TLS communication.
.It Ic certfile Aq path
.Pp
-Path to a file that contains certificate for TLS communication.
+Path to a file that contains the certificate for TLS communication.
.It Ic fingerprint Aq algo=hash
.Pp
-Finger print of the receiver's public key.
-Currently only SHA256 algorithm is supported.
-Certificate public key's fingerprint ready to be pasted into auditdistd
+Fingerprint of the receiver's public key.
+Currently only the SHA256 algorithm is supported.
+The certificate public key's fingerprint ready to be pasted into the
+.Nm auditdistd
configuration file can be obtained by running:
-.Bd -literal -offset
+.Bd -literal
# openssl x509 -in /etc/security/auditdistd.cert.pem -noout -fingerprint -sha256 | awk -F '[ =]' '{printf("%s=%s\\n", $1, $3)}'
.Ed
.It Ic password Aq password
@@ -352,10 +355,10 @@ receiver {
.Ed
.Sh SEE ALSO
.Xr audit 4 ,
-.Xr auditdistd 8 .
+.Xr auditdistd 8
.Sh AUTHORS
The
.Nm auditdistd
-was developed by
+daemon was developed by
.An Pawel Jakub Dawidek Aq pawel@dawidek.net
under sponsorship of the FreeBSD Foundation.
diff --git a/contrib/openbsm/bin/auditdistd/auditdistd.h b/contrib/openbsm/bin/auditdistd/auditdistd.h
index 9ac2850..d0594f2 100644
--- a/contrib/openbsm/bin/auditdistd/auditdistd.h
+++ b/contrib/openbsm/bin/auditdistd/auditdistd.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/auditdistd.h#2 $
*/
#ifndef _AUDITDISTD_H_
diff --git a/contrib/openbsm/bin/auditdistd/faccessat.h b/contrib/openbsm/bin/auditdistd/faccessat.h
index 37d8b89..568a6b7 100644
--- a/contrib/openbsm/bin/auditdistd/faccessat.h
+++ b/contrib/openbsm/bin/auditdistd/faccessat.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/faccessat.h#1 $
*/
#ifndef _FACCESSAT_H_
diff --git a/contrib/openbsm/bin/auditdistd/fstatat.h b/contrib/openbsm/bin/auditdistd/fstatat.h
index a2716b9..5327a7c 100644
--- a/contrib/openbsm/bin/auditdistd/fstatat.h
+++ b/contrib/openbsm/bin/auditdistd/fstatat.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/fstatat.h#1 $
*/
#ifndef _FSTATAT_H_
diff --git a/contrib/openbsm/bin/auditdistd/openat.h b/contrib/openbsm/bin/auditdistd/openat.h
index defb947..1d98014 100644
--- a/contrib/openbsm/bin/auditdistd/openat.h
+++ b/contrib/openbsm/bin/auditdistd/openat.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/openat.h#1 $
*/
#ifndef _OPENAT_H_
diff --git a/contrib/openbsm/bin/auditdistd/parse.y b/contrib/openbsm/bin/auditdistd/parse.y
index fbe1000..1f80d50 100644
--- a/contrib/openbsm/bin/auditdistd/parse.y
+++ b/contrib/openbsm/bin/auditdistd/parse.y
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/parse.y#5 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/pjdlog.c b/contrib/openbsm/bin/auditdistd/pjdlog.c
index e8d5876..16f176e 100644
--- a/contrib/openbsm/bin/auditdistd/pjdlog.c
+++ b/contrib/openbsm/bin/auditdistd/pjdlog.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/pjdlog.c#1 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/bin/auditdistd/pjdlog.h b/contrib/openbsm/bin/auditdistd/pjdlog.h
index 0cb6121..d6f217f 100644
--- a/contrib/openbsm/bin/auditdistd/pjdlog.h
+++ b/contrib/openbsm/bin/auditdistd/pjdlog.h
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/pjdlog.h#1 $
*/
#ifndef _PJDLOG_H_
diff --git a/contrib/openbsm/bin/auditdistd/proto.c b/contrib/openbsm/bin/auditdistd/proto.c
index 25daf0c..4e9bea0 100644
--- a/contrib/openbsm/bin/auditdistd/proto.c
+++ b/contrib/openbsm/bin/auditdistd/proto.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/proto.c#1 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/bin/auditdistd/proto.h b/contrib/openbsm/bin/auditdistd/proto.h
index 79047b0..f26c0ad 100644
--- a/contrib/openbsm/bin/auditdistd/proto.h
+++ b/contrib/openbsm/bin/auditdistd/proto.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/proto.h#1 $
*/
#ifndef _PROTO_H_
diff --git a/contrib/openbsm/bin/auditdistd/proto_common.c b/contrib/openbsm/bin/auditdistd/proto_common.c
index 0fa4d3c..acd2294 100644
--- a/contrib/openbsm/bin/auditdistd/proto_common.c
+++ b/contrib/openbsm/bin/auditdistd/proto_common.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/proto_common.c#1 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/bin/auditdistd/proto_impl.h b/contrib/openbsm/bin/auditdistd/proto_impl.h
index c2ce2d9..7915ee9 100644
--- a/contrib/openbsm/bin/auditdistd/proto_impl.h
+++ b/contrib/openbsm/bin/auditdistd/proto_impl.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/proto_impl.h#1 $
*/
#ifndef _PROTO_IMPL_H_
diff --git a/contrib/openbsm/bin/auditdistd/proto_socketpair.c b/contrib/openbsm/bin/auditdistd/proto_socketpair.c
index 8d04c49..fc65c76 100644
--- a/contrib/openbsm/bin/auditdistd/proto_socketpair.c
+++ b/contrib/openbsm/bin/auditdistd/proto_socketpair.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/proto_socketpair.c#1 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/bin/auditdistd/proto_tcp.c b/contrib/openbsm/bin/auditdistd/proto_tcp.c
index 74d5cd4..465221d 100644
--- a/contrib/openbsm/bin/auditdistd/proto_tcp.c
+++ b/contrib/openbsm/bin/auditdistd/proto_tcp.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/proto_tcp.c#2 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/proto_tls.c b/contrib/openbsm/bin/auditdistd/proto_tls.c
index faeb3d8..de89147 100644
--- a/contrib/openbsm/bin/auditdistd/proto_tls.c
+++ b/contrib/openbsm/bin/auditdistd/proto_tls.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/proto_tls.c#2 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/proto_uds.c b/contrib/openbsm/bin/auditdistd/proto_uds.c
index 3b3dfb7..3168bbf 100644
--- a/contrib/openbsm/bin/auditdistd/proto_uds.c
+++ b/contrib/openbsm/bin/auditdistd/proto_uds.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/proto_uds.c#2 $
*/
/* UDS - UNIX Domain Socket */
diff --git a/contrib/openbsm/bin/auditdistd/receiver.c b/contrib/openbsm/bin/auditdistd/receiver.c
index 698619d..9dc3b018 100644
--- a/contrib/openbsm/bin/auditdistd/receiver.c
+++ b/contrib/openbsm/bin/auditdistd/receiver.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/receiver.c#3 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/renameat.h b/contrib/openbsm/bin/auditdistd/renameat.h
index a6a67f8..0becb8a 100644
--- a/contrib/openbsm/bin/auditdistd/renameat.h
+++ b/contrib/openbsm/bin/auditdistd/renameat.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/renameat.h#1 $
*/
#ifndef _RENAMEAT_H_
diff --git a/contrib/openbsm/bin/auditdistd/sandbox.c b/contrib/openbsm/bin/auditdistd/sandbox.c
index 9e4f134..53cd6b3 100644
--- a/contrib/openbsm/bin/auditdistd/sandbox.c
+++ b/contrib/openbsm/bin/auditdistd/sandbox.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/sandbox.c#3 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/sandbox.h b/contrib/openbsm/bin/auditdistd/sandbox.h
index 2dc59e4..7bcde25 100644
--- a/contrib/openbsm/bin/auditdistd/sandbox.h
+++ b/contrib/openbsm/bin/auditdistd/sandbox.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/sandbox.h#1 $
*/
#ifndef _SANDBOX_H_
diff --git a/contrib/openbsm/bin/auditdistd/sender.c b/contrib/openbsm/bin/auditdistd/sender.c
index ab90e6c..928eedc 100644
--- a/contrib/openbsm/bin/auditdistd/sender.c
+++ b/contrib/openbsm/bin/auditdistd/sender.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/sender.c#3 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/sigtimedwait.h b/contrib/openbsm/bin/auditdistd/sigtimedwait.h
index 187c6d6..06a4d13 100644
--- a/contrib/openbsm/bin/auditdistd/sigtimedwait.h
+++ b/contrib/openbsm/bin/auditdistd/sigtimedwait.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/sigtimedwait.h#2 $
*/
#ifndef _SIGTIMEDWAIT_H_
diff --git a/contrib/openbsm/bin/auditdistd/strndup.h b/contrib/openbsm/bin/auditdistd/strndup.h
index 6cf3c95..c36a950 100644
--- a/contrib/openbsm/bin/auditdistd/strndup.h
+++ b/contrib/openbsm/bin/auditdistd/strndup.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/strndup.h#1 $
*/
#ifndef _STRNDUP_H_
diff --git a/contrib/openbsm/bin/auditdistd/subr.c b/contrib/openbsm/bin/auditdistd/subr.c
index 0f531cc..ecc626c 100644
--- a/contrib/openbsm/bin/auditdistd/subr.c
+++ b/contrib/openbsm/bin/auditdistd/subr.c
@@ -22,8 +22,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/subr.c#3 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/subr.h b/contrib/openbsm/bin/auditdistd/subr.h
index 2f11b65..7e2ddeb 100644
--- a/contrib/openbsm/bin/auditdistd/subr.h
+++ b/contrib/openbsm/bin/auditdistd/subr.h
@@ -22,8 +22,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/subr.h#1 $
*/
#ifndef _AUDITDISTD_SUBR_H_
diff --git a/contrib/openbsm/bin/auditdistd/synch.h b/contrib/openbsm/bin/auditdistd/synch.h
index e6fe19d..6d83a9b 100644
--- a/contrib/openbsm/bin/auditdistd/synch.h
+++ b/contrib/openbsm/bin/auditdistd/synch.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/synch.h#3 $
*/
#ifndef _SYNCH_H_
diff --git a/contrib/openbsm/bin/auditdistd/token.l b/contrib/openbsm/bin/auditdistd/token.l
index f459013..e3c4624 100644
--- a/contrib/openbsm/bin/auditdistd/token.l
+++ b/contrib/openbsm/bin/auditdistd/token.l
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/token.l#2 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/trail.c b/contrib/openbsm/bin/auditdistd/trail.c
index d4be51e..b8a9881 100644
--- a/contrib/openbsm/bin/auditdistd/trail.c
+++ b/contrib/openbsm/bin/auditdistd/trail.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/trail.c#3 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/bin/auditdistd/trail.h b/contrib/openbsm/bin/auditdistd/trail.h
index 33c88b2..204ea2b 100644
--- a/contrib/openbsm/bin/auditdistd/trail.h
+++ b/contrib/openbsm/bin/auditdistd/trail.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/trail.h#1 $
*/
#ifndef _AUDITDISTD_TRAIL_H_
diff --git a/contrib/openbsm/bin/auditdistd/unlinkat.h b/contrib/openbsm/bin/auditdistd/unlinkat.h
index ee9c023..6364208 100644
--- a/contrib/openbsm/bin/auditdistd/unlinkat.h
+++ b/contrib/openbsm/bin/auditdistd/unlinkat.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditdistd/unlinkat.h#1 $
*/
#ifndef _UNLINKAT_H_
diff --git a/contrib/openbsm/bin/auditfilterd/Makefile.am b/contrib/openbsm/bin/auditfilterd/Makefile.am
index 81d4fb5..400a1d9 100644
--- a/contrib/openbsm/bin/auditfilterd/Makefile.am
+++ b/contrib/openbsm/bin/auditfilterd/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/bin/auditfilterd/Makefile.am#4 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/bin/auditfilterd/auditfilterd.8 b/contrib/openbsm/bin/auditfilterd/auditfilterd.8
index 034c81b..f78c664 100644
--- a/contrib/openbsm/bin/auditfilterd/auditfilterd.8
+++ b/contrib/openbsm/bin/auditfilterd/auditfilterd.8
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/bin/auditfilterd/auditfilterd.8#6 $
-.\"
.Dd October 3, 2006
.Dt AUDITFILTERD 8
.Os
diff --git a/contrib/openbsm/bin/auditfilterd/auditfilterd.c b/contrib/openbsm/bin/auditfilterd/auditfilterd.c
index ba42834..46c86b2 100644
--- a/contrib/openbsm/bin/auditfilterd/auditfilterd.c
+++ b/contrib/openbsm/bin/auditfilterd/auditfilterd.c
@@ -24,8 +24,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditfilterd/auditfilterd.c#13 $
*/
/*
@@ -131,7 +129,7 @@ present_rawrecord(struct timespec *ts, u_char *data, u_int len)
}
/*
- * Parse the BSM into a set of tokens, which will be pased to registered
+ * Parse the BSM into a set of tokens, which will be passed to registered
* and interested filters.
*/
#define MAX_TOKENS 128 /* Maximum tokens we handle per record. */
diff --git a/contrib/openbsm/bin/auditfilterd/auditfilterd.h b/contrib/openbsm/bin/auditfilterd/auditfilterd.h
index d55aeee..c178b82 100644
--- a/contrib/openbsm/bin/auditfilterd/auditfilterd.h
+++ b/contrib/openbsm/bin/auditfilterd/auditfilterd.h
@@ -24,8 +24,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditfilterd/auditfilterd.h#5 $
*/
#define AUDITFILTERD_CONFFILE "/etc/security/audit_filter"
diff --git a/contrib/openbsm/bin/auditfilterd/auditfilterd_conf.c b/contrib/openbsm/bin/auditfilterd/auditfilterd_conf.c
index b0642fa..bf3b3bb 100644
--- a/contrib/openbsm/bin/auditfilterd/auditfilterd_conf.c
+++ b/contrib/openbsm/bin/auditfilterd/auditfilterd_conf.c
@@ -24,8 +24,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditfilterd/auditfilterd_conf.c#5 $
*/
/*
diff --git a/contrib/openbsm/bin/auditreduce/Makefile.am b/contrib/openbsm/bin/auditreduce/Makefile.am
index a02178b..b5e2433 100644
--- a/contrib/openbsm/bin/auditreduce/Makefile.am
+++ b/contrib/openbsm/bin/auditreduce/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/bin/auditreduce/Makefile.am#4 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/bin/auditreduce/auditreduce.1 b/contrib/openbsm/bin/auditreduce/auditreduce.1
index 157f31d..3266ad9 100644
--- a/contrib/openbsm/bin/auditreduce/auditreduce.1
+++ b/contrib/openbsm/bin/auditreduce/auditreduce.1
@@ -25,8 +25,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/bin/auditreduce/auditreduce.1#18 $
-.\"
.Dd January 24, 2004
.Dt AUDITREDUCE 1
.Os
diff --git a/contrib/openbsm/bin/auditreduce/auditreduce.c b/contrib/openbsm/bin/auditreduce/auditreduce.c
index 0faadda..f73d341 100644
--- a/contrib/openbsm/bin/auditreduce/auditreduce.c
+++ b/contrib/openbsm/bin/auditreduce/auditreduce.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditreduce/auditreduce.c#31 $
*/
/*
diff --git a/contrib/openbsm/bin/auditreduce/auditreduce.h b/contrib/openbsm/bin/auditreduce/auditreduce.h
index 5f54893..655b45d 100644
--- a/contrib/openbsm/bin/auditreduce/auditreduce.h
+++ b/contrib/openbsm/bin/auditreduce/auditreduce.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/auditreduce/auditreduce.h#7 $
*/
#ifndef _AUDITREDUCE_H_
diff --git a/contrib/openbsm/bin/praudit/Makefile.am b/contrib/openbsm/bin/praudit/Makefile.am
index c28afd4..4643b7c 100644
--- a/contrib/openbsm/bin/praudit/Makefile.am
+++ b/contrib/openbsm/bin/praudit/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/bin/praudit/Makefile.am#4 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/bin/praudit/praudit.1 b/contrib/openbsm/bin/praudit/praudit.1
index 99ea7c8..2954ba3 100644
--- a/contrib/openbsm/bin/praudit/praudit.1
+++ b/contrib/openbsm/bin/praudit/praudit.1
@@ -25,8 +25,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/bin/praudit/praudit.1#14 $
-.\"
.Dd August 4, 2009
.Dt PRAUDIT 1
.Os
diff --git a/contrib/openbsm/bin/praudit/praudit.c b/contrib/openbsm/bin/praudit/praudit.c
index f20f245..f795434 100644
--- a/contrib/openbsm/bin/praudit/praudit.c
+++ b/contrib/openbsm/bin/praudit/praudit.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bin/praudit/praudit.c#16 $
*/
/*
diff --git a/contrib/openbsm/bsm/Makefile.am b/contrib/openbsm/bsm/Makefile.am
index c36d576..c3df79e 100644
--- a/contrib/openbsm/bsm/Makefile.am
+++ b/contrib/openbsm/bsm/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/bsm/Makefile.am#5 $
-##
-
openbsmdir = $(includedir)/bsm
openbsm_HEADERS = \
diff --git a/contrib/openbsm/bsm/audit_filter.h b/contrib/openbsm/bsm/audit_filter.h
index 8a548f7..b751ba8 100644
--- a/contrib/openbsm/bsm/audit_filter.h
+++ b/contrib/openbsm/bsm/audit_filter.h
@@ -24,8 +24,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bsm/audit_filter.h#4 $
*/
#ifndef _BSM_AUDIT_FILTER_H_
diff --git a/contrib/openbsm/bsm/audit_uevents.h b/contrib/openbsm/bsm/audit_uevents.h
index f71797b..d9dacde 100644
--- a/contrib/openbsm/bsm/audit_uevents.h
+++ b/contrib/openbsm/bsm/audit_uevents.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bsm/audit_uevents.h#11 $
*/
#ifndef _BSM_AUDIT_UEVENTS_H_
diff --git a/contrib/openbsm/bsm/auditd_lib.h b/contrib/openbsm/bsm/auditd_lib.h
index fb3ca36..926ca03 100644
--- a/contrib/openbsm/bsm/auditd_lib.h
+++ b/contrib/openbsm/bsm/auditd_lib.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bsm/auditd_lib.h#5 $
*/
#ifndef _BSM_AUDITD_LIB_H_
diff --git a/contrib/openbsm/bsm/libbsm.h b/contrib/openbsm/bsm/libbsm.h
index 5e92583..efaf850 100644
--- a/contrib/openbsm/bsm/libbsm.h
+++ b/contrib/openbsm/bsm/libbsm.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/bsm/libbsm.h#50 $
*/
#ifndef _LIBBSM_H_
diff --git a/contrib/openbsm/compat/clock_gettime.h b/contrib/openbsm/compat/clock_gettime.h
index ad9315f..7492b16 100644
--- a/contrib/openbsm/compat/clock_gettime.h
+++ b/contrib/openbsm/compat/clock_gettime.h
@@ -22,8 +22,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/compat/clock_gettime.h#3 $
*/
/*
diff --git a/contrib/openbsm/compat/closefrom.h b/contrib/openbsm/compat/closefrom.h
index b0545f3..fdfcfcf 100644
--- a/contrib/openbsm/compat/closefrom.h
+++ b/contrib/openbsm/compat/closefrom.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/compat/closefrom.h#1 $
*/
#ifndef _CLOSEFROM_H_
diff --git a/contrib/openbsm/compat/compat.h b/contrib/openbsm/compat/compat.h
index 5cd7446..e3c4d35 100644
--- a/contrib/openbsm/compat/compat.h
+++ b/contrib/openbsm/compat/compat.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/compat/compat.h#1 $
*/
#ifndef _COMPAT_H_
diff --git a/contrib/openbsm/compat/endian.h b/contrib/openbsm/compat/endian.h
index d01c7d4..b4961d5 100644
--- a/contrib/openbsm/compat/endian.h
+++ b/contrib/openbsm/compat/endian.h
@@ -25,7 +25,6 @@
* SUCH DAMAGE.
*
* Derived from FreeBSD src/sys/sys/endian.h:1.6.
- * $P4: //depot/projects/trustedbsd/openbsm/compat/endian.h#10 $
*/
#ifndef _COMPAT_ENDIAN_H_
diff --git a/contrib/openbsm/compat/endian_enc.h b/contrib/openbsm/compat/endian_enc.h
index 9e671b7..c131e43 100644
--- a/contrib/openbsm/compat/endian_enc.h
+++ b/contrib/openbsm/compat/endian_enc.h
@@ -25,7 +25,6 @@
* SUCH DAMAGE.
*
* Derived from FreeBSD src/sys/sys/endian.h:1.6.
- * $P4: //depot/projects/trustedbsd/openbsm/compat/endian_enc.h#1 $
*/
#ifndef _COMPAT_ENDIAN_ENC_H_
diff --git a/contrib/openbsm/compat/flopen.h b/contrib/openbsm/compat/flopen.h
index c68f4a2..7871b13 100644
--- a/contrib/openbsm/compat/flopen.h
+++ b/contrib/openbsm/compat/flopen.h
@@ -25,7 +25,6 @@
* SUCH DAMAGE.
*
* Derived from FreeBSD head/lib/libutil/flopen.c r193591
- * $P4: //depot/projects/trustedbsd/openbsm/compat/flopen.h#1 $
*/
#include <sys/file.h>
diff --git a/contrib/openbsm/compat/pidfile.h b/contrib/openbsm/compat/pidfile.h
index c3a259b..5286b69 100644
--- a/contrib/openbsm/compat/pidfile.h
+++ b/contrib/openbsm/compat/pidfile.h
@@ -24,7 +24,6 @@
* SUCH DAMAGE.
*
* Derived from FreeBSD head/lib/libutil/pidfile.c r231938
- * $P4: //depot/projects/trustedbsd/openbsm/compat/pidfile.h#1 $
*/
#include <sys/param.h>
diff --git a/contrib/openbsm/compat/queue.h b/contrib/openbsm/compat/queue.h
index a73a1f7..4236e62 100644
--- a/contrib/openbsm/compat/queue.h
+++ b/contrib/openbsm/compat/queue.h
@@ -29,7 +29,6 @@
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*
* Derived from FreeBSD src/sys/sys/queue.h:1.63.
- * $P4: //depot/projects/trustedbsd/openbsm/compat/queue.h#3 $
*/
#ifndef _COMPAT_QUEUE_H_
diff --git a/contrib/openbsm/compat/strlcat.h b/contrib/openbsm/compat/strlcat.h
index f10109b..70a851c 100644
--- a/contrib/openbsm/compat/strlcat.h
+++ b/contrib/openbsm/compat/strlcat.h
@@ -25,7 +25,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* dollar OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp dollar
- * $P4: //depot/projects/trustedbsd/openbsm/compat/strlcat.h#3 $
*/
/*
diff --git a/contrib/openbsm/compat/strlcpy.h b/contrib/openbsm/compat/strlcpy.h
index 2f6455d..1d206b6 100644
--- a/contrib/openbsm/compat/strlcpy.h
+++ b/contrib/openbsm/compat/strlcpy.h
@@ -25,7 +25,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* dollar OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp dollar
- * $P4: //depot/projects/trustedbsd/openbsm/compat/strlcpy.h#1 $
*/
/*
diff --git a/contrib/openbsm/config/config.h b/contrib/openbsm/config/config.h
index f900b3f..807ad4d 100644
--- a/contrib/openbsm/config/config.h
+++ b/contrib/openbsm/config/config.h
@@ -229,13 +229,13 @@
#define PACKAGE "OpenBSM"
/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT "trustedbsd-audit@TrustesdBSD.org"
+#define PACKAGE_BUGREPORT "trustedbsd-audit@TrustedBSD.org"
/* Define to the full name of this package. */
#define PACKAGE_NAME "OpenBSM"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "OpenBSM 1.2-alpha3"
+#define PACKAGE_STRING "OpenBSM 1.2-alpha4"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "openbsm"
@@ -244,7 +244,7 @@
#define PACKAGE_URL ""
/* Define to the version of this package. */
-#define PACKAGE_VERSION "1.2-alpha3"
+#define PACKAGE_VERSION "1.2-alpha4"
/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
@@ -280,7 +280,7 @@
#define USE_SYS_ENDIAN_H /**/
/* Version number of package */
-#define VERSION "1.2-alpha3"
+#define VERSION "1.2-alpha4"
/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
`char[]'. */
diff --git a/contrib/openbsm/configure b/contrib/openbsm/configure
index 197a9be..14ae320 100755
--- a/contrib/openbsm/configure
+++ b/contrib/openbsm/configure
@@ -1,9 +1,8 @@
#! /bin/sh
-# From configure.ac P4: //depot/projects/trustedbsd/openbsm/configure.ac#65 .
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for OpenBSM 1.2-alpha3.
+# Generated by GNU Autoconf 2.69 for OpenBSM 1.2-alpha4.
#
-# Report bugs to <trustedbsd-audit@TrustesdBSD.org>.
+# Report bugs to <trustedbsd-audit@TrustedBSD.org>.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -276,7 +275,7 @@ fi
$as_echo "$0: be upgraded to zsh 4.3.4 or later."
else
$as_echo "$0: Please tell bug-autoconf@gnu.org and
-$0: trustedbsd-audit@TrustesdBSD.org about your system,
+$0: trustedbsd-audit@TrustedBSD.org about your system,
$0: including any error possibly output before this
$0: message. Then install a modern shell, or manually run
$0: the script under such a shell if you do have one."
@@ -591,9 +590,9 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='OpenBSM'
PACKAGE_TARNAME='openbsm'
-PACKAGE_VERSION='1.2-alpha3'
-PACKAGE_STRING='OpenBSM 1.2-alpha3'
-PACKAGE_BUGREPORT='trustedbsd-audit@TrustesdBSD.org'
+PACKAGE_VERSION='1.2-alpha4'
+PACKAGE_STRING='OpenBSM 1.2-alpha4'
+PACKAGE_BUGREPORT='trustedbsd-audit@TrustedBSD.org'
PACKAGE_URL=''
ac_unique_file="bin/auditreduce/auditreduce.c"
@@ -1327,7 +1326,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures OpenBSM 1.2-alpha3 to adapt to many kinds of systems.
+\`configure' configures OpenBSM 1.2-alpha4 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1397,7 +1396,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of OpenBSM 1.2-alpha3:";;
+ short | recursive ) echo "Configuration of OpenBSM 1.2-alpha4:";;
esac
cat <<\_ACEOF
@@ -1448,7 +1447,7 @@ Some influential environment variables:
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
-Report bugs to <trustedbsd-audit@TrustesdBSD.org>.
+Report bugs to <trustedbsd-audit@TrustedBSD.org>.
_ACEOF
ac_status=$?
fi
@@ -1511,7 +1510,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-OpenBSM configure 1.2-alpha3
+OpenBSM configure 1.2-alpha4
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1856,9 +1855,9 @@ $as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
-( $as_echo "## ----------------------------------------------- ##
-## Report this to trustedbsd-audit@TrustesdBSD.org ##
-## ----------------------------------------------- ##"
+( $as_echo "## ---------------------------------------------- ##
+## Report this to trustedbsd-audit@TrustedBSD.org ##
+## ---------------------------------------------- ##"
) | sed "s/^/$as_me: WARNING: /" >&2
;;
esac
@@ -1991,7 +1990,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by OpenBSM $as_me 1.2-alpha3, which was
+It was created by OpenBSM $as_me 1.2-alpha4, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -2344,7 +2343,6 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
ac_aux_dir=
for ac_dir in config "$srcdir"/config; do
if test -f "$ac_dir/install-sh"; then
@@ -11132,6 +11130,17 @@ CC="$lt_save_CC"
# Only expand once:
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5
+$as_echo_n "checking whether ln -s works... " >&6; }
+LN_S=$as_ln_s
+if test "$LN_S" = "ln -s"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5
+$as_echo "no, using $LN_S" >&6; }
+fi
+
for ac_prog in 'bison -y' byacc
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
@@ -11552,7 +11561,7 @@ fi
# Define the identity of the package.
PACKAGE=OpenBSM
- VERSION=1.2-alpha3
+ VERSION=1.2-alpha4
cat >>confdefs.h <<_ACEOF
@@ -14174,7 +14183,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by OpenBSM $as_me 1.2-alpha3, which was
+This file was extended by OpenBSM $as_me 1.2-alpha4, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -14234,13 +14243,13 @@ $config_headers
Configuration commands:
$config_commands
-Report bugs to <trustedbsd-audit@TrustesdBSD.org>."
+Report bugs to <trustedbsd-audit@TrustedBSD.org>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-OpenBSM config.status 1.2-alpha3
+OpenBSM config.status 1.2-alpha4
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
diff --git a/contrib/openbsm/configure.ac b/contrib/openbsm/configure.ac
index d176487..19762e4 100644
--- a/contrib/openbsm/configure.ac
+++ b/contrib/openbsm/configure.ac
@@ -2,8 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([OpenBSM], [1.2-alpha3], [trustedbsd-audit@TrustesdBSD.org],[openbsm])
-AC_REVISION([$P4: //depot/projects/trustedbsd/openbsm/configure.ac#66 $])
+AC_INIT([OpenBSM], [1.2-alpha4], [trustedbsd-audit@TrustedBSD.org],[openbsm])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([bin/auditreduce/auditreduce.c])
AC_CONFIG_AUX_DIR(config)
@@ -29,6 +28,7 @@ AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LEX
AC_PROG_LIBTOOL
+AC_PROG_LN_S
AC_PROG_YACC
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
diff --git a/contrib/openbsm/etc/audit_class b/contrib/openbsm/etc/audit_class
index 9e020ebb..47868b1 100644
--- a/contrib/openbsm/etc/audit_class
+++ b/contrib/openbsm/etc/audit_class
@@ -1,5 +1,4 @@
#
-# $P4: //depot/projects/trustedbsd/openbsm/etc/audit_class#6 $
# $FreeBSD$
#
0x00000000:no:invalid class
diff --git a/contrib/openbsm/etc/audit_control b/contrib/openbsm/etc/audit_control
index 1081708..d71b9a8 100644
--- a/contrib/openbsm/etc/audit_control
+++ b/contrib/openbsm/etc/audit_control
@@ -1,5 +1,4 @@
#
-# $P4: //depot/projects/trustedbsd/openbsm/etc/audit_control#9 $
# $FreeBSD$
#
dir:/var/audit
diff --git a/contrib/openbsm/etc/audit_event b/contrib/openbsm/etc/audit_event
index b4596b0..b7d4cba 100644
--- a/contrib/openbsm/etc/audit_event
+++ b/contrib/openbsm/etc/audit_event
@@ -1,5 +1,4 @@
#
-# $P4: //depot/projects/trustedbsd/openbsm/etc/audit_event#43 $
# $FreeBSD$
#
# The mapping between event identifiers and values is also hard-coded in
diff --git a/contrib/openbsm/etc/audit_filter b/contrib/openbsm/etc/audit_filter
index 64f5c0e0..d0dc1c0 100644
--- a/contrib/openbsm/etc/audit_filter
+++ b/contrib/openbsm/etc/audit_filter
@@ -1,5 +1,5 @@
#
-# $P4: //depot/projects/trustedbsd/openbsm/etc/audit_filter#1 $
+# $FreeBSD$
#
# modulename:various arguments here
#
diff --git a/contrib/openbsm/etc/audit_user b/contrib/openbsm/etc/audit_user
index 0cce4f1..0350662 100644
--- a/contrib/openbsm/etc/audit_user
+++ b/contrib/openbsm/etc/audit_user
@@ -1,5 +1,4 @@
#
-# $P4: //depot/projects/trustedbsd/openbsm/etc/audit_user#3 $
# $FreeBSD$
#
root:lo:no
diff --git a/contrib/openbsm/etc/audit_warn b/contrib/openbsm/etc/audit_warn
index c5a3159..4b8498e 100644
--- a/contrib/openbsm/etc/audit_warn
+++ b/contrib/openbsm/etc/audit_warn
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $P4: //depot/projects/trustedbsd/openbsm/etc/audit_warn#3 $
# $FreeBSD$
#
+
logger -p security.warning "audit warning: $@"
diff --git a/contrib/openbsm/libauditd/Makefile.am b/contrib/openbsm/libauditd/Makefile.am
index 3a4e7ab..c6e09aa 100644
--- a/contrib/openbsm/libauditd/Makefile.am
+++ b/contrib/openbsm/libauditd/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/libauditd/Makefile.am#3 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/libauditd/auditd_lib.c b/contrib/openbsm/libauditd/auditd_lib.c
index 3c03348..6079df0 100644
--- a/contrib/openbsm/libauditd/auditd_lib.c
+++ b/contrib/openbsm/libauditd/auditd_lib.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libauditd/auditd_lib.c#18 $
*/
#include <sys/param.h>
@@ -402,12 +400,13 @@ trailname_to_tstamp(char *fn, time_t *tstamp)
* ADE_NOERR on success or there is nothing to do.
* ADE_PARSE if error parsing audit_control(5).
* ADE_NOMEM if could not allocate memory.
- * ADE_EXPIRE if there was an unespected error.
+ * ADE_READLINK if could not read link file.
+ * ADE_EXPIRE if there was an unexpected error.
*/
int
auditd_expire_trails(int (*warn_expired)(char *))
{
- int andflg, ret = ADE_NOERR;
+ int andflg, len, ret = ADE_NOERR;
size_t expire_size, total_size = 0L;
time_t expire_age, oldest_time, current_time = time(NULL);
struct dir_ent *traildir;
@@ -431,7 +430,9 @@ auditd_expire_trails(int (*warn_expired)(char *))
* Read the 'current' trail file name. Trim off directory path.
*/
activefn[0] = '\0';
- readlink(AUDIT_CURRENT_LINK, activefn, MAXPATHLEN - 1);
+ len = readlink(AUDIT_CURRENT_LINK, activefn, MAXPATHLEN - 1);
+ if (len < 0)
+ return (ADE_READLINK);
if ((afnp = strrchr(activefn, '/')) != NULL)
afnp++;
diff --git a/contrib/openbsm/libauditd/libauditd.3 b/contrib/openbsm/libauditd/libauditd.3
index 0fece29..06c5246 100644
--- a/contrib/openbsm/libauditd/libauditd.3
+++ b/contrib/openbsm/libauditd/libauditd.3
@@ -26,8 +26,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libauditd/libauditd.3#1 $
-.\"
.Dd December 27, 2008
.Dt LIBAUDITD 3
.Os
@@ -45,7 +43,7 @@ library provides the internal implementation of
There are no public interfaces in
.Nm .
.Sh SEE ALSO
-.Xr auditd 8 .
+.Xr auditd 8
.Sh HISTORY
The OpenBSM implementation was created by McAfee Research, the security
division of McAfee Inc., under contract to Apple Computer, Inc., in 2004.
diff --git a/contrib/openbsm/libbsm/Makefile.am b/contrib/openbsm/libbsm/Makefile.am
index bfad93b..278f228 100644
--- a/contrib/openbsm/libbsm/Makefile.am
+++ b/contrib/openbsm/libbsm/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/libbsm/Makefile.am#10 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
@@ -41,9 +37,121 @@ man3_MANS = \
au_free_token.3 \
au_io.3 \
au_mask.3 \
+ au_notify.3 \
au_open.3 \
au_socket_type.3 \
au_token.3 \
au_user.3 \
libbsm.3
+install-exec-hook:
+ cd $(DESTDIR)$(mandir) && \
+ $(LN_S) -f au_class.3 getauclassent.3 && \
+ $(LN_S) -f au_class.3 getauclassent_r.3 && \
+ $(LN_S) -f au_class.3 getauclassnam.3 && \
+ $(LN_S) -f au_class.3 getauclassnam_r.3 && \
+ $(LN_S) -f au_class.3 setauclass.3 && \
+ $(LN_S) -f au_class.3 endauclass.3 && \
+ $(LN_S) -f au_control.3 setac.3 && \
+ $(LN_S) -f au_control.3 endac.3 && \
+ $(LN_S) -f au_control.3 getacdir.3 && \
+ $(LN_S) -f au_control.3 getacdist.3 && \
+ $(LN_S) -f au_control.3 getacexpire.3 && \
+ $(LN_S) -f au_control.3 getacfilesz.3 && \
+ $(LN_S) -f au_control.3 getacflg.3 && \
+ $(LN_S) -f au_control.3 getachost.3 && \
+ $(LN_S) -f au_control.3 getacmin.3 && \
+ $(LN_S) -f au_control.3 getacna.3 && \
+ $(LN_S) -f au_control.3 getacpol.3 && \
+ $(LN_S) -f au_control.3 au_poltostr.3 && \
+ $(LN_S) -f au_control.3 ac_strtopol.3 && \
+ $(LN_S) -f au_domain.3 au_bsm_to_domain.3 && \
+ $(LN_S) -f au_domain.3 au_domain_to_bsm.3 && \
+ $(LN_S) -f au_errno.3 au_bsm_to_errno.3 && \
+ $(LN_S) -f au_errno.3 au_errno_to_bsm.3 && \
+ $(LN_S) -f au_errno.3 au_strerror.3 && \
+ $(LN_S) -f au_event.3 setauevent.3 && \
+ $(LN_S) -f au_event.3 endauevent.3 && \
+ $(LN_S) -f au_event.3 getauevent.3 && \
+ $(LN_S) -f au_event.3 getauevent_r.3 && \
+ $(LN_S) -f au_event.3 getauevnam.3 && \
+ $(LN_S) -f au_event.3 getauevnam_r.3 && \
+ $(LN_S) -f au_event.3 getauevnum.3 && \
+ $(LN_S) -f au_event.3 getauevnum_r.3 && \
+ $(LN_S) -f au_event.3 getauevnonam.3 && \
+ $(LN_S) -f au_event.3 getauevnonam_r.3 && \
+ $(LN_S) -f au_fcntl.3 au_bsm_to_fcntl_cmd.3 && \
+ $(LN_S) -f au_fcntl.3 au_fcntl_cmd_to_bsm.3 && \
+ $(LN_S) -f au_io.3 au_fetch_tok.3 && \
+ $(LN_S) -f au_io.3 au_print_tok.3 && \
+ $(LN_S) -f au_io.3 au_print_flags_tok.3 && \
+ $(LN_S) -f au_io.3 au_read_rec.3 && \
+ $(LN_S) -f au_mask.3 au_preselect.3 && \
+ $(LN_S) -f au_mask.3 getauditflagsbin.3 && \
+ $(LN_S) -f au_mask.3 getauditflagschar.3 && \
+ $(LN_S) -f au_notify.3 au_get_state.3 && \
+ $(LN_S) -f au_notify.3 au_notify_initialize.3 && \
+ $(LN_S) -f au_notify.3 au_notify_terminate.3 && \
+ $(LN_S) -f au_open.3 au_open.3 && \
+ $(LN_S) -f au_open.3 au_write.3 && \
+ $(LN_S) -f au_open.3 au_close.3 && \
+ $(LN_S) -f au_open.3 au_close_buffer.3 && \
+ $(LN_S) -f au_open.3 au_close_token.3 && \
+ $(LN_S) -f au_socket_type.3 au_bsm_to_socket_type.3 && \
+ $(LN_S) -f au_socket_type.3 au_socket_type_to_bsm.3 && \
+ $(LN_S) -f au_token.3 au_to_arg32.3 && \
+ $(LN_S) -f au_token.3 au_to_arg64.3 && \
+ $(LN_S) -f au_token.3 au_to_arg.3 && \
+ $(LN_S) -f au_token.3 au_to_attr64.3 && \
+ $(LN_S) -f au_token.3 au_to_data.3 && \
+ $(LN_S) -f au_token.3 au_to_exit.3 && \
+ $(LN_S) -f au_token.3 au_to_groups.3 && \
+ $(LN_S) -f au_token.3 au_to_newgroups.3 && \
+ $(LN_S) -f au_token.3 au_to_in_addr.3 && \
+ $(LN_S) -f au_token.3 au_to_in_addr_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_ip.3 && \
+ $(LN_S) -f au_token.3 au_to_ipc.3 && \
+ $(LN_S) -f au_token.3 au_to_ipc_perm.3 && \
+ $(LN_S) -f au_token.3 au_to_iport.3 && \
+ $(LN_S) -f au_token.3 au_to_opaque.3 && \
+ $(LN_S) -f au_token.3 au_to_file.3 && \
+ $(LN_S) -f au_token.3 au_to_text.3 && \
+ $(LN_S) -f au_token.3 au_to_path.3 && \
+ $(LN_S) -f au_token.3 au_to_process32.3 && \
+ $(LN_S) -f au_token.3 au_to_process64.3 && \
+ $(LN_S) -f au_token.3 au_to_process.3 && \
+ $(LN_S) -f au_token.3 au_to_process32_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_process64_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_process_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_return32.3 && \
+ $(LN_S) -f au_token.3 au_to_return64.3 && \
+ $(LN_S) -f au_token.3 au_to_return.3 && \
+ $(LN_S) -f au_token.3 au_to_seq.3 && \
+ $(LN_S) -f au_token.3 au_to_sock_inet32.3 && \
+ $(LN_S) -f au_token.3 au_to_sock_inet128.3 && \
+ $(LN_S) -f au_token.3 au_to_sock_inet.3 && \
+ $(LN_S) -f au_token.3 au_to_socket_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_subject32.3 && \
+ $(LN_S) -f au_token.3 au_to_subject64.3 && \
+ $(LN_S) -f au_token.3 au_to_subject.3 && \
+ $(LN_S) -f au_token.3 au_to_subject32_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_subject64_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_subject_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_me.3 && \
+ $(LN_S) -f au_token.3 au_to_exec_args.3 && \
+ $(LN_S) -f au_token.3 au_to_exec_env.3 && \
+ $(LN_S) -f au_token.3 au_to_header.3 && \
+ $(LN_S) -f au_token.3 au_to_header32.3 && \
+ $(LN_S) -f au_token.3 au_to_header64.3 && \
+ $(LN_S) -f au_token.3 au_to_header_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_header32_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_trailer.3 && \
+ $(LN_S) -f au_token.3 au_to_zonename.3 && \
+ $(LN_S) -f au_user.3 setauuser.3 && \
+ $(LN_S) -f au_user.3 endauuser.3 && \
+ $(LN_S) -f au_user.3 getauuserent.3 && \
+ $(LN_S) -f au_user.3 getauuserent_r.3 && \
+ $(LN_S) -f au_user.3 getauusernam.3 && \
+ $(LN_S) -f au_user.3 getauusernam_r.3 && \
+ $(LN_S) -f au_user.3 au_user_mask.3 && \
+ $(LN_S) -f au_user.3 getfauditflags.3
diff --git a/contrib/openbsm/libbsm/Makefile.in b/contrib/openbsm/libbsm/Makefile.in
index 956d66f..0549153 100644
--- a/contrib/openbsm/libbsm/Makefile.in
+++ b/contrib/openbsm/libbsm/Makefile.in
@@ -269,6 +269,7 @@ man3_MANS = \
au_free_token.3 \
au_io.3 \
au_mask.3 \
+ au_notify.3 \
au_open.3 \
au_socket_type.3 \
au_token.3 \
@@ -612,7 +613,8 @@ install-dvi: install-dvi-am
install-dvi-am:
install-exec-am: install-libLTLIBRARIES
-
+ @$(NORMAL_INSTALL)
+ $(MAKE) $(AM_MAKEFLAGS) install-exec-hook
install-html: install-html-am
install-html-am:
@@ -655,15 +657,15 @@ uninstall-am: uninstall-libLTLIBRARIES uninstall-man
uninstall-man: uninstall-man3
-.MAKE: install-am install-strip
+.MAKE: install-am install-exec-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libLTLIBRARIES clean-libtool cscopelist ctags distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
- install-dvi-am install-exec install-exec-am install-html \
- install-html-am install-info install-info-am \
+ install-dvi-am install-exec install-exec-am install-exec-hook \
+ install-html install-html-am install-info install-info-am \
install-libLTLIBRARIES install-man install-man3 install-pdf \
install-pdf-am install-ps install-ps-am install-strip \
installcheck installcheck-am installdirs maintainer-clean \
@@ -673,6 +675,118 @@ uninstall-man: uninstall-man3
uninstall-man uninstall-man3
+install-exec-hook:
+ cd $(DESTDIR)$(mandir) && \
+ $(LN_S) -f au_class.3 getauclassent.3 && \
+ $(LN_S) -f au_class.3 getauclassent_r.3 && \
+ $(LN_S) -f au_class.3 getauclassnam.3 && \
+ $(LN_S) -f au_class.3 getauclassnam_r.3 && \
+ $(LN_S) -f au_class.3 setauclass.3 && \
+ $(LN_S) -f au_class.3 endauclass.3 && \
+ $(LN_S) -f au_control.3 setac.3 && \
+ $(LN_S) -f au_control.3 endac.3 && \
+ $(LN_S) -f au_control.3 getacdir.3 && \
+ $(LN_S) -f au_control.3 getacdist.3 && \
+ $(LN_S) -f au_control.3 getacexpire.3 && \
+ $(LN_S) -f au_control.3 getacfilesz.3 && \
+ $(LN_S) -f au_control.3 getacflg.3 && \
+ $(LN_S) -f au_control.3 getachost.3 && \
+ $(LN_S) -f au_control.3 getacmin.3 && \
+ $(LN_S) -f au_control.3 getacna.3 && \
+ $(LN_S) -f au_control.3 getacpol.3 && \
+ $(LN_S) -f au_control.3 au_poltostr.3 && \
+ $(LN_S) -f au_control.3 ac_strtopol.3 && \
+ $(LN_S) -f au_domain.3 au_bsm_to_domain.3 && \
+ $(LN_S) -f au_domain.3 au_domain_to_bsm.3 && \
+ $(LN_S) -f au_errno.3 au_bsm_to_errno.3 && \
+ $(LN_S) -f au_errno.3 au_errno_to_bsm.3 && \
+ $(LN_S) -f au_errno.3 au_strerror.3 && \
+ $(LN_S) -f au_event.3 setauevent.3 && \
+ $(LN_S) -f au_event.3 endauevent.3 && \
+ $(LN_S) -f au_event.3 getauevent.3 && \
+ $(LN_S) -f au_event.3 getauevent_r.3 && \
+ $(LN_S) -f au_event.3 getauevnam.3 && \
+ $(LN_S) -f au_event.3 getauevnam_r.3 && \
+ $(LN_S) -f au_event.3 getauevnum.3 && \
+ $(LN_S) -f au_event.3 getauevnum_r.3 && \
+ $(LN_S) -f au_event.3 getauevnonam.3 && \
+ $(LN_S) -f au_event.3 getauevnonam_r.3 && \
+ $(LN_S) -f au_fcntl.3 au_bsm_to_fcntl_cmd.3 && \
+ $(LN_S) -f au_fcntl.3 au_fcntl_cmd_to_bsm.3 && \
+ $(LN_S) -f au_io.3 au_fetch_tok.3 && \
+ $(LN_S) -f au_io.3 au_print_tok.3 && \
+ $(LN_S) -f au_io.3 au_print_flags_tok.3 && \
+ $(LN_S) -f au_io.3 au_read_rec.3 && \
+ $(LN_S) -f au_mask.3 au_preselect.3 && \
+ $(LN_S) -f au_mask.3 getauditflagsbin.3 && \
+ $(LN_S) -f au_mask.3 getauditflagschar.3 && \
+ $(LN_S) -f au_notify.3 au_get_state.3 && \
+ $(LN_S) -f au_notify.3 au_notify_initialize.3 && \
+ $(LN_S) -f au_notify.3 au_notify_terminate.3 && \
+ $(LN_S) -f au_open.3 au_open.3 && \
+ $(LN_S) -f au_open.3 au_write.3 && \
+ $(LN_S) -f au_open.3 au_close.3 && \
+ $(LN_S) -f au_open.3 au_close_buffer.3 && \
+ $(LN_S) -f au_open.3 au_close_token.3 && \
+ $(LN_S) -f au_socket_type.3 au_bsm_to_socket_type.3 && \
+ $(LN_S) -f au_socket_type.3 au_socket_type_to_bsm.3 && \
+ $(LN_S) -f au_token.3 au_to_arg32.3 && \
+ $(LN_S) -f au_token.3 au_to_arg64.3 && \
+ $(LN_S) -f au_token.3 au_to_arg.3 && \
+ $(LN_S) -f au_token.3 au_to_attr64.3 && \
+ $(LN_S) -f au_token.3 au_to_data.3 && \
+ $(LN_S) -f au_token.3 au_to_exit.3 && \
+ $(LN_S) -f au_token.3 au_to_groups.3 && \
+ $(LN_S) -f au_token.3 au_to_newgroups.3 && \
+ $(LN_S) -f au_token.3 au_to_in_addr.3 && \
+ $(LN_S) -f au_token.3 au_to_in_addr_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_ip.3 && \
+ $(LN_S) -f au_token.3 au_to_ipc.3 && \
+ $(LN_S) -f au_token.3 au_to_ipc_perm.3 && \
+ $(LN_S) -f au_token.3 au_to_iport.3 && \
+ $(LN_S) -f au_token.3 au_to_opaque.3 && \
+ $(LN_S) -f au_token.3 au_to_file.3 && \
+ $(LN_S) -f au_token.3 au_to_text.3 && \
+ $(LN_S) -f au_token.3 au_to_path.3 && \
+ $(LN_S) -f au_token.3 au_to_process32.3 && \
+ $(LN_S) -f au_token.3 au_to_process64.3 && \
+ $(LN_S) -f au_token.3 au_to_process.3 && \
+ $(LN_S) -f au_token.3 au_to_process32_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_process64_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_process_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_return32.3 && \
+ $(LN_S) -f au_token.3 au_to_return64.3 && \
+ $(LN_S) -f au_token.3 au_to_return.3 && \
+ $(LN_S) -f au_token.3 au_to_seq.3 && \
+ $(LN_S) -f au_token.3 au_to_sock_inet32.3 && \
+ $(LN_S) -f au_token.3 au_to_sock_inet128.3 && \
+ $(LN_S) -f au_token.3 au_to_sock_inet.3 && \
+ $(LN_S) -f au_token.3 au_to_socket_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_subject32.3 && \
+ $(LN_S) -f au_token.3 au_to_subject64.3 && \
+ $(LN_S) -f au_token.3 au_to_subject.3 && \
+ $(LN_S) -f au_token.3 au_to_subject32_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_subject64_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_subject_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_me.3 && \
+ $(LN_S) -f au_token.3 au_to_exec_args.3 && \
+ $(LN_S) -f au_token.3 au_to_exec_env.3 && \
+ $(LN_S) -f au_token.3 au_to_header.3 && \
+ $(LN_S) -f au_token.3 au_to_header32.3 && \
+ $(LN_S) -f au_token.3 au_to_header64.3 && \
+ $(LN_S) -f au_token.3 au_to_header_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_header32_ex.3 && \
+ $(LN_S) -f au_token.3 au_to_trailer.3 && \
+ $(LN_S) -f au_token.3 au_to_zonename.3 && \
+ $(LN_S) -f au_user.3 setauuser.3 && \
+ $(LN_S) -f au_user.3 endauuser.3 && \
+ $(LN_S) -f au_user.3 getauuserent.3 && \
+ $(LN_S) -f au_user.3 getauuserent_r.3 && \
+ $(LN_S) -f au_user.3 getauusernam.3 && \
+ $(LN_S) -f au_user.3 getauusernam_r.3 && \
+ $(LN_S) -f au_user.3 au_user_mask.3 && \
+ $(LN_S) -f au_user.3 getfauditflags.3
+
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
diff --git a/contrib/openbsm/libbsm/au_class.3 b/contrib/openbsm/libbsm/au_class.3
index a3f200f..acdac62 100644
--- a/contrib/openbsm/libbsm/au_class.3
+++ b/contrib/openbsm/libbsm/au_class.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_class.3#7 $
-.\"
.Dd April 19, 2005
.Dt AU_CLASS 3
.Os
diff --git a/contrib/openbsm/libbsm/au_control.3 b/contrib/openbsm/libbsm/au_control.3
index 622fae2..d4d4450 100644
--- a/contrib/openbsm/libbsm/au_control.3
+++ b/contrib/openbsm/libbsm/au_control.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_control.3#17 $
-.\"
.Dd April 19, 2005
.Dt AU_CONTROL 3
.Os
@@ -56,7 +54,7 @@
.Ft int
.Fn getacdist "void"
.Ft int
-.Fn getacexpire "int *andflg, time_t *age, size_t *size"
+.Fn getacexpire "int *andflg" "time_t *age" "size_t *size"
.Ft int
.Fn getacfilesz "size_t *size_val"
.Ft int
diff --git a/contrib/openbsm/libbsm/au_domain.3 b/contrib/openbsm/libbsm/au_domain.3
index 6d57d2b..2f16b38 100644
--- a/contrib/openbsm/libbsm/au_domain.3
+++ b/contrib/openbsm/libbsm/au_domain.3
@@ -26,8 +26,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_domain.3#2 $
-.\"
.Dd December 28, 2008
.Dt AU_BSM_TO_DOMAIN 3
.Os
diff --git a/contrib/openbsm/libbsm/au_errno.3 b/contrib/openbsm/libbsm/au_errno.3
index 3680a4e..93873ce 100644
--- a/contrib/openbsm/libbsm/au_errno.3
+++ b/contrib/openbsm/libbsm/au_errno.3
@@ -26,8 +26,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_errno.3#4 $
-.\"
.Dd December 8, 2008
.Dt AU_BSM_TO_ERRNO 3
.Os
@@ -54,7 +52,7 @@ and BSM error number spaces found in BSM return tokens.
The
.Fn au_bsm_to_errno
function accepts a BSM error value,
-.Fa bsm_error,
+.Fa bsm_error ,
and converts it to an
.Xr errno 2
that will be stored in the integer pointed to by
diff --git a/contrib/openbsm/libbsm/au_event.3 b/contrib/openbsm/libbsm/au_event.3
index 8fe25b4..781ba1b 100644
--- a/contrib/openbsm/libbsm/au_event.3
+++ b/contrib/openbsm/libbsm/au_event.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_event.3#8 $
-.\"
.Dd April 19, 2005
.Dt AU_EVENT 3
.Os
diff --git a/contrib/openbsm/libbsm/au_fcntl_cmd.3 b/contrib/openbsm/libbsm/au_fcntl_cmd.3
index 7843c94..a87c3ec 100644
--- a/contrib/openbsm/libbsm/au_fcntl_cmd.3
+++ b/contrib/openbsm/libbsm/au_fcntl_cmd.3
@@ -26,8 +26,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_fcntl_cmd.3#2 $
-.\"
.Dd March 5, 2009
.Dt AU_BSM_TO_FCNTL_CMD 3
.Os
@@ -79,8 +77,8 @@ not set
.Sh SEE ALSO
.Xr fcntl 2 ,
.Xr au_bsm_to_domain 3 ,
-.Xr au_domain_to_bsm 3 ,
.Xr au_bsm_to_socket_type 3 ,
+.Xr au_domain_to_bsm 3 ,
.Xr au_socket_type_to_bsm 3 ,
.Xr libbsm 3
.Sh HISTORY
diff --git a/contrib/openbsm/libbsm/au_free_token.3 b/contrib/openbsm/libbsm/au_free_token.3
index 223d50a..8820645 100644
--- a/contrib/openbsm/libbsm/au_free_token.3
+++ b/contrib/openbsm/libbsm/au_free_token.3
@@ -27,8 +27,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_free_token.3#7 $
-.\"
.Dd April 19, 2005
.Dt AU_FREE_TOKEN 3
.Os
@@ -75,8 +73,8 @@ This is, in fact, what
.Xr audit_write 3
does, in keeping with the existing memory management model of the BSM API.
.Sh SEE ALSO
-.Xr audit_write 3 ,
.Xr au_write 3 ,
+.Xr audit_write 3 ,
.Xr libbsm 3
.Sh HISTORY
The OpenBSM implementation was created by McAfee Research, the security
diff --git a/contrib/openbsm/libbsm/au_io.3 b/contrib/openbsm/libbsm/au_io.3
index bd8e5a1..bfea1a8 100644
--- a/contrib/openbsm/libbsm/au_io.3
+++ b/contrib/openbsm/libbsm/au_io.3
@@ -24,8 +24,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_io.3#9 $
-.\"
.Dd August 4, 2009
.Dt AU_IO 3
.Os
diff --git a/contrib/openbsm/libbsm/au_mask.3 b/contrib/openbsm/libbsm/au_mask.3
index 2845279..c2099ea 100644
--- a/contrib/openbsm/libbsm/au_mask.3
+++ b/contrib/openbsm/libbsm/au_mask.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_mask.3#6 $
-.\"
.Dd April 19, 2005
.Dt AU_MASK 3
.Os
diff --git a/contrib/openbsm/libbsm/au_notify.3 b/contrib/openbsm/libbsm/au_notify.3
new file mode 100644
index 0000000..06e63bf
--- /dev/null
+++ b/contrib/openbsm/libbsm/au_notify.3
@@ -0,0 +1,118 @@
+.\"-
+.\" Copyright (c) 2004-2009 Apple Inc.
+.\" Copyright (c) 2015 Christian Brueffer
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. Neither the name of the author nor the names of
+.\" its contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" 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.
+.\"
+.Dd July 29, 2015
+.Dt AU_NOTIFY 3
+.Os
+.Sh NAME
+.Nm au_get_state ,
+.Nm au_notify_initialize ,
+.Nm au_notify_terminate
+.Nd "audit event notification"
+.Sh LIBRARY
+.Lb libbsm
+.Sh SYNOPSIS
+.In bsm/libbsm.h
+.Ft int
+.Fn au_get_state "void"
+.Ft uint32_t
+.Fn au_notify_initialize "void"
+.Ft int
+.Fn au_notify_terminate "void"
+.Sh DESCRIPTION
+The
+.Nm au_notify
+audit notification API tracks audit state in a form permitting efficient
+update, avoiding frequent system calls to check the kernel audit state.
+It is implemented only for Darwin/Mac OS X.
+.Pp
+The
+.Fn au_get_state
+function provides a lightweight way to check whether or not auditing is
+enabled.
+If a client wants to use this function to determine whether an entire
+series of audit calls should be made -- as in the common case of a caller
+building a set of tokens, then writing them -- it should cache the audit
+status in a local variable.
+This function always returns the current state of auditing.
+If audit notification has not already been initialized by calling
+.Fn au_notify_initialize
+it will be automatically initialized on the first call of
+this function.
+.Pp
+The
+.Fn au_notify_initialize
+function initializes audit notification.
+.Pp
+The
+.Fn au_notify_terminate
+function cancels audit notification and frees the resources associated with it.
+Responsible code that no longer needs to use
+.Fn au_get_state
+should call this function.
+.Sh RETURN VALUES
+If no error occurred the
+.Fn au_get_state
+function returns
+.Dv AUC_NOAUDIT
+if auditing is disabled or suspended, and
+.Dv AUC_AUDITING
+if auditing is enabled and active.
+Otherwise, the function can return any of the errno values defined for
+.Xr setaudit 2 ,
+or
+.Dv AU_UNIMPL
+if audit does not appear to be supported by the system.
+.Pp
+The
+.Fn au_notify_initialize
+function returns 0 on success,
+.Dv AU_UNIMPL
+if audit does not appear to be supported by the system,
+or one of the status codes defined in
+.In notify.h
+on Mac OS X to indicate the error.
+.Pp
+The
+.Fn au_notify_terminate
+function returns 0 on success, or \-1 on failure.
+.Sh SEE ALSO
+.Xr libbsm 3 ,
+.Xr notify 3 (Mac OS X)
+.Sh HISTORY
+The OpenBSM implementation was created by McAfee Research, the security
+division of McAfee Inc., under contract to Apple Computer, Inc., in 2004.
+It was subsequently adopted by the TrustedBSD Project as the foundation for
+the OpenBSM distribution.
+.Sh AUTHORS
+This software was created by
+.An Apple Computer, Inc .
+.Pp
+The Basic Security Module (BSM) interface to audit records and audit event
+stream format were defined by Sun Microsystems.
diff --git a/contrib/openbsm/libbsm/au_open.3 b/contrib/openbsm/libbsm/au_open.3
index bbb0eca..522354f 100644
--- a/contrib/openbsm/libbsm/au_open.3
+++ b/contrib/openbsm/libbsm/au_open.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_open.3#8 $
-.\"
.Dd March 4, 2006
.Dt AU_OPEN 3
.Os
diff --git a/contrib/openbsm/libbsm/au_socket_type.3 b/contrib/openbsm/libbsm/au_socket_type.3
index 174e5c7..5668569 100644
--- a/contrib/openbsm/libbsm/au_socket_type.3
+++ b/contrib/openbsm/libbsm/au_socket_type.3
@@ -26,8 +26,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_socket_type.3#1 $
-.\"
.Dd December 28, 2008
.Dt AU_BSM_TO_SOCKET_TYPE 3
.Os
diff --git a/contrib/openbsm/libbsm/au_token.3 b/contrib/openbsm/libbsm/au_token.3
index 2888729..0459242 100644
--- a/contrib/openbsm/libbsm/au_token.3
+++ b/contrib/openbsm/libbsm/au_token.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_token.3#17 $
-.\"
.Dd April 19, 2005
.Dt AU_TOKEN 3
.Os
diff --git a/contrib/openbsm/libbsm/au_user.3 b/contrib/openbsm/libbsm/au_user.3
index 3016f65..d2a4fa1 100644
--- a/contrib/openbsm/libbsm/au_user.3
+++ b/contrib/openbsm/libbsm/au_user.3
@@ -23,8 +23,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_user.3#10 $
-.\"
.Dd April 19, 2005
.Dt AU_USER 3
.Os
diff --git a/contrib/openbsm/libbsm/audit_submit.3 b/contrib/openbsm/libbsm/audit_submit.3
index ab1fc64..c3be666 100644
--- a/contrib/openbsm/libbsm/audit_submit.3
+++ b/contrib/openbsm/libbsm/audit_submit.3
@@ -24,8 +24,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/audit_submit.3#19 $
-.\"
.Dd January 18, 2008
.Dt AUDIT_SUBMIT 3
.Os
diff --git a/contrib/openbsm/libbsm/bsm_audit.c b/contrib/openbsm/libbsm/bsm_audit.c
index 693419f..f7a00c6 100644
--- a/contrib/openbsm/libbsm/bsm_audit.c
+++ b/contrib/openbsm/libbsm/bsm_audit.c
@@ -29,8 +29,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_audit.c#37 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/libbsm/bsm_class.c b/contrib/openbsm/libbsm/bsm_class.c
index 358afbb..8ee193f 100644
--- a/contrib/openbsm/libbsm/bsm_class.c
+++ b/contrib/openbsm/libbsm/bsm_class.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_class.c#16 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/libbsm/bsm_control.c b/contrib/openbsm/libbsm/bsm_control.c
index baaa0a5..94d9420 100644
--- a/contrib/openbsm/libbsm/bsm_control.c
+++ b/contrib/openbsm/libbsm/bsm_control.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#41 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/libbsm/bsm_domain.c b/contrib/openbsm/libbsm/bsm_domain.c
index 2b011f5..f6aeef6 100644
--- a/contrib/openbsm/libbsm/bsm_domain.c
+++ b/contrib/openbsm/libbsm/bsm_domain.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_domain.c#3 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/libbsm/bsm_errno.c b/contrib/openbsm/libbsm/bsm_errno.c
index 8682fc7..b4b22f3 100644
--- a/contrib/openbsm/libbsm/bsm_errno.c
+++ b/contrib/openbsm/libbsm/bsm_errno.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#22 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/libbsm/bsm_event.c b/contrib/openbsm/libbsm/bsm_event.c
index f3c6601..5499083 100644
--- a/contrib/openbsm/libbsm/bsm_event.c
+++ b/contrib/openbsm/libbsm/bsm_event.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_event.c#17 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/libbsm/bsm_fcntl.c b/contrib/openbsm/libbsm/bsm_fcntl.c
index 41b6d0d..45ae5da 100644
--- a/contrib/openbsm/libbsm/bsm_fcntl.c
+++ b/contrib/openbsm/libbsm/bsm_fcntl.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_fcntl.c#2 $
*/
#include <sys/param.h>
diff --git a/contrib/openbsm/libbsm/bsm_flags.c b/contrib/openbsm/libbsm/bsm_flags.c
index c87ae84..46b8a1f 100644
--- a/contrib/openbsm/libbsm/bsm_flags.c
+++ b/contrib/openbsm/libbsm/bsm_flags.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_flags.c#16 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/libbsm/bsm_io.c b/contrib/openbsm/libbsm/bsm_io.c
index 44c3b35..43cf7e9 100644
--- a/contrib/openbsm/libbsm/bsm_io.c
+++ b/contrib/openbsm/libbsm/bsm_io.c
@@ -31,8 +31,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#75 $
*/
#include <sys/types.h>
@@ -268,7 +266,7 @@ print_xml_string(FILE *fp, const char *str, size_t len)
}
/*
- * Prints the beggining of attribute.
+ * Prints the beginning of an attribute.
*/
static void
open_attr(FILE *fp, const char *str)
@@ -278,7 +276,7 @@ open_attr(FILE *fp, const char *str)
}
/*
- * Prints the end of attribute.
+ * Prints the end of an attribute.
*/
static void
close_attr(FILE *fp)
@@ -288,7 +286,7 @@ close_attr(FILE *fp)
}
/*
- * Prints the end of tag.
+ * Prints the end of a tag.
*/
static void
close_tag(FILE *fp, u_char type)
@@ -596,6 +594,7 @@ print_tok_type(FILE *fp, u_char type, const char *tokname, int oflags)
case AUT_SOCKINET128:
fprintf(fp, "<socket-inet6 ");
+ break;
case AUT_SUBJECT32:
fprintf(fp, "<subject ");
diff --git a/contrib/openbsm/libbsm/bsm_mask.c b/contrib/openbsm/libbsm/bsm_mask.c
index afbed5e..42e4e71 100644
--- a/contrib/openbsm/libbsm/bsm_mask.c
+++ b/contrib/openbsm/libbsm/bsm_mask.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_mask.c#15 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/libbsm/bsm_notify.c b/contrib/openbsm/libbsm/bsm_notify.c
index df972aa..a2dda74 100644
--- a/contrib/openbsm/libbsm/bsm_notify.c
+++ b/contrib/openbsm/libbsm/bsm_notify.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_notify.c#17 $
*/
/*
diff --git a/contrib/openbsm/libbsm/bsm_socket_type.c b/contrib/openbsm/libbsm/bsm_socket_type.c
index a10b609..ffbe39e 100644
--- a/contrib/openbsm/libbsm/bsm_socket_type.c
+++ b/contrib/openbsm/libbsm/bsm_socket_type.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_socket_type.c#1 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/libbsm/bsm_token.c b/contrib/openbsm/libbsm/bsm_token.c
index a6b975d..682836f 100644
--- a/contrib/openbsm/libbsm/bsm_token.c
+++ b/contrib/openbsm/libbsm/bsm_token.c
@@ -29,8 +29,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#99 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/libbsm/bsm_user.c b/contrib/openbsm/libbsm/bsm_user.c
index c7464f0..5b48070 100644
--- a/contrib/openbsm/libbsm/bsm_user.c
+++ b/contrib/openbsm/libbsm/bsm_user.c
@@ -26,8 +26,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_user.c#20 $
*/
#include <config/config.h>
diff --git a/contrib/openbsm/libbsm/bsm_wrappers.c b/contrib/openbsm/libbsm/bsm_wrappers.c
index 2d24a0c..01daaf1 100644
--- a/contrib/openbsm/libbsm/bsm_wrappers.c
+++ b/contrib/openbsm/libbsm/bsm_wrappers.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_wrappers.c#32 $
*/
#ifdef __APPLE__
diff --git a/contrib/openbsm/libbsm/libbsm.3 b/contrib/openbsm/libbsm/libbsm.3
index 151e048..d84e774 100644
--- a/contrib/openbsm/libbsm/libbsm.3
+++ b/contrib/openbsm/libbsm/libbsm.3
@@ -24,8 +24,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/libbsm.3#17 $
-.\"
.Dd March 5, 2009
.Dt LIBBSM 3
.Os
diff --git a/contrib/openbsm/man/Makefile.am b/contrib/openbsm/man/Makefile.am
index ad1802e..26e89f6 100644
--- a/contrib/openbsm/man/Makefile.am
+++ b/contrib/openbsm/man/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/man/Makefile.am#2 $
-##
-
man2_MANS = \
audit.2 \
auditctl.2 \
@@ -19,6 +15,7 @@ man5_MANS = \
audit_user.5 \
audit_warn.5
-# How to do MLINKS in automake?
-# MLINKS= getaudit.2 getaudit_addr.2 \
-# setaudit.2 setaudit_addr.2
+install-exec-hook:
+ cd $(DESTDIR)$(mandir) && \
+ $(LN_S) -f getaudit.2 getaudit_addr.2 && \
+ $(LN_S) -f setaudit.2 setaudit_addr.2
diff --git a/contrib/openbsm/man/Makefile.in b/contrib/openbsm/man/Makefile.in
index 56772f2..bd416e2 100644
--- a/contrib/openbsm/man/Makefile.in
+++ b/contrib/openbsm/man/Makefile.in
@@ -473,7 +473,8 @@ install-dvi: install-dvi-am
install-dvi-am:
install-exec-am:
-
+ @$(NORMAL_INSTALL)
+ $(MAKE) $(AM_MAKEFLAGS) install-exec-hook
install-html: install-html-am
install-html-am:
@@ -514,25 +515,26 @@ uninstall-am: uninstall-man
uninstall-man: uninstall-man2 uninstall-man5
-.MAKE: install-am install-strip
+.MAKE: install-am install-exec-am install-strip
.PHONY: all all-am check check-am clean clean-generic clean-libtool \
distclean distclean-generic distclean-libtool distdir dvi \
dvi-am html html-am info info-am install install-am \
install-data install-data-am install-dvi install-dvi-am \
- install-exec install-exec-am install-html install-html-am \
- install-info install-info-am install-man install-man2 \
- install-man5 install-pdf install-pdf-am install-ps \
- install-ps-am install-strip installcheck installcheck-am \
- installdirs maintainer-clean maintainer-clean-generic \
- mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \
- ps ps-am uninstall uninstall-am uninstall-man uninstall-man2 \
- uninstall-man5
-
-
-# How to do MLINKS in automake?
-# MLINKS= getaudit.2 getaudit_addr.2 \
-# setaudit.2 setaudit_addr.2
+ install-exec install-exec-am install-exec-hook install-html \
+ install-html-am install-info install-info-am install-man \
+ install-man2 install-man5 install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-generic \
+ mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am \
+ uninstall-man uninstall-man2 uninstall-man5
+
+
+install-exec-hook:
+ cd $(DESTDIR)$(mandir) && \
+ $(LN_S) -f getaudit.2 getaudit_addr.2 && \
+ $(LN_S) -f setaudit.2 setaudit_addr.2
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/contrib/openbsm/man/audit.2 b/contrib/openbsm/man/audit.2
index 1ee61b9..d64dfe9 100644
--- a/contrib/openbsm/man/audit.2
+++ b/contrib/openbsm/man/audit.2
@@ -24,8 +24,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/audit.2#9 $
-.\"
.Dd April 19, 2005
.Dt AUDIT 2
.Os
diff --git a/contrib/openbsm/man/audit.log.5 b/contrib/openbsm/man/audit.log.5
index fd52896..d85fdcc 100644
--- a/contrib/openbsm/man/audit.log.5
+++ b/contrib/openbsm/man/audit.log.5
@@ -24,8 +24,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/audit.log.5#26 $
-.\"
.Dd November 5, 2006
.Dt AUDIT.LOG 5
.Os
diff --git a/contrib/openbsm/man/audit_class.5 b/contrib/openbsm/man/audit_class.5
index c92f57f..8ea21d3 100644
--- a/contrib/openbsm/man/audit_class.5
+++ b/contrib/openbsm/man/audit_class.5
@@ -25,8 +25,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/audit_class.5#11 $
-.\"
.Dd January 24, 2004
.Dt AUDIT_CLASS 5
.Os
diff --git a/contrib/openbsm/man/audit_control.5 b/contrib/openbsm/man/audit_control.5
index 69ff80c..3077785 100644
--- a/contrib/openbsm/man/audit_control.5
+++ b/contrib/openbsm/man/audit_control.5
@@ -26,8 +26,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/audit_control.5#26 $
-.\"
.Dd May 14, 2009
.Dt AUDIT_CONTROL 5
.Os
diff --git a/contrib/openbsm/man/audit_event.5 b/contrib/openbsm/man/audit_event.5
index 184a82d..1305ef5 100644
--- a/contrib/openbsm/man/audit_event.5
+++ b/contrib/openbsm/man/audit_event.5
@@ -25,8 +25,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/audit_event.5#12 $
-.\"
.Dd January 24, 2004
.Dt AUDIT_EVENT 5
.Os
diff --git a/contrib/openbsm/man/audit_user.5 b/contrib/openbsm/man/audit_user.5
index 5075f4a..cac47a3 100644
--- a/contrib/openbsm/man/audit_user.5
+++ b/contrib/openbsm/man/audit_user.5
@@ -25,8 +25,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/audit_user.5#14 $
-.\"
.Dd January 4, 2008
.Dt AUDIT_USER 5
.Os
diff --git a/contrib/openbsm/man/audit_warn.5 b/contrib/openbsm/man/audit_warn.5
index c53f163..8734b37 100644
--- a/contrib/openbsm/man/audit_warn.5
+++ b/contrib/openbsm/man/audit_warn.5
@@ -25,8 +25,6 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/audit_warn.5#10 $
-.\"
.Dd March 17, 2004
.Dt AUDIT_WARN 5
.Os
diff --git a/contrib/openbsm/man/auditctl.2 b/contrib/openbsm/man/auditctl.2
index a5346fb..f4b2629 100644
--- a/contrib/openbsm/man/auditctl.2
+++ b/contrib/openbsm/man/auditctl.2
@@ -24,8 +24,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/auditctl.2#9 $
-.\"
.Dd April 19, 2005
.Dt AUDITCTL 2
.Os
diff --git a/contrib/openbsm/man/auditon.2 b/contrib/openbsm/man/auditon.2
index 8b880b7..aa5c760 100644
--- a/contrib/openbsm/man/auditon.2
+++ b/contrib/openbsm/man/auditon.2
@@ -26,8 +26,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/auditon.2#18 $
-.\"
.Dd January 29, 2009
.Dt AUDITON 2
.Os
diff --git a/contrib/openbsm/man/getaudit.2 b/contrib/openbsm/man/getaudit.2
index 5935273..ae5843d 100644
--- a/contrib/openbsm/man/getaudit.2
+++ b/contrib/openbsm/man/getaudit.2
@@ -24,8 +24,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/getaudit.2#11 $
-.\"
.Dd October 19, 2008
.Dt GETAUDIT 2
.Os
diff --git a/contrib/openbsm/man/getauid.2 b/contrib/openbsm/man/getauid.2
index dc6ae0a..3d28d0f 100644
--- a/contrib/openbsm/man/getauid.2
+++ b/contrib/openbsm/man/getauid.2
@@ -24,8 +24,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/getauid.2#9 $
-.\"
.Dd April 19, 2005
.Dt GETAUID 2
.Os
diff --git a/contrib/openbsm/man/setaudit.2 b/contrib/openbsm/man/setaudit.2
index 41448d6..8565b71 100644
--- a/contrib/openbsm/man/setaudit.2
+++ b/contrib/openbsm/man/setaudit.2
@@ -24,8 +24,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/setaudit.2#12 $
-.\"
.Dd April 19, 2005
.Dt SETAUDIT 2
.Os
diff --git a/contrib/openbsm/man/setauid.2 b/contrib/openbsm/man/setauid.2
index 770c32b..11b5dae 100644
--- a/contrib/openbsm/man/setauid.2
+++ b/contrib/openbsm/man/setauid.2
@@ -24,8 +24,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/man/setauid.2#9 $
-.\"
.Dd April 19, 2005
.Dt SETAUID 2
.Os
diff --git a/contrib/openbsm/modules/Makefile.am b/contrib/openbsm/modules/Makefile.am
index 7d59ec2..c4a3c20 100644
--- a/contrib/openbsm/modules/Makefile.am
+++ b/contrib/openbsm/modules/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/modules/Makefile.am#2 $
-##
-
SUBDIRS = \
auditfilter_noop
diff --git a/contrib/openbsm/modules/auditfilter_noop/Makefile.am b/contrib/openbsm/modules/auditfilter_noop/Makefile.am
index 5b43206..3500fd0 100644
--- a/contrib/openbsm/modules/auditfilter_noop/Makefile.am
+++ b/contrib/openbsm/modules/auditfilter_noop/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/modules/auditfilter_noop/Makefile.am#4 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/modules/auditfilter_noop/auditfilter_noop.c b/contrib/openbsm/modules/auditfilter_noop/auditfilter_noop.c
index 79834d4..7e2e973 100644
--- a/contrib/openbsm/modules/auditfilter_noop/auditfilter_noop.c
+++ b/contrib/openbsm/modules/auditfilter_noop/auditfilter_noop.c
@@ -24,8 +24,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/modules/auditfilter_noop/auditfilter_noop.c#6 $
*/
/*
diff --git a/contrib/openbsm/sys/Makefile.am b/contrib/openbsm/sys/Makefile.am
index 17b3afb..0b0261c 100644
--- a/contrib/openbsm/sys/Makefile.am
+++ b/contrib/openbsm/sys/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/sys/Makefile.am#2 $
-##
-
SUBDIRS = \
bsm
diff --git a/contrib/openbsm/sys/bsm/Makefile.am b/contrib/openbsm/sys/bsm/Makefile.am
index 66e79b1..266243d 100644
--- a/contrib/openbsm/sys/bsm/Makefile.am
+++ b/contrib/openbsm/sys/bsm/Makefile.am
@@ -1,8 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/Makefile.am#5 $
-##
-
-
if ! USE_NATIVE_INCLUDES
openbsmdir = $(includedir)/bsm
diff --git a/contrib/openbsm/sys/bsm/audit.h b/contrib/openbsm/sys/bsm/audit.h
index bb4a949..2159813 100644
--- a/contrib/openbsm/sys/bsm/audit.h
+++ b/contrib/openbsm/sys/bsm/audit.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit.h#10 $
*/
#ifndef _BSM_AUDIT_H
diff --git a/contrib/openbsm/sys/bsm/audit_domain.h b/contrib/openbsm/sys/bsm/audit_domain.h
index 3969183..373afa7 100644
--- a/contrib/openbsm/sys/bsm/audit_domain.h
+++ b/contrib/openbsm/sys/bsm/audit_domain.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_domain.h#2 $
*/
#ifndef _BSM_AUDIT_DOMAIN_H_
diff --git a/contrib/openbsm/sys/bsm/audit_errno.h b/contrib/openbsm/sys/bsm/audit_errno.h
index abdaff8..1c467ee 100644
--- a/contrib/openbsm/sys/bsm/audit_errno.h
+++ b/contrib/openbsm/sys/bsm/audit_errno.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_errno.h#7 $
*/
#ifndef _BSM_AUDIT_ERRNO_H_
diff --git a/contrib/openbsm/sys/bsm/audit_fcntl.h b/contrib/openbsm/sys/bsm/audit_fcntl.h
index 1398b2f0..708991e 100644
--- a/contrib/openbsm/sys/bsm/audit_fcntl.h
+++ b/contrib/openbsm/sys/bsm/audit_fcntl.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_fcntl.h#2 $
*/
#ifndef _BSM_AUDIT_FCNTL_H_
diff --git a/contrib/openbsm/sys/bsm/audit_internal.h b/contrib/openbsm/sys/bsm/audit_internal.h
index 21176c8..77d3dbe 100644
--- a/contrib/openbsm/sys/bsm/audit_internal.h
+++ b/contrib/openbsm/sys/bsm/audit_internal.h
@@ -29,8 +29,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#6 $
*/
#ifndef _AUDIT_INTERNAL_H
diff --git a/contrib/openbsm/sys/bsm/audit_kevents.h b/contrib/openbsm/sys/bsm/audit_kevents.h
index 94e42ab..3f92b71 100644
--- a/contrib/openbsm/sys/bsm/audit_kevents.h
+++ b/contrib/openbsm/sys/bsm/audit_kevents.h
@@ -25,18 +25,16 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_kevents.h#10 $
*/
#ifndef _BSM_AUDIT_KEVENTS_H_
#define _BSM_AUDIT_KEVENTS_H_
/*
- * The reserved event numbers for kernel events are 1...2047 and 43001..44900.
+ * The reserved event numbers for kernel events are 1...2047 and 43001..44999.
*/
-#define AUE_IS_A_KEVENT(e) (((e) > 0 && (e) < 2048) || \
- ((e) > 43000 && (e) < 45000))
+#define AUE_IS_A_KEVENT(e) (((e) > 0 && (e) < 2048) || \
+ ((e) > 43000 && (e) < 45000))
/*
* Values marked as AUE_NULL are not required to be audited as per CAPP.
@@ -587,7 +585,8 @@
#define AUE_OPENAT 43184 /* FreeBSD. */
#define AUE_POSIX_OPENPT 43185 /* FreeBSD. */
#define AUE_CAP_NEW 43186 /* TrustedBSD. */
-#define AUE_CAP_GETRIGHTS 43187 /* TrustedBSD. */
+#define AUE_CAP_RIGHTS_GET 43187 /* TrustedBSD. */
+#define AUE_CAP_GETRIGHTS AUE_CAP_RIGHTS_GET
#define AUE_CAP_ENTER 43188 /* TrustedBSD. */
#define AUE_CAP_GETMODE 43189 /* TrustedBSD. */
#define AUE_POSIX_SPAWN 43190 /* Darwin. */
@@ -602,6 +601,14 @@
#define AUE_PDGETPID 43199 /* FreeBSD. */
#define AUE_PDWAIT 43200 /* FreeBSD. */
#define AUE_WAIT6 43201 /* FreeBSD. */
+#define AUE_CAP_RIGHTS_LIMIT 43202 /* TrustedBSD. */
+#define AUE_CAP_IOCTLS_LIMIT 43203 /* TrustedBSD. */
+#define AUE_CAP_IOCTLS_GET 43204 /* TrustedBSD. */
+#define AUE_CAP_FCNTLS_LIMIT 43205 /* TrustedBSD. */
+#define AUE_CAP_FCNTLS_GET 43206 /* TrustedBSD. */
+#define AUE_BINDAT 43207 /* TrustedBSD. */
+#define AUE_CONNECTAT 43208 /* TrustedBSD. */
+#define AUE_CHFLAGSAT 43209 /* FreeBSD-specific. */
/*
* Darwin BSM uses a number of AUE_O_* definitions, which are aliased to the
diff --git a/contrib/openbsm/sys/bsm/audit_record.h b/contrib/openbsm/sys/bsm/audit_record.h
index 2a49cdc..bd87fe8 100644
--- a/contrib/openbsm/sys/bsm/audit_record.h
+++ b/contrib/openbsm/sys/bsm/audit_record.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_record.h#12 $
*/
#ifndef _BSM_AUDIT_RECORD_H_
diff --git a/contrib/openbsm/sys/bsm/audit_socket_type.h b/contrib/openbsm/sys/bsm/audit_socket_type.h
index 85f6aef..660ef0f 100644
--- a/contrib/openbsm/sys/bsm/audit_socket_type.h
+++ b/contrib/openbsm/sys/bsm/audit_socket_type.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_socket_type.h#1 $
*/
#ifndef _BSM_AUDIT_SOCKET_TYPE_H_
diff --git a/contrib/openbsm/test/Makefile.am b/contrib/openbsm/test/Makefile.am
index 7b936ed..5868349 100644
--- a/contrib/openbsm/test/Makefile.am
+++ b/contrib/openbsm/test/Makefile.am
@@ -1,6 +1,2 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/test/Makefile.am#3 $
-##
-
SUBDIRS = \
bsm
diff --git a/contrib/openbsm/test/bsm/Makefile.am b/contrib/openbsm/test/bsm/Makefile.am
index 577e7cb..c787f95 100644
--- a/contrib/openbsm/test/bsm/Makefile.am
+++ b/contrib/openbsm/test/bsm/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/test/bsm/Makefile.am#4 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/test/bsm/generate.c b/contrib/openbsm/test/bsm/generate.c
index bbc81bb..3416fa3 100644
--- a/contrib/openbsm/test/bsm/generate.c
+++ b/contrib/openbsm/test/bsm/generate.c
@@ -23,8 +23,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/test/bsm/generate.c#14 $
*/
/*
diff --git a/contrib/openbsm/tools/Makefile.am b/contrib/openbsm/tools/Makefile.am
index 13aa10d..47ef3cb 100644
--- a/contrib/openbsm/tools/Makefile.am
+++ b/contrib/openbsm/tools/Makefile.am
@@ -1,7 +1,3 @@
-##
-## $P4: //depot/projects/trustedbsd/openbsm/tools/Makefile.am#5 $
-##
-
if USE_NATIVE_INCLUDES
INCLUDES = -I$(top_builddir) -I$(top_srcdir)
else
diff --git a/contrib/openbsm/tools/audump.c b/contrib/openbsm/tools/audump.c
index 82d17ea..cdb8ed1 100644
--- a/contrib/openbsm/tools/audump.c
+++ b/contrib/openbsm/tools/audump.c
@@ -22,8 +22,6 @@
* 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.
- *
- * $P4: //depot/projects/trustedbsd/openbsm/tools/audump.c#9 $
*/
#include <bsm/libbsm.h>
diff --git a/contrib/pf/pflogd/pflogd.c b/contrib/pf/pflogd/pflogd.c
index 2fc2338..de8d4ac 100644
--- a/contrib/pf/pflogd/pflogd.c
+++ b/contrib/pf/pflogd/pflogd.c
@@ -766,7 +766,7 @@ main(int argc, char **argv)
np = pcap_dispatch(hpcap, PCAP_NUM_PKTS,
phandler, (u_char *)dpcap);
if (np < 0) {
- if (!if_exists(interface) == -1) {
+ if (!if_exists(interface)) {
logmsg(LOG_NOTICE, "interface %s went away",
interface);
ret = -1;
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index f189ea9..38fc83f 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -144,6 +144,8 @@
..
libmp
..
+ libnv
+ ..
librt
..
libthr
@@ -212,6 +214,12 @@
..
kqueue
..
+ mac
+ bsdextended
+ ..
+ portacl
+ ..
+ ..
mqueue
..
netinet
diff --git a/etc/rc.d/jail b/etc/rc.d/jail
index d1307db..7dd25ea 100755
--- a/etc/rc.d/jail
+++ b/etc/rc.d/jail
@@ -28,16 +28,16 @@ extra_commands="config console status"
need_dad_wait=
-# extract_var jail name param num defval
-# Extract value from ${jail_$jail_$name} or ${jail_$name} and
+# extract_var jv name param num defval
+# Extract value from ${jail_$jv_$name} or ${jail_$name} and
# set it to $param. If not defined, $defval is used.
-# When $num is [0-9]*, ${jail_$jail_$name$num} are looked up and
+# When $num is [0-9]*, ${jail_$jv_$name$num} are looked up and
# $param is set by using +=.
# When $num is YN or NY, the value is interpret as boolean.
extract_var()
{
- local i _j _name _param _num _def _name1 _name2
- _j=$1
+ local i _jv _name _param _num _def _name1 _name2
+ _jv=$1
_name=$2
_param=$3
_num=$4
@@ -45,7 +45,7 @@ extract_var()
case $_num in
YN)
- _name1=jail_${_j}_${_name}
+ _name1=jail_${_jv}_${_name}
_name2=jail_${_name}
eval $_name1=\"\${$_name1:-\${$_name2:-$_def}}\"
if checkyesno $_name1; then
@@ -55,7 +55,7 @@ extract_var()
fi
;;
NY)
- _name1=jail_${_j}_${_name}
+ _name1=jail_${_jv}_${_name}
_name2=jail_${_name}
eval $_name1=\"\${$_name1:-\${$_name2:-$_def}}\"
if checkyesno $_name1; then
@@ -67,7 +67,7 @@ extract_var()
[0-9]*)
i=$_num
while : ; do
- _name1=jail_${_j}_${_name}${i}
+ _name1=jail_${_jv}_${_name}${i}
_name2=jail_${_name}${i}
eval _tmpargs=\"\${$_name1:-\${$_name2:-$_def}}\"
if [ -n "$_tmpargs" ]; then
@@ -79,7 +79,7 @@ extract_var()
done
;;
*)
- _name1=jail_${_j}_${_name}
+ _name1=jail_${_jv}_${_name}
_name2=jail_${_name}
eval _tmpargs=\"\${$_name1:-\${$_name2:-$_def}}\"
if [ -n "$_tmpargs" ]; then
@@ -89,22 +89,23 @@ extract_var()
esac
}
-# parse_options _j
+# parse_options _j _jv
# Parse options and create a temporary configuration file if necessary.
#
parse_options()
{
- local _j _p
+ local _j _jv _p
_j=$1
+ _jv=$2
_confwarn=0
if [ -z "$_j" ]; then
warn "parse_options: you must specify a jail"
return
fi
- eval _jconf=\"\${jail_${_j}_conf:-/etc/jail.${_j}.conf}\"
- eval _rootdir=\"\$jail_${_j}_rootdir\"
- eval _hostname=\"\$jail_${_j}_hostname\"
+ eval _jconf=\"\${jail_${_jv}_conf:-/etc/jail.${_j}.conf}\"
+ eval _rootdir=\"\$jail_${_jv}_rootdir\"
+ eval _hostname=\"\$jail_${_jv}_hostname\"
if [ -z "$_rootdir" -o \
-z "$_hostname" ]; then
if [ -r "$_jconf" ]; then
@@ -120,7 +121,7 @@ parse_options()
fi
return 1
fi
- eval _ip=\"\$jail_${_j}_ip\"
+ eval _ip=\"\$jail_${_jv}_ip\"
if [ -z "$_ip" ] && ! check_kern_features vimage; then
warn "no ipaddress specified and no vimage support. " \
"Jail $_j was ignored."
@@ -138,10 +139,10 @@ parse_options()
fi
/usr/bin/install -m 0644 -o root -g wheel /dev/null $_conf || return 1
- eval : \${jail_${_j}_flags:=${jail_flags}}
- eval _exec=\"\$jail_${_j}_exec\"
- eval _exec_start=\"\$jail_${_j}_exec_start\"
- eval _exec_stop=\"\$jail_${_j}_exec_stop\"
+ eval : \${jail_${_jv}_flags:=${jail_flags}}
+ eval _exec=\"\$jail_${_jv}_exec\"
+ eval _exec_start=\"\$jail_${_jv}_exec_start\"
+ eval _exec_stop=\"\$jail_${_jv}_exec_stop\"
if [ -n "${_exec}" ]; then
# simple/backward-compatible execution
_exec_start="${_exec}"
@@ -155,20 +156,20 @@ parse_options()
fi
fi
fi
- eval _interface=\"\${jail_${_j}_interface:-${jail_interface}}\"
- eval _parameters=\"\${jail_${_j}_parameters:-${jail_parameters}}\"
- eval _fstab=\"\${jail_${_j}_fstab:-${jail_fstab:-/etc/fstab.$_j}}\"
+ eval _interface=\"\${jail_${_jv}_interface:-${jail_interface}}\"
+ eval _parameters=\"\${jail_${_jv}_parameters:-${jail_parameters}}\"
+ eval _fstab=\"\${jail_${_jv}_fstab:-${jail_fstab:-/etc/fstab.$_j}}\"
(
date +"# Generated by rc.d/jail at %Y-%m-%d %H:%M:%S"
echo "$_j {"
- extract_var $_j hostname host.hostname - ""
- extract_var $_j rootdir path - ""
+ extract_var $_jv hostname host.hostname - ""
+ extract_var $_jv rootdir path - ""
if [ -n "$_ip" ]; then
- extract_var $_j interface interface - ""
+ extract_var $_jv interface interface - ""
jail_handle_ips_option $_ip $_interface
alias=0
while : ; do
- eval _x=\"\$jail_${_j}_ip_multi${alias}\"
+ eval _x=\"\$jail_${_jv}_ip_multi${alias}\"
[ -z "$_x" ] && break
jail_handle_ips_option $_x $_interface
@@ -184,37 +185,37 @@ parse_options()
;;
esac
# These are applicable only to non-vimage jails.
- extract_var $_j fib exec.fib - ""
- extract_var $_j socket_unixiproute_only \
+ extract_var $_jv fib exec.fib - ""
+ extract_var $_jv socket_unixiproute_only \
allow.raw_sockets NY YES
else
echo " vnet;"
- extract_var $_j vnet_interface vnet.interface - ""
+ extract_var $_jv vnet_interface vnet.interface - ""
fi
echo " exec.clean;"
echo " exec.system_user = \"root\";"
echo " exec.jail_user = \"root\";"
- extract_var $_j exec_prestart exec.prestart 0 ""
- extract_var $_j exec_poststart exec.poststart 0 ""
- extract_var $_j exec_prestop exec.prestop 0 ""
- extract_var $_j exec_poststop exec.poststop 0 ""
+ extract_var $_jv exec_prestart exec.prestart 0 ""
+ extract_var $_jv exec_poststart exec.poststart 0 ""
+ extract_var $_jv exec_prestop exec.prestop 0 ""
+ extract_var $_jv exec_poststop exec.poststop 0 ""
echo " exec.start += \"$_exec_start\";"
- extract_var $_j exec_afterstart exec.start 1 ""
+ extract_var $_jv exec_afterstart exec.start 1 ""
echo " exec.stop = \"$_exec_stop\";"
- extract_var $_j consolelog exec.consolelog - \
+ extract_var $_jv consolelog exec.consolelog - \
/var/log/jail_${_j}_console.log
if [ -r $_fstab ]; then
echo " mount.fstab = \"$_fstab\";"
fi
- eval : \${jail_${_j}_devfs_enable:=${jail_devfs_enable:-NO}}
- if checkyesno jail_${_j}_devfs_enable; then
+ eval : \${jail_${_jv}_devfs_enable:=${jail_devfs_enable:-NO}}
+ if checkyesno jail_${_jv}_devfs_enable; then
echo " mount.devfs;"
- eval _ruleset=\${jail_${_j}_devfs_ruleset:-${jail_devfs_ruleset}}
+ eval _ruleset=\${jail_${_jv}_devfs_ruleset:-${jail_devfs_ruleset}}
case $_ruleset in
"") ;;
[0-9]*) echo " devfs_ruleset = \"$_ruleset\";" ;;
@@ -227,22 +228,22 @@ parse_options()
*) warn "devfs_ruleset must be an integer." ;;
esac
fi
- eval : \${jail_${_j}_fdescfs_enable:=${jail_fdescfs_enable:-NO}}
- if checkyesno jail_${_j}_fdescfs_enable; then
+ eval : \${jail_${_jv}_fdescfs_enable:=${jail_fdescfs_enable:-NO}}
+ if checkyesno jail_${_jv}_fdescfs_enable; then
echo " mount.fdescfs;"
fi
- eval : \${jail_${_j}_procfs_enable:=${jail_procfs_enable:-NO}}
- if checkyesno jail_${_j}_procfs_enable; then
+ eval : \${jail_${_jv}_procfs_enable:=${jail_procfs_enable:-NO}}
+ if checkyesno jail_${_jv}_procfs_enable; then
echo " mount.procfs;"
fi
- eval : \${jail_${_j}_mount_enable:=${jail_mount_enable:-NO}}
- if checkyesno jail_${_j}_mount_enable; then
- echo " allow.mount;" >> $_conf
+ eval : \${jail_${_jv}_mount_enable:=${jail_mount_enable:-NO}}
+ if checkyesno jail_${_jv}_mount_enable; then
+ echo " allow.mount;"
fi
- extract_var $_j set_hostname_allow allow.set_hostname YN NO
- extract_var $_j sysvipc_allow allow.sysvipc YN NO
+ extract_var $_jv set_hostname_allow allow.set_hostname YN NO
+ extract_var $_jv sysvipc_allow allow.sysvipc YN NO
for _p in $_parameters; do
echo " ${_p%\;};"
done
@@ -380,14 +381,15 @@ jail_handle_ips_option()
jail_config()
{
- local _j
+ local _j _jv
case $1 in
_ALL) return ;;
esac
for _j in $@; do
_j=$(echo $_j | tr /. _)
- if parse_options $_j; then
+ _jv=$(echo -n $_j | tr -c '[:alnum:]' _)
+ if parse_options $_j $_jv; then
echo "$_j: parameters are in $_conf."
fi
done
@@ -395,7 +397,7 @@ jail_config()
jail_console()
{
- local _j _cmd
+ local _j _jv _cmd
# One argument that is not _ALL.
case $#:$1 in
@@ -403,9 +405,10 @@ jail_console()
1:*) ;;
esac
_j=$(echo $1 | tr /. _)
+ _jv=$(echo -n $1 | tr -c '[:alnum:]' _)
shift
case $# in
- 0) eval _cmd=\${jail_${_j}_consolecmd:-$jail_consolecmd} ;;
+ 0) eval _cmd=\${jail_${_jv}_consolecmd:-$jail_consolecmd} ;;
*) _cmd=$@ ;;
esac
$jail_jexec $_j $_cmd
@@ -419,7 +422,7 @@ jail_status()
jail_start()
{
- local _j _jid _jl _id _name
+ local _j _jv _jid _jl _id _name
if [ $# = 0 ]; then
return
@@ -452,11 +455,12 @@ jail_start()
_jl=
for _j in $@; do
_j=$(echo $_j | tr /. _)
- parse_options $_j || continue
+ _jv=$(echo -n $_j | tr -c '[:alnum:]' _)
+ parse_options $_j $_jv || continue
_jl="$_jl $_j"
- eval rc_flags=\${jail_${_j}_flags:-$jail_flags}
- eval command=\${jail_${_j}_program:-$jail_program}
+ eval rc_flags=\${jail_${_jv}_flags:-$jail_flags}
+ eval command=\${jail_${_jv}_program:-$jail_program}
command_args="-i -f $_conf -c $_j"
$command $rc_flags $command_args \
>/dev/null 2>&1 </dev/null &
@@ -478,10 +482,11 @@ jail_start()
#
for _j in $@; do
_j=$(echo $_j | tr /. _)
- parse_options $_j || continue
+ _jv=$(echo -n $_j | tr -c '[:alnum:]' _)
+ parse_options $_j $_jv || continue
- eval rc_flags=\${jail_${_j}_flags:-$jail_flags}
- eval command=\${jail_${_j}_program:-$jail_program}
+ eval rc_flags=\${jail_${_jv}_flags:-$jail_flags}
+ eval command=\${jail_${_jv}_program:-$jail_program}
command_args="-i -f $_conf -c $_j"
_tmp=`mktemp -t jail` || exit 3
if $command $rc_flags $command_args \
@@ -503,7 +508,7 @@ jail_start()
jail_stop()
{
- local _j
+ local _j _jv
if [ $# = 0 ]; then
return
@@ -531,11 +536,12 @@ jail_stop()
esac
for _j in $@; do
_j=$(echo $_j | tr /. _)
- parse_options $_j || continue
+ _jv=$(echo -n $_j | tr -c '[:alnum:]' _)
+ parse_options $_j $_jv || continue
if ! $jail_jls -j $_j > /dev/null 2>&1; then
continue
fi
- eval command=\${jail_${_j}_program:-$jail_program}
+ eval command=\${jail_${_jv}_program:-$jail_program}
echo -n " ${_hostname:-${_j}}"
_tmp=`mktemp -t jail` || exit 3
$command -q -f $_conf -r $_j >> $_tmp 2>&1
diff --git a/lib/Makefile b/lib/Makefile
index ee83d59..250d583 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -70,6 +70,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
libnetbsd \
${_libnetgraph} \
${_libngatm} \
+ libnv \
libopie \
libpam \
libpcap \
diff --git a/lib/libbsm/Makefile b/lib/libbsm/Makefile
index eec2c40..2e0dbe1 100644
--- a/lib/libbsm/Makefile
+++ b/lib/libbsm/Makefile
@@ -48,6 +48,7 @@ MAN= libbsm.3 \
au_free_token.3 \
au_io.3 \
au_mask.3 \
+ au_notify.3 \
au_open.3 \
au_socket_type.3 \
au_token.3 \
@@ -112,6 +113,9 @@ MLINKS= libbsm.3 bsm.3 \
au_mask.3 au_preselect.3 \
au_mask.3 getauditflagsbin.3 \
au_mask.3 getauditflagschar.3 \
+ au_notify.3 au_get_state.3 \
+ au_notify.3 au_notify_initialize.3 \
+ au_notify.3 au_notify_terminate.3 \
au_open.3 au_close.3 \
au_open.3 au_close_buffer.3 \
au_open.3 au_close_token.3 \
diff --git a/lib/libc/net/gethostbynis.c b/lib/libc/net/gethostbynis.c
index c0d5177..6bafdb1 100644
--- a/lib/libc/net/gethostbynis.c
+++ b/lib/libc/net/gethostbynis.c
@@ -198,61 +198,6 @@ _gethostbynisaddr_r(const void *addr, socklen_t len, int af,
}
#endif /* YP */
-/* XXX _gethostbynisname/_gethostbynisaddr only used by getipnodeby*() */
-struct hostent *
-_gethostbynisname(const char *name, int af)
-{
-#ifdef YP
- struct hostent *he;
- struct hostent_data *hed;
- u_long oresopt;
- int error;
- res_state statp;
-
- statp = __res_state();
- if ((he = __hostent_init()) == NULL ||
- (hed = __hostent_data_init()) == NULL) {
- RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
- return (NULL);
- }
-
- oresopt = statp->options;
- statp->options &= ~RES_USE_INET6;
- error = _gethostbynisname_r(name, af, he, hed);
- statp->options = oresopt;
- return (error == 0) ? he : NULL;
-#else
- return (NULL);
-#endif
-}
-
-struct hostent *
-_gethostbynisaddr(const void *addr, socklen_t len, int af)
-{
-#ifdef YP
- struct hostent *he;
- struct hostent_data *hed;
- u_long oresopt;
- int error;
- res_state statp;
-
- statp = __res_state();
- if ((he = __hostent_init()) == NULL ||
- (hed = __hostent_data_init()) == NULL) {
- RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
- return (NULL);
- }
-
- oresopt = statp->options;
- statp->options &= ~RES_USE_INET6;
- error = _gethostbynisaddr_r(addr, len, af, he, hed);
- statp->options = oresopt;
- return (error == 0) ? he : NULL;
-#else
- return (NULL);
-#endif
-}
-
int
_nis_gethostbyname(void *rval, void *cb_data, va_list ap)
{
diff --git a/lib/libc/net/netdb_private.h b/lib/libc/net/netdb_private.h
index b48dd7b..4ed598c 100644
--- a/lib/libc/net/netdb_private.h
+++ b/lib/libc/net/netdb_private.h
@@ -133,8 +133,6 @@ void _endhostdnsent(void);
void _endhosthtent(struct hostent_data *);
void _endnetdnsent(void);
void _endnethtent(struct netent_data *);
-struct hostent *_gethostbynisaddr(const void *, socklen_t, int);
-struct hostent *_gethostbynisname(const char *, int);
void _map_v4v6_address(const char *, char *);
void _map_v4v6_hostent(struct hostent *, char **, char *);
void _sethostdnsent(int);
diff --git a/lib/libnv/Makefile b/lib/libnv/Makefile
new file mode 100644
index 0000000..47dfe04
--- /dev/null
+++ b/lib/libnv/Makefile
@@ -0,0 +1,92 @@
+# $FreeBSD$
+
+SHLIBDIR?= /lib
+
+.include <bsd.own.mk>
+
+LIB= nv
+SHLIB_MAJOR= 0
+
+.PATH: ${.CURDIR}/../../sys/kern ${.CURDIR}/../../sys/sys
+CFLAGS+=-I${.CURDIR}/../../sys -I${.CURDIR}
+
+SRCS= subr_dnvlist.c
+SRCS+= msgio.c
+SRCS+= subr_nvlist.c
+SRCS+= subr_nvpair.c
+
+INCS= dnv.h
+INCS+= nv.h
+
+MAN+= nv.3
+
+MLINKS+=nv.3 libnv.3 \
+ nv.3 nvlist.3
+MLINKS+=nv.3 nvlist_add_binary.3 \
+ nv.3 nvlist_add_bool.3 \
+ nv.3 nvlist_add_descriptor.3 \
+ nv.3 nvlist_add_null.3 \
+ nv.3 nvlist_add_number.3 \
+ nv.3 nvlist_add_nvlist.3 \
+ nv.3 nvlist_add_string.3 \
+ nv.3 nvlist_add_stringf.3 \
+ nv.3 nvlist_add_stringv.3 \
+ nv.3 nvlist_clone.3 \
+ nv.3 nvlist_create.3 \
+ nv.3 nvlist_destroy.3 \
+ nv.3 nvlist_dump.3 \
+ nv.3 nvlist_empty.3 \
+ nv.3 nvlist_error.3 \
+ nv.3 nvlist_exists.3 \
+ nv.3 nvlist_exists_binary.3 \
+ nv.3 nvlist_exists_bool.3 \
+ nv.3 nvlist_exists_descriptor.3 \
+ nv.3 nvlist_exists_null.3 \
+ nv.3 nvlist_exists_number.3 \
+ nv.3 nvlist_exists_nvlist.3 \
+ nv.3 nvlist_exists_string.3 \
+ nv.3 nvlist_exists_type.3 \
+ nv.3 nvlist_fdump.3 \
+ nv.3 nvlist_flags.3 \
+ nv.3 nvlist_free.3 \
+ nv.3 nvlist_free_binary.3 \
+ nv.3 nvlist_free_bool.3 \
+ nv.3 nvlist_free_descriptor.3 \
+ nv.3 nvlist_free_null.3 \
+ nv.3 nvlist_free_number.3 \
+ nv.3 nvlist_free_nvlist.3 \
+ nv.3 nvlist_free_string.3 \
+ nv.3 nvlist_free_type.3 \
+ nv.3 nvlist_get_binary.3 \
+ nv.3 nvlist_get_bool.3 \
+ nv.3 nvlist_get_descriptor.3 \
+ nv.3 nvlist_get_number.3 \
+ nv.3 nvlist_get_nvlist.3 \
+ nv.3 nvlist_get_parent.3 \
+ nv.3 nvlist_get_string.3 \
+ nv.3 nvlist_move_binary.3 \
+ nv.3 nvlist_move_descriptor.3 \
+ nv.3 nvlist_move_nvlist.3 \
+ nv.3 nvlist_move_string.3 \
+ nv.3 nvlist_next.3 \
+ nv.3 nvlist_pack.3 \
+ nv.3 nvlist_recv.3 \
+ nv.3 nvlist_send.3 \
+ nv.3 nvlist_set_error.3 \
+ nv.3 nvlist_size.3 \
+ nv.3 nvlist_take_binary.3 \
+ nv.3 nvlist_take_bool.3 \
+ nv.3 nvlist_take_descriptor.3 \
+ nv.3 nvlist_take_number.3 \
+ nv.3 nvlist_take_nvlist.3 \
+ nv.3 nvlist_take_string.3 \
+ nv.3 nvlist_unpack.3 \
+ nv.3 nvlist_xfer.3
+
+WARNS?= 6
+
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
+.include <bsd.lib.mk>
diff --git a/lib/libnv/common_impl.h b/lib/libnv/common_impl.h
new file mode 100644
index 0000000..5af4db2
--- /dev/null
+++ b/lib/libnv/common_impl.h
@@ -0,0 +1,37 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#ifndef _COMMON_IMPL_H_
+#define _COMMON_IMPL_H_
+
+#define fd_is_valid(fd) (fcntl((fd), F_GETFL) != -1 || errno != EBADF)
+
+#endif /* !_COMMON_IMPL_H_ */
diff --git a/lib/libnv/msgio.c b/lib/libnv/msgio.c
new file mode 100644
index 0000000..27620a1
--- /dev/null
+++ b/lib/libnv/msgio.c
@@ -0,0 +1,469 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * Copyright (c) 2013 Mariusz Zaborski <oshogbo@FreeBSD.org>
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef HAVE_PJDLOG
+#include <pjdlog.h>
+#endif
+
+#include "common_impl.h"
+#include "msgio.h"
+
+#ifndef HAVE_PJDLOG
+#include <assert.h>
+#define PJDLOG_ASSERT(...) assert(__VA_ARGS__)
+#define PJDLOG_RASSERT(expr, ...) assert(expr)
+#define PJDLOG_ABORT(...) abort()
+#endif
+
+#define PKG_MAX_SIZE (MCLBYTES / CMSG_SPACE(sizeof(int)) - 1)
+
+static int
+msghdr_add_fd(struct cmsghdr *cmsg, int fd)
+{
+
+ PJDLOG_ASSERT(fd >= 0);
+
+ if (!fd_is_valid(fd)) {
+ errno = EBADF;
+ return (-1);
+ }
+
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
+ bcopy(&fd, CMSG_DATA(cmsg), sizeof(fd));
+
+ return (0);
+}
+
+static int
+msghdr_get_fd(struct cmsghdr *cmsg)
+{
+ int fd;
+
+ if (cmsg == NULL || cmsg->cmsg_level != SOL_SOCKET ||
+ cmsg->cmsg_type != SCM_RIGHTS ||
+ cmsg->cmsg_len != CMSG_LEN(sizeof(fd))) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ bcopy(CMSG_DATA(cmsg), &fd, sizeof(fd));
+#ifndef MSG_CMSG_CLOEXEC
+ /*
+ * If the MSG_CMSG_CLOEXEC flag is not available we cannot set the
+ * close-on-exec flag atomically, but we still want to set it for
+ * consistency.
+ */
+ (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
+
+ return (fd);
+}
+
+static void
+fd_wait(int fd, bool doread)
+{
+ fd_set fds;
+
+ PJDLOG_ASSERT(fd >= 0);
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ (void)select(fd + 1, doread ? &fds : NULL, doread ? NULL : &fds,
+ NULL, NULL);
+}
+
+static int
+msg_recv(int sock, struct msghdr *msg)
+{
+ int flags;
+
+ PJDLOG_ASSERT(sock >= 0);
+
+#ifdef MSG_CMSG_CLOEXEC
+ flags = MSG_CMSG_CLOEXEC;
+#else
+ flags = 0;
+#endif
+
+ for (;;) {
+ fd_wait(sock, true);
+ if (recvmsg(sock, msg, flags) == -1) {
+ if (errno == EINTR)
+ continue;
+ return (-1);
+ }
+ break;
+ }
+
+ return (0);
+}
+
+static int
+msg_send(int sock, const struct msghdr *msg)
+{
+
+ PJDLOG_ASSERT(sock >= 0);
+
+ for (;;) {
+ fd_wait(sock, false);
+ if (sendmsg(sock, msg, 0) == -1) {
+ if (errno == EINTR)
+ continue;
+ return (-1);
+ }
+ break;
+ }
+
+ return (0);
+}
+
+int
+cred_send(int sock)
+{
+ unsigned char credbuf[CMSG_SPACE(sizeof(struct cmsgcred))];
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
+ struct iovec iov;
+ uint8_t dummy;
+
+ bzero(credbuf, sizeof(credbuf));
+ bzero(&msg, sizeof(msg));
+ bzero(&iov, sizeof(iov));
+
+ /*
+ * XXX: We send one byte along with the control message, because
+ * setting msg_iov to NULL only works if this is the first
+ * packet send over the socket. Once we send some data we
+ * won't be able to send credentials anymore. This is most
+ * likely a kernel bug.
+ */
+ dummy = 0;
+ iov.iov_base = &dummy;
+ iov.iov_len = sizeof(dummy);
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = credbuf;
+ msg.msg_controllen = sizeof(credbuf);
+
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_len = CMSG_LEN(sizeof(struct cmsgcred));
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_CREDS;
+
+ if (msg_send(sock, &msg) == -1)
+ return (-1);
+
+ return (0);
+}
+
+int
+cred_recv(int sock, struct cmsgcred *cred)
+{
+ unsigned char credbuf[CMSG_SPACE(sizeof(struct cmsgcred))];
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
+ struct iovec iov;
+ uint8_t dummy;
+
+ bzero(credbuf, sizeof(credbuf));
+ bzero(&msg, sizeof(msg));
+ bzero(&iov, sizeof(iov));
+
+ iov.iov_base = &dummy;
+ iov.iov_len = sizeof(dummy);
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = credbuf;
+ msg.msg_controllen = sizeof(credbuf);
+
+ if (msg_recv(sock, &msg) == -1)
+ return (-1);
+
+ cmsg = CMSG_FIRSTHDR(&msg);
+ if (cmsg == NULL ||
+ cmsg->cmsg_len != CMSG_LEN(sizeof(struct cmsgcred)) ||
+ cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_CREDS) {
+ errno = EINVAL;
+ return (-1);
+ }
+ bcopy(CMSG_DATA(cmsg), cred, sizeof(*cred));
+
+ return (0);
+}
+
+static int
+fd_package_send(int sock, const int *fds, size_t nfds)
+{
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
+ struct iovec iov;
+ unsigned int i;
+ int serrno, ret;
+ uint8_t dummy;
+
+ PJDLOG_ASSERT(sock >= 0);
+ PJDLOG_ASSERT(fds != NULL);
+ PJDLOG_ASSERT(nfds > 0);
+
+ bzero(&msg, sizeof(msg));
+
+ /*
+ * XXX: Look into cred_send function for more details.
+ */
+ dummy = 0;
+ iov.iov_base = &dummy;
+ iov.iov_len = sizeof(dummy);
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_controllen = nfds * CMSG_SPACE(sizeof(int));
+ msg.msg_control = calloc(1, msg.msg_controllen);
+ if (msg.msg_control == NULL)
+ return (-1);
+
+ ret = -1;
+
+ for (i = 0, cmsg = CMSG_FIRSTHDR(&msg); i < nfds && cmsg != NULL;
+ i++, cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ if (msghdr_add_fd(cmsg, fds[i]) == -1)
+ goto end;
+ }
+
+ if (msg_send(sock, &msg) == -1)
+ goto end;
+
+ ret = 0;
+end:
+ serrno = errno;
+ free(msg.msg_control);
+ errno = serrno;
+ return (ret);
+}
+
+static int
+fd_package_recv(int sock, int *fds, size_t nfds)
+{
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
+ unsigned int i;
+ int serrno, ret;
+ struct iovec iov;
+ uint8_t dummy;
+
+ PJDLOG_ASSERT(sock >= 0);
+ PJDLOG_ASSERT(nfds > 0);
+ PJDLOG_ASSERT(fds != NULL);
+
+ i = 0;
+ bzero(&msg, sizeof(msg));
+ bzero(&iov, sizeof(iov));
+
+ /*
+ * XXX: Look into cred_send function for more details.
+ */
+ iov.iov_base = &dummy;
+ iov.iov_len = sizeof(dummy);
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_controllen = nfds * CMSG_SPACE(sizeof(int));
+ msg.msg_control = calloc(1, msg.msg_controllen);
+ if (msg.msg_control == NULL)
+ return (-1);
+
+ ret = -1;
+
+ if (msg_recv(sock, &msg) == -1)
+ goto end;
+
+ for (i = 0, cmsg = CMSG_FIRSTHDR(&msg); i < nfds && cmsg != NULL;
+ i++, cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ fds[i] = msghdr_get_fd(cmsg);
+ if (fds[i] < 0)
+ break;
+ }
+
+ if (cmsg != NULL || i < nfds) {
+ int fd;
+
+ /*
+ * We need to close all received descriptors, even if we have
+ * different control message (eg. SCM_CREDS) in between.
+ */
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
+ cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ fd = msghdr_get_fd(cmsg);
+ if (fd >= 0)
+ close(fd);
+ }
+ errno = EINVAL;
+ goto end;
+ }
+
+ ret = 0;
+end:
+ serrno = errno;
+ free(msg.msg_control);
+ errno = serrno;
+ return (ret);
+}
+
+int
+fd_recv(int sock, int *fds, size_t nfds)
+{
+ unsigned int i, step, j;
+ int ret, serrno;
+
+ if (nfds == 0 || fds == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ ret = i = step = 0;
+ while (i < nfds) {
+ if (PKG_MAX_SIZE < nfds - i)
+ step = PKG_MAX_SIZE;
+ else
+ step = nfds - i;
+ ret = fd_package_recv(sock, fds + i, step);
+ if (ret != 0) {
+ /* Close all received descriptors. */
+ serrno = errno;
+ for (j = 0; j < i; j++)
+ close(fds[j]);
+ errno = serrno;
+ break;
+ }
+ i += step;
+ }
+
+ return (ret);
+}
+
+int
+fd_send(int sock, const int *fds, size_t nfds)
+{
+ unsigned int i, step;
+ int ret;
+
+ if (nfds == 0 || fds == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ ret = i = step = 0;
+ while (i < nfds) {
+ if (PKG_MAX_SIZE < nfds - i)
+ step = PKG_MAX_SIZE;
+ else
+ step = nfds - i;
+ ret = fd_package_send(sock, fds + i, step);
+ if (ret != 0)
+ break;
+ i += step;
+ }
+
+ return (ret);
+}
+
+int
+buf_send(int sock, void *buf, size_t size)
+{
+ ssize_t done;
+ unsigned char *ptr;
+
+ PJDLOG_ASSERT(sock >= 0);
+ PJDLOG_ASSERT(size > 0);
+ PJDLOG_ASSERT(buf != NULL);
+
+ ptr = buf;
+ do {
+ fd_wait(sock, false);
+ done = send(sock, ptr, size, 0);
+ if (done == -1) {
+ if (errno == EINTR)
+ continue;
+ return (-1);
+ } else if (done == 0) {
+ errno = ENOTCONN;
+ return (-1);
+ }
+ size -= done;
+ ptr += done;
+ } while (size > 0);
+
+ return (0);
+}
+
+int
+buf_recv(int sock, void *buf, size_t size)
+{
+ ssize_t done;
+ unsigned char *ptr;
+
+ PJDLOG_ASSERT(sock >= 0);
+ PJDLOG_ASSERT(buf != NULL);
+
+ ptr = buf;
+ while (size > 0) {
+ fd_wait(sock, true);
+ done = recv(sock, ptr, size, 0);
+ if (done == -1) {
+ if (errno == EINTR)
+ continue;
+ return (-1);
+ } else if (done == 0) {
+ errno = ENOTCONN;
+ return (-1);
+ }
+ size -= done;
+ ptr += done;
+ }
+
+ return (0);
+}
diff --git a/sys/boot/i386/efi/i386_copy.c b/lib/libnv/msgio.h
index 43c26ce..fd5e462 100644
--- a/sys/boot/i386/efi/i386_copy.c
+++ b/lib/libnv/msgio.h
@@ -1,7 +1,12 @@
/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
+ * Copyright (c) 2013 The FreeBSD Foundation
* All rights reserved.
*
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Copyright (c) 2013 Mariusz Zaborski <oshogbo@FreeBSD.org>
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -11,10 +16,10 @@
* 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
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS 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)
@@ -22,38 +27,24 @@
* 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * MD primitives supporting placement of module data
*
- * XXX should check load address/size against memory top.
+ * $FreeBSD$
*/
-#include <stand.h>
-#include "libi386.h"
-#include "btxv86.h"
+#ifndef _MSGIO_H_
+#define _MSGIO_H_
+
+struct cmsgcred;
+struct iovec;
+struct msghdr;
-ssize_t
-i386_copyin(const void *src, vm_offset_t dest, const size_t len)
-{
- bcopy(src, PTOV(dest), len);
- return(len);
-}
+int cred_send(int sock);
+int cred_recv(int sock, struct cmsgcred *cred);
-ssize_t
-i386_copyout(const vm_offset_t src, void *dest, const size_t len)
-{
- bcopy(PTOV(src), dest, len);
- return(len);
-}
+int fd_send(int sock, const int *fds, size_t nfds);
+int fd_recv(int sock, int *fds, size_t nfds);
+int buf_send(int sock, void *buf, size_t size);
+int buf_recv(int sock, void *buf, size_t size);
-ssize_t
-i386_readin(const int fd, vm_offset_t dest, const size_t len)
-{
- return (read(fd, PTOV(dest), len));
-}
+#endif /* !_MSGIO_H_ */
diff --git a/lib/libnv/nv.3 b/lib/libnv/nv.3
new file mode 100644
index 0000000..947bca8
--- /dev/null
+++ b/lib/libnv/nv.3
@@ -0,0 +1,653 @@
+.\"
+.\" Copyright (c) 2013 The FreeBSD Foundation
+.\" All rights reserved.
+.\"
+.\" This documentation was written by Pawel Jakub Dawidek under sponsorship
+.\" the FreeBSD Foundation.
+.\"
+.\" 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$
+.\"
+.Dd May 1, 2015
+.Dt NV 3
+.Os
+.Sh NAME
+.Nm nvlist_create ,
+.Nm nvlist_destroy ,
+.Nm nvlist_error ,
+.Nm nvlist_set_error ,
+.Nm nvlist_empty ,
+.Nm nvlist_flags ,
+.Nm nvlist_exists ,
+.Nm nvlist_free ,
+.Nm nvlist_clone ,
+.Nm nvlist_dump ,
+.Nm nvlist_fdump ,
+.Nm nvlist_size ,
+.Nm nvlist_pack ,
+.Nm nvlist_unpack ,
+.Nm nvlist_send ,
+.Nm nvlist_recv ,
+.Nm nvlist_xfer ,
+.Nm nvlist_next ,
+.Nm nvlist_add ,
+.Nm nvlist_move ,
+.Nm nvlist_get ,
+.Nm nvlist_take
+.Nd "library for name/value pairs"
+.Sh LIBRARY
+.Lb libnv
+.Sh SYNOPSIS
+.In nv.h
+.Ft "nvlist_t *"
+.Fn nvlist_create "int flags"
+.Ft void
+.Fn nvlist_destroy "nvlist_t *nvl"
+.Ft int
+.Fn nvlist_error "const nvlist_t *nvl"
+.Ft void
+.Fn nvlist_set_error "nvlist_t *nvl, int error"
+.Ft bool
+.Fn nvlist_empty "const nvlist_t *nvl"
+.Ft int
+.Fn nvlist_flags "const nvlist_t *nvl"
+.\"
+.Ft "nvlist_t *"
+.Fn nvlist_clone "const nvlist_t *nvl"
+.\"
+.Ft void
+.Fn nvlist_dump "const nvlist_t *nvl, int fd"
+.Ft void
+.Fn nvlist_fdump "const nvlist_t *nvl, FILE *fp"
+.\"
+.Ft size_t
+.Fn nvlist_size "const nvlist_t *nvl"
+.Ft "void *"
+.Fn nvlist_pack "const nvlist_t *nvl" "size_t *sizep"
+.Ft "nvlist_t *"
+.Fn nvlist_unpack "const void *buf" "size_t size"
+.\"
+.Ft int
+.Fn nvlist_send "int sock" "const nvlist_t *nvl"
+.Ft "nvlist_t *"
+.Fn nvlist_recv "int sock"
+.Ft "nvlist_t *"
+.Fn nvlist_xfer "int sock" "nvlist_t *nvl"
+.\"
+.Ft "const char *"
+.Fn nvlist_next "const nvlist_t *nvl" "int *typep" "void **cookiep"
+.\"
+.Ft bool
+.Fn nvlist_exists "const nvlist_t *nvl" "const char *name"
+.Ft bool
+.Fn nvlist_exists_type "const nvlist_t *nvl" "const char *name" "int type"
+.Ft bool
+.Fn nvlist_exists_null "const nvlist_t *nvl" "const char *name"
+.Ft bool
+.Fn nvlist_exists_bool "const nvlist_t *nvl" "const char *name"
+.Ft bool
+.Fn nvlist_exists_number "const nvlist_t *nvl" "const char *name"
+.Ft bool
+.Fn nvlist_exists_string "const nvlist_t *nvl" "const char *name"
+.Ft bool
+.Fn nvlist_exists_nvlist "const nvlist_t *nvl" "const char *name"
+.Ft bool
+.Fn nvlist_exists_descriptor "const nvlist_t *nvl" "const char *name"
+.Ft bool
+.Fn nvlist_exists_binary "const nvlist_t *nvl" "const char *name"
+.\"
+.Ft void
+.Fn nvlist_add_null "nvlist_t *nvl" "const char *name"
+.Ft void
+.Fn nvlist_add_bool "nvlist_t *nvl" "const char *name" "bool value"
+.Ft void
+.Fn nvlist_add_number "nvlist_t *nvl" "const char *name" "uint64_t value"
+.Ft void
+.Fn nvlist_add_string "nvlist_t *nvl" "const char *name" "const char *value"
+.Ft void
+.Fn nvlist_add_stringf "nvlist_t *nvl" "const char *name" "const char *valuefmt" "..."
+.Ft void
+.Fn nvlist_add_stringv "nvlist_t *nvl" "const char *name" "const char *valuefmt" "va_list valueap"
+.Ft void
+.Fn nvlist_add_nvlist "nvlist_t *nvl" "const char *name" "const nvlist_t *value"
+.Ft void
+.Fn nvlist_add_descriptor "nvlist_t *nvl" "const char *name" "int value"
+.Ft void
+.Fn nvlist_add_binary "nvlist_t *nvl" "const char *name" "const void *value" "size_t size"
+.\"
+.Ft void
+.Fn nvlist_move_string "nvlist_t *nvl" "const char *name" "char *value"
+.Ft void
+.Fn nvlist_move_nvlist "nvlist_t *nvl" "const char *name" "nvlist_t *value"
+.Ft void
+.Fn nvlist_move_descriptor "nvlist_t *nvl" "const char *name" "int value"
+.Ft void
+.Fn nvlist_move_binary "nvlist_t *nvl" "const char *name" "void *value" "size_t size"
+.\"
+.Ft bool
+.Fn nvlist_get_bool "const nvlist_t *nvl" "const char *name"
+.Ft uint64_t
+.Fn nvlist_get_number "const nvlist_t *nvl" "const char *name"
+.Ft "const char *"
+.Fn nvlist_get_string "const nvlist_t *nvl" "const char *name"
+.Ft "const nvlist_t *"
+.Fn nvlist_get_nvlist "const nvlist_t *nvl" "const char *name"
+.Ft int
+.Fn nvlist_get_descriptor "const nvlist_t *nvl" "const char *name"
+.Ft "const void *"
+.Fn nvlist_get_binary "const nvlist_t *nvl" "const char *name" "size_t *sizep"
+.Ft "const nvlist_t *"
+.Fn nvlist_get_parent "const nvlist_t *nvl" "void **cookiep"
+.\"
+.Ft bool
+.Fn nvlist_take_bool "nvlist_t *nvl" "const char *name"
+.Ft uint64_t
+.Fn nvlist_take_number "nvlist_t *nvl" "const char *name"
+.Ft "char *"
+.Fn nvlist_take_string "nvlist_t *nvl" "const char *name"
+.Ft "nvlist_t *"
+.Fn nvlist_take_nvlist "nvlist_t *nvl" "const char *name"
+.Ft int
+.Fn nvlist_take_descriptor "nvlist_t *nvl" "const char *name"
+.Ft "void *"
+.Fn nvlist_take_binary "nvlist_t *nvl" "const char *name" "size_t *sizep"
+.\"
+.Ft void
+.Fn nvlist_free "nvlist_t *nvl" "const char *name"
+.Ft void
+.Fn nvlist_free_type "nvlist_t *nvl" "const char *name" "int type"
+.\"
+.Ft void
+.Fn nvlist_free_null "nvlist_t *nvl" "const char *name"
+.Ft void
+.Fn nvlist_free_bool "nvlist_t *nvl" "const char *name"
+.Ft void
+.Fn nvlist_free_number "nvlist_t *nvl" "const char *name"
+.Ft void
+.Fn nvlist_free_string "nvlist_t *nvl" "const char *name"
+.Ft void
+.Fn nvlist_free_nvlist "nvlist_t *nvl" "const char *name"
+.Ft void
+.Fn nvlist_free_descriptor "nvlist_t *nvl" "const char *name"
+.Ft void
+.Fn nvlist_free_binary "nvlist_t *nvl" "const char *name"
+.Sh DESCRIPTION
+The
+.Nm libnv
+library allows to easily manage name value pairs as well as send and receive
+them over sockets.
+A group (list) of name value pairs is called an
+.Nm nvlist .
+The API supports the following data types:
+.Bl -ohang -offset indent
+.It Sy null ( NV_TYPE_NULL )
+There is no data associated with the name.
+.It Sy bool ( NV_TYPE_BOOL )
+The value can be either
+.Dv true
+or
+.Dv false .
+.It Sy number ( NV_TYPE_NUMBER )
+The value is a number stored as
+.Vt uint64_t .
+.It Sy string ( NV_TYPE_STRING )
+The value is a C string.
+.It Sy nvlist ( NV_TYPE_NVLIST )
+The value is a nested nvlist.
+.It Sy descriptor ( NV_TYPE_DESCRIPTOR )
+The value is a file descriptor.
+Note that file descriptors can be sent only over
+.Xr unix 4
+domain sockets.
+.It Sy binary ( NV_TYPE_BINARY )
+The value is a binary buffer.
+.El
+.Pp
+The
+.Fn nvlist_create
+function allocates memory and initializes an nvlist.
+.Pp
+The following flag can be provided:
+.Pp
+.Bl -tag -width "NV_FLAG_IGNORE_CASE" -compact -offset indent
+.It Dv NV_FLAG_IGNORE_CASE
+Perform case-insensitive lookups of provided names.
+.El
+.Pp
+The
+.Fn nvlist_destroy
+function destroys the given nvlist.
+Function does nothing if
+.Dv NULL
+nvlist is provided.
+Function never modifies the
+.Va errno
+global variable.
+.Pp
+The
+.Fn nvlist_error
+function returns any error value that the nvlist accumulated.
+If the given nvlist is
+.Dv NULL
+the
+.Er ENOMEM
+error will be returned.
+.Pp
+The
+.Fn nvlist_set_error
+function sets an nvlist to be in the error state.
+Subsequent calls to
+.Fn nvlist_error
+will return the given error value.
+This function cannot be used to clear the error state from an nvlist.
+This function does nothing if the nvlist is already in the error state.
+.Pp
+The
+.Fn nvlist_empty
+function returns
+.Dv true
+if the given nvlist is empty and
+.Dv false
+otherwise.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_flags
+function returns flags used to create the nvlist with the
+.Fn nvlist_create
+function.
+.Pp
+The
+.Fn nvlist_clone
+functions clones the given nvlist.
+The clone shares no resources with its origin.
+This also means that all file descriptors that are part of the nvlist will be
+duplicated with the
+.Xr dup 2
+system call before placing them in the clone.
+.Pp
+The
+.Fn nvlist_dump
+dumps nvlist content for debugging purposes to the given file descriptor
+.Fa fd .
+.Pp
+The
+.Fn nvlist_fdump
+dumps nvlist content for debugging purposes to the given file stream
+.Fa fp .
+.Pp
+The
+.Fn nvlist_size
+function returns the size of the given nvlist after converting it to binary
+buffer with the
+.Fn nvlist_pack
+function.
+.Pp
+The
+.Fn nvlist_pack
+function converts the given nvlist to a binary buffer.
+The function allocates memory for the buffer, which should be freed with the
+.Xr free 3
+function.
+If the
+.Fa sizep
+argument is not
+.Dv NULL ,
+the size of the buffer will be stored there.
+The function returns
+.Dv NULL
+in case of an error (allocation failure).
+If the nvlist contains any file descriptors
+.Dv NULL
+will be returned.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_unpack
+function converts the given buffer to the nvlist.
+The function returns
+.Dv NULL
+in case of an error.
+.Pp
+The
+.Fn nvlist_send
+function sends the given nvlist over the socket given by the
+.Fa sock
+argument.
+Note that nvlist that contains file descriptors can only be send over
+.Xr unix 4
+domain sockets.
+.Pp
+The
+.Fn nvlist_recv
+function receives nvlist over the socket given by the
+.Fa sock
+argument.
+.Pp
+The
+.Fn nvlist_xfer
+function sends the given nvlist over the socket given by the
+.Fa sock
+argument and receives nvlist over the same socket.
+The given nvlist is always destroyed.
+.Pp
+The
+.Fn nvlist_next
+function iterates over the given nvlist returning names and types of subsequent
+elements.
+The
+.Fa cookiep
+argument allows the function to figure out which element should be returned
+next.
+The
+.Va *cookiep
+should be set to
+.Dv NULL
+for the first call and should not be changed later.
+Returning
+.Dv NULL
+means there are no more elements on the nvlist.
+The
+.Fa typep
+argument can be NULL.
+Elements may not be removed from the nvlist while traversing it.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_exists
+function returns
+.Dv true
+if element of the given name exists (besides of its type) or
+.Dv false
+otherwise.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_exists_type
+function returns
+.Dv true
+if element of the given name and the given type exists or
+.Dv false
+otherwise.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_exists_null ,
+.Fn nvlist_exists_bool ,
+.Fn nvlist_exists_number ,
+.Fn nvlist_exists_string ,
+.Fn nvlist_exists_nvlist ,
+.Fn nvlist_exists_descriptor ,
+.Fn nvlist_exists_binary
+functions return
+.Dv true
+if element of the given name and the given type determined by the function name
+exists or
+.Dv false
+otherwise.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_add_null ,
+.Fn nvlist_add_bool ,
+.Fn nvlist_add_number ,
+.Fn nvlist_add_string ,
+.Fn nvlist_add_stringf ,
+.Fn nvlist_add_stringv ,
+.Fn nvlist_add_nvlist ,
+.Fn nvlist_add_descriptor ,
+.Fn nvlist_add_binary
+functions add element to the given nvlist.
+When adding string or binary buffor the functions will allocate memory
+and copy the data over.
+When adding nvlist, the nvlist will be cloned and clone will be added.
+When adding descriptor, the descriptor will be duplicated using the
+.Xr dup 2
+system call and the new descriptor will be added.
+If an error occurs while adding new element, internal error is set which can be
+examined using the
+.Fn nvlist_error
+function.
+.Pp
+The
+.Fn nvlist_move_string ,
+.Fn nvlist_move_nvlist ,
+.Fn nvlist_move_descriptor ,
+.Fn nvlist_move_binary
+functions add new element to the given nvlist, but unlike
+.Fn nvlist_add_<type>
+functions they will consume the given resource.
+If an error occurs while adding new element, the resource is destroyed and
+internal error is set which can be examined using the
+.Fn nvlist_error
+function.
+.Pp
+The
+.Fn nvlist_get_bool ,
+.Fn nvlist_get_number ,
+.Fn nvlist_get_string ,
+.Fn nvlist_get_nvlist ,
+.Fn nvlist_get_descriptor ,
+.Fn nvlist_get_binary
+functions allow to obtain value of the given name.
+In case of string, nvlist, descriptor or binary, returned resource should
+not be modified - it still belongs to the nvlist.
+If element of the given name does not exist, the program will be aborted.
+To avoid that the caller should check for existence before trying to obtain
+the value or use
+.Xr dnvlist 3
+extension, which allows to provide default value for a missing element.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_get_parent
+function allows to obtain the parent nvlist from the nested nvlist.
+.Pp
+The
+.Fn nvlist_take_bool ,
+.Fn nvlist_take_number ,
+.Fn nvlist_take_string ,
+.Fn nvlist_take_nvlist ,
+.Fn nvlist_take_descriptor ,
+.Fn nvlist_take_binary
+functions return value associated with the given name and remove the element
+from the nvlist.
+In case of string and binary values, the caller is responsible for free returned
+memory using the
+.Xr free 3
+function.
+In case of nvlist, the caller is responsible for destroying returned nvlist
+using the
+.Fn nvlist_destroy
+function.
+In case of descriptor, the caller is responsible for closing returned descriptor
+using the
+.Fn close 2
+system call.
+If element of the given name does not exist, the program will be aborted.
+To avoid that the caller should check for existence before trying to obtain
+the value or use
+.Xr dnvlist 3
+extension, which allows to provide default value for a missing element.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_free
+function removes element of the given name from the nvlist (besides of its type)
+and frees all resources associated with it.
+If element of the given name does not exist, the program will be aborted.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_free_type
+function removes element of the given name and the given type from the nvlist
+and frees all resources associated with it.
+If element of the given name and the given type does not exist, the program
+will be aborted.
+The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_free_null ,
+.Fn nvlist_free_bool ,
+.Fn nvlist_free_number ,
+.Fn nvlist_free_string ,
+.Fn nvlist_free_nvlist ,
+.Fn nvlist_free_descriptor ,
+.Fn nvlist_free_binary
+functions remove element of the given name and the given type determined by the
+function name from the nvlist and free all resources associated with it.
+If element of the given name and the given type does not exist, the program
+will be aborted.
+The nvlist must not be in error state.
+.Sh EXAMPLES
+The following example demonstrates how to prepare an nvlist and send it over
+.Xr unix 4
+domain socket.
+.Bd -literal
+nvlist_t *nvl;
+int fd;
+
+fd = open("/tmp/foo", O_RDONLY);
+if (fd < 0)
+ err(1, "open(\\"/tmp/foo\\") failed");
+
+nvl = nvlist_create(0);
+/*
+ * There is no need to check if nvlist_create() succeeded,
+ * as the nvlist_add_<type>() functions can cope.
+ * If it failed, nvlist_send() will fail.
+ */
+nvlist_add_string(nvl, "filename", "/tmp/foo");
+nvlist_add_number(nvl, "flags", O_RDONLY);
+/*
+ * We just want to send the descriptor, so we can give it
+ * for the nvlist to consume (that's why we use nvlist_move
+ * not nvlist_add).
+ */
+nvlist_move_descriptor(nvl, "fd", fd);
+if (nvlist_send(sock, nvl) < 0) {
+ nvlist_destroy(nvl);
+ err(1, "nvlist_send() failed");
+}
+nvlist_destroy(nvl);
+.Ed
+.Pp
+Receiving nvlist and getting data:
+.Bd -literal
+nvlist_t *nvl;
+const char *command;
+char *filename;
+int fd;
+
+nvl = nvlist_recv(sock);
+if (nvl == NULL)
+ err(1, "nvlist_recv() failed");
+
+/* For command we take pointer to nvlist's buffer. */
+command = nvlist_get_string(nvl, "command");
+/*
+ * For filename we remove it from the nvlist and take
+ * ownership of the buffer.
+ */
+filename = nvlist_take_string(nvl, "filename");
+/* The same for the descriptor. */
+fd = nvlist_take_descriptor(nvl, "fd");
+
+printf("command=%s filename=%s fd=%d\n", command, filename, fd);
+
+nvlist_destroy(nvl);
+free(filename);
+close(fd);
+/* command was freed by nvlist_destroy() */
+.Ed
+.Pp
+Iterating over nvlist:
+.Bd -literal
+nvlist_t *nvl;
+const char *name;
+void *cookie;
+int type;
+
+nvl = nvlist_recv(sock);
+if (nvl == NULL)
+ err(1, "nvlist_recv() failed");
+
+cookie = NULL;
+while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
+ printf("%s=", name);
+ switch (type) {
+ case NV_TYPE_NUMBER:
+ printf("%ju", (uintmax_t)nvlist_get_number(nvl, name));
+ break;
+ case NV_TYPE_STRING:
+ printf("%s", nvlist_get_string(nvl, name));
+ break;
+ default:
+ printf("N/A");
+ break;
+ }
+ printf("\\n");
+}
+.Ed
+.Pp
+Iterating over every nested nvlist:
+.Bd -literal
+nvlist_t *nvl;
+const char *name;
+void *cookie;
+int type;
+
+nvl = nvlist_recv(sock);
+if (nvl == NULL)
+ err(1, "nvlist_recv() failed");
+
+cookie = NULL;
+do {
+ while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
+ if (type == NV_TYPE_NVLIST) {
+ nvl = nvlist_get_nvlist(nvl, name);
+ cookie = NULL;
+ }
+ }
+} while ((nvl = nvlist_get_parent(nvl, &cookie)) != NULL);
+.Ed
+.Sh SEE ALSO
+.Xr close 2 ,
+.Xr dup 2 ,
+.Xr open 2 ,
+.Xr err 3 ,
+.Xr free 3 ,
+.Xr printf 3 ,
+.Xr unix 4
+.Sh HISTORY
+The
+.Nm libnv
+library appeared in
+.Fx 11.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm libnv
+library was implemented by
+.An Pawel Jakub Dawidek Aq pawel@dawidek.net
+under sponsorship from the FreeBSD Foundation.
diff --git a/lib/libnv/tests/Makefile b/lib/libnv/tests/Makefile
new file mode 100644
index 0000000..d8e0904
--- /dev/null
+++ b/lib/libnv/tests/Makefile
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+TESTSDIR= ${TESTSBASE}/lib/libnv
+
+ATF_TESTS_CXX= \
+ dnv_tests \
+ nv_tests \
+
+TAP_TESTS_C+= nvlist_add_test
+TAP_TESTS_C+= nvlist_exists_test
+TAP_TESTS_C+= nvlist_free_test
+TAP_TESTS_C+= nvlist_get_test
+TAP_TESTS_C+= nvlist_move_test
+TAP_TESTS_C+= nvlist_send_recv_test
+
+DPADD+= ${LIBNV}
+LDADD+= -lnv
+
+WARNS?= 3
+
+.include <bsd.test.mk>
diff --git a/lib/libnv/tests/dnv_tests.cc b/lib/libnv/tests/dnv_tests.cc
new file mode 100644
index 0000000..2f92d9d
--- /dev/null
+++ b/lib/libnv/tests/dnv_tests.cc
@@ -0,0 +1,567 @@
+/*-
+ * Copyright (c) 2014-2015 Sandvine Inc. All rights reserved.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <atf-c++.hpp>
+#include <dnv.h>
+#include <nv.h>
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_bool__present);
+ATF_TEST_CASE_BODY(dnvlist_get_bool__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ bool value;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = true;
+ nvlist_add_bool(nvl, key, value);
+
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, key, false), value);
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "name", false), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_bool__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_bool__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ key = "123";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, key, false), false);
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "123", true), true);
+
+ nvlist_add_bool(nvl, key, true);
+
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "otherkey", true), true);
+ ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "12c", false), false);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_number__present);
+ATF_TEST_CASE_BODY(dnvlist_get_number__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ uint64_t value;
+
+ nvl = nvlist_create(0);
+
+ key = "key";
+ value = 48952;
+ nvlist_add_number(nvl, key, value);
+
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, key, 19), value);
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "key", 65), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_number__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_number__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ key = "123";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, key, 5), 5);
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "1234", 5), 5);
+
+ nvlist_add_number(nvl, key, 24841);
+
+ ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "1234", 5641), 5641);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_string__present);
+ATF_TEST_CASE_BODY(dnvlist_get_string__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ const char *value, *actual_value;
+
+ nvl = nvlist_create(0);
+
+ key = "string";
+ value = "fjdojfdi";
+ nvlist_add_string(nvl, key, value);
+
+ ATF_REQUIRE_EQ(strcmp(dnvlist_get_string(nvl, key, "g"), value), 0);
+
+ actual_value = dnvlist_get_string(nvl, key, "rs");
+ ATF_REQUIRE_EQ(strcmp(actual_value, value), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_string__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_string__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+ const char *actual_value;
+
+ key = "123";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(strcmp(dnvlist_get_string(nvl, key, "bar"), "bar"), 0);
+
+ actual_value = dnvlist_get_string(nvl, key, "d");
+ ATF_REQUIRE_EQ(strcmp(actual_value, "d"), 0);
+
+ nvlist_add_string(nvl, key, "cxhweh");
+
+ ATF_REQUIRE_EQ(strcmp(dnvlist_get_string(nvl, "hthth", "fd"), "fd"), 0);
+ actual_value = dnvlist_get_string(nvl, "5", "5");
+ ATF_REQUIRE_EQ(strcmp("5", "5"), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_nvlist__present);
+ATF_TEST_CASE_BODY(dnvlist_get_nvlist__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ nvlist_t *value;
+ const nvlist_t *actual_value;
+
+ nvl = nvlist_create(0);
+
+ key = "nvlist";
+ value = nvlist_create(0);
+ nvlist_move_nvlist(nvl, key, value);
+
+ actual_value = dnvlist_get_nvlist(nvl, key, NULL);
+ ATF_REQUIRE(actual_value != NULL);
+ ATF_REQUIRE(nvlist_empty(actual_value));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_nvlist__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_nvlist__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+ nvlist_t *dummy;
+
+ key = "123";
+ nvl = nvlist_create(0);
+ dummy = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, key, dummy), dummy);
+
+ nvlist_move_nvlist(nvl, key, nvlist_create(0));
+ ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, "456", dummy), dummy);
+ ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, "gh", dummy), dummy);
+
+ nvlist_destroy(nvl);
+}
+
+static void
+set_const_binary_value(const void *&value, size_t &size, const char *str)
+{
+
+ value = str;
+ size = strlen(str) + 1; /* +1 to include '\0' */
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_binary__present);
+ATF_TEST_CASE_BODY(dnvlist_get_binary__present)
+{
+ nvlist_t *nvl;
+ const char *k;
+ const void *value, *actual_value;
+ size_t value_size, actual_size;
+
+ nvl = nvlist_create(0);
+
+ k = "binary";
+ set_const_binary_value(value, value_size, "fjdojfdi");
+ nvlist_add_binary(nvl, k, value, value_size);
+
+ actual_value = dnvlist_get_binary(nvl, k, &actual_size, "g", 1);
+ ATF_REQUIRE_EQ(value_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, value, actual_size), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_get_binary__default_value);
+ATF_TEST_CASE_BODY(dnvlist_get_binary__default_value)
+{
+ nvlist_t *nvl;
+ const char *key;
+ const void *default_value, *actual_value;
+ size_t default_size, actual_size;
+
+ key = "123";
+ nvl = nvlist_create(0);
+
+ set_const_binary_value(default_value, default_size, "bar");
+ actual_value = dnvlist_get_binary(nvl, key, &actual_size, default_value,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0);
+
+ set_const_binary_value(default_value, default_size, "atf");
+ actual_value = dnvlist_get_binary(nvl, key, &actual_size, default_value,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0);
+
+ nvlist_add_binary(nvl, key, "test", 4);
+
+ set_const_binary_value(default_value, default_size, "bthrg");
+ actual_value = dnvlist_get_binary(nvl, "k", &actual_size, default_value,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0);
+
+ set_const_binary_value(default_value, default_size,
+ "rrhgrythtyrtgbrhgrtdsvdfbtjlkul");
+ actual_value = dnvlist_get_binary(nvl, "s", &actual_size, default_value,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, default_value, actual_size), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_bool__present);
+ATF_TEST_CASE_BODY(dnvlist_take_bool__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ bool value;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = true;
+ nvlist_add_bool(nvl, key, value);
+
+ ATF_REQUIRE_EQ(dnvlist_take_bool(nvl, key, false), value);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_bool__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_bool__empty)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_take_bool(nvl, "123", false), false);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_bool__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_bool__default_value)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_bool(nvl, "key", true);
+
+ ATF_REQUIRE_EQ(dnvlist_take_bool(nvl, "otherkey", true), true);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_number__present);
+ATF_TEST_CASE_BODY(dnvlist_take_number__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ uint64_t value;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = 194154;
+ nvlist_add_number(nvl, key, value);
+
+ ATF_REQUIRE_EQ(dnvlist_take_number(nvl, key, 2), value);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_number__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_number__empty)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE_EQ(dnvlist_take_number(nvl, "123", 126484), 126484);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_number__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_number__default_value)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_number(nvl, "key", 12);
+
+ ATF_REQUIRE_EQ(dnvlist_take_number(nvl, "otherkey", 13), 13);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_string__present);
+ATF_TEST_CASE_BODY(dnvlist_take_string__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ const char *value;
+ char *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = "wrowm";
+ default_val = strdup("default");
+ nvlist_add_string(nvl, key, value);
+
+ actual_val = dnvlist_take_string(nvl, key, default_val);
+ ATF_REQUIRE_EQ(strcmp(actual_val, value), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ free(actual_val);
+ free(default_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_string__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_string__empty)
+{
+ nvlist_t *nvl;
+ char *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+ default_val = strdup("");
+
+ actual_val = dnvlist_take_string(nvl, "123", default_val);
+ ATF_REQUIRE_EQ(strcmp(actual_val, default_val), 0);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_string__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_string__default_value)
+{
+ nvlist_t *nvl;
+ char *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "key", "foobar");
+ default_val = strdup("other");
+
+ actual_val = dnvlist_take_string(nvl, "otherkey", default_val);
+ ATF_REQUIRE_EQ(strcmp(actual_val, default_val), 0);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_nvlist__present);
+ATF_TEST_CASE_BODY(dnvlist_take_nvlist__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ nvlist_t *value, *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ value = nvlist_create(0);
+ default_val = nvlist_create(0);
+ nvlist_move_nvlist(nvl, key, value);
+
+ actual_val = dnvlist_take_nvlist(nvl, key, default_val);
+ ATF_REQUIRE_EQ(actual_val, value);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ free(actual_val);
+ free(default_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_nvlist__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_nvlist__empty)
+{
+ nvlist_t *nvl, *actual_val;
+
+ nvl = nvlist_create(0);
+
+ actual_val = dnvlist_take_nvlist(nvl, "123", NULL);
+ ATF_REQUIRE_EQ(actual_val, static_cast<nvlist_t *>(NULL));
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_nvlist__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_nvlist__default_value)
+{
+ nvlist_t *nvl;
+ nvlist_t *default_val, *actual_val;
+
+ nvl = nvlist_create(0);
+ nvlist_move_nvlist(nvl, "key", nvlist_create(0));
+ default_val = nvlist_create(0);
+
+ actual_val = dnvlist_take_nvlist(nvl, "otherkey", default_val);
+ ATF_REQUIRE_EQ(actual_val, default_val);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+static void
+set_binary_value(void *&value, size_t &size, const char *str)
+{
+
+ value = strdup(str);
+ size = strlen(str) + 1; /* +1 to include '\0' */
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_binary__present);
+ATF_TEST_CASE_BODY(dnvlist_take_binary__present)
+{
+ nvlist_t *nvl;
+ const char *key;
+ void *value, *default_val, *actual_val;
+ size_t value_size, default_size, actual_size;
+
+ nvl = nvlist_create(0);
+
+ key = "name";
+ set_binary_value(value, value_size, "fkdojvmo908");
+ set_binary_value(default_val, default_size, "16546");
+ nvlist_add_binary(nvl, key, value, value_size);
+
+ actual_val = dnvlist_take_binary(nvl, key, &actual_size, default_val,
+ default_size);
+ ATF_REQUIRE_EQ(value_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_val, value, value_size), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ free(actual_val);
+ free(default_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_binary__empty);
+ATF_TEST_CASE_BODY(dnvlist_take_binary__empty)
+{
+ nvlist_t *nvl;
+ void *default_val, *actual_val;
+ size_t default_size, actual_size;
+
+ nvl = nvlist_create(0);
+ set_binary_value(default_val, default_size, "\xa8\x89\x49\xff\xe2\x08");
+
+ actual_val = dnvlist_take_binary(nvl, "123", &actual_size, default_val,
+ default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_val, default_val, actual_size), 0);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(dnvlist_take_binary__default_value);
+ATF_TEST_CASE_BODY(dnvlist_take_binary__default_value)
+{
+ nvlist_t *nvl;
+ void *default_val, *actual_val;
+ size_t default_size, actual_size;
+
+ nvl = nvlist_create(0);
+ nvlist_add_binary(nvl, "key", "foobar", 6);
+ set_binary_value(default_val, default_size, "vbhag");
+
+ actual_val = dnvlist_take_binary(nvl, "otherkey", &actual_size,
+ default_val, default_size);
+ ATF_REQUIRE_EQ(default_size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_val, default_val, default_size), 0);
+
+ free(actual_val);
+ nvlist_destroy(nvl);
+}
+
+ATF_INIT_TEST_CASES(tp)
+{
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_bool__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_bool__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_number__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_number__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_string__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_string__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_nvlist__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_nvlist__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_binary__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_get_binary__default_value);
+
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_bool__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_bool__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_bool__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_number__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_number__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_number__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_string__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_string__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_string__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_nvlist__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_nvlist__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_nvlist__default_value);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_binary__present);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_binary__empty);
+ ATF_ADD_TEST_CASE(tp, dnvlist_take_binary__default_value);
+}
diff --git a/lib/libnv/tests/nv_tests.cc b/lib/libnv/tests/nv_tests.cc
new file mode 100644
index 0000000..2d9fd97
--- /dev/null
+++ b/lib/libnv/tests/nv_tests.cc
@@ -0,0 +1,1240 @@
+/*-
+ * Copyright (c) 2014-2015 Sandvine Inc. All rights reserved.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <atf-c++.hpp>
+#include <nv.h>
+
+#include <errno.h>
+#include <limits>
+#include <set>
+#include <sstream>
+#include <string>
+
+/*
+ * Test that a newly created nvlist has no errors, and is empty.
+ */
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_create__is_empty);
+ATF_TEST_CASE_BODY(nvlist_create__is_empty)
+{
+ nvlist_t *nvl;
+ int type;
+ void *it;
+
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+
+ ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ it = NULL;
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_null__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_null__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ int type;
+
+ key = "key";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_null(nvl, key);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists_null(nvl, key));
+ ATF_REQUIRE(nvlist_exists_null(nvl, "key"));
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NULL);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_bool__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_bool__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ int type;
+
+ key = "name";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_bool(nvl, key, true);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "name"));
+ ATF_REQUIRE(nvlist_exists_bool(nvl, key));
+ ATF_REQUIRE(nvlist_exists_bool(nvl, "name"));
+ ATF_REQUIRE_EQ(nvlist_get_bool(nvl, key), true);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_BOOL);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_number__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_number__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ uint64_t value;
+ int type;
+
+ key = "foo123";
+ value = 71965;
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_number(nvl, key, value);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "foo123"));
+ ATF_REQUIRE(nvlist_exists_number(nvl, key));
+ ATF_REQUIRE_EQ(nvlist_get_number(nvl, key), value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_string__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_string__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ const char *value;
+ int type;
+
+ key = "test";
+ value = "fgjdkgjdk";
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_string(nvl, key, value);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "test"));
+ ATF_REQUIRE(nvlist_exists_string(nvl, key));
+ ATF_REQUIRE(nvlist_exists_string(nvl, "test"));
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, key), value), 0);
+
+ /* nvlist_add_* is required to clone the value, so check for that. */
+ ATF_REQUIRE(nvlist_get_string(nvl, key) != value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_nvlist__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key, *subkey;
+ nvlist_t *sublist;
+ const nvlist_t *value;
+ int type;
+
+ key = "test";
+ subkey = "subkey";
+ sublist = nvlist_create(0);
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_null(sublist, subkey);
+ nvlist_add_nvlist(nvl, key, sublist);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "test"));
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, key));
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, "test"));
+
+ value = nvlist_get_nvlist(nvl, key);
+ ATF_REQUIRE(nvlist_exists_null(value, subkey));
+
+ /* nvlist_add_* is required to clone the value, so check for that. */
+ ATF_REQUIRE(sublist != value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(sublist);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__child_with_error);
+ATF_TEST_CASE_BODY(nvlist_add_nvlist__child_with_error)
+{
+ nvlist_t *nvl, *parent;
+
+ nvl = nvlist_create(0);
+ parent = nvlist_create(0);
+
+ nvlist_set_error(nvl, EBADF);
+ nvlist_add_nvlist(parent, "test", nvl);
+ ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
+
+ nvlist_destroy(nvl);
+ nvlist_destroy(parent);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_binary__single_insert);
+ATF_TEST_CASE_BODY(nvlist_add_binary__single_insert)
+{
+ nvlist_t *nvl;
+ void *it;
+ const char *key;
+ void *value;
+ const void *ret_value;
+ size_t value_size, ret_size;
+ int type;
+
+ key = "binary";
+ value_size = 13;
+ value = malloc(value_size);
+ memset(value, 0xa5, value_size);
+ nvl = nvlist_create(0);
+
+ ATF_REQUIRE(nvl != NULL);
+ ATF_REQUIRE(!nvlist_exists(nvl, key));
+
+ nvlist_add_binary(nvl, key, value, value_size);
+
+ ATF_REQUIRE(!nvlist_empty(nvl));
+ ATF_REQUIRE(nvlist_exists(nvl, key));
+ ATF_REQUIRE(nvlist_exists(nvl, "binary"));
+ ATF_REQUIRE(nvlist_exists_binary(nvl, key));
+ ATF_REQUIRE(nvlist_exists_binary(nvl, "binary"));
+
+ ret_value = nvlist_get_binary(nvl, key, &ret_size);
+ ATF_REQUIRE_EQ(value_size, ret_size);
+ ATF_REQUIRE_EQ(memcmp(value, ret_value, ret_size), 0);
+
+ /* nvlist_add_* is required to clone the value, so check for that. */
+ ATF_REQUIRE(value != ret_value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_BINARY);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(nvl);
+ free(value);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__empty_nvlist);
+ATF_TEST_CASE_BODY(nvlist_clone__empty_nvlist)
+{
+ nvlist_t *nvl, *clone;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ clone = nvlist_clone(nvl);
+ ATF_REQUIRE(clone != NULL);
+ ATF_REQUIRE(clone != nvl);
+ ATF_REQUIRE(nvlist_empty(clone));
+
+ nvlist_destroy(clone);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__nonempty_nvlist);
+ATF_TEST_CASE_BODY(nvlist_clone__nonempty_nvlist)
+{
+ nvlist_t *nvl, *clone;
+ const char *key;
+ void *it;
+ uint64_t value;
+ int type;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ value = 684874;
+ nvlist_add_number(nvl, key, value);
+
+ clone = nvlist_clone(nvl);
+ ATF_REQUIRE(clone != NULL);
+ ATF_REQUIRE(clone != nvl);
+ ATF_REQUIRE(nvlist_exists_number(clone, key));
+ ATF_REQUIRE_EQ(nvlist_get_number(clone, key), value);
+
+ /* Iterate over the nvlist; ensure that it has only our one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(clone, &type, &it), key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
+ ATF_REQUIRE_EQ(nvlist_next(clone, &type, &it), static_cast<const char *>(NULL));
+
+ nvlist_destroy(clone);
+ nvlist_destroy(nvl);
+}
+
+static const char * const test_subnvlist_key = "nvlist";
+
+static const char * const test_string_key = "string";
+static const char * const test_string_val = "59525";
+
+static nvlist_t*
+create_test_nvlist(void)
+{
+ nvlist_t *nvl, *sublist;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ sublist = nvlist_create(0);
+ ATF_REQUIRE(sublist != NULL);
+
+ nvlist_add_string(sublist, test_string_key, test_string_val);
+ nvlist_move_nvlist(nvl, test_subnvlist_key, sublist);
+
+ return (nvl);
+}
+
+static void
+verify_test_nvlist(const nvlist_t *nvl)
+{
+ void *it;
+ const nvlist_t *value;
+ int type;
+
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, test_subnvlist_key));
+
+ value = nvlist_get_nvlist(nvl, test_subnvlist_key);
+
+ ATF_REQUIRE(nvlist_exists_string(value, test_string_key));
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(value, test_string_key), test_string_val), 0);
+ ATF_REQUIRE(nvlist_get_string(value, test_string_key) != test_string_val);
+
+ /* Iterate over both nvlists; ensure that each has only the one key. */
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(value, &type, &it),
+ test_string_key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
+ ATF_REQUIRE_EQ(nvlist_next(value, &type, &it), static_cast<const char *>(NULL));
+
+ it = NULL;
+ ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it),
+ test_subnvlist_key), 0);
+ ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
+ ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), static_cast<const char *>(NULL));
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__nested_nvlist);
+ATF_TEST_CASE_BODY(nvlist_clone__nested_nvlist)
+{
+ nvlist_t *nvl, *clone;
+
+ nvl = create_test_nvlist();
+ clone = nvlist_clone(nvl);
+
+ ATF_REQUIRE(clone != NULL);
+ ATF_REQUIRE(clone != nvl);
+ verify_test_nvlist(clone);
+
+ nvlist_destroy(clone);
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__error_nvlist);
+ATF_TEST_CASE_BODY(nvlist_clone__error_nvlist)
+{
+ nvlist_t *nvl, *clone;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ nvlist_set_error(nvl, ENOMEM);
+
+ clone = nvlist_clone(nvl);
+ ATF_REQUIRE(clone == NULL);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__empty_nvlist);
+ATF_TEST_CASE_BODY(nvlist_pack__empty_nvlist)
+{
+ nvlist_t *nvl, *unpacked;
+ void *packed;
+ size_t packed_size;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ packed = nvlist_pack(nvl, &packed_size);
+ ATF_REQUIRE(packed != NULL);
+
+ unpacked = nvlist_unpack(packed, packed_size);
+ ATF_REQUIRE(unpacked != NULL);
+ ATF_REQUIRE(unpacked != nvl);
+ ATF_REQUIRE(nvlist_empty(unpacked));
+
+ nvlist_destroy(unpacked);
+ nvlist_destroy(nvl);
+ free(packed);
+}
+
+static void
+verify_null(const nvlist_t *nvl, int type)
+{
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_NULL);
+}
+
+static void
+verify_number(const nvlist_t *nvl, const char *name, int type, uint64_t value)
+{
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
+ ATF_REQUIRE_EQ(nvlist_get_number(nvl, name), value);
+}
+
+static void
+verify_string(const nvlist_t *nvl, const char *name, int type,
+ const char * value)
+{
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, name), value), 0);
+}
+
+static void
+verify_nvlist(const nvlist_t *nvl, const char *name, int type)
+{
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
+ verify_test_nvlist(nvlist_get_nvlist(nvl, name));
+}
+
+static void
+verify_binary(const nvlist_t *nvl, const char *name, int type,
+ const void * value, size_t size)
+{
+ const void *actual_value;
+ size_t actual_size;
+
+ ATF_REQUIRE_EQ(type, NV_TYPE_BINARY);
+ actual_value = nvlist_get_binary(nvl, name, &actual_size);
+ ATF_REQUIRE_EQ(size, actual_size);
+ ATF_REQUIRE_EQ(memcmp(value, actual_value, size), 0);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__multiple_values);
+ATF_TEST_CASE_BODY(nvlist_pack__multiple_values)
+{
+ std::ostringstream msg;
+ std::set<std::string> keys_seen;
+ nvlist_t *nvl, *unpacked, *nvvalue;
+ const char *nullkey, *numkey, *strkey, *nvkey, *binkey, *name;
+ int numvalue;
+ const char * strvalue;
+ void *binvalue, *packed, *it;
+ size_t binsize, packed_size;
+ int type;
+
+ nvl = nvlist_create(0);
+
+ nullkey = "null";
+ nvlist_add_null(nvl, nullkey);
+
+ numkey = "number";
+ numvalue = 939853984;
+ nvlist_add_number(nvl, numkey, numvalue);
+
+ strkey = "string";
+ strvalue = "jfieutijf";
+ nvlist_add_string(nvl, strkey, strvalue);
+
+ nvkey = "nvlist";
+ nvvalue = create_test_nvlist();
+ nvlist_move_nvlist(nvl, nvkey, nvvalue);
+
+ binkey = "binary";
+ binsize = 4;
+ binvalue = malloc(binsize);
+ memset(binvalue, 'b', binsize);
+ nvlist_move_binary(nvl, binkey, binvalue, binsize);
+
+ packed = nvlist_pack(nvl, &packed_size);
+ ATF_REQUIRE(packed != NULL);
+
+ unpacked = nvlist_unpack(packed, packed_size);
+ ATF_REQUIRE(unpacked != 0);
+
+ it = NULL;
+ while ((name = nvlist_next(unpacked, &type, &it)) != NULL) {
+ /* Ensure that we see every key only once. */
+ ATF_REQUIRE_EQ(keys_seen.count(name), 0);
+
+ if (strcmp(name, nullkey) == 0)
+ verify_null(unpacked, type);
+ else if (strcmp(name, numkey) == 0)
+ verify_number(unpacked, name, type, numvalue);
+ else if (strcmp(name, strkey) == 0)
+ verify_string(unpacked, name, type, strvalue);
+ else if (strcmp(name, nvkey) == 0)
+ verify_nvlist(unpacked, name, type);
+ else if (strcmp(name, binkey) == 0)
+ verify_binary(unpacked, name, type, binvalue, binsize);
+ else {
+ msg << "Unexpected key :'" << name << "'";
+ ATF_FAIL(msg.str().c_str());
+ }
+
+ keys_seen.insert(name);
+ }
+
+ /* Ensure that we saw every key. */
+ ATF_REQUIRE_EQ(keys_seen.size(), 5);
+
+ nvlist_destroy(nvl);
+ nvlist_destroy(unpacked);
+ free(packed);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__error_nvlist);
+ATF_TEST_CASE_BODY(nvlist_pack__error_nvlist)
+{
+ nvlist_t *nvl;
+ void *packed;
+ size_t size;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ nvlist_set_error(nvl, ENOMEM);
+
+ packed = nvlist_pack(nvl, &size);
+ ATF_REQUIRE(packed == NULL);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_unpack__duplicate_key);
+ATF_TEST_CASE_BODY(nvlist_unpack__duplicate_key)
+{
+ nvlist_t *nvl, *unpacked;
+ const char *key1, *key2;
+ void *packed, *keypos;
+ size_t size, keylen;
+
+ nvl = nvlist_create(0);
+
+ key1 = "key1";
+ keylen = strlen(key1);
+ nvlist_add_number(nvl, key1, 5);
+
+ key2 = "key2";
+ ATF_REQUIRE_EQ(keylen, strlen(key2));
+ nvlist_add_number(nvl, key2, 10);
+
+ packed = nvlist_pack(nvl, &size);
+
+ /*
+ * Mangle the packed nvlist by replacing key1 with key2, creating a
+ * packed nvlist with a duplicate key.
+ */
+ keypos = memmem(packed, size, key1, keylen);
+ ATF_REQUIRE(keypos != NULL);
+ memcpy(keypos, key2, keylen);
+
+ unpacked = nvlist_unpack(packed, size);
+ ATF_REQUIRE(nvlist_error(unpacked) != 0);
+
+ free(packed);
+ nvlist_destroy(nvl);
+ nvlist_destroy(unpacked);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_string__single_insert);
+ATF_TEST_CASE_BODY(nvlist_move_string__single_insert)
+{
+ nvlist_t *nvl;
+ const char *key;
+ char *value;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ value = strdup("testval");
+ ATF_REQUIRE(value != NULL);
+
+ nvlist_move_string(nvl, key, value);
+ ATF_REQUIRE_EQ(nvlist_get_string(nvl, key), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__null_child);
+ATF_TEST_CASE_BODY(nvlist_move_nvlist__null_child)
+{
+ nvlist_t *parent;
+
+ parent = nvlist_create(0);
+
+ nvlist_move_nvlist(parent, "test", NULL);
+
+ ATF_REQUIRE(nvlist_error(parent) != 0);
+
+ nvlist_destroy(parent);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__child_with_error);
+ATF_TEST_CASE_BODY(nvlist_move_nvlist__child_with_error)
+{
+ nvlist_t *nvl, *parent;
+
+ nvl = nvlist_create(0);
+ parent = nvlist_create(0);
+
+ nvlist_set_error(nvl, EBADF);
+ nvlist_move_nvlist(parent, "test", nvl);
+ ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
+
+ nvlist_destroy(parent);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__single_insert);
+ATF_TEST_CASE_BODY(nvlist_move_nvlist__single_insert)
+{
+ nvlist_t *nvl;
+ const char *key;
+ nvlist_t *value;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ value = nvlist_create(0);
+ ATF_REQUIRE(value != NULL);
+
+ nvlist_move_nvlist(nvl, key, value);
+ ATF_REQUIRE_EQ(nvlist_get_nvlist(nvl, key), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_binary__single_insert);
+ATF_TEST_CASE_BODY(nvlist_move_binary__single_insert)
+{
+ nvlist_t *nvl;
+ const char *key;
+ void *value;
+ size_t size, actual_size;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ size = 73;
+ value = malloc(size);
+ ATF_REQUIRE(value != NULL);
+
+ nvlist_move_binary(nvl, key, value, size);
+ ATF_REQUIRE_EQ(nvlist_get_binary(nvl, key, &actual_size), value);
+ ATF_REQUIRE_EQ(size, actual_size);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_bool__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ bool testval;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "boolkey";
+ testval = false;
+ nvlist_add_bool(nvl, testkey, testval);
+
+ ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_bool__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ bool testval, otherval1;
+ nvlist_t *otherval2;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "boolkey";
+ testval = true;
+ nvlist_add_bool(nvl, testkey, testval);
+
+ otherkey1 = "key1";
+ otherval1 = false;
+ nvlist_add_bool(nvl, otherkey1, otherval1);
+
+ otherkey2 = "key2";
+ otherval2 = create_test_nvlist();
+ nvlist_move_nvlist(nvl, otherkey2, otherval2);
+
+ ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
+
+ ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey1));
+ ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey1), otherval1);
+
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey2));
+ verify_test_nvlist(nvlist_get_nvlist(nvl, otherkey2));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_number__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ uint64_t testval;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "numkey";
+ testval = std::numeric_limits<uint64_t>::max();
+ nvlist_add_number(nvl, testkey, testval);
+
+ ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_number__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ uint64_t testval, otherval1;
+ const char *otherval2;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ otherkey1 = "key1";
+ otherval1 = 5;
+ nvlist_add_number(nvl, otherkey1, otherval1);
+
+ testkey = "numkey";
+ testval = 1654;
+ nvlist_add_number(nvl, testkey, testval);
+
+ otherkey2 = "key2";
+ otherval2 = "string";
+ nvlist_add_string(nvl, otherkey2, otherval2);
+
+ ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
+
+ ATF_REQUIRE(nvlist_exists_number(nvl, otherkey1));
+ ATF_REQUIRE_EQ(nvlist_get_number(nvl, otherkey1), otherval1);
+
+ ATF_REQUIRE(nvlist_exists_string(nvl, otherkey2));
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey2), otherval2), 0);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_string__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ const char *testval;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "numkey";
+ testval = "nvlist";
+ nvlist_add_string(nvl, testkey, testval);
+
+ ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_string__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ const char *testval, *otherval1;
+ bool otherval2;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ otherkey1 = "key1";
+ otherval1 = "fjdifjdk";
+ nvlist_add_string(nvl, otherkey1, otherval1);
+
+ otherkey2 = "key2";
+ otherval2 = true;
+ nvlist_add_bool(nvl, otherkey2, otherval2);
+
+ testkey = "strkey";
+ testval = "1654";
+ nvlist_add_string(nvl, testkey, testval);
+
+ ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
+
+ ATF_REQUIRE(nvlist_exists_string(nvl, otherkey1));
+ ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey1), otherval1), 0);
+
+ ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
+ ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_nvlist__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ nvlist_t *testval;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "numkey";
+ testval = create_test_nvlist();
+ nvlist_move_nvlist(nvl, testkey, testval);
+
+ verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_nvlist__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ nvlist_t *testval, *otherval1;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "strkey";
+ testval = create_test_nvlist();
+ nvlist_move_nvlist(nvl, testkey, testval);
+
+ otherkey1 = "key1";
+ otherval1 = nvlist_create(0);
+ nvlist_move_nvlist(nvl, otherkey1, otherval1);
+
+ otherkey2 = "key2";
+ nvlist_add_null(nvl, otherkey2);
+
+ verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
+
+ ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey1));
+ ATF_REQUIRE(nvlist_empty(nvlist_get_nvlist(nvl, otherkey1)));
+
+ ATF_REQUIRE(nvlist_exists_null(nvl, otherkey2));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__single_remove);
+ATF_TEST_CASE_BODY(nvlist_take_binary__single_remove)
+{
+ nvlist_t *nvl;
+ const char *testkey;
+ void *testval;
+ const void *actual_val;
+ size_t testsize, actual_size;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ testkey = "numkey";
+ testsize = 457;
+ testval = malloc(testsize);
+ memset(testval, '5', testsize);
+ nvlist_move_binary(nvl, testkey, testval, testsize);
+
+ actual_val = nvlist_take_binary(nvl, testkey, &actual_size);
+ ATF_REQUIRE_EQ(testsize, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_val, testval, testsize), 0);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__other_keys_unchanged);
+ATF_TEST_CASE_BODY(nvlist_take_binary__other_keys_unchanged)
+{
+ nvlist_t *nvl;
+ const char *testkey, *otherkey1, *otherkey2;
+ const void *actual_value;
+ char testval[] = "gjiertj";
+ char otherval1[] = "fdreg";
+ size_t testsize, othersize, actual_size;
+ bool otherval2;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ otherkey1 = "key1";
+ othersize = sizeof(otherval1);
+ nvlist_add_binary(nvl, otherkey1, otherval1, othersize);
+
+ otherkey2 = "key2";
+ otherval2 = true;
+ nvlist_add_bool(nvl, otherkey2, otherval2);
+
+ testkey = "strkey";
+ testsize = sizeof(testval);
+ nvlist_add_binary(nvl, testkey, testval, testsize);
+
+ actual_value = nvlist_take_binary(nvl, testkey, &actual_size);
+ ATF_REQUIRE_EQ(testsize, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, testval, testsize), 0);
+
+ ATF_REQUIRE(nvlist_exists_binary(nvl, otherkey1));
+ actual_value = nvlist_get_binary(nvl, otherkey1, &actual_size);
+ ATF_REQUIRE_EQ(othersize, actual_size);
+ ATF_REQUIRE_EQ(memcmp(actual_value, otherval1, othersize), 0);
+
+ ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
+ ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_null);
+ATF_TEST_CASE_BODY(nvlist_free__single_null)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_null(nvl, key);
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_bool);
+ATF_TEST_CASE_BODY(nvlist_free__single_bool)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_bool(nvl, key, true);
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_number);
+ATF_TEST_CASE_BODY(nvlist_free__single_number)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_number(nvl, key, 584);
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_string);
+ATF_TEST_CASE_BODY(nvlist_free__single_string)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_string(nvl, key, "gjkfkjd");
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_nvlist);
+ATF_TEST_CASE_BODY(nvlist_free__single_nvlist)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_nvlist(nvl, key, nvlist_create(0));
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_binary);
+ATF_TEST_CASE_BODY(nvlist_free__single_binary)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_binary(nvl, key, "jgjgfd", 6);
+
+ nvlist_free(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_null__single_null);
+ATF_TEST_CASE_BODY(nvlist_free_null__single_null)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_null(nvl, key);
+
+ nvlist_free_null(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_bool__single_bool);
+ATF_TEST_CASE_BODY(nvlist_free_bool__single_bool)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_bool(nvl, key, true);
+
+ nvlist_free_bool(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_number__single_number);
+ATF_TEST_CASE_BODY(nvlist_free_number__single_number)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_number(nvl, key, 584);
+
+ nvlist_free_number(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_string__single_string);
+ATF_TEST_CASE_BODY(nvlist_free_string__single_string)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_string(nvl, key, "gjkfkjd");
+
+ nvlist_free_string(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_nvlist__single_nvlist);
+ATF_TEST_CASE_BODY(nvlist_free_nvlist__single_nvlist)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_nvlist(nvl, key, nvlist_create(0));
+
+ nvlist_free_nvlist(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_binary__single_binary);
+ATF_TEST_CASE_BODY(nvlist_free_binary__single_binary)
+{
+ nvlist_t *nvl;
+ const char *key;
+
+ nvl = nvlist_create(0);
+ key = "test";
+ nvlist_add_binary(nvl, key, "jgjgfd", 6);
+
+ nvlist_free_binary(nvl, key);
+ ATF_REQUIRE(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+}
+
+ATF_INIT_TEST_CASES(tp)
+{
+ ATF_ADD_TEST_CASE(tp, nvlist_create__is_empty);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_null__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_bool__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_number__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_string__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__child_with_error);
+ ATF_ADD_TEST_CASE(tp, nvlist_add_binary__single_insert);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_clone__empty_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_clone__nonempty_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_clone__nested_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_clone__error_nvlist);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_pack__empty_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_pack__multiple_values);
+ ATF_ADD_TEST_CASE(tp, nvlist_pack__error_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_unpack__duplicate_key);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_move_string__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__null_child);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__child_with_error);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_binary__single_insert);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_take_bool__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_bool__other_keys_unchanged);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_number__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_number__other_keys_unchanged);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_string__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_string__other_keys_unchanged);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__other_keys_unchanged);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_binary__single_remove);
+ ATF_ADD_TEST_CASE(tp, nvlist_take_binary__other_keys_unchanged);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_null);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_bool);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_number);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_string);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_free__single_binary);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_free_null__single_null);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_bool__single_bool);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_number__single_number);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_string__single_string);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_nvlist__single_nvlist);
+ ATF_ADD_TEST_CASE(tp, nvlist_free_binary__single_binary);
+}
diff --git a/lib/libnv/tests/nvlist_add_test.c b/lib/libnv/tests/nvlist_add_test.c
new file mode 100644
index 0000000..06bcc63
--- /dev/null
+++ b/lib/libnv/tests/nvlist_add_test.c
@@ -0,0 +1,196 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <nv.h>
+
+static int ntest = 1;
+
+#define CHECK(expr) do { \
+ if ((expr)) \
+ printf("ok # %d %s:%u\n", ntest, __FILE__, __LINE__); \
+ else \
+ printf("not ok # %d %s:%u\n", ntest, __FILE__, __LINE__);\
+ ntest++; \
+} while (0)
+
+int
+main(void)
+{
+ const nvlist_t *cnvl;
+ nvlist_t *nvl;
+
+ printf("1..94\n");
+
+ nvl = nvlist_create(0);
+
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ nvlist_add_null(nvl, "nvlist/null");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_null(nvl, "nvlist/null"));
+
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool/true"));
+ nvlist_add_bool(nvl, "nvlist/bool/true", true);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool/true"));
+
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool/false"));
+ nvlist_add_bool(nvl, "nvlist/bool/false", false);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool/false"));
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/0"));
+ nvlist_add_number(nvl, "nvlist/number/0", 0);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/0"));
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/1"));
+ nvlist_add_number(nvl, "nvlist/number/1", 1);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/1"));
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/-1"));
+ nvlist_add_number(nvl, "nvlist/number/-1", -1);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/-1"));
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/UINT64_MAX"));
+ nvlist_add_number(nvl, "nvlist/number/UINT64_MAX", UINT64_MAX);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/UINT64_MAX"));
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/INT64_MIN"));
+ nvlist_add_number(nvl, "nvlist/number/INT64_MIN", INT64_MIN);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/INT64_MIN"));
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/INT64_MAX"));
+ nvlist_add_number(nvl, "nvlist/number/INT64_MAX", INT64_MAX);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/INT64_MAX"));
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string/"));
+ nvlist_add_string(nvl, "nvlist/string/", "");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/"));
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string/x"));
+ nvlist_add_string(nvl, "nvlist/string/x", "x");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/x"));
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+ nvlist_add_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/stringf/"));
+ nvlist_add_stringf(nvl, "nvlist/stringf/", "%s", "");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_string(nvl, "nvlist/stringf/"));
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/stringf/x"));
+ nvlist_add_stringf(nvl, "nvlist/stringf/x", "%s", "x");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_string(nvl, "nvlist/stringf/x"));
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/stringf/666Xabc"));
+ nvlist_add_stringf(nvl, "nvlist/stringf/666Xabc", "%d%c%s", 666, 'X', "abc");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_string(nvl, "nvlist/stringf/666Xabc"));
+
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
+ nvlist_add_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", STDERR_FILENO);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
+
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/binary/x"));
+ nvlist_add_binary(nvl, "nvlist/binary/x", "x", 1);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary/x"));
+
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
+ nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz"));
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
+
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+
+ CHECK(nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool/true"));
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool/false"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/0"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/1"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/-1"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/UINT64_MAX"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/INT64_MIN"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number/INT64_MAX"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/x"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/stringf/"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/stringf/x"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/stringf/666Xabc"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary/x"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+
+ cnvl = nvlist_get_nvlist(nvl, "nvlist/nvlist");
+ CHECK(nvlist_exists_null(cnvl, "nvlist/null"));
+ CHECK(nvlist_exists_bool(cnvl, "nvlist/bool/true"));
+ CHECK(nvlist_exists_bool(cnvl, "nvlist/bool/false"));
+ CHECK(nvlist_exists_number(cnvl, "nvlist/number/0"));
+ CHECK(nvlist_exists_number(cnvl, "nvlist/number/1"));
+ CHECK(nvlist_exists_number(cnvl, "nvlist/number/-1"));
+ CHECK(nvlist_exists_number(cnvl, "nvlist/number/UINT64_MAX"));
+ CHECK(nvlist_exists_number(cnvl, "nvlist/number/INT64_MIN"));
+ CHECK(nvlist_exists_number(cnvl, "nvlist/number/INT64_MAX"));
+ CHECK(nvlist_exists_string(cnvl, "nvlist/string/"));
+ CHECK(nvlist_exists_string(cnvl, "nvlist/string/x"));
+ CHECK(nvlist_exists_string(cnvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+ CHECK(nvlist_exists_string(cnvl, "nvlist/stringf/"));
+ CHECK(nvlist_exists_string(cnvl, "nvlist/stringf/x"));
+ CHECK(nvlist_exists_string(cnvl, "nvlist/stringf/666Xabc"));
+ CHECK(nvlist_exists_descriptor(cnvl, "nvlist/descriptor/STDERR_FILENO"));
+ CHECK(nvlist_exists_binary(cnvl, "nvlist/binary/x"));
+ CHECK(nvlist_exists_binary(cnvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
+
+ nvlist_destroy(nvl);
+
+ return (0);
+}
diff --git a/lib/libnv/tests/nvlist_exists_test.c b/lib/libnv/tests/nvlist_exists_test.c
new file mode 100644
index 0000000..cb595d7
--- /dev/null
+++ b/lib/libnv/tests/nvlist_exists_test.c
@@ -0,0 +1,321 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include <nv.h>
+
+static int ntest = 1;
+
+#define CHECK(expr) do { \
+ if ((expr)) \
+ printf("ok # %d %s:%u\n", ntest, __FILE__, __LINE__); \
+ else \
+ printf("not ok # %d %s:%u\n", ntest, __FILE__, __LINE__);\
+ ntest++; \
+} while (0)
+
+int
+main(void)
+{
+ nvlist_t *nvl;
+
+ printf("1..232\n");
+
+ nvl = nvlist_create(0);
+
+ CHECK(!nvlist_exists(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/null"));
+ nvlist_add_null(nvl, "nvlist/null");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists(nvl, "nvlist/null"));
+ CHECK(nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/null"));
+
+ CHECK(!nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/bool"));
+ nvlist_add_bool(nvl, "nvlist/bool", true);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/bool"));
+
+ CHECK(!nvlist_exists(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/number"));
+ nvlist_add_number(nvl, "nvlist/number", 0);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/number"));
+
+ CHECK(!nvlist_exists(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/string"));
+ nvlist_add_string(nvl, "nvlist/string", "test");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/string"));
+
+ CHECK(!nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/nvlist"));
+ nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/nvlist"));
+
+ CHECK(!nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/descriptor"));
+ nvlist_add_descriptor(nvl, "nvlist/descriptor", STDERR_FILENO);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/descriptor"));
+
+ CHECK(!nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/binary"));
+ nvlist_add_binary(nvl, "nvlist/binary", "test", 4);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/binary"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ CHECK(nvlist_exists(nvl, "nvlist/null"));
+ CHECK(nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists(nvl, "nvlist/number"));
+ CHECK(nvlist_exists(nvl, "nvlist/string"));
+ CHECK(nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_null(nvl, "nvlist/null");
+ CHECK(!nvlist_exists(nvl, "nvlist/null"));
+ CHECK(nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists(nvl, "nvlist/number"));
+ CHECK(nvlist_exists(nvl, "nvlist/string"));
+ CHECK(nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_bool(nvl, "nvlist/bool");
+ CHECK(!nvlist_exists(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists(nvl, "nvlist/number"));
+ CHECK(nvlist_exists(nvl, "nvlist/string"));
+ CHECK(nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_number(nvl, "nvlist/number");
+ CHECK(!nvlist_exists(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists(nvl, "nvlist/number"));
+ CHECK(nvlist_exists(nvl, "nvlist/string"));
+ CHECK(nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_string(nvl, "nvlist/string");
+ CHECK(!nvlist_exists(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists(nvl, "nvlist/string"));
+ CHECK(nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_nvlist(nvl, "nvlist/nvlist");
+ CHECK(!nvlist_exists(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_descriptor(nvl, "nvlist/descriptor");
+ CHECK(!nvlist_exists(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_binary(nvl, "nvlist/binary");
+ CHECK(!nvlist_exists(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists(nvl, "nvlist/binary"));
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ CHECK(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+
+ return (0);
+}
diff --git a/lib/libnv/tests/nvlist_free_test.c b/lib/libnv/tests/nvlist_free_test.c
new file mode 100644
index 0000000..4417a44
--- /dev/null
+++ b/lib/libnv/tests/nvlist_free_test.c
@@ -0,0 +1,221 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include <nv.h>
+
+static int ntest = 1;
+
+#define CHECK(expr) do { \
+ if ((expr)) \
+ printf("ok # %d %s:%u\n", ntest, __FILE__, __LINE__); \
+ else \
+ printf("not ok # %d %s:%u\n", ntest, __FILE__, __LINE__);\
+ ntest++; \
+} while (0)
+
+int
+main(void)
+{
+ nvlist_t *nvl;
+
+ printf("1..114\n");
+
+ nvl = nvlist_create(0);
+
+ nvlist_add_null(nvl, "nvlist/null");
+ nvlist_add_bool(nvl, "nvlist/bool", true);
+ nvlist_add_number(nvl, "nvlist/number", 0);
+ nvlist_add_string(nvl, "nvlist/string", "test");
+ nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl);
+ nvlist_add_descriptor(nvl, "nvlist/descriptor", STDERR_FILENO);
+ nvlist_add_binary(nvl, "nvlist/binary", "test", 4);
+
+ CHECK(nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_null(nvl, "nvlist/null");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_bool(nvl, "nvlist/bool");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_number(nvl, "nvlist/number");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_string(nvl, "nvlist/string");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_nvlist(nvl, "nvlist/nvlist");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_descriptor(nvl, "nvlist/descriptor");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free_binary(nvl, "nvlist/binary");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ CHECK(nvlist_empty(nvl));
+
+ nvlist_add_null(nvl, "nvlist/null");
+ nvlist_add_bool(nvl, "nvlist/bool", true);
+ nvlist_add_number(nvl, "nvlist/number", 0);
+ nvlist_add_string(nvl, "nvlist/string", "test");
+ nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl);
+ nvlist_add_descriptor(nvl, "nvlist/descriptor", STDERR_FILENO);
+ nvlist_add_binary(nvl, "nvlist/binary", "test", 4);
+
+ CHECK(nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free(nvl, "nvlist/null");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free(nvl, "nvlist/bool");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free(nvl, "nvlist/number");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free(nvl, "nvlist/string");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free(nvl, "nvlist/nvlist");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free(nvl, "nvlist/descriptor");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ nvlist_free(nvl, "nvlist/binary");
+ CHECK(!nvlist_exists_null(nvl, "nvlist/null"));
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool"));
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number"));
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string"));
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor"));
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/binary"));
+
+ CHECK(nvlist_empty(nvl));
+
+ nvlist_destroy(nvl);
+
+ return (0);
+}
diff --git a/lib/libnv/tests/nvlist_get_test.c b/lib/libnv/tests/nvlist_get_test.c
new file mode 100644
index 0000000..b4468db
--- /dev/null
+++ b/lib/libnv/tests/nvlist_get_test.c
@@ -0,0 +1,182 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <nv.h>
+
+static int ntest = 1;
+
+#define CHECK(expr) do { \
+ if ((expr)) \
+ printf("ok # %d %s:%u\n", ntest, __FILE__, __LINE__); \
+ else \
+ printf("not ok # %d %s:%u\n", ntest, __FILE__, __LINE__);\
+ ntest++; \
+} while (0)
+
+#define fd_is_valid(fd) (fcntl((fd), F_GETFL) != -1 || errno != EBADF)
+
+int
+main(void)
+{
+ const nvlist_t *cnvl;
+ nvlist_t *nvl;
+ size_t size;
+
+ printf("1..83\n");
+
+ nvl = nvlist_create(0);
+
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool/true"));
+ nvlist_add_bool(nvl, "nvlist/bool/true", true);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_get_bool(nvl, "nvlist/bool/true") == true);
+
+ CHECK(!nvlist_exists_bool(nvl, "nvlist/bool/false"));
+ nvlist_add_bool(nvl, "nvlist/bool/false", false);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_get_bool(nvl, "nvlist/bool/false") == false);
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/0"));
+ nvlist_add_number(nvl, "nvlist/number/0", 0);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_get_number(nvl, "nvlist/number/0") == 0);
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/1"));
+ nvlist_add_number(nvl, "nvlist/number/1", 1);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_get_number(nvl, "nvlist/number/1") == 1);
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/-1"));
+ nvlist_add_number(nvl, "nvlist/number/-1", -1);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK((int)nvlist_get_number(nvl, "nvlist/number/-1") == -1);
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/UINT64_MAX"));
+ nvlist_add_number(nvl, "nvlist/number/UINT64_MAX", UINT64_MAX);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_get_number(nvl, "nvlist/number/UINT64_MAX") == UINT64_MAX);
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/INT64_MIN"));
+ nvlist_add_number(nvl, "nvlist/number/INT64_MIN", INT64_MIN);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK((int64_t)nvlist_get_number(nvl, "nvlist/number/INT64_MIN") == INT64_MIN);
+
+ CHECK(!nvlist_exists_number(nvl, "nvlist/number/INT64_MAX"));
+ nvlist_add_number(nvl, "nvlist/number/INT64_MAX", INT64_MAX);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK((int64_t)nvlist_get_number(nvl, "nvlist/number/INT64_MAX") == INT64_MAX);
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string/"));
+ nvlist_add_string(nvl, "nvlist/string/", "");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/"), "") == 0);
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string/x"));
+ nvlist_add_string(nvl, "nvlist/string/x", "x");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/x"), "x") == 0);
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+ nvlist_add_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz");
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"), "abcdefghijklmnopqrstuvwxyz") == 0);
+
+ CHECK(!nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
+ nvlist_add_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", STDERR_FILENO);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(fd_is_valid(nvlist_get_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO")));
+
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/binary/x"));
+ nvlist_add_binary(nvl, "nvlist/binary/x", "x", 1);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/x", NULL), "x", 1) == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/x", &size), "x", 1) == 0);
+ CHECK(size == 1);
+
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
+ nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz"));
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz"));
+
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl);
+ CHECK(nvlist_error(nvl) == 0);
+ cnvl = nvlist_get_nvlist(nvl, "nvlist/nvlist");
+ CHECK(nvlist_get_bool(cnvl, "nvlist/bool/true") == true);
+ CHECK(nvlist_get_bool(cnvl, "nvlist/bool/false") == false);
+ CHECK(nvlist_get_number(cnvl, "nvlist/number/0") == 0);
+ CHECK(nvlist_get_number(cnvl, "nvlist/number/1") == 1);
+ CHECK((int)nvlist_get_number(cnvl, "nvlist/number/-1") == -1);
+ CHECK(nvlist_get_number(cnvl, "nvlist/number/UINT64_MAX") == UINT64_MAX);
+ CHECK((int64_t)nvlist_get_number(cnvl, "nvlist/number/INT64_MIN") == INT64_MIN);
+ CHECK((int64_t)nvlist_get_number(cnvl, "nvlist/number/INT64_MAX") == INT64_MAX);
+ CHECK(strcmp(nvlist_get_string(cnvl, "nvlist/string/"), "") == 0);
+ CHECK(strcmp(nvlist_get_string(cnvl, "nvlist/string/x"), "x") == 0);
+ CHECK(strcmp(nvlist_get_string(cnvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"), "abcdefghijklmnopqrstuvwxyz") == 0);
+ /* TODO */
+ CHECK(memcmp(nvlist_get_binary(cnvl, "nvlist/binary/x", NULL), "x", 1) == 0);
+ CHECK(memcmp(nvlist_get_binary(cnvl, "nvlist/binary/x", &size), "x", 1) == 0);
+ CHECK(size == 1);
+ CHECK(memcmp(nvlist_get_binary(cnvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(memcmp(nvlist_get_binary(cnvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz"));
+
+ CHECK(nvlist_get_bool(nvl, "nvlist/bool/true") == true);
+ CHECK(nvlist_get_bool(nvl, "nvlist/bool/false") == false);
+ CHECK(nvlist_get_number(nvl, "nvlist/number/0") == 0);
+ CHECK(nvlist_get_number(nvl, "nvlist/number/1") == 1);
+ CHECK((int)nvlist_get_number(nvl, "nvlist/number/-1") == -1);
+ CHECK(nvlist_get_number(nvl, "nvlist/number/UINT64_MAX") == UINT64_MAX);
+ CHECK((int64_t)nvlist_get_number(nvl, "nvlist/number/INT64_MIN") == INT64_MIN);
+ CHECK((int64_t)nvlist_get_number(nvl, "nvlist/number/INT64_MAX") == INT64_MAX);
+ CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/"), "") == 0);
+ CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/x"), "x") == 0);
+ CHECK(strcmp(nvlist_get_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"), "abcdefghijklmnopqrstuvwxyz") == 0);
+ CHECK(fd_is_valid(nvlist_get_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO")));
+ CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/x", NULL), "x", 1) == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/x", &size), "x", 1) == 0);
+ CHECK(size == 1);
+ CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz"));
+
+ nvlist_destroy(nvl);
+
+ return (0);
+}
diff --git a/lib/libnv/tests/nvlist_move_test.c b/lib/libnv/tests/nvlist_move_test.c
new file mode 100644
index 0000000..760399d
--- /dev/null
+++ b/lib/libnv/tests/nvlist_move_test.c
@@ -0,0 +1,161 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <nv.h>
+
+static int ntest = 1;
+
+#define CHECK(expr) do { \
+ if ((expr)) \
+ printf("ok # %d %s:%u\n", ntest, __FILE__, __LINE__); \
+ else \
+ printf("not ok # %d %s:%u\n", ntest, __FILE__, __LINE__);\
+ ntest++; \
+} while (0)
+
+int
+main(void)
+{
+ const nvlist_t *cnvl;
+ nvlist_t *nvl;
+ void *ptr;
+ size_t size;
+ int fd;
+
+ printf("1..52\n");
+
+ nvl = nvlist_create(0);
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string/"));
+ ptr = strdup("");
+ CHECK(ptr != NULL);
+ nvlist_move_string(nvl, "nvlist/string/", ptr);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/"));
+ CHECK(ptr == nvlist_get_string(nvl, "nvlist/string/"));
+
+ CHECK(!nvlist_exists_string(nvl, "nvlist/string/x"));
+ ptr = strdup("x");
+ CHECK(ptr != NULL);
+ nvlist_move_string(nvl, "nvlist/string/x", ptr);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/x"));
+ CHECK(ptr == nvlist_get_string(nvl, "nvlist/string/x"));
+
+ CHECK(!nvlist_exists_string(nvl,
+ "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+ ptr = strdup("abcdefghijklmnopqrstuvwxyz");
+ CHECK(ptr != NULL);
+ nvlist_move_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz",
+ ptr);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_string(nvl,
+ "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+ CHECK(ptr ==
+ nvlist_get_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+
+ CHECK(!nvlist_exists_descriptor(nvl,
+ "nvlist/descriptor/STDERR_FILENO"));
+ fd = dup(STDERR_FILENO);
+ CHECK(fd >= 0);
+ nvlist_move_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", fd);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
+ CHECK(fd ==
+ nvlist_get_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
+
+ CHECK(!nvlist_exists_binary(nvl, "nvlist/binary/x"));
+ ptr = malloc(1);
+ CHECK(ptr != NULL);
+ memcpy(ptr, "x", 1);
+ nvlist_move_binary(nvl, "nvlist/binary/x", ptr, 1);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary/x"));
+ CHECK(ptr == nvlist_get_binary(nvl, "nvlist/binary/x", NULL));
+ CHECK(ptr == nvlist_get_binary(nvl, "nvlist/binary/x", &size));
+ CHECK(size == 1);
+
+ CHECK(!nvlist_exists_binary(nvl,
+ "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
+ ptr = malloc(sizeof("abcdefghijklmnopqrstuvwxyz"));
+ CHECK(ptr != NULL);
+ memcpy(ptr, "abcdefghijklmnopqrstuvwxyz",
+ sizeof("abcdefghijklmnopqrstuvwxyz"));
+ nvlist_move_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz",
+ ptr, sizeof("abcdefghijklmnopqrstuvwxyz"));
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_binary(nvl,
+ "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
+ CHECK(ptr == nvlist_get_binary(nvl,
+ "nvlist/binary/abcdefghijklmnopqrstuvwxyz", NULL));
+ CHECK(ptr == nvlist_get_binary(nvl,
+ "nvlist/binary/abcdefghijklmnopqrstuvwxyz", &size));
+ CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz"));
+
+ CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ ptr = nvlist_clone(nvl);
+ CHECK(ptr != NULL);
+ nvlist_move_nvlist(nvl, "nvlist/nvlist", ptr);
+ CHECK(nvlist_error(nvl) == 0);
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+ CHECK(ptr == nvlist_get_nvlist(nvl, "nvlist/nvlist"));
+
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/"));
+ CHECK(nvlist_exists_string(nvl, "nvlist/string/x"));
+ CHECK(nvlist_exists_string(nvl,
+ "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+ CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
+ CHECK(nvlist_exists_binary(nvl, "nvlist/binary/x"));
+ CHECK(nvlist_exists_binary(nvl,
+ "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
+ CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
+
+ cnvl = nvlist_get_nvlist(nvl, "nvlist/nvlist");
+ CHECK(nvlist_exists_string(cnvl, "nvlist/string/"));
+ CHECK(nvlist_exists_string(cnvl, "nvlist/string/x"));
+ CHECK(nvlist_exists_string(cnvl,
+ "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
+ CHECK(nvlist_exists_descriptor(cnvl,
+ "nvlist/descriptor/STDERR_FILENO"));
+ CHECK(nvlist_exists_binary(cnvl, "nvlist/binary/x"));
+ CHECK(nvlist_exists_binary(cnvl,
+ "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
+
+ nvlist_destroy(nvl);
+
+ return (0);
+}
diff --git a/lib/libnv/tests/nvlist_send_recv_test.c b/lib/libnv/tests/nvlist_send_recv_test.c
new file mode 100644
index 0000000..1b083c3
--- /dev/null
+++ b/lib/libnv/tests/nvlist_send_recv_test.c
@@ -0,0 +1,342 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <nv.h>
+
+static int ntest = 1;
+
+#define CHECK(expr) do { \
+ if ((expr)) \
+ printf("ok # %d %s:%u\n", ntest, __FILE__, __LINE__); \
+ else \
+ printf("not ok # %d %s:%u\n", ntest, __FILE__, __LINE__);\
+ ntest++; \
+} while (0)
+
+#define fd_is_valid(fd) (fcntl((fd), F_GETFL) != -1 || errno != EBADF)
+
+static void
+child(int sock)
+{
+ nvlist_t *nvl;
+ nvlist_t *empty;
+
+ nvl = nvlist_create(0);
+ empty = nvlist_create(0);
+
+ nvlist_add_bool(nvl, "nvlist/bool/true", true);
+ nvlist_add_bool(nvl, "nvlist/bool/false", false);
+ nvlist_add_number(nvl, "nvlist/number/0", 0);
+ nvlist_add_number(nvl, "nvlist/number/1", 1);
+ nvlist_add_number(nvl, "nvlist/number/-1", -1);
+ nvlist_add_number(nvl, "nvlist/number/UINT64_MAX", UINT64_MAX);
+ nvlist_add_number(nvl, "nvlist/number/INT64_MIN", INT64_MIN);
+ nvlist_add_number(nvl, "nvlist/number/INT64_MAX", INT64_MAX);
+ nvlist_add_string(nvl, "nvlist/string/", "");
+ nvlist_add_string(nvl, "nvlist/string/x", "x");
+ nvlist_add_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz");
+ nvlist_add_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", STDERR_FILENO);
+ nvlist_add_binary(nvl, "nvlist/binary/x", "x", 1);
+ nvlist_add_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz"));
+ nvlist_move_nvlist(nvl, "nvlist/nvlist/empty", empty);
+ nvlist_add_nvlist(nvl, "nvlist/nvlist", nvl);
+
+ nvlist_send(sock, nvl);
+
+ nvlist_destroy(nvl);
+}
+
+static void
+parent(int sock)
+{
+ nvlist_t *nvl;
+ const nvlist_t *cnvl, *empty;
+ const char *name, *cname;
+ void *cookie, *ccookie;
+ int type, ctype;
+ size_t size;
+
+ nvl = nvlist_recv(sock);
+ CHECK(nvlist_error(nvl) == 0);
+ if (nvlist_error(nvl) != 0)
+ err(1, "nvlist_recv() failed");
+
+ cookie = NULL;
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_BOOL);
+ CHECK(strcmp(name, "nvlist/bool/true") == 0);
+ CHECK(nvlist_get_bool(nvl, name) == true);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_BOOL);
+ CHECK(strcmp(name, "nvlist/bool/false") == 0);
+ CHECK(nvlist_get_bool(nvl, name) == false);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_NUMBER);
+ CHECK(strcmp(name, "nvlist/number/0") == 0);
+ CHECK(nvlist_get_number(nvl, name) == 0);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_NUMBER);
+ CHECK(strcmp(name, "nvlist/number/1") == 0);
+ CHECK(nvlist_get_number(nvl, name) == 1);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_NUMBER);
+ CHECK(strcmp(name, "nvlist/number/-1") == 0);
+ CHECK((int)nvlist_get_number(nvl, name) == -1);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_NUMBER);
+ CHECK(strcmp(name, "nvlist/number/UINT64_MAX") == 0);
+ CHECK(nvlist_get_number(nvl, name) == UINT64_MAX);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_NUMBER);
+ CHECK(strcmp(name, "nvlist/number/INT64_MIN") == 0);
+ CHECK((int64_t)nvlist_get_number(nvl, name) == INT64_MIN);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_NUMBER);
+ CHECK(strcmp(name, "nvlist/number/INT64_MAX") == 0);
+ CHECK((int64_t)nvlist_get_number(nvl, name) == INT64_MAX);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_STRING);
+ CHECK(strcmp(name, "nvlist/string/") == 0);
+ CHECK(strcmp(nvlist_get_string(nvl, name), "") == 0);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_STRING);
+ CHECK(strcmp(name, "nvlist/string/x") == 0);
+ CHECK(strcmp(nvlist_get_string(nvl, name), "x") == 0);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_STRING);
+ CHECK(strcmp(name, "nvlist/string/abcdefghijklmnopqrstuvwxyz") == 0);
+ CHECK(strcmp(nvlist_get_string(nvl, name), "abcdefghijklmnopqrstuvwxyz") == 0);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_DESCRIPTOR);
+ CHECK(strcmp(name, "nvlist/descriptor/STDERR_FILENO") == 0);
+ CHECK(fd_is_valid(nvlist_get_descriptor(nvl, name)));
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_BINARY);
+ CHECK(strcmp(name, "nvlist/binary/x") == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, name, NULL), "x", 1) == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, name, &size), "x", 1) == 0);
+ CHECK(size == 1);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_BINARY);
+ CHECK(strcmp(name, "nvlist/binary/abcdefghijklmnopqrstuvwxyz") == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, name, NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(memcmp(nvlist_get_binary(nvl, name, &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz"));
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_NVLIST);
+ CHECK(strcmp(name, "nvlist/nvlist/empty") == 0);
+ cnvl = nvlist_get_nvlist(nvl, name);
+ CHECK(nvlist_empty(cnvl));
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name != NULL);
+ CHECK(type == NV_TYPE_NVLIST);
+ CHECK(strcmp(name, "nvlist/nvlist") == 0);
+ cnvl = nvlist_get_nvlist(nvl, name);
+
+ ccookie = NULL;
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_BOOL);
+ CHECK(strcmp(cname, "nvlist/bool/true") == 0);
+ CHECK(nvlist_get_bool(cnvl, cname) == true);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_BOOL);
+ CHECK(strcmp(cname, "nvlist/bool/false") == 0);
+ CHECK(nvlist_get_bool(cnvl, cname) == false);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_NUMBER);
+ CHECK(strcmp(cname, "nvlist/number/0") == 0);
+ CHECK(nvlist_get_number(cnvl, cname) == 0);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_NUMBER);
+ CHECK(strcmp(cname, "nvlist/number/1") == 0);
+ CHECK(nvlist_get_number(cnvl, cname) == 1);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_NUMBER);
+ CHECK(strcmp(cname, "nvlist/number/-1") == 0);
+ CHECK((int)nvlist_get_number(cnvl, cname) == -1);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_NUMBER);
+ CHECK(strcmp(cname, "nvlist/number/UINT64_MAX") == 0);
+ CHECK(nvlist_get_number(cnvl, cname) == UINT64_MAX);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_NUMBER);
+ CHECK(strcmp(cname, "nvlist/number/INT64_MIN") == 0);
+ CHECK((int64_t)nvlist_get_number(cnvl, cname) == INT64_MIN);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_NUMBER);
+ CHECK(strcmp(cname, "nvlist/number/INT64_MAX") == 0);
+ CHECK((int64_t)nvlist_get_number(cnvl, cname) == INT64_MAX);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_STRING);
+ CHECK(strcmp(cname, "nvlist/string/") == 0);
+ CHECK(strcmp(nvlist_get_string(cnvl, cname), "") == 0);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_STRING);
+ CHECK(strcmp(cname, "nvlist/string/x") == 0);
+ CHECK(strcmp(nvlist_get_string(cnvl, cname), "x") == 0);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_STRING);
+ CHECK(strcmp(cname, "nvlist/string/abcdefghijklmnopqrstuvwxyz") == 0);
+ CHECK(strcmp(nvlist_get_string(cnvl, cname), "abcdefghijklmnopqrstuvwxyz") == 0);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_DESCRIPTOR);
+ CHECK(strcmp(cname, "nvlist/descriptor/STDERR_FILENO") == 0);
+ CHECK(fd_is_valid(nvlist_get_descriptor(cnvl, cname)));
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_BINARY);
+ CHECK(strcmp(cname, "nvlist/binary/x") == 0);
+ CHECK(memcmp(nvlist_get_binary(cnvl, cname, NULL), "x", 1) == 0);
+ CHECK(memcmp(nvlist_get_binary(cnvl, cname, &size), "x", 1) == 0);
+ CHECK(size == 1);
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_BINARY);
+ CHECK(strcmp(cname, "nvlist/binary/abcdefghijklmnopqrstuvwxyz") == 0);
+ CHECK(memcmp(nvlist_get_binary(cnvl, cname, NULL), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(memcmp(nvlist_get_binary(cnvl, cname, &size), "abcdefghijklmnopqrstuvwxyz", sizeof("abcdefghijklmnopqrstuvwxyz")) == 0);
+ CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz"));
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname != NULL);
+ CHECK(ctype == NV_TYPE_NVLIST);
+ CHECK(strcmp(cname, "nvlist/nvlist/empty") == 0);
+ empty = nvlist_get_nvlist(cnvl, cname);
+ CHECK(nvlist_empty(empty));
+
+ cname = nvlist_next(cnvl, &ctype, &ccookie);
+ CHECK(cname == NULL);
+
+ name = nvlist_next(nvl, &type, &cookie);
+ CHECK(name == NULL);
+}
+
+int
+main(void)
+{
+ int status, socks[2];
+ pid_t pid;
+
+ printf("1..134\n");
+ fflush(stdout);
+
+ if (socketpair(PF_UNIX, SOCK_STREAM, 0, socks) < 0)
+ err(1, "socketpair() failed");
+ pid = fork();
+ switch (pid) {
+ case -1:
+ /* Failure. */
+ err(1, "unable to fork");
+ case 0:
+ /* Child. */
+ close(socks[0]);
+ child(socks[1]);
+ return (0);
+ default:
+ /* Parent. */
+ close(socks[1]);
+ parent(socks[0]);
+ break;
+ }
+
+ if (waitpid(pid, &status, 0) < 0)
+ err(1, "waitpid() failed");
+
+ return (0);
+}
diff --git a/lib/msun/tests/Makefile b/lib/msun/tests/Makefile
index 7199ea7..ffa1765 100644
--- a/lib/msun/tests/Makefile
+++ b/lib/msun/tests/Makefile
@@ -36,12 +36,34 @@ NETBSD_ATF_TESTS_C+= sqrt_test
NETBSD_ATF_TESTS_C+= tan_test
NETBSD_ATF_TESTS_C+= tanh_test
+TAP_TESTS_C+= cexp_test
+TAP_TESTS_C+= conj_test
+TAP_TESTS_C+= csqrt_test
+TAP_TESTS_C+= fenv_test
+TAP_TESTS_C+= fmaxmin_test
+TAP_TESTS_C+= ilogb_test
+TAP_TESTS_C+= invctrig_test
+TAP_TESTS_C+= logarithm_test
+TAP_TESTS_C+= lrint_test
+TAP_TESTS_C+= nan_test
+TAP_TESTS_C+= nearbyint_test
+TAP_TESTS_C+= next_test
+TAP_TESTS_C+= rem_test
+TAP_TESTS_C+= trig_test
+
+.for t in ${TAP_TESTS_C}
+CFLAGS.$t+= -O0
+CFLAGS.$t+= -I${SRCTOP}/tools/regression/lib/msun
+.endfor
+
CSTD= c99
LDADD+= -lm
DPADD+= ${LIBM}
#COPTS+= -Wfloat-equal
+IGNORE_PRAGMA=
+
# Copied from lib/msun/Makefile
.if ${MACHINE_CPUARCH} == "i386"
ARCH_SUBDIR= i387
diff --git a/lib/msun/tests/cexp_test.c b/lib/msun/tests/cexp_test.c
new file mode 100644
index 0000000..6be71ad
--- /dev/null
+++ b/lib/msun/tests/cexp_test.c
@@ -0,0 +1,322 @@
+/*-
+ * Copyright (c) 2008-2011 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+/*
+ * Tests for corner cases in cexp*().
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+
+#include <assert.h>
+#include <complex.h>
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "test-utils.h"
+
+#pragma STDC FENV_ACCESS ON
+#pragma STDC CX_LIMITED_RANGE OFF
+
+/*
+ * Test that a function returns the correct value and sets the
+ * exception flags correctly. The exceptmask specifies which
+ * exceptions we should check. We need to be lenient for several
+ * reasons, but mainly because on some architectures it's impossible
+ * to raise FE_OVERFLOW without raising FE_INEXACT. In some cases,
+ * whether cexp() raises an invalid exception is unspecified.
+ *
+ * These are macros instead of functions so that assert provides more
+ * meaningful error messages.
+ *
+ * XXX The volatile here is to avoid gcc's bogus constant folding and work
+ * around the lack of support for the FENV_ACCESS pragma.
+ */
+#define test(func, z, result, exceptmask, excepts, checksign) do { \
+ volatile long double complex _d = z; \
+ assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
+ assert(cfpequal_cs((func)(_d), (result), (checksign))); \
+ assert(((void)(func), fetestexcept(exceptmask) == (excepts))); \
+} while (0)
+
+/* Test within a given tolerance. */
+#define test_tol(func, z, result, tol) do { \
+ volatile long double complex _d = z; \
+ assert(cfpequal_tol((func)(_d), (result), (tol), \
+ FPE_ABS_ZERO | CS_BOTH)); \
+} while (0)
+
+/* Test all the functions that compute cexp(x). */
+#define testall(x, result, exceptmask, excepts, checksign) do { \
+ test(cexp, x, result, exceptmask, excepts, checksign); \
+ test(cexpf, x, result, exceptmask, excepts, checksign); \
+} while (0)
+
+/*
+ * Test all the functions that compute cexp(x), within a given tolerance.
+ * The tolerance is specified in ulps.
+ */
+#define testall_tol(x, result, tol) do { \
+ test_tol(cexp, x, result, tol * DBL_ULP()); \
+ test_tol(cexpf, x, result, tol * FLT_ULP()); \
+} while (0)
+
+/* Various finite non-zero numbers to test. */
+static const float finites[] =
+{ -42.0e20, -1.0, -1.0e-10, -0.0, 0.0, 1.0e-10, 1.0, 42.0e20 };
+
+
+/* Tests for 0 */
+void
+test_zero(void)
+{
+
+ /* cexp(0) = 1, no exceptions raised */
+ testall(0.0, 1.0, ALL_STD_EXCEPT, 0, 1);
+ testall(-0.0, 1.0, ALL_STD_EXCEPT, 0, 1);
+ testall(CMPLXL(0.0, -0.0), CMPLXL(1.0, -0.0), ALL_STD_EXCEPT, 0, 1);
+ testall(CMPLXL(-0.0, -0.0), CMPLXL(1.0, -0.0), ALL_STD_EXCEPT, 0, 1);
+}
+
+/*
+ * Tests for NaN. The signs of the results are indeterminate unless the
+ * imaginary part is 0.
+ */
+void
+test_nan()
+{
+ int i;
+
+ /* cexp(x + NaNi) = NaN + NaNi and optionally raises invalid */
+ /* cexp(NaN + yi) = NaN + NaNi and optionally raises invalid (|y|>0) */
+ for (i = 0; i < nitems(finites); i++) {
+ printf("# Run %d..\n", i);
+ testall(CMPLXL(finites[i], NAN), CMPLXL(NAN, NAN),
+ ALL_STD_EXCEPT & ~FE_INVALID, 0, 0);
+ if (finites[i] == 0.0)
+ continue;
+ /* XXX FE_INEXACT shouldn't be raised here */
+ testall(CMPLXL(NAN, finites[i]), CMPLXL(NAN, NAN),
+ ALL_STD_EXCEPT & ~(FE_INVALID | FE_INEXACT), 0, 0);
+ }
+
+ /* cexp(NaN +- 0i) = NaN +- 0i */
+ testall(CMPLXL(NAN, 0.0), CMPLXL(NAN, 0.0), ALL_STD_EXCEPT, 0, 1);
+ testall(CMPLXL(NAN, -0.0), CMPLXL(NAN, -0.0), ALL_STD_EXCEPT, 0, 1);
+
+ /* cexp(inf + NaN i) = inf + nan i */
+ testall(CMPLXL(INFINITY, NAN), CMPLXL(INFINITY, NAN),
+ ALL_STD_EXCEPT, 0, 0);
+ /* cexp(-inf + NaN i) = 0 */
+ testall(CMPLXL(-INFINITY, NAN), CMPLXL(0.0, 0.0),
+ ALL_STD_EXCEPT, 0, 0);
+ /* cexp(NaN + NaN i) = NaN + NaN i */
+ testall(CMPLXL(NAN, NAN), CMPLXL(NAN, NAN),
+ ALL_STD_EXCEPT, 0, 0);
+}
+
+void
+test_inf(void)
+{
+ int i;
+
+ /* cexp(x + inf i) = NaN + NaNi and raises invalid */
+ for (i = 0; i < nitems(finites); i++) {
+ printf("# Run %d..\n", i);
+ testall(CMPLXL(finites[i], INFINITY), CMPLXL(NAN, NAN),
+ ALL_STD_EXCEPT, FE_INVALID, 1);
+ }
+ /* cexp(-inf + yi) = 0 * (cos(y) + sin(y)i) */
+ /* XXX shouldn't raise an inexact exception */
+ testall(CMPLXL(-INFINITY, M_PI_4), CMPLXL(0.0, 0.0),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ testall(CMPLXL(-INFINITY, 3 * M_PI_4), CMPLXL(-0.0, 0.0),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ testall(CMPLXL(-INFINITY, 5 * M_PI_4), CMPLXL(-0.0, -0.0),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ testall(CMPLXL(-INFINITY, 7 * M_PI_4), CMPLXL(0.0, -0.0),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ testall(CMPLXL(-INFINITY, 0.0), CMPLXL(0.0, 0.0),
+ ALL_STD_EXCEPT, 0, 1);
+ testall(CMPLXL(-INFINITY, -0.0), CMPLXL(0.0, -0.0),
+ ALL_STD_EXCEPT, 0, 1);
+ /* cexp(inf + yi) = inf * (cos(y) + sin(y)i) (except y=0) */
+ /* XXX shouldn't raise an inexact exception */
+ testall(CMPLXL(INFINITY, M_PI_4), CMPLXL(INFINITY, INFINITY),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ testall(CMPLXL(INFINITY, 3 * M_PI_4), CMPLXL(-INFINITY, INFINITY),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ testall(CMPLXL(INFINITY, 5 * M_PI_4), CMPLXL(-INFINITY, -INFINITY),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ testall(CMPLXL(INFINITY, 7 * M_PI_4), CMPLXL(INFINITY, -INFINITY),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ /* cexp(inf + 0i) = inf + 0i */
+ testall(CMPLXL(INFINITY, 0.0), CMPLXL(INFINITY, 0.0),
+ ALL_STD_EXCEPT, 0, 1);
+ testall(CMPLXL(INFINITY, -0.0), CMPLXL(INFINITY, -0.0),
+ ALL_STD_EXCEPT, 0, 1);
+}
+
+void
+test_reals(void)
+{
+ int i;
+
+ for (i = 0; i < nitems(finites); i++) {
+ /* XXX could check exceptions more meticulously */
+ printf("# Run %d..\n", i);
+ test(cexp, CMPLXL(finites[i], 0.0),
+ CMPLXL(exp(finites[i]), 0.0),
+ FE_INVALID | FE_DIVBYZERO, 0, 1);
+ test(cexp, CMPLXL(finites[i], -0.0),
+ CMPLXL(exp(finites[i]), -0.0),
+ FE_INVALID | FE_DIVBYZERO, 0, 1);
+ test(cexpf, CMPLXL(finites[i], 0.0),
+ CMPLXL(expf(finites[i]), 0.0),
+ FE_INVALID | FE_DIVBYZERO, 0, 1);
+ test(cexpf, CMPLXL(finites[i], -0.0),
+ CMPLXL(expf(finites[i]), -0.0),
+ FE_INVALID | FE_DIVBYZERO, 0, 1);
+ }
+}
+
+void
+test_imaginaries(void)
+{
+ int i;
+
+ for (i = 0; i < nitems(finites); i++) {
+ printf("# Run %d..\n", i);
+ test(cexp, CMPLXL(0.0, finites[i]),
+ CMPLXL(cos(finites[i]), sin(finites[i])),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ test(cexp, CMPLXL(-0.0, finites[i]),
+ CMPLXL(cos(finites[i]), sin(finites[i])),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ test(cexpf, CMPLXL(0.0, finites[i]),
+ CMPLXL(cosf(finites[i]), sinf(finites[i])),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ test(cexpf, CMPLXL(-0.0, finites[i]),
+ CMPLXL(cosf(finites[i]), sinf(finites[i])),
+ ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
+ }
+}
+
+void
+test_small(void)
+{
+ static const double tests[] = {
+ /* csqrt(a + bI) = x + yI */
+ /* a b x y */
+ 1.0, M_PI_4, M_SQRT2 * 0.5 * M_E, M_SQRT2 * 0.5 * M_E,
+ -1.0, M_PI_4, M_SQRT2 * 0.5 / M_E, M_SQRT2 * 0.5 / M_E,
+ 2.0, M_PI_2, 0.0, M_E * M_E,
+ M_LN2, M_PI, -2.0, 0.0,
+ };
+ double a, b;
+ double x, y;
+ int i;
+
+ for (i = 0; i < nitems(tests); i += 4) {
+ printf("# Run %d..\n", i);
+ a = tests[i];
+ b = tests[i + 1];
+ x = tests[i + 2];
+ y = tests[i + 3];
+ test_tol(cexp, CMPLXL(a, b), CMPLXL(x, y), 3 * DBL_ULP());
+
+ /* float doesn't have enough precision to pass these tests */
+ if (x == 0 || y == 0)
+ continue;
+ test_tol(cexpf, CMPLXL(a, b), CMPLXL(x, y), 1 * FLT_ULP());
+ }
+}
+
+/* Test inputs with a real part r that would overflow exp(r). */
+void
+test_large(void)
+{
+
+ test_tol(cexp, CMPLXL(709.79, 0x1p-1074),
+ CMPLXL(INFINITY, 8.94674309915433533273e-16), DBL_ULP());
+ test_tol(cexp, CMPLXL(1000, 0x1p-1074),
+ CMPLXL(INFINITY, 9.73344457300016401328e+110), DBL_ULP());
+ test_tol(cexp, CMPLXL(1400, 0x1p-1074),
+ CMPLXL(INFINITY, 5.08228858149196559681e+284), DBL_ULP());
+ test_tol(cexp, CMPLXL(900, 0x1.23456789abcdep-1020),
+ CMPLXL(INFINITY, 7.42156649354218408074e+83), DBL_ULP());
+ test_tol(cexp, CMPLXL(1300, 0x1.23456789abcdep-1020),
+ CMPLXL(INFINITY, 3.87514844965996756704e+257), DBL_ULP());
+
+ test_tol(cexpf, CMPLXL(88.73, 0x1p-149),
+ CMPLXL(INFINITY, 4.80265603e-07), 2 * FLT_ULP());
+ test_tol(cexpf, CMPLXL(90, 0x1p-149),
+ CMPLXL(INFINITY, 1.7101492622e-06f), 2 * FLT_ULP());
+ test_tol(cexpf, CMPLXL(192, 0x1p-149),
+ CMPLXL(INFINITY, 3.396809344e+38f), 2 * FLT_ULP());
+ test_tol(cexpf, CMPLXL(120, 0x1.234568p-120),
+ CMPLXL(INFINITY, 1.1163382522e+16f), 2 * FLT_ULP());
+ test_tol(cexpf, CMPLXL(170, 0x1.234568p-120),
+ CMPLXL(INFINITY, 5.7878851079e+37f), 2 * FLT_ULP());
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ printf("1..7\n");
+
+ test_zero();
+ printf("ok 1 - cexp zero\n");
+
+ test_nan();
+ printf("ok 2 - cexp nan\n");
+
+ test_inf();
+ printf("ok 3 - cexp inf\n");
+
+#if defined(__i386__)
+ printf("not ok 4 - cexp reals # TODO: PR # 191676 fails assertion on i386\n");
+#else
+ test_reals();
+ printf("ok 4 - cexp reals\n");
+#endif
+
+ test_imaginaries();
+ printf("ok 5 - cexp imaginaries\n");
+
+ test_small();
+ printf("ok 6 - cexp small\n");
+
+ test_large();
+ printf("ok 7 - cexp large\n");
+
+ return (0);
+}
diff --git a/lib/msun/tests/conj_test.c b/lib/msun/tests/conj_test.c
new file mode 100644
index 0000000..7426f9e
--- /dev/null
+++ b/lib/msun/tests/conj_test.c
@@ -0,0 +1,139 @@
+/*-
+ * Copyright (c) 2008 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+/*
+ * Tests for conj{,f,l}()
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <assert.h>
+#include <complex.h>
+#include <fenv.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "test-utils.h"
+
+#pragma STDC CX_LIMITED_RANGE OFF
+
+/* Make sure gcc doesn't use builtin versions of these or honor __pure2. */
+static float complex (*libconjf)(float complex) = conjf;
+static double complex (*libconj)(double complex) = conj;
+static long double complex (*libconjl)(long double complex) = conjl;
+static float (*libcrealf)(float complex) = crealf;
+static double (*libcreal)(double complex) = creal;
+static long double (*libcreall)(long double complex) = creall;
+static float (*libcimagf)(float complex) = cimagf;
+static double (*libcimag)(double complex) = cimag;
+static long double (*libcimagl)(long double complex) = cimagl;
+
+static const double tests[] = {
+ /* a + bI */
+ 0.0, 0.0,
+ 0.0, 1.0,
+ 1.0, 0.0,
+ -1.0, 0.0,
+ 1.0, -0.0,
+ 0.0, -1.0,
+ 2.0, 4.0,
+ 0.0, INFINITY,
+ 0.0, -INFINITY,
+ INFINITY, 0.0,
+ NAN, 1.0,
+ 1.0, NAN,
+ NAN, NAN,
+ -INFINITY, INFINITY,
+};
+
+int
+main(int argc, char *argv[])
+{
+ static const int ntests = sizeof(tests) / sizeof(tests[0]) / 2;
+ complex float in;
+ complex long double expected;
+ int i;
+
+ printf("1..%d\n", ntests * 3);
+
+ for (i = 0; i < ntests; i++) {
+ __real__ expected = __real__ in = tests[2 * i];
+ __imag__ in = tests[2 * i + 1];
+ __imag__ expected = -cimag(in);
+
+ assert(fpequal(libcrealf(in), __real__ in));
+ assert(fpequal(libcreal(in), __real__ in));
+ assert(fpequal(libcreall(in), __real__ in));
+ assert(fpequal(libcimagf(in), __imag__ in));
+ assert(fpequal(libcimag(in), __imag__ in));
+ assert(fpequal(libcimagl(in), __imag__ in));
+
+ feclearexcept(FE_ALL_EXCEPT);
+ if (!cfpequal(libconjf(in), expected)) {
+ printf("not ok %d\t# conjf(%#.2g + %#.2gI): "
+ "wrong value\n",
+ 3 * i + 1, creal(in), cimag(in));
+ } else if (fetestexcept(FE_ALL_EXCEPT)) {
+ printf("not ok %d\t# conjf(%#.2g + %#.2gI): "
+ "threw an exception\n",
+ 3 * i + 1, creal(in), cimag(in));
+ } else {
+ printf("ok %d\t\t# conjf(%#.2g + %#.2gI)\n",
+ 3 * i + 1, creal(in), cimag(in));
+ }
+
+ feclearexcept(FE_ALL_EXCEPT);
+ if (!cfpequal(libconj(in), expected)) {
+ printf("not ok %d\t# conj(%#.2g + %#.2gI): "
+ "wrong value\n",
+ 3 * i + 2, creal(in), cimag(in));
+ } else if (fetestexcept(FE_ALL_EXCEPT)) {
+ printf("not ok %d\t# conj(%#.2g + %#.2gI): "
+ "threw an exception\n",
+ 3 * i + 2, creal(in), cimag(in));
+ } else {
+ printf("ok %d\t\t# conj(%#.2g + %#.2gI)\n",
+ 3 * i + 2, creal(in), cimag(in));
+ }
+
+ feclearexcept(FE_ALL_EXCEPT);
+ if (!cfpequal(libconjl(in), expected)) {
+ printf("not ok %d\t# conjl(%#.2g + %#.2gI): "
+ "wrong value\n",
+ 3 * i + 3, creal(in), cimag(in));
+ } else if (fetestexcept(FE_ALL_EXCEPT)) {
+ printf("not ok %d\t# conjl(%#.2g + %#.2gI): "
+ "threw an exception\n",
+ 3 * i + 3, creal(in), cimag(in));
+ } else {
+ printf("ok %d\t\t# conjl(%#.2g + %#.2gI)\n",
+ 3 * i + 3, creal(in), cimag(in));
+ }
+ }
+
+ return (0);
+}
diff --git a/lib/msun/tests/csqrt_test.c b/lib/msun/tests/csqrt_test.c
new file mode 100644
index 0000000..aa119d1
--- /dev/null
+++ b/lib/msun/tests/csqrt_test.c
@@ -0,0 +1,295 @@
+/*-
+ * Copyright (c) 2007 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+/*
+ * Tests for csqrt{,f}()
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+
+#include <assert.h>
+#include <complex.h>
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "test-utils.h"
+
+/*
+ * This is a test hook that can point to csqrtl(), _csqrt(), or to _csqrtf().
+ * The latter two convert to float or double, respectively, and test csqrtf()
+ * and csqrt() with the same arguments.
+ */
+long double complex (*t_csqrt)(long double complex);
+
+static long double complex
+_csqrtf(long double complex d)
+{
+
+ return (csqrtf((float complex)d));
+}
+
+static long double complex
+_csqrt(long double complex d)
+{
+
+ return (csqrt((double complex)d));
+}
+
+#pragma STDC CX_LIMITED_RANGE OFF
+
+/*
+ * Compare d1 and d2 using special rules: NaN == NaN and +0 != -0.
+ * Fail an assertion if they differ.
+ */
+static void
+assert_equal(long double complex d1, long double complex d2)
+{
+
+ assert(cfpequal(d1, d2));
+}
+
+/*
+ * Test csqrt for some finite arguments where the answer is exact.
+ * (We do not test if it produces correctly rounded answers when the
+ * result is inexact, nor do we check whether it throws spurious
+ * exceptions.)
+ */
+static void
+test_finite()
+{
+ static const double tests[] = {
+ /* csqrt(a + bI) = x + yI */
+ /* a b x y */
+ 0, 8, 2, 2,
+ 0, -8, 2, -2,
+ 4, 0, 2, 0,
+ -4, 0, 0, 2,
+ 3, 4, 2, 1,
+ 3, -4, 2, -1,
+ -3, 4, 1, 2,
+ -3, -4, 1, -2,
+ 5, 12, 3, 2,
+ 7, 24, 4, 3,
+ 9, 40, 5, 4,
+ 11, 60, 6, 5,
+ 13, 84, 7, 6,
+ 33, 56, 7, 4,
+ 39, 80, 8, 5,
+ 65, 72, 9, 4,
+ 987, 9916, 74, 67,
+ 5289, 6640, 83, 40,
+ 460766389075.0, 16762287900.0, 678910, 12345
+ };
+ /*
+ * We also test some multiples of the above arguments. This
+ * array defines which multiples we use. Note that these have
+ * to be small enough to not cause overflow for float precision
+ * with all of the constants in the above table.
+ */
+ static const double mults[] = {
+ 1,
+ 2,
+ 3,
+ 13,
+ 16,
+ 0x1.p30,
+ 0x1.p-30,
+ };
+
+ double a, b;
+ double x, y;
+ int i, j;
+
+ for (i = 0; i < nitems(tests); i += 4) {
+ for (j = 0; j < nitems(mults); j++) {
+ a = tests[i] * mults[j] * mults[j];
+ b = tests[i + 1] * mults[j] * mults[j];
+ x = tests[i + 2] * mults[j];
+ y = tests[i + 3] * mults[j];
+ assert(t_csqrt(CMPLXL(a, b)) == CMPLXL(x, y));
+ }
+ }
+
+}
+
+/*
+ * Test the handling of +/- 0.
+ */
+static void
+test_zeros()
+{
+
+ assert_equal(t_csqrt(CMPLXL(0.0, 0.0)), CMPLXL(0.0, 0.0));
+ assert_equal(t_csqrt(CMPLXL(-0.0, 0.0)), CMPLXL(0.0, 0.0));
+ assert_equal(t_csqrt(CMPLXL(0.0, -0.0)), CMPLXL(0.0, -0.0));
+ assert_equal(t_csqrt(CMPLXL(-0.0, -0.0)), CMPLXL(0.0, -0.0));
+}
+
+/*
+ * Test the handling of infinities when the other argument is not NaN.
+ */
+static void
+test_infinities()
+{
+ static const double vals[] = {
+ 0.0,
+ -0.0,
+ 42.0,
+ -42.0,
+ INFINITY,
+ -INFINITY,
+ };
+
+ int i;
+
+ for (i = 0; i < nitems(vals); i++) {
+ if (isfinite(vals[i])) {
+ assert_equal(t_csqrt(CMPLXL(-INFINITY, vals[i])),
+ CMPLXL(0.0, copysignl(INFINITY, vals[i])));
+ assert_equal(t_csqrt(CMPLXL(INFINITY, vals[i])),
+ CMPLXL(INFINITY, copysignl(0.0, vals[i])));
+ }
+ assert_equal(t_csqrt(CMPLXL(vals[i], INFINITY)),
+ CMPLXL(INFINITY, INFINITY));
+ assert_equal(t_csqrt(CMPLXL(vals[i], -INFINITY)),
+ CMPLXL(INFINITY, -INFINITY));
+ }
+}
+
+/*
+ * Test the handling of NaNs.
+ */
+static void
+test_nans()
+{
+
+ assert(creall(t_csqrt(CMPLXL(INFINITY, NAN))) == INFINITY);
+ assert(isnan(cimagl(t_csqrt(CMPLXL(INFINITY, NAN)))));
+
+ assert(isnan(creall(t_csqrt(CMPLXL(-INFINITY, NAN)))));
+ assert(isinf(cimagl(t_csqrt(CMPLXL(-INFINITY, NAN)))));
+
+ assert_equal(t_csqrt(CMPLXL(NAN, INFINITY)),
+ CMPLXL(INFINITY, INFINITY));
+ assert_equal(t_csqrt(CMPLXL(NAN, -INFINITY)),
+ CMPLXL(INFINITY, -INFINITY));
+
+ assert_equal(t_csqrt(CMPLXL(0.0, NAN)), CMPLXL(NAN, NAN));
+ assert_equal(t_csqrt(CMPLXL(-0.0, NAN)), CMPLXL(NAN, NAN));
+ assert_equal(t_csqrt(CMPLXL(42.0, NAN)), CMPLXL(NAN, NAN));
+ assert_equal(t_csqrt(CMPLXL(-42.0, NAN)), CMPLXL(NAN, NAN));
+ assert_equal(t_csqrt(CMPLXL(NAN, 0.0)), CMPLXL(NAN, NAN));
+ assert_equal(t_csqrt(CMPLXL(NAN, -0.0)), CMPLXL(NAN, NAN));
+ assert_equal(t_csqrt(CMPLXL(NAN, 42.0)), CMPLXL(NAN, NAN));
+ assert_equal(t_csqrt(CMPLXL(NAN, -42.0)), CMPLXL(NAN, NAN));
+ assert_equal(t_csqrt(CMPLXL(NAN, NAN)), CMPLXL(NAN, NAN));
+}
+
+/*
+ * Test whether csqrt(a + bi) works for inputs that are large enough to
+ * cause overflow in hypot(a, b) + a. In this case we are using
+ * csqrt(115 + 252*I) == 14 + 9*I
+ * scaled up to near MAX_EXP.
+ */
+static void
+test_overflow(int maxexp)
+{
+ long double a, b;
+ long double complex result;
+
+ a = ldexpl(115 * 0x1p-8, maxexp);
+ b = ldexpl(252 * 0x1p-8, maxexp);
+ result = t_csqrt(CMPLXL(a, b));
+ assert(creall(result) == ldexpl(14 * 0x1p-4, maxexp / 2));
+ assert(cimagl(result) == ldexpl(9 * 0x1p-4, maxexp / 2));
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ printf("1..15\n");
+
+ /* Test csqrt() */
+ t_csqrt = _csqrt;
+
+ test_finite();
+ printf("ok 1 - csqrt\n");
+
+ test_zeros();
+ printf("ok 2 - csqrt\n");
+
+ test_infinities();
+ printf("ok 3 - csqrt\n");
+
+ test_nans();
+ printf("ok 4 - csqrt\n");
+
+ test_overflow(DBL_MAX_EXP);
+ printf("ok 5 - csqrt\n");
+
+ /* Now test csqrtf() */
+ t_csqrt = _csqrtf;
+
+ test_finite();
+ printf("ok 6 - csqrt\n");
+
+ test_zeros();
+ printf("ok 7 - csqrt\n");
+
+ test_infinities();
+ printf("ok 8 - csqrt\n");
+
+ test_nans();
+ printf("ok 9 - csqrt\n");
+
+ test_overflow(FLT_MAX_EXP);
+ printf("ok 10 - csqrt\n");
+
+ /* Now test csqrtl() */
+ t_csqrt = csqrtl;
+
+ test_finite();
+ printf("ok 11 - csqrt\n");
+
+ test_zeros();
+ printf("ok 12 - csqrt\n");
+
+ test_infinities();
+ printf("ok 13 - csqrt\n");
+
+ test_nans();
+ printf("ok 14 - csqrt\n");
+
+ test_overflow(LDBL_MAX_EXP);
+ printf("ok 15 - csqrt\n");
+
+ return (0);
+}
diff --git a/tools/regression/lib/msun/test-fenv.c b/lib/msun/tests/fenv_test.c
index 0ea6e42..0ea6e42 100644
--- a/tools/regression/lib/msun/test-fenv.c
+++ b/lib/msun/tests/fenv_test.c
diff --git a/tools/regression/lib/msun/test-fmaxmin.c b/lib/msun/tests/fmaxmin_test.c
index 7ddcc87..7ddcc87 100644
--- a/tools/regression/lib/msun/test-fmaxmin.c
+++ b/lib/msun/tests/fmaxmin_test.c
diff --git a/tools/regression/lib/msun/test-ilogb.c b/lib/msun/tests/ilogb_test.c
index a1440c4..a1440c4 100644
--- a/tools/regression/lib/msun/test-ilogb.c
+++ b/lib/msun/tests/ilogb_test.c
diff --git a/tools/regression/lib/msun/test-invctrig.c b/lib/msun/tests/invctrig_test.c
index 34e78a1..34e78a1 100644
--- a/tools/regression/lib/msun/test-invctrig.c
+++ b/lib/msun/tests/invctrig_test.c
diff --git a/tools/regression/lib/msun/test-logarithm.c b/lib/msun/tests/logarithm_test.c
index 18b9ebe..18b9ebe 100644
--- a/tools/regression/lib/msun/test-logarithm.c
+++ b/lib/msun/tests/logarithm_test.c
diff --git a/tools/regression/lib/msun/test-lrint.c b/lib/msun/tests/lrint_test.c
index ba099aa..ba099aa 100644
--- a/tools/regression/lib/msun/test-lrint.c
+++ b/lib/msun/tests/lrint_test.c
diff --git a/tools/regression/lib/msun/test-nan.c b/lib/msun/tests/nan_test.c
index c12926b..c12926b 100644
--- a/tools/regression/lib/msun/test-nan.c
+++ b/lib/msun/tests/nan_test.c
diff --git a/tools/regression/lib/msun/test-nearbyint.c b/lib/msun/tests/nearbyint_test.c
index 602ea2a..602ea2a 100644
--- a/tools/regression/lib/msun/test-nearbyint.c
+++ b/lib/msun/tests/nearbyint_test.c
diff --git a/tools/regression/lib/msun/test-next.c b/lib/msun/tests/next_test.c
index d16fa77..d16fa77 100644
--- a/tools/regression/lib/msun/test-next.c
+++ b/lib/msun/tests/next_test.c
diff --git a/tools/regression/lib/msun/test-rem.c b/lib/msun/tests/rem_test.c
index 36e3476..36e3476 100644
--- a/tools/regression/lib/msun/test-rem.c
+++ b/lib/msun/tests/rem_test.c
diff --git a/lib/msun/tests/trig_test.c b/lib/msun/tests/trig_test.c
new file mode 100644
index 0000000..1dcce1f
--- /dev/null
+++ b/lib/msun/tests/trig_test.c
@@ -0,0 +1,280 @@
+/*-
+ * Copyright (c) 2008 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+/*
+ * Tests for corner cases in trigonometric functions. Some accuracy tests
+ * are included as well, but these are very basic sanity checks, not
+ * intended to be comprehensive.
+ *
+ * The program for generating representable numbers near multiples of pi is
+ * available at http://www.cs.berkeley.edu/~wkahan/testpi/ .
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+
+#include <assert.h>
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "test-utils.h"
+
+#pragma STDC FENV_ACCESS ON
+
+/*
+ * Test that a function returns the correct value and sets the
+ * exception flags correctly. The exceptmask specifies which
+ * exceptions we should check. We need to be lenient for several
+ * reasons, but mainly because on some architectures it's impossible
+ * to raise FE_OVERFLOW without raising FE_INEXACT.
+ *
+ * These are macros instead of functions so that assert provides more
+ * meaningful error messages.
+ *
+ * XXX The volatile here is to avoid gcc's bogus constant folding and work
+ * around the lack of support for the FENV_ACCESS pragma.
+ */
+#define test(func, x, result, exceptmask, excepts) do { \
+ volatile long double _d = x; \
+ assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
+ assert(fpequal((func)(_d), (result))); \
+ assert(((void)(func), fetestexcept(exceptmask) == (excepts))); \
+} while (0)
+
+#define testall(prefix, x, result, exceptmask, excepts) do { \
+ test(prefix, x, (double)result, exceptmask, excepts); \
+ test(prefix##f, x, (float)result, exceptmask, excepts); \
+ test(prefix##l, x, result, exceptmask, excepts); \
+} while (0)
+
+#define testdf(prefix, x, result, exceptmask, excepts) do { \
+ test(prefix, x, (double)result, exceptmask, excepts); \
+ test(prefix##f, x, (float)result, exceptmask, excepts); \
+} while (0)
+
+/*
+ * Test special cases in sin(), cos(), and tan().
+ */
+static void
+run_special_tests(void)
+{
+
+ /* Values at 0 should be exact. */
+ testall(tan, 0.0, 0.0, ALL_STD_EXCEPT, 0);
+ testall(tan, -0.0, -0.0, ALL_STD_EXCEPT, 0);
+ testall(cos, 0.0, 1.0, ALL_STD_EXCEPT, 0);
+ testall(cos, -0.0, 1.0, ALL_STD_EXCEPT, 0);
+ testall(sin, 0.0, 0.0, ALL_STD_EXCEPT, 0);
+ testall(sin, -0.0, -0.0, ALL_STD_EXCEPT, 0);
+
+ /* func(+-Inf) == NaN */
+ testall(tan, INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall(sin, INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall(cos, INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall(tan, -INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall(sin, -INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall(cos, -INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+
+ /* func(NaN) == NaN */
+ testall(tan, NAN, NAN, ALL_STD_EXCEPT, 0);
+ testall(sin, NAN, NAN, ALL_STD_EXCEPT, 0);
+ testall(cos, NAN, NAN, ALL_STD_EXCEPT, 0);
+}
+
+/*
+ * Tests to ensure argument reduction for large arguments is accurate.
+ */
+static void
+run_reduction_tests(void)
+{
+ /* floats very close to odd multiples of pi */
+ static const float f_pi_odd[] = {
+ 85563208.0f,
+ 43998769152.0f,
+ 9.2763667655669323e+25f,
+ 1.5458357838905804e+29f,
+ };
+ /* doubles very close to odd multiples of pi */
+ static const double d_pi_odd[] = {
+ 3.1415926535897931,
+ 91.106186954104004,
+ 642615.9188844458,
+ 3397346.5699258847,
+ 6134899525417045.0,
+ 3.0213551960457761e+43,
+ 1.2646209897993783e+295,
+ 6.2083625380677099e+307,
+ };
+ /* long doubles very close to odd multiples of pi */
+#if LDBL_MANT_DIG == 64
+ static const long double ld_pi_odd[] = {
+ 1.1891886960373841596e+101L,
+ 1.07999475322710967206e+2087L,
+ 6.522151627890431836e+2147L,
+ 8.9368974898260328229e+2484L,
+ 9.2961044110572205863e+2555L,
+ 4.90208421886578286e+3189L,
+ 1.5275546401232615884e+3317L,
+ 1.7227465626338900093e+3565L,
+ 2.4160090594000745334e+3808L,
+ 9.8477555741888350649e+4314L,
+ 1.6061597222105160737e+4326L,
+ };
+#elif LDBL_MANT_DIG == 113
+ static const long double ld_pi_odd[] = {
+ /* XXX */
+ };
+#endif
+
+ int i;
+
+ for (i = 0; i < nitems(f_pi_odd); i++) {
+ assert(fabs(sinf(f_pi_odd[i])) < FLT_EPSILON);
+ assert(cosf(f_pi_odd[i]) == -1.0);
+ assert(fabs(tan(f_pi_odd[i])) < FLT_EPSILON);
+
+ assert(fabs(sinf(-f_pi_odd[i])) < FLT_EPSILON);
+ assert(cosf(-f_pi_odd[i]) == -1.0);
+ assert(fabs(tanf(-f_pi_odd[i])) < FLT_EPSILON);
+
+ assert(fabs(sinf(f_pi_odd[i] * 2)) < FLT_EPSILON);
+ assert(cosf(f_pi_odd[i] * 2) == 1.0);
+ assert(fabs(tanf(f_pi_odd[i] * 2)) < FLT_EPSILON);
+
+ assert(fabs(sinf(-f_pi_odd[i] * 2)) < FLT_EPSILON);
+ assert(cosf(-f_pi_odd[i] * 2) == 1.0);
+ assert(fabs(tanf(-f_pi_odd[i] * 2)) < FLT_EPSILON);
+ }
+
+ for (i = 0; i < nitems(d_pi_odd); i++) {
+ assert(fabs(sin(d_pi_odd[i])) < 2 * DBL_EPSILON);
+ assert(cos(d_pi_odd[i]) == -1.0);
+ assert(fabs(tan(d_pi_odd[i])) < 2 * DBL_EPSILON);
+
+ assert(fabs(sin(-d_pi_odd[i])) < 2 * DBL_EPSILON);
+ assert(cos(-d_pi_odd[i]) == -1.0);
+ assert(fabs(tan(-d_pi_odd[i])) < 2 * DBL_EPSILON);
+
+ assert(fabs(sin(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON);
+ assert(cos(d_pi_odd[i] * 2) == 1.0);
+ assert(fabs(tan(d_pi_odd[i] * 2)) < 2 * DBL_EPSILON);
+
+ assert(fabs(sin(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON);
+ assert(cos(-d_pi_odd[i] * 2) == 1.0);
+ assert(fabs(tan(-d_pi_odd[i] * 2)) < 2 * DBL_EPSILON);
+ }
+
+#if LDBL_MANT_DIG > 53
+ for (i = 0; i < nitems(ld_pi_odd); i++) {
+ assert(fabsl(sinl(ld_pi_odd[i])) < LDBL_EPSILON);
+ assert(cosl(ld_pi_odd[i]) == -1.0);
+ assert(fabsl(tanl(ld_pi_odd[i])) < LDBL_EPSILON);
+
+ assert(fabsl(sinl(-ld_pi_odd[i])) < LDBL_EPSILON);
+ assert(cosl(-ld_pi_odd[i]) == -1.0);
+ assert(fabsl(tanl(-ld_pi_odd[i])) < LDBL_EPSILON);
+
+ assert(fabsl(sinl(ld_pi_odd[i] * 2)) < LDBL_EPSILON);
+ assert(cosl(ld_pi_odd[i] * 2) == 1.0);
+ assert(fabsl(tanl(ld_pi_odd[i] * 2)) < LDBL_EPSILON);
+
+ assert(fabsl(sinl(-ld_pi_odd[i] * 2)) < LDBL_EPSILON);
+ assert(cosl(-ld_pi_odd[i] * 2) == 1.0);
+ assert(fabsl(tanl(-ld_pi_odd[i] * 2)) < LDBL_EPSILON);
+ }
+#endif
+}
+
+/*
+ * Tests the accuracy of these functions over the primary range.
+ */
+static void
+run_accuracy_tests(void)
+{
+
+ /* For small args, sin(x) = tan(x) = x, and cos(x) = 1. */
+ testall(sin, 0xd.50ee515fe4aea16p-114L, 0xd.50ee515fe4aea16p-114L,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ testall(tan, 0xd.50ee515fe4aea16p-114L, 0xd.50ee515fe4aea16p-114L,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ testall(cos, 0xd.50ee515fe4aea16p-114L, 1.0,
+ ALL_STD_EXCEPT, FE_INEXACT);
+
+ /*
+ * These tests should pass for f32, d64, and ld80 as long as
+ * the error is <= 0.75 ulp (round to nearest)
+ */
+#if LDBL_MANT_DIG <= 64
+#define testacc testall
+#else
+#define testacc testdf
+#endif
+ testacc(sin, 0.17255452780841205174L, 0.17169949801444412683L,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ testacc(sin, -0.75431944555904520893L, -0.68479288156557286353L,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ testacc(cos, 0.70556358769838947292L, 0.76124620693117771850L,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ testacc(cos, -0.34061437849088045332L, 0.94254960031831729956L,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ testacc(tan, -0.15862817413325692897L, -0.15997221861309522115L,
+ ALL_STD_EXCEPT, FE_INEXACT);
+ testacc(tan, 0.38374784931303813530L, 0.40376500259976759951L,
+ ALL_STD_EXCEPT, FE_INEXACT);
+
+ /*
+ * XXX missing:
+ * - tests for ld128
+ * - tests for other rounding modes (probably won't pass for now)
+ * - tests for large numbers that get reduced to hi+lo with lo!=0
+ */
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ printf("1..3\n");
+
+ run_special_tests();
+ printf("ok 1 - trig\n");
+
+#ifndef __i386__
+ run_reduction_tests();
+#endif
+ printf("ok 2 - trig\n");
+
+#ifndef __i386__
+ run_accuracy_tests();
+#endif
+ printf("ok 3 - trig\n");
+
+ return (0);
+}
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 76310dd..9a0860f 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -1115,7 +1115,6 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_Dyn **dyn_rpath,
#ifndef __mips__
case DT_DEBUG:
- /* XXX - not implemented yet */
if (!early)
dbg("Filling in DT_DEBUG entry");
((Elf_Dyn*)dynp)->d_un.d_ptr = (Elf_Addr) &r_debug;
diff --git a/sbin/devd/devd.cc b/sbin/devd/devd.cc
index 9c46453..a0cb037 100644
--- a/sbin/devd/devd.cc
+++ b/sbin/devd/devd.cc
@@ -850,7 +850,7 @@ create_socket(const char *name, int socktype)
return (fd);
}
-unsigned int max_clients = 10; /* Default, can be overriden on cmdline. */
+unsigned int max_clients = 10; /* Default, can be overridden on cmdline. */
unsigned int num_clients;
list<client_t> clients;
diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h
index c0ec651..57e0773 100644
--- a/sbin/fsck_ffs/fsck.h
+++ b/sbin/fsck_ffs/fsck.h
@@ -301,7 +301,7 @@ extern char snapname[BUFSIZ]; /* when doing snapshots, the name of the file */
extern char *cdevname; /* name of device being checked */
extern long dev_bsize; /* computed value of DEV_BSIZE */
extern long secsize; /* actual disk sector size */
-extern u_int real_dev_bsize; /* actual disk sector size, not overriden */
+extern u_int real_dev_bsize; /* actual disk sector size, not overridden */
extern char nflag; /* assume a no response */
extern char yflag; /* assume a yes response */
extern int bkgrdflag; /* use a snapshot to run on an active system */
diff --git a/sbin/fsck_ffs/globs.c b/sbin/fsck_ffs/globs.c
index c5b1e1b..e910bc9 100644
--- a/sbin/fsck_ffs/globs.c
+++ b/sbin/fsck_ffs/globs.c
@@ -73,7 +73,7 @@ char snapname[BUFSIZ]; /* when doing snapshots, the name of the file */
char *cdevname; /* name of device being checked */
long dev_bsize; /* computed value of DEV_BSIZE */
long secsize; /* actual disk sector size */
-u_int real_dev_bsize; /* actual disk sector size, not overriden */
+u_int real_dev_bsize; /* actual disk sector size, not overridden */
char nflag; /* assume a no response */
char yflag; /* assume a yes response */
int bkgrdflag; /* use a snapshot to run on an active system */
diff --git a/sbin/natd/natd.c b/sbin/natd/natd.c
index 959e1ee..1215351 100644
--- a/sbin/natd/natd.c
+++ b/sbin/natd/natd.c
@@ -223,7 +223,7 @@ int main (int argc, char** argv)
/*
* Create divert sockets. Use only one socket if -p was specified
* on command line. Otherwise, create separate sockets for
- * outgoing and incoming connnections.
+ * outgoing and incoming connections.
*/
if (mip->inOutPort) {
diff --git a/sbin/newfs_nandfs/newfs_nandfs.c b/sbin/newfs_nandfs/newfs_nandfs.c
index 3990dbb..9500805 100644
--- a/sbin/newfs_nandfs/newfs_nandfs.c
+++ b/sbin/newfs_nandfs/newfs_nandfs.c
@@ -1088,7 +1088,7 @@ static void
print_summary(void)
{
- printf("filesystem created succesfully\n");
+ printf("filesystem was created successfully\n");
printf("total segments: %#jx valid segments: %#jx\n", nsegments,
nsegments - bad_segments_count);
printf("total space: %ju MB free: %ju MB\n",
diff --git a/sbin/rcorder/rcorder.c b/sbin/rcorder/rcorder.c
index 8c46b4f..1d10a40 100644
--- a/sbin/rcorder/rcorder.c
+++ b/sbin/rcorder/rcorder.c
@@ -220,7 +220,7 @@ strnode_add(strnodelist **listp, char *s, filenode *fnode)
/*
* below are the functions that deal with creating the lists
- * from the filename's given and the dependancies and provisions
+ * from the filename's given dependencies and provisions
* in each of these files. no ordering or checking is done here.
*/
@@ -696,7 +696,7 @@ keep_ok(filenode *fnode)
*
* NOTE: do_file() is called recursively from several places and cannot
* safely free() anything related to items that may be recursed on.
- * Circular dependancies will cause problems if we do.
+ * Circular dependencies will cause problems if we do.
*/
static void
do_file(filenode *fnode)
diff --git a/sbin/reboot/reboot.8 b/sbin/reboot/reboot.8
index 13d7098..84dd887 100644
--- a/sbin/reboot/reboot.8
+++ b/sbin/reboot/reboot.8
@@ -29,6 +29,7 @@
.\" $FreeBSD$
.\"
.Dd October 11, 2010
+.Dd Jan 06, 2016
.Dt REBOOT 8
.Os
.Sh NAME
@@ -39,16 +40,16 @@
.Nd stopping and restarting the system
.Sh SYNOPSIS
.Nm halt
-.Op Fl lnpq
+.Op Fl lNnpq
.Op Fl k Ar kernel
.Nm
-.Op Fl dlnpq
+.Op Fl dlNnpq
.Op Fl k Ar kernel
.Nm fasthalt
-.Op Fl lnpq
+.Op Fl lNnpq
.Op Fl k Ar kernel
.Nm fastboot
-.Op Fl dlnpq
+.Op Fl dlNnpq
.Op Fl k Ar kernel
.Sh DESCRIPTION
The
@@ -94,6 +95,16 @@ that call
or
.Nm halt
and log this themselves.
+.It Fl N
+The file system cache is not flushed during the initial process clean-up,
+however the kernel level
+.Xr reboot 2
+is still processed with a sync.
+This option can be useful for performing a
+.Dq best-effort
+reboot when devices might be unavailable.
+This can happen when devices have been disconnected, such as with
+.Xr iscsi 4 .
.It Fl n
The file system cache is not flushed.
This option should probably not be used.
diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c
index d927db0..6d590ac 100644
--- a/sbin/reboot/reboot.c
+++ b/sbin/reboot/reboot.c
@@ -67,7 +67,7 @@ main(int argc, char *argv[])
{
struct utmpx utx;
const struct passwd *pw;
- int ch, howto, i, fd, lflag, nflag, qflag, sverrno;
+ int ch, howto, i, fd, lflag, nflag, qflag, sverrno, Nflag;
u_int pageins;
const char *user, *kernel = NULL;
@@ -76,8 +76,8 @@ main(int argc, char *argv[])
howto = RB_HALT;
} else
howto = 0;
- lflag = nflag = qflag = 0;
- while ((ch = getopt(argc, argv, "dk:lnpq")) != -1)
+ lflag = nflag = qflag = Nflag = 0;
+ while ((ch = getopt(argc, argv, "dk:lNnpq")) != -1)
switch(ch) {
case 'd':
howto |= RB_DUMP;
@@ -92,6 +92,10 @@ main(int argc, char *argv[])
nflag = 1;
howto |= RB_NOSYNC;
break;
+ case 'N':
+ nflag = 1;
+ Nflag = 1;
+ break;
case 'p':
howto |= RB_POWEROFF;
break;
@@ -107,6 +111,8 @@ main(int argc, char *argv[])
if ((howto & (RB_DUMP | RB_HALT)) == (RB_DUMP | RB_HALT))
errx(1, "cannot dump (-d) when halting; must reboot instead");
+ if (Nflag && (howto & RB_NOSYNC) != 0)
+ errx(1, "-N cannot be used with -n");
if (geteuid()) {
errno = EPERM;
err(1, NULL);
diff --git a/sbin/route/route.c b/sbin/route/route.c
index b3641ac..6f73ded 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -1239,6 +1239,9 @@ getaddr(int idx, char *str, struct hostent **hpp, int nrflags)
freeifaddrs(ifap);
if (sdl != NULL)
return(1);
+ else
+ errx(EX_DATAERR,
+ "interface '%s' does not exist", str);
}
break;
case RTAX_IFP:
diff --git a/share/mk/bsd.compiler.mk b/share/mk/bsd.compiler.mk
index 511d377..2c62778 100644
--- a/share/mk/bsd.compiler.mk
+++ b/share/mk/bsd.compiler.mk
@@ -40,7 +40,7 @@ COMPILER_TYPE:= clang
. endif
.endif
.if !defined(COMPILER_VERSION)
-COMPILER_VERSION!=echo ${_v:M[1-9].[0-9]*} | awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
+COMPILER_VERSION!=echo "${_v:M[1-9].[0-9]*}" | awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
.endif
.undef _v
.endif
diff --git a/share/mk/bsd.libnames.mk b/share/mk/bsd.libnames.mk
index 6ba1b79..096b08c 100644
--- a/share/mk/bsd.libnames.mk
+++ b/share/mk/bsd.libnames.mk
@@ -100,6 +100,7 @@ LIBNCURSES?= ${DESTDIR}${LIBDIR}/libncurses.a
LIBNCURSESW?= ${DESTDIR}${LIBDIR}/libncursesw.a
LIBNETGRAPH?= ${DESTDIR}${LIBDIR}/libnetgraph.a
LIBNGATM?= ${DESTDIR}${LIBDIR}/libngatm.a
+LIBNV?= ${DESTDIR}${LIBDIR}/libnv.a
LIBNVPAIR?= ${DESTDIR}${LIBDIR}/libnvpair.a
LIBOPIE?= ${DESTDIR}${LIBDIR}/libopie.a
diff --git a/sys/boot/amd64/Makefile b/sys/boot/amd64/Makefile
deleted file mode 100644
index 59940e9..0000000
--- a/sys/boot/amd64/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-.include <bsd.own.mk>
-
-SUBDIR= efi boot1.efi
-
-.include <bsd.subdir.mk>
diff --git a/sys/boot/amd64/Makefile.inc b/sys/boot/amd64/Makefile.inc
deleted file mode 100644
index 7b10385..0000000
--- a/sys/boot/amd64/Makefile.inc
+++ /dev/null
@@ -1,12 +0,0 @@
-# Common defines for all of /sys/boot/amd64/
-#
-# $FreeBSD$
-
-BINDIR?= /boot
-
-# See conf/kern.mk for the correct set of these
-CFLAGS+= -ffreestanding -mno-red-zone
-CFLAGS+= -mno-mmx -mno-sse -mno-aes -mno-avx -msoft-float
-LDFLAGS+= -nostdlib
-
-.include "../Makefile.inc"
diff --git a/sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu b/sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu
deleted file mode 100644
index 2af4244..0000000
--- a/sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu
+++ /dev/null
@@ -1,22 +0,0 @@
-FAT template boot filesystem created by generate-fat.sh
-DO NOT EDIT
-$FreeBSD$
-begin 644 fat.tmpl.bz2
-M0EIH.3%!62936?1V`!$`&J7____[ZZKJJ_^N_ZO^Z_^[ON_\`4`00!0$#$$"
-M0D)$6&(<P`(Y=SNY1(2DHTC":::-`!H`&@-````#)IH#3(&@:`!IIDT--,@E
-M53TFCWZJGJ`-!D`-`#(::```:```&@:!D`!D``&*B3:C]4T]0#0`:``-`T``
-M``````````&@)131/4T-*>IZC3RGZH\B&$,U&AH#)B:,$8TAF@@]0T>IZF&A
-M&GZID,1IZFAMO%FPGL0"(QIZV"3_!`$@N(@`DD$?C&$["`)`!)$6@#\HOB42
-M0`"2(X0FGX1#L"`'7E,'#-'HM!'QUD0\R,?9U,6ZE8F,Y6*L<9S<6PH)"%_"
-MX'_PL4A),QB"(`B(=14*-"8,(QCG.(2$A(1J'010CB&R$(0B00FPP(0A"$)E
-M#`A"$(1]LB&!"$(0B4&1#`A"$(14W<9J.:&A@8&!@8'`Z$(D(02@^L=UL>:+
-MBG:Q5+4&'[/P4@D2?M<,E!0&YBF8+],4^%$`4<YVD4=K")O.IZ\#)``!CU-1
-M``!L%C7V^RL80`#K(AUU+"D])9/B4@>*%$N9MF:Z29-_VG2G7<$LJ-44RST&
-MB53YE@H%(G5G$.FU;=L[DQVA]"(V4B1+%BP%.A<-10-%#R#NKR='@\'#"_'U
-M'I36ZT:8QIN*3E$:HZIZRJ?$Y1L&<1'C)G(=8,E.L(KU<9X=%/NX.6\=@^IW
-M\-PC$B&I"T\!(VI3"K!X:\%.01Y#X/83[SH.J*H5BH:ILFV1'X/D/V1$W6'\
-MFY>YE:*(I!.X@'D>H_(PY'(W1+B;:,Y?H8Y%(Q')!>DDE;\J1-DRXJJ/O(1@
-M'X/24=!+/V8S1)B(R:UE"0&&1:PUS(1`!$04``++GZ/8(CE5P1P8?^7QB[DB
-(G"A(>CL`"(``
-`
-end
diff --git a/sys/boot/efi/Makefile b/sys/boot/efi/Makefile
index ce52113..5dfb648 100644
--- a/sys/boot/efi/Makefile
+++ b/sys/boot/efi/Makefile
@@ -2,4 +2,8 @@
SUBDIR= libefi
+.if ${MACHINE_CPUARCH} == "amd64"
+SUBDIR+= loader boot1
+.endif
+
.include <bsd.subdir.mk>
diff --git a/sys/boot/efi/Makefile.inc b/sys/boot/efi/Makefile.inc
index 29ebae4..58c4726 100644
--- a/sys/boot/efi/Makefile.inc
+++ b/sys/boot/efi/Makefile.inc
@@ -7,7 +7,10 @@ CFLAGS+= -march=i386
.endif
# Options used when building app-specific efi components
+# See conf/kern.mk for the correct set of these
CFLAGS+= -ffreestanding -fshort-wchar -Wformat
+CFLAGS+= -mno-red-zone
+CFLAGS+= -mno-mmx -mno-sse -mno-aes -mno-avx -msoft-float
LDFLAGS+= -nostdlib
.include "../Makefile.inc"
diff --git a/sys/boot/amd64/boot1.efi/Makefile b/sys/boot/efi/boot1/Makefile
index dd8eaf9..554df39 100644
--- a/sys/boot/amd64/boot1.efi/Makefile
+++ b/sys/boot/efi/boot1/Makefile
@@ -17,19 +17,19 @@ SRCS= boot1.c reloc.c start.S
CFLAGS+= -fPIC
CFLAGS+= -I.
-CFLAGS+= -I${.CURDIR}/../../efi/include
-CFLAGS+= -I${.CURDIR}/../../efi/include/${MACHINE_CPUARCH}
+CFLAGS+= -I${.CURDIR}/../include
+CFLAGS+= -I${.CURDIR}/../include/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}/../../../contrib/dev/acpica/include
CFLAGS+= -I${.CURDIR}/../../..
# Always add MI sources and REGULAR efi loader bits
-.PATH: ${.CURDIR}/../efi ${.CURDIR}/../../common
+.PATH: ${.CURDIR}/../loader/arch/amd64 ${.CURDIR}/../../common
CFLAGS+= -I${.CURDIR}/../../common
FILES= boot1.efi boot1.efifat
FILESMODE_boot1.efi= ${BINMODE}
-LDSCRIPT= ${.CURDIR}/../efi/ldscript.${MACHINE_CPUARCH}
+LDSCRIPT= ${.CURDIR}/../loader/arch/${MACHINE_CPUARCH}/ldscript.${MACHINE_CPUARCH}
LDFLAGS= -Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared -Wl,-znocombreloc
${PROG}: ${LDSCRIPT}
@@ -39,7 +39,7 @@ OBJDUMP?= objdump
.if ${MACHINE_CPUARCH} == "amd64"
EFI_TARGET= efi-app-x86_64
-.else
+.elif ${MACHINE_CPUARCH} == "i386"
EFI_TARGET= efi-app-ia32
.endif
@@ -53,8 +53,6 @@ boot1.efi: loader.sym
-j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
-CFLAGS+= -I${.CURDIR}/../../common
-
boot1.o: ${.CURDIR}/../../common/ufsread.c
# The following inserts out objects into a template FAT file system
diff --git a/sys/boot/amd64/boot1.efi/Makefile.fat b/sys/boot/efi/boot1/Makefile.fat
index 324481e..324481e 100644
--- a/sys/boot/amd64/boot1.efi/Makefile.fat
+++ b/sys/boot/efi/boot1/Makefile.fat
diff --git a/sys/boot/amd64/boot1.efi/boot1.c b/sys/boot/efi/boot1/boot1.c
index 4a8f951..e0c26da 100644
--- a/sys/boot/amd64/boot1.efi/boot1.c
+++ b/sys/boot/efi/boot1/boot1.c
@@ -308,18 +308,21 @@ load(const char *fname)
status = systab->BootServices->LoadImage(TRUE, image, bootdevpath,
buffer, bufsize, &loaderhandle);
if (EFI_ERROR(status))
- printf("LoadImage failed with error %lx\n", status);
+ printf("LoadImage failed with error %lu\n",
+ status & ~EFI_ERROR_MASK);
status = systab->BootServices->HandleProtocol(loaderhandle,
&LoadedImageGUID, (VOID**)&loaded_image);
if (EFI_ERROR(status))
- printf("HandleProtocol failed with error %lx\n", status);
+ printf("HandleProtocol failed with error %lu\n",
+ status & ~EFI_ERROR_MASK);
loaded_image->DeviceHandle = bootdevhandle;
status = systab->BootServices->StartImage(loaderhandle, NULL, NULL);
if (EFI_ERROR(status))
- printf("StartImage failed with error %lx\n", status);
+ printf("StartImage failed with error %lu\n",
+ status & ~EFI_ERROR_MASK);
}
static void
diff --git a/sys/boot/efi/boot1/fat.tmpl.bz2.uu b/sys/boot/efi/boot1/fat.tmpl.bz2.uu
new file mode 100644
index 0000000..c9044ee
--- /dev/null
+++ b/sys/boot/efi/boot1/fat.tmpl.bz2.uu
@@ -0,0 +1,20 @@
+FAT template boot filesystem created by generate-fat.sh
+DO NOT EDIT
+$FreeBSD$
+begin 644 fat.tmpl.bz2
+M0EIH.3%!629362AK*D(`&I+____[ZZKJZ_^N_ZO^Z_Z_OJ[L`4`!7I0$#&$"
+M0$!$3&(<P`(;J*C:0E0E#30&AH`T````9#0```9````#)ZF0:,-3U/409,`)
+M@`"8`C3",````$R:8F@P`C`````"24U,D>I-DTU,)ZAZ0VA-!M0T'J`>H#"9
+M'I#0-H&HQI&0&3&FH>H>*`JHHU3V]1%/4/2``T#0`!H``#0`````#1H,@``6
+M'1&G'&@?$6[T#A)?X8$A160"20BO#")0J4TB1*4GXF$B4I,&>43+=_?K=#3*
+M6]<E0HE`UBF?(J%8BRF#?8OQ2'D)`)(EL2;F4.'R>R"ZNKJZI,9*68E8*E2Q
+M4J5*E3'(1830A"$(12A-"<(0A#]VD)H0A"$,>I0FA"$(0I\>P^=F5:M6K5JU
+M:DI3:64UN;[7%5B]Y-^\]@_K@B:N\/,5F%&H<\G#IXQXAEFC&D?![6%0'6MR
+MX1@@%FC"FD`M7,/SXFNG:2`'-0<-C$8^+$N.7M1B,^6)9,DV9,0A\OL<:C"L
+ML1V&,<\9YRB>XV#BG")'6NKRK^("UF2XO?_L!#29">MGDF$R3).!PX&%E,4C
+M''=(FL1.`_3?CN@-IB2PI3!FF\<8X.X@D,>CA90I)#M$XRPNDFJELL<3=1?8
+M2B7\5Z64,!7Z;EEBW-MXN-4IJ@W$462]-*\YCR,-B,5[W?=3&L/U>SX,WV#\
+M\B`:I"'0Z)5"$1B.E)(K[5I4RS`%R$>Y\D0NR*,;<9CZ:^V3P(I?D<D#!UC)
+D^M-HEE3SAN-8O0FQ$(`$(DF`?ZQ]'U2F_XNY(IPH2!0UE2$`
+`
+end
diff --git a/sys/boot/amd64/boot1.efi/generate-fat.sh b/sys/boot/efi/boot1/generate-fat.sh
index eafd3e0..2688da3 100755
--- a/sys/boot/amd64/boot1.efi/generate-fat.sh
+++ b/sys/boot/efi/boot1/generate-fat.sh
@@ -13,14 +13,26 @@
FAT_SIZE=1600 #Size in 512-byte blocks of the produced image
-BOOT1_SIZE=64k
+BOOT1_SIZE=128k
+
+#
+# Known filenames
+# amd64: BOOTx64.efi
+# arm64: BOOTaa64.efi
+#
+if [ -z "$1" ]; then
+ echo "Usage: $0 filename"
+ exit 1
+fi
+
+FILENAME=$1
# Generate 800K FAT image
OUTPUT_FILE=fat.tmpl
dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE
DEVICE=`mdconfig -a -f $OUTPUT_FILE`
-newfs_msdos -F 12 $DEVICE
+newfs_msdos -F 12 -L EFI $DEVICE
mkdir stub
mount -t msdosfs /dev/$DEVICE stub
@@ -28,16 +40,16 @@ mount -t msdosfs /dev/$DEVICE stub
mkdir -p stub/efi/boot
# Make a dummy file for boot1
-echo 'Boot1 START' | dd of=stub/efi/boot/BOOTx64.efi cbs=$BOOT1_SIZE count=1 conv=block
+echo 'Boot1 START' | dd of=stub/efi/boot/$FILENAME cbs=$BOOT1_SIZE count=1 conv=block
umount stub
mdconfig -d -u $DEVICE
rmdir stub
-# Locate the offsets of the two fake files
+# Locate the offset of the fake file
BOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ')
-# Convert to numbers of blocks
+# Convert to number of blocks
BOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}')
echo '# This file autogenerated by generate-fat.sh - DO NOT EDIT' > Makefile.fat
diff --git a/sys/boot/amd64/efi/Makefile b/sys/boot/efi/loader/Makefile
index 29e5389..26fd8a0 100644
--- a/sys/boot/amd64/efi/Makefile
+++ b/sys/boot/efi/loader/Makefile
@@ -12,27 +12,27 @@ MK_SSP= no
PROG= loader.sym
INTERNALPROG=
+.PATH: ${.CURDIR}/../../efi/loader
# architecture-specific loader code
SRCS= autoload.c \
bootinfo.c \
conf.c \
copy.c \
devicename.c \
- elf64_freebsd.c \
- framebuffer.c \
main.c \
- reloc.c \
smbios.c \
vers.c
-SRCS+= amd64_tramp.S \
- start.S
-SRCS+= nullconsole.c \
- comconsole.c
+
+.PATH: ${.CURDIR}/arch/${MACHINE_CPUARCH}
+# For smbios.c
+.PATH: ${.CURDIR}/../../i386/libi386
+.include "${.CURDIR}/arch/${MACHINE_CPUARCH}/Makefile.inc"
CFLAGS+= -fPIC
-CFLAGS+= -I.
-CFLAGS+= -I${.CURDIR}/../../efi/include
-CFLAGS+= -I${.CURDIR}/../../efi/include/${MACHINE_CPUARCH}
+CFLAGS+= -I${.CURDIR}
+CFLAGS+= -I${.CURDIR}/arch/${MACHINE_CPUARCH}
+CFLAGS+= -I${.CURDIR}/../include
+CFLAGS+= -I${.CURDIR}/../include/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}/../../../contrib/dev/acpica/include
CFLAGS+= -I${.CURDIR}/../../..
CFLAGS+= -I${.CURDIR}/../../i386/libi386
@@ -55,24 +55,20 @@ CFLAGS+= -DEFI_STAGING_SIZE=${EFI_STAGING_SIZE}
# Always add MI sources
.PATH: ${.CURDIR}/../../common
-# For smbios.c, nullconsole.c, comconsole.c
-.PATH: ${.CURDIR}/../../i386/libi386
.include "${.CURDIR}/../../common/Makefile.inc"
CFLAGS+= -I${.CURDIR}/../../common
FILES= loader.efi
FILESMODE_loader.efi= ${BINMODE}
-LDSCRIPT= ${.CURDIR}/ldscript.${MACHINE_CPUARCH}
+LDSCRIPT= ${.CURDIR}/arch/${MACHINE_CPUARCH}/ldscript.${MACHINE_CPUARCH}
LDFLAGS= -Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared -Wl,-znocombreloc
-${PROG}: ${LDSCRIPT}
-
CLEANFILES= vers.c loader.efi
NEWVERSWHAT= "EFI loader" ${MACHINE_CPUARCH}
-vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
+vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../../efi/loader/version
sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
OBJCOPY?= objcopy
@@ -80,7 +76,7 @@ OBJDUMP?= objdump
.if ${MACHINE_CPUARCH} == "amd64"
EFI_TARGET= efi-app-x86_64
-.else
+.elif ${MACHINE_CPUARCH} == "i386"
EFI_TARGET= efi-app-ia32
.endif
@@ -94,10 +90,9 @@ loader.efi: loader.sym
-j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
-LIBEFI= ${.OBJDIR}/../../efi/libefi/libefi.a
-CFLAGS+= -I${.CURDIR}/../../common
+LIBEFI= ${.OBJDIR}/../libefi/libefi.a
-DPADD= ${LIBFICL} ${LIBEFI} ${LIBSTAND}
+DPADD= ${LIBFICL} ${LIBEFI} ${LIBSTAND} ${LDSCRIPT}
LDADD= ${LIBFICL} ${LIBEFI} ${LIBSTAND}
.endif # ${COMPILER_TYPE} != "gcc"
diff --git a/sys/boot/efi/loader/arch/amd64/Makefile.inc b/sys/boot/efi/loader/arch/amd64/Makefile.inc
new file mode 100644
index 0000000..3f2b68e
--- /dev/null
+++ b/sys/boot/efi/loader/arch/amd64/Makefile.inc
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+SRCS+= amd64_tramp.S \
+ start.S \
+ framebuffer.c \
+ elf64_freebsd.c \
+ reloc.c
+
+.PATH: ${.CURDIR}/../../i386/libi386
+SRCS+= nullconsole.c \
+ comconsole.c
diff --git a/sys/boot/amd64/efi/amd64_tramp.S b/sys/boot/efi/loader/arch/amd64/amd64_tramp.S
index c102d92..c102d92 100644
--- a/sys/boot/amd64/efi/amd64_tramp.S
+++ b/sys/boot/efi/loader/arch/amd64/amd64_tramp.S
diff --git a/sys/boot/amd64/efi/elf64_freebsd.c b/sys/boot/efi/loader/arch/amd64/elf64_freebsd.c
index 0fb82b0..c1dbec2 100644
--- a/sys/boot/amd64/efi/elf64_freebsd.c
+++ b/sys/boot/efi/loader/arch/amd64/elf64_freebsd.c
@@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
#include "actypes.h"
#include "actbl.h"
-#include "x86_efi.h"
+#include "loader_efi.h"
static EFI_GUID acpi_guid = ACPI_TABLE_GUID;
static EFI_GUID acpi20_guid = ACPI_20_TABLE_GUID;
@@ -57,8 +57,14 @@ extern int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp);
static int elf64_exec(struct preloaded_file *amp);
static int elf64_obj_exec(struct preloaded_file *amp);
-struct file_format amd64_elf = { elf64_loadfile, elf64_exec };
-struct file_format amd64_elf_obj = { elf64_obj_loadfile, elf64_obj_exec };
+static struct file_format amd64_elf = { elf64_loadfile, elf64_exec };
+static struct file_format amd64_elf_obj = { elf64_obj_loadfile, elf64_obj_exec };
+
+struct file_format *file_formats[] = {
+ &amd64_elf,
+ &amd64_elf_obj,
+ NULL
+};
#define PG_V 0x001
#define PG_RW 0x002
@@ -168,16 +174,9 @@ elf64_exec(struct preloaded_file *fp)
if (err != 0)
return(err);
- status = BS->ExitBootServices(IH, x86_efi_mapkey);
- if (EFI_ERROR(status)) {
- printf("%s: ExitBootServices() returned 0x%lx\n", __func__,
- (long)status);
- return (EINVAL);
- }
-
dev_cleanup();
- trampoline(trampstack, x86_efi_copy_finish, kernend, modulep, PT4,
+ trampoline(trampstack, efi_copy_finish, kernend, modulep, PT4,
ehdr->e_entry);
panic("exec returned");
diff --git a/sys/boot/amd64/efi/framebuffer.c b/sys/boot/efi/loader/arch/amd64/framebuffer.c
index 90bf992..90bf992 100644
--- a/sys/boot/amd64/efi/framebuffer.c
+++ b/sys/boot/efi/loader/arch/amd64/framebuffer.c
diff --git a/sys/boot/amd64/efi/framebuffer.h b/sys/boot/efi/loader/arch/amd64/framebuffer.h
index 2ec9017..2ec9017 100644
--- a/sys/boot/amd64/efi/framebuffer.h
+++ b/sys/boot/efi/loader/arch/amd64/framebuffer.h
diff --git a/sys/boot/amd64/efi/ldscript.amd64 b/sys/boot/efi/loader/arch/amd64/ldscript.amd64
index 14e1f06..14e1f06 100644
--- a/sys/boot/amd64/efi/ldscript.amd64
+++ b/sys/boot/efi/loader/arch/amd64/ldscript.amd64
diff --git a/sys/boot/amd64/efi/reloc.c b/sys/boot/efi/loader/arch/amd64/reloc.c
index 98bcf8e..98bcf8e 100644
--- a/sys/boot/amd64/efi/reloc.c
+++ b/sys/boot/efi/loader/arch/amd64/reloc.c
diff --git a/sys/boot/amd64/efi/start.S b/sys/boot/efi/loader/arch/amd64/start.S
index beaeeff..beaeeff 100644
--- a/sys/boot/amd64/efi/start.S
+++ b/sys/boot/efi/loader/arch/amd64/start.S
diff --git a/sys/boot/amd64/efi/autoload.c b/sys/boot/efi/loader/autoload.c
index efb32d4..694a6da 100644
--- a/sys/boot/amd64/efi/autoload.c
+++ b/sys/boot/efi/loader/autoload.c
@@ -28,7 +28,7 @@
__FBSDID("$FreeBSD$");
int
-x86_efi_autoload(void)
+efi_autoload(void)
{
return (0);
diff --git a/sys/boot/amd64/efi/bootinfo.c b/sys/boot/efi/loader/bootinfo.c
index 2d45dd0..f3bb9cc 100644
--- a/sys/boot/amd64/efi/bootinfo.c
+++ b/sys/boot/efi/loader/bootinfo.c
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/linker.h>
#include <sys/boot.h>
#include <machine/cpufunc.h>
+#include <machine/elf.h>
#include <machine/metadata.h>
#include <machine/psl.h>
#include <machine/specialreg.h>
@@ -45,9 +46,7 @@ __FBSDID("$FreeBSD$");
#include "bootstrap.h"
#include "framebuffer.h"
-#include "x86_efi.h"
-
-UINTN x86_efi_mapkey;
+#include "loader_efi.h"
static const char howto_switches[] = "aCdrgDmphsv";
static int howto_masks[] = {
@@ -114,24 +113,24 @@ bi_copyenv(vm_offset_t start)
/* Traverse the environment. */
for (ep = environ; ep != NULL; ep = ep->ev_next) {
len = strlen(ep->ev_name);
- if (x86_efi_copyin(ep->ev_name, addr, len) != len)
+ if (archsw.arch_copyin(ep->ev_name, addr, len) != len)
break;
addr += len;
- if (x86_efi_copyin("=", addr, 1) != 1)
+ if (archsw.arch_copyin("=", addr, 1) != 1)
break;
addr++;
if (ep->ev_value != NULL) {
len = strlen(ep->ev_value);
- if (x86_efi_copyin(ep->ev_value, addr, len) != len)
+ if (archsw.arch_copyin(ep->ev_value, addr, len) != len)
break;
addr += len;
}
- if (x86_efi_copyin("", addr, 1) != 1)
+ if (archsw.arch_copyin("", addr, 1) != 1)
break;
last = ++addr;
}
- if (x86_efi_copyin("", last++, 1) != 1)
+ if (archsw.arch_copyin("", last++, 1) != 1)
last = start;
return(last);
}
@@ -155,7 +154,7 @@ bi_copyenv(vm_offset_t start)
#define COPY32(v, a, c) { \
uint32_t x = (v); \
if (c) \
- x86_efi_copyin(&x, a, sizeof(x)); \
+ archsw.arch_copyin(&x, a, sizeof(x)); \
a += sizeof(x); \
}
@@ -163,8 +162,8 @@ bi_copyenv(vm_offset_t start)
COPY32(t, a, c); \
COPY32(strlen(s) + 1, a, c); \
if (c) \
- x86_efi_copyin(s, a, strlen(s) + 1); \
- a += roundup(strlen(s) + 1, sizeof(uint64_t)); \
+ archsw.arch_copyin(s, a, strlen(s) + 1); \
+ a += roundup(strlen(s) + 1, sizeof(u_long)); \
}
#define MOD_NAME(a, s, c) MOD_STR(MODINFO_NAME, a, s, c)
@@ -175,8 +174,8 @@ bi_copyenv(vm_offset_t start)
COPY32(t, a, c); \
COPY32(sizeof(s), a, c); \
if (c) \
- x86_efi_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(uint64_t)); \
+ archsw.arch_copyin(&s, a, sizeof(s)); \
+ a += roundup(sizeof(s), sizeof(u_long)); \
}
#define MOD_ADDR(a, s, c) MOD_VAR(MODINFO_ADDR, a, s, c)
@@ -186,8 +185,8 @@ bi_copyenv(vm_offset_t start)
COPY32(MODINFO_METADATA | mm->md_type, a, c); \
COPY32(mm->md_size, a, c); \
if (c) \
- x86_efi_copyin(mm->md_data, a, mm->md_size); \
- a += roundup(mm->md_size, sizeof(uint64_t)); \
+ archsw.arch_copyin(mm->md_data, a, mm->md_size); \
+ a += roundup(mm->md_size, sizeof(u_long)); \
}
#define MOD_END(a, c) { \
@@ -229,60 +228,86 @@ bi_load_efi_data(struct preloaded_file *kfp)
EFI_PHYSICAL_ADDRESS addr;
EFI_STATUS status;
size_t efisz;
- UINTN mmsz, pages, sz;
+ UINTN efi_mapkey;
+ UINTN mmsz, pages, retry, sz;
UINT32 mmver;
struct efi_map_header *efihdr;
struct efi_fb efifb;
- if (efi_find_framebuffer(&efifb) == 0)
+ if (efi_find_framebuffer(&efifb) == 0) {
+ printf("EFI framebuffer information:\n");
+ printf("addr, size 0x%lx, 0x%lx\n", efifb.fb_addr,
+ efifb.fb_size);
+ printf("dimensions %d x %d\n", efifb.fb_width,
+ efifb.fb_height);
+ printf("stride %d\n", efifb.fb_stride);
+ printf("masks 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
+ efifb.fb_mask_red, efifb.fb_mask_green, efifb.fb_mask_blue,
+ efifb.fb_mask_reserved);
+
file_addmetadata(kfp, MODINFOMD_EFI_FB, sizeof(efifb), &efifb);
+ }
efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf;
/*
- * Allocate enough pages to hold the bootinfo block and the memory
- * map EFI will return to us. The memory map has an unknown size,
- * so we have to determine that first. Note that the AllocatePages
- * call can itself modify the memory map, so we have to take that
- * into account as well. The changes to the memory map are caused
- * by splitting a range of free memory into two (AFAICT), so that
- * one is marked as being loader data.
+ * It is possible that the first call to ExitBootServices may change
+ * the map key. Fetch a new map key and retry ExitBootServices in that
+ * case.
*/
- sz = 0;
- BS->GetMemoryMap(&sz, NULL, &x86_efi_mapkey, &mmsz, &mmver);
- sz += mmsz;
- sz = (sz + 0xf) & ~0xf;
- pages = EFI_SIZE_TO_PAGES(sz + efisz);
- status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, pages,
- &addr);
- if (EFI_ERROR(status)) {
- printf("%s: AllocatePages() returned 0x%lx\n", __func__,
- (long)status);
- return (ENOMEM);
- }
+ for (retry = 2; retry > 0; retry--) {
+ /*
+ * Allocate enough pages to hold the bootinfo block and the
+ * memory map EFI will return to us. The memory map has an
+ * unknown size, so we have to determine that first. Note that
+ * the AllocatePages call can itself modify the memory map, so
+ * we have to take that into account as well. The changes to
+ * the memory map are caused by splitting a range of free
+ * memory into two (AFAICT), so that one is marked as being
+ * loader data.
+ */
+ sz = 0;
+ BS->GetMemoryMap(&sz, NULL, &efi_mapkey, &mmsz, &mmver);
+ sz += mmsz;
+ sz = (sz + 0xf) & ~0xf;
+ pages = EFI_SIZE_TO_PAGES(sz + efisz);
+ status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
+ pages, &addr);
+ if (EFI_ERROR(status)) {
+ printf("%s: AllocatePages error %lu\n", __func__,
+ (unsigned long)(status & ~EFI_ERROR_MASK));
+ return (ENOMEM);
+ }
- /*
- * Read the memory map and stash it after bootinfo. Align the
- * memory map on a 16-byte boundary (the bootinfo block is page
- * aligned).
- */
- efihdr = (struct efi_map_header *)addr;
- mm = (void *)((uint8_t *)efihdr + efisz);
- sz = (EFI_PAGE_SIZE * pages) - efisz;
- status = BS->GetMemoryMap(&sz, mm, &x86_efi_mapkey, &mmsz, &mmver);
- if (EFI_ERROR(status)) {
- printf("%s: GetMemoryMap() returned 0x%lx\n", __func__,
- (long)status);
- return (EINVAL);
+ /*
+ * Read the memory map and stash it after bootinfo. Align the
+ * memory map on a 16-byte boundary (the bootinfo block is page
+ * aligned).
+ */
+ efihdr = (struct efi_map_header *)addr;
+ mm = (void *)((uint8_t *)efihdr + efisz);
+ sz = (EFI_PAGE_SIZE * pages) - efisz;
+
+ status = BS->GetMemoryMap(&sz, mm, &efi_mapkey, &mmsz, &mmver);
+ if (EFI_ERROR(status)) {
+ printf("%s: GetMemoryMap error %lu\n", __func__,
+ (unsigned long)(status & ~EFI_ERROR_MASK));
+ return (EINVAL);
+ }
+ status = BS->ExitBootServices(IH, efi_mapkey);
+ if (EFI_ERROR(status) == 0) {
+ efihdr->memory_size = sz;
+ efihdr->descriptor_size = mmsz;
+ efihdr->descriptor_version = mmver;
+ file_addmetadata(kfp, MODINFOMD_EFI_MAP, efisz + sz,
+ efihdr);
+ return (0);
+ }
+ BS->FreePages(addr, pages);
}
-
- efihdr->memory_size = sz;
- efihdr->descriptor_size = mmsz;
- efihdr->descriptor_version = mmver;
-
- file_addmetadata(kfp, MODINFOMD_EFI_MAP, efisz + sz, efihdr);
-
- return (0);
+ printf("ExitBootServices error %lu\n",
+ (unsigned long)(status & ~EFI_ERROR_MASK));
+ return (EINVAL);
}
/*
@@ -315,14 +340,14 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp)
* tested/set by MI code before launching the kernel.
*/
rootdevname = getenv("rootdev");
- x86_efi_getdev((void**)(&rootdev), rootdevname, NULL);
+ archsw.arch_getdev((void**)(&rootdev), rootdevname, NULL);
if (rootdev == NULL) {
printf("Can't determine root device.\n");
return(EINVAL);
}
/* Try reading the /etc/fstab file to select the root device */
- getrootmount(x86_efi_fmtdev((void *)rootdev));
+ getrootmount(efi_fmtdev((void *)rootdev));
addr = 0;
for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
@@ -364,6 +389,6 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp)
/* Copy module list and metadata. */
(void)bi_copymodules(addr);
-
+
return (0);
}
diff --git a/sys/boot/amd64/efi/conf.c b/sys/boot/efi/loader/conf.c
index 97dd352..8c063fd 100644
--- a/sys/boot/amd64/efi/conf.c
+++ b/sys/boot/efi/loader/conf.c
@@ -53,15 +53,6 @@ struct netif_driver *netif_drivers[] = {
NULL
};
-extern struct file_format amd64_elf;
-extern struct file_format amd64_elf_obj;
-
-struct file_format *file_formats[] = {
- &amd64_elf,
- &amd64_elf_obj,
- NULL
-};
-
extern struct console efi_console;
extern struct console comconsole;
extern struct console nullconsole;
diff --git a/sys/boot/amd64/efi/copy.c b/sys/boot/efi/loader/copy.c
index cd8b6da..a7d6bf1 100644
--- a/sys/boot/amd64/efi/copy.c
+++ b/sys/boot/efi/loader/copy.c
@@ -48,7 +48,7 @@ int stage_offset_set = 0;
ssize_t stage_offset;
int
-x86_efi_copy_init(void)
+efi_copy_init(void)
{
EFI_STATUS status;
@@ -65,7 +65,7 @@ x86_efi_copy_init(void)
}
ssize_t
-x86_efi_copyin(const void *src, vm_offset_t dest, const size_t len)
+efi_copyin(const void *src, vm_offset_t dest, const size_t len)
{
if (!stage_offset_set) {
@@ -83,7 +83,7 @@ x86_efi_copyin(const void *src, vm_offset_t dest, const size_t len)
}
ssize_t
-x86_efi_copyout(const vm_offset_t src, void *dest, const size_t len)
+efi_copyout(const vm_offset_t src, void *dest, const size_t len)
{
/* XXX: Callers do not check for failure. */
@@ -97,7 +97,7 @@ x86_efi_copyout(const vm_offset_t src, void *dest, const size_t len)
ssize_t
-x86_efi_readin(const int fd, vm_offset_t dest, const size_t len)
+efi_readin(const int fd, vm_offset_t dest, const size_t len)
{
if (dest + stage_offset + len > staging_end) {
@@ -108,7 +108,7 @@ x86_efi_readin(const int fd, vm_offset_t dest, const size_t len)
}
void
-x86_efi_copy_finish(void)
+efi_copy_finish(void)
{
uint64_t *src, *dst, *last;
diff --git a/sys/boot/amd64/efi/devicename.c b/sys/boot/efi/loader/devicename.c
index aa43628..a9327dc 100644
--- a/sys/boot/amd64/efi/devicename.c
+++ b/sys/boot/efi/loader/devicename.c
@@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
#include <efi.h>
#include <efilib.h>
-static int x86_efi_parsedev(struct devdesc **, const char *, const char **);
+static int efi_parsedev(struct devdesc **, const char *, const char **);
/*
* Point (dev) at an allocated device specifier for the device matching the
@@ -44,7 +44,7 @@ static int x86_efi_parsedev(struct devdesc **, const char *, const char **);
* use that. If not, use the default device.
*/
int
-x86_efi_getdev(void **vdev, const char *devspec, const char **path)
+efi_getdev(void **vdev, const char *devspec, const char **path)
{
struct devdesc **dev = (struct devdesc **)vdev;
int rv;
@@ -54,14 +54,14 @@ x86_efi_getdev(void **vdev, const char *devspec, const char **path)
* use the current device instead.
*/
if (devspec == NULL || *devspec == '/' || !strchr(devspec, ':')) {
- rv = x86_efi_parsedev(dev, getenv("currdev"), NULL);
+ rv = efi_parsedev(dev, getenv("currdev"), NULL);
if (rv == 0 && path != NULL)
*path = devspec;
return (rv);
}
/* Parse the device name off the beginning of the devspec. */
- return (x86_efi_parsedev(dev, devspec, path));
+ return (efi_parsedev(dev, devspec, path));
}
/*
@@ -78,7 +78,7 @@ x86_efi_getdev(void **vdev, const char *devspec, const char **path)
* fs<unit>:
*/
static int
-x86_efi_parsedev(struct devdesc **dev, const char *devspec, const char **path)
+efi_parsedev(struct devdesc **dev, const char *devspec, const char **path)
{
struct devdesc *idev;
struct devsw *dv;
@@ -132,7 +132,7 @@ x86_efi_parsedev(struct devdesc **dev, const char *devspec, const char **path)
}
char *
-x86_efi_fmtdev(void *vdev)
+efi_fmtdev(void *vdev)
{
struct devdesc *dev = (struct devdesc *)vdev;
static char buf[32]; /* XXX device length constant? */
@@ -154,12 +154,12 @@ x86_efi_fmtdev(void *vdev)
* Set currdev to suit the value being supplied in (value)
*/
int
-x86_efi_setcurrdev(struct env_var *ev, int flags, const void *value)
+efi_setcurrdev(struct env_var *ev, int flags, const void *value)
{
struct devdesc *ncurr;
int rv;
- rv = x86_efi_parsedev(&ncurr, value, NULL);
+ rv = efi_parsedev(&ncurr, value, NULL);
if (rv != 0)
return(rv);
diff --git a/sys/boot/amd64/efi/x86_efi.h b/sys/boot/efi/loader/loader_efi.h
index 73a61c8..5819d78 100644
--- a/sys/boot/amd64/efi/x86_efi.h
+++ b/sys/boot/efi/loader/loader_efi.h
@@ -28,22 +28,22 @@
* $FreeBSD$
*/
-#ifndef _X86_EFI_COPY_H_
-#define _X86_EFI_COPY_H_
+#ifndef _LOADER_EFI_COPY_H_
+#define _LOADER_EFI_COPY_H_
-int x86_efi_autoload(void);
+int efi_autoload(void);
-int x86_efi_getdev(void **vdev, const char *devspec, const char **path);
-char *x86_efi_fmtdev(void *vdev);
-int x86_efi_setcurrdev(struct env_var *ev, int flags, const void *value);
+int efi_getdev(void **vdev, const char *devspec, const char **path);
+char *efi_fmtdev(void *vdev);
+int efi_setcurrdev(struct env_var *ev, int flags, const void *value);
-int x86_efi_copy_init(void);
-void x86_efi_copy_finish(void);
+int efi_copy_init(void);
-ssize_t x86_efi_copyin(const void *src, vm_offset_t dest, const size_t len);
-ssize_t x86_efi_copyout(const vm_offset_t src, void *dest, const size_t len);
-ssize_t x86_efi_readin(const int fd, vm_offset_t dest, const size_t len);
+ssize_t efi_copyin(const void *src, vm_offset_t dest, const size_t len);
+ssize_t efi_copyout(const vm_offset_t src, void *dest, const size_t len);
+ssize_t efi_readin(const int fd, vm_offset_t dest, const size_t len);
+void * efi_translate(vm_offset_t ptr);
-extern UINTN x86_efi_mapkey;
+void efi_copy_finish(void);
-#endif /* _X86_EFI_COPY_H_ */
+#endif /* _LOADER_EFI_COPY_H_ */
diff --git a/sys/boot/amd64/efi/main.c b/sys/boot/efi/loader/main.c
index ea4c3e7..e6e13f1 100644
--- a/sys/boot/amd64/efi/main.c
+++ b/sys/boot/efi/loader/main.c
@@ -37,7 +37,8 @@ __FBSDID("$FreeBSD$");
#include <bootstrap.h>
#include <smbios.h>
-#include "x86_efi.h"
+
+#include "loader_efi.h"
extern char bootprog_name[];
extern char bootprog_rev[];
@@ -75,7 +76,7 @@ main(int argc, CHAR16 *argv[])
*/
cons_probe();
- if (x86_efi_copy_init()) {
+ if (efi_copy_init()) {
printf("failed to allocate staging area\n");
return (EFI_BUFFER_TOO_SMALL);
}
@@ -117,18 +118,18 @@ main(int argc, CHAR16 *argv[])
*/
BS->SetWatchdogTimer(0, 0, 0, NULL);
- env_setenv("currdev", EV_VOLATILE, x86_efi_fmtdev(&currdev),
- x86_efi_setcurrdev, env_nounset);
- env_setenv("loaddev", EV_VOLATILE, x86_efi_fmtdev(&currdev), env_noset,
+ env_setenv("currdev", EV_VOLATILE, efi_fmtdev(&currdev),
+ efi_setcurrdev, env_nounset);
+ env_setenv("loaddev", EV_VOLATILE, efi_fmtdev(&currdev), env_noset,
env_nounset);
setenv("LINES", "24", 1); /* optional */
- archsw.arch_autoload = x86_efi_autoload;
- archsw.arch_getdev = x86_efi_getdev;
- archsw.arch_copyin = x86_efi_copyin;
- archsw.arch_copyout = x86_efi_copyout;
- archsw.arch_readin = x86_efi_readin;
+ archsw.arch_autoload = efi_autoload;
+ archsw.arch_getdev = efi_getdev;
+ archsw.arch_copyin = efi_copyin;
+ archsw.arch_copyout = efi_copyout;
+ archsw.arch_readin = efi_readin;
for (i = 0; i < ST->NumberOfTableEntries; i++) {
guid = &ST->ConfigurationTable[i].VendorGuid;
diff --git a/sys/boot/amd64/efi/version b/sys/boot/efi/loader/version
index 3a4c47c..3a4c47c 100644
--- a/sys/boot/amd64/efi/version
+++ b/sys/boot/efi/loader/version
diff --git a/sys/boot/forth/loader.conf b/sys/boot/forth/loader.conf
index 020239a..88f5411 100644
--- a/sys/boot/forth/loader.conf
+++ b/sys/boot/forth/loader.conf
@@ -12,7 +12,7 @@
### Basic configuration options ############################
##############################################################
-exec=".( Loading /boot/defaults/loader.conf ) cr"
+exec="echo Loading /boot/defaults/loader.conf"
kernel="kernel" # /boot sub-directory containing kernel and modules
bootfile="kernel" # Kernel name (possibly absolute path)
@@ -39,7 +39,7 @@ bitmap_type="splash_image_data" # and place it on the module_path
##############################################################
-### Random number generator configuration ###################
+### Random number generator configuration ##################
##############################################################
entropy_cache_load="NO" # Set this to YES to load entropy at boot time
@@ -156,7 +156,7 @@ module_path="/boot/modules" # Set the module search path
##############################################################
-### ATA modules ##############################################
+### ATA modules ############################################
##############################################################
ataacard_load="NO" # ACARD
@@ -378,6 +378,7 @@ if_xe_load="NO" # Xircom CreditCard PCMCIA
if_xl_load="NO" # 3Com Etherlink XL (3c900, 3c905, 3c905B)
utopia_load="NO" # ATM PHY driver
+
##############################################################
### Netgraph modules #######################################
##############################################################
@@ -420,6 +421,7 @@ ng_tty_load="NO" # Netgraph node type that is also a line
ng_vjc_load="NO" # Van Jacobsen compression netgraph node type
ng_vlan_load="NO" # IEEE 802.1Q VLAN tagging netgraph node type
+
##############################################################
### Sound modules ##########################################
##############################################################
@@ -456,6 +458,7 @@ snd_via82c686_load="NO" # via82c686
snd_vibes_load="NO" # vibes
snd_driver_load="NO" # All sound drivers
+
##############################################################
### USB modules ############################################
##############################################################
@@ -488,6 +491,7 @@ if_ural_load="NO" # Ralink RT2500USB 802.11 wireless adapter
if_zyd_load="NO" # ZyDAS ZD1211(B) USB 802.11 wireless adapter
snd_uaudio_load="NO" # USB audio
+
##############################################################
### Other modules ##########################################
##############################################################
@@ -512,6 +516,7 @@ amdtemp_load="NO" # AMD K8/K10/K11 temperature monitor
tpm_load="NO" # Trusted Platform Module
wbwd_load="NO" # Winbond watchdog
+
##############################################################
### ACPI settings ##########################################
##############################################################
@@ -522,8 +527,9 @@ acpi_dsdt_name="/boot/acpi_dsdt.aml"
# Override DSDT in BIOS by this file
acpi_video_load="NO" # Load the ACPI video extension driver
+
##############################################################
-### TrustedBSD MAC settings ##################################
+### TrustedBSD MAC settings ################################
##############################################################
mac_biba_load="NO" # Biba MAC policy
@@ -534,6 +540,7 @@ mac_none_load="NO" # Null MAC policy
mac_partition_load="NO" # Partition MAC policy
mac_seeotheruids_load="NO" # UID visbility MAC policy
+
##############################################################
### Module loading syntax example ##########################
##############################################################
diff --git a/sys/boot/forth/loader.rc b/sys/boot/forth/loader.rc
index b4a6d51..0bc6657 100644
--- a/sys/boot/forth/loader.rc
+++ b/sys/boot/forth/loader.rc
@@ -1,6 +1,9 @@
\ Loader.rc
\ $FreeBSD$
\
+\ You should not edit this file! Put any overrides in loader.rc.local
+\ instead as this file can be replaced during system updates.
+\
\ Includes additional commands
include /boot/loader.4th
try-include /boot/loader.rc.local
diff --git a/sys/boot/forth/menu.rc b/sys/boot/forth/menu.rc
index e650848..7ffeef4 100644
--- a/sys/boot/forth/menu.rc
+++ b/sys/boot/forth/menu.rc
@@ -1,6 +1,9 @@
\ Menu.rc
\ $FreeBSD$
\
+\ You should not edit this file! Put any overrides in menu.rc.local
+\ instead as this file can be replaced during system updates.
+\
\ Load required Forth modules
include /boot/version.4th
include /boot/brand.4th
diff --git a/sys/boot/forth/support.4th b/sys/boot/forth/support.4th
index 7da92bc..6db232b 100644
--- a/sys/boot/forth/support.4th
+++ b/sys/boot/forth/support.4th
@@ -684,7 +684,7 @@ only forth also support-functions also file-processing definitions
s" loader_conf_files" getenv conf_files string=
;
-: set_nextboot_conf \ XXX maybe do as set_conf_files ?
+: set_nextboot_conf
value_buffer strget unquote nextboot_conf_file string=
;
@@ -833,7 +833,7 @@ get-current ( -- wid ) previous definitions >search ( wid -- )
repeat
;
-: peek_file
+: peek_file ( addr len -- )
0 to end_of_file?
reset_line_reading
O_RDONLY fopen fd !
@@ -844,6 +844,7 @@ get-current ( -- wid ) previous definitions >search ( wid -- )
['] process_assignment catch
['] free_buffers catch
fd @ fclose
+ swap throw throw
;
only forth also support-functions definitions
@@ -851,7 +852,6 @@ only forth also support-functions definitions
\ Interface to loading conf files
: load_conf ( addr len -- )
- \ ." ----- Trying conf " 2dup type cr \ debugging
0 to end_of_file?
reset_line_reading
O_RDONLY fopen fd !
@@ -943,7 +943,6 @@ string current_file_name_ref \ used to print the file name
\ loader_conf_files processing support functions
: get_conf_files ( -- addr len ) \ put addr/len on stack, reset var
- \ ." -- starting on <" conf_files strtype ." >" cr \ debugging
conf_files strget 0 0 conf_files strset
;
@@ -970,7 +969,6 @@ string current_file_name_ref \ used to print the file name
pos char+ to pos
repeat
addr len pos addr r@ + pos r> -
- \ 2dup ." get_file_name has " type cr \ debugging
;
: get_next_file ( addr len ptr -- addr len ptr' addr' len' | 0 )
@@ -1021,25 +1019,26 @@ string current_file_name_ref \ used to print the file name
;
: get_nextboot_conf_file ( -- addr len )
- nextboot_conf_file strget strdup \ XXX is the strdup a leak ?
+ nextboot_conf_file strget
;
: rewrite_nextboot_file ( -- )
get_nextboot_conf_file
O_WRONLY fopen fd !
fd @ -1 = if EOPEN throw then
- fd @ s' nextboot_enable="NO" ' fwrite
+ fd @ s' nextboot_enable="NO" ' fwrite ( fd buf len -- nwritten ) drop
fd @ fclose
;
-: include_nextboot_file
+: include_nextboot_file ( -- )
get_nextboot_conf_file
- ['] peek_file catch
+ ['] peek_file catch if 2drop then
nextboot? if
get_nextboot_conf_file
+ current_file_name_ref strref
['] load_conf catch
process_conf_errors
- ['] rewrite_nextboot_file catch
+ ['] rewrite_nextboot_file catch if 2drop then
then
;
diff --git a/sys/boot/i386/efi/bootinfo.c b/sys/boot/i386/efi/bootinfo.c
deleted file mode 100644
index 853d044..0000000
--- a/sys/boot/i386/efi/bootinfo.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * Copyright (c) 2006 Marcel Moolenaar
- * All rights reserved.
- *
- * 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stand.h>
-#include <string.h>
-#include <sys/param.h>
-#include <sys/reboot.h>
-#include <sys/linker.h>
-#include <sys/boot.h>
-
-#include <efi.h>
-#include <efilib.h>
-
-#include "bootstrap.h"
-#include "libi386.h"
-#include <machine/bootinfo.h>
-
-static const char howto_switches[] = "aCdrgDmphsv";
-static int howto_masks[] = {
- RB_ASKNAME, RB_CDROM, RB_KDB, RB_DFLTROOT, RB_GDB, RB_MULTIPLE,
- RB_MUTE, RB_PAUSE, RB_SERIAL, RB_SINGLE, RB_VERBOSE
-};
-
-int
-bi_getboothowto(char *kargs)
-{
- const char *sw;
- char *opts;
- int howto, i;
-
- howto = 0;
-
- /* Get the boot options from the environment first. */
- for (i = 0; howto_names[i].ev != NULL; i++) {
- if (getenv(howto_names[i].ev) != NULL)
- howto |= howto_names[i].mask;
- }
-
- /* Parse kargs */
- if (kargs == NULL)
- return (howto);
-
- opts = strchr(kargs, '-');
- while (opts != NULL) {
- while (*(++opts) != '\0') {
- sw = strchr(howto_switches, *opts);
- if (sw == NULL)
- break;
- howto |= howto_masks[sw - howto_switches];
- }
- opts = strchr(opts, '-');
- }
-
- return (howto);
-}
-
-/*
- * Copy the environment into the load area starting at (addr).
- * Each variable is formatted as <name>=<value>, with a single nul
- * separating each variable, and a double nul terminating the environment.
- */
-vm_offset_t
-bi_copyenv(vm_offset_t start)
-{
- struct env_var *ep;
- vm_offset_t addr, last;
- size_t len;
-
- addr = last = start;
-
- /* Traverse the environment. */
- for (ep = environ; ep != NULL; ep = ep->ev_next) {
- len = strlen(ep->ev_name);
- if (i386_copyin(ep->ev_name, addr, len) != len)
- break;
- addr += len;
- if (i386_copyin("=", addr, 1) != 1)
- break;
- addr++;
- if (ep->ev_value != NULL) {
- len = strlen(ep->ev_value);
- if (i386_copyin(ep->ev_value, addr, len) != len)
- break;
- addr += len;
- }
- if (i386_copyin("", addr, 1) != 1)
- break;
- last = ++addr;
- }
-
- if (i386_copyin("", last++, 1) != 1)
- last = start;
- return(last);
-}
-
-/*
- * Copy module-related data into the load area, where it can be
- * used as a directory for loaded modules.
- *
- * Module data is presented in a self-describing format. Each datum
- * is preceded by a 32-bit identifier and a 32-bit size field.
- *
- * Currently, the following data are saved:
- *
- * MOD_NAME (variable) module name (string)
- * MOD_TYPE (variable) module type (string)
- * MOD_ARGS (variable) module parameters (string)
- * MOD_ADDR sizeof(vm_offset_t) module load address
- * MOD_SIZE sizeof(size_t) module size
- * MOD_METADATA (variable) type-specific metadata
- */
-#define COPY32(v, a) { \
- u_int32_t x = (v); \
- i386_copyin(&x, a, sizeof(x)); \
- a += sizeof(x); \
-}
-
-#define MOD_STR(t, a, s) { \
- COPY32(t, a); \
- COPY32(strlen(s) + 1, a); \
- i386_copyin(s, a, strlen(s) + 1); \
- a += roundup(strlen(s) + 1, sizeof(u_int64_t));\
-}
-
-#define MOD_NAME(a, s) MOD_STR(MODINFO_NAME, a, s)
-#define MOD_TYPE(a, s) MOD_STR(MODINFO_TYPE, a, s)
-#define MOD_ARGS(a, s) MOD_STR(MODINFO_ARGS, a, s)
-
-#define MOD_VAR(t, a, s) { \
- COPY32(t, a); \
- COPY32(sizeof(s), a); \
- i386_copyin(&s, a, sizeof(s)); \
- a += roundup(sizeof(s), sizeof(u_int64_t)); \
-}
-
-#define MOD_ADDR(a, s) MOD_VAR(MODINFO_ADDR, a, s)
-#define MOD_SIZE(a, s) MOD_VAR(MODINFO_SIZE, a, s)
-
-#define MOD_METADATA(a, mm) { \
- COPY32(MODINFO_METADATA | mm->md_type, a); \
- COPY32(mm->md_size, a); \
- i386_copyin(mm->md_data, a, mm->md_size); \
- a += roundup(mm->md_size, sizeof(u_int64_t));\
-}
-
-#define MOD_END(a) { \
- COPY32(MODINFO_END, a); \
- COPY32(0, a); \
-}
-
-vm_offset_t
-bi_copymodules(vm_offset_t addr)
-{
- struct preloaded_file *fp;
- struct file_metadata *md;
-
- /* Start with the first module on the list, should be the kernel. */
- for (fp = file_findfile(NULL, NULL); fp != NULL; fp = fp->f_next) {
- /* The name field must come first. */
- MOD_NAME(addr, fp->f_name);
- MOD_TYPE(addr, fp->f_type);
- if (fp->f_args)
- MOD_ARGS(addr, fp->f_args);
- MOD_ADDR(addr, fp->f_addr);
- MOD_SIZE(addr, fp->f_size);
- for (md = fp->f_metadata; md != NULL; md = md->md_next) {
- if (!(md->md_type & MODINFOMD_NOCOPY))
- MOD_METADATA(addr, md);
- }
- }
- MOD_END(addr);
- return(addr);
-}
-
-/*
- * Load the information expected by the kernel.
- *
- * - The kernel environment is copied into kernel space.
- * - Module metadata are formatted and placed in kernel space.
- */
-int
-bi_load(struct preloaded_file *fp, uint64_t *bi_addr)
-{
- struct bootinfo bi;
- struct preloaded_file *xp;
- struct file_metadata *md;
- struct devdesc *rootdev;
- char *rootdevname;
- vm_offset_t addr, ssym, esym;
-
- bzero(&bi, sizeof(struct bootinfo));
- bi.bi_version = 1;
-// bi.bi_boothowto = bi_getboothowto(fp->f_args);
-
- /*
- * Allow the environment variable 'rootdev' to override the supplied
- * device. This should perhaps go to MI code and/or have $rootdev
- * tested/set by MI code before launching the kernel.
- */
- rootdevname = getenv("rootdev");
- i386_getdev((void**)&rootdev, rootdevname, NULL);
- if (rootdev != NULL) {
- /* Try reading /etc/fstab to select the root device. */
- getrootmount(i386_fmtdev(rootdev));
- free(rootdev);
- }
-
- md = file_findmetadata(fp, MODINFOMD_SSYM);
- ssym = (md != NULL) ? *((vm_offset_t *)&(md->md_data)) : 0;
- md = file_findmetadata(fp, MODINFOMD_ESYM);
- esym = (md != NULL) ? *((vm_offset_t *)&(md->md_data)) : 0;
- if (ssym != 0 && esym != 0) {
- bi.bi_symtab = ssym;
- bi.bi_esymtab = esym;
- }
-
- /* Find the last module in the chain. */
- addr = 0;
- for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
- if (addr < (xp->f_addr + xp->f_size))
- addr = xp->f_addr + xp->f_size;
- }
-
- addr = (addr + 15) & ~15;
-
- /* Copy module list and metadata. */
- bi.bi_modulep = addr;
- addr = bi_copymodules(addr);
- if (addr <= bi.bi_modulep) {
- addr = bi.bi_modulep;
- bi.bi_modulep = 0;
- }
-
- addr = (addr + 15) & ~15;
-
- /* Copy our environment. */
- bi.bi_envp = addr;
- addr = bi_copyenv(addr);
- if (addr <= bi.bi_envp) {
- addr = bi.bi_envp;
- bi.bi_envp = 0;
- }
-
- addr = (addr + PAGE_MASK) & ~PAGE_MASK;
- bi.bi_kernend = addr;
-
- return (ldr_bootinfo(&bi, bi_addr));
-}
diff --git a/sys/boot/i386/efi/efimd.c b/sys/boot/i386/efi/efimd.c
deleted file mode 100644
index 01905e6..0000000
--- a/sys/boot/i386/efi/efimd.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*-
- * Copyright (c) 2004, 2006 Marcel Moolenaar
- * All rights reserved.
- *
- * 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 ``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 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stand.h>
-
-#include <efi.h>
-#include <efilib.h>
-
-#include <libi386.h>
-#include <machine/bootinfo.h>
-
-#define EFI_INTEL_FPSWA \
- {0xc41b6531,0x97b9,0x11d3,{0x9a,0x29,0x00,0x90,0x27,0x3f,0xc1,0x4d}}
-
-static EFI_GUID fpswa_guid = EFI_INTEL_FPSWA;
-
-/* DIG64 Headless Console & Debug Port Table. */
-#define HCDP_TABLE_GUID \
- {0xf951938d,0x620b,0x42ef,{0x82,0x79,0xa8,0x4b,0x79,0x61,0x78,0x98}}
-
-static EFI_GUID hcdp_guid = HCDP_TABLE_GUID;
-
-static UINTN mapkey;
-
-uint64_t
-ldr_alloc(vm_offset_t va)
-{
-
- return (0);
-}
-
-int
-ldr_bootinfo(struct bootinfo *bi, uint64_t *bi_addr)
-{
- VOID *fpswa;
- EFI_MEMORY_DESCRIPTOR *mm;
- EFI_PHYSICAL_ADDRESS addr;
- EFI_HANDLE handle;
- EFI_STATUS status;
- size_t bisz;
- UINTN mmsz, pages, sz;
- UINT32 mmver;
-
- bi->bi_systab = (uint64_t)ST;
- bi->bi_hcdp = (uint64_t)efi_get_table(&hcdp_guid);
-
- sz = sizeof(EFI_HANDLE);
- status = BS->LocateHandle(ByProtocol, &fpswa_guid, 0, &sz, &handle);
- if (status == 0)
- status = BS->HandleProtocol(handle, &fpswa_guid, &fpswa);
- bi->bi_fpswa = (status == 0) ? (uint64_t)fpswa : 0;
-
- bisz = (sizeof(struct bootinfo) + 0x0f) & ~0x0f;
-
- /*
- * Allocate enough pages to hold the bootinfo block and the memory
- * map EFI will return to us. The memory map has an unknown size,
- * so we have to determine that first. Note that the AllocatePages
- * call can itself modify the memory map, so we have to take that
- * into account as well. The changes to the memory map are caused
- * by splitting a range of free memory into two (AFAICT), so that
- * one is marked as being loader data.
- */
- sz = 0;
- BS->GetMemoryMap(&sz, NULL, &mapkey, &mmsz, &mmver);
- sz += mmsz;
- sz = (sz + 15) & ~15;
- pages = EFI_SIZE_TO_PAGES(sz + bisz);
- status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, pages,
- &addr);
- if (EFI_ERROR(status)) {
- printf("%s: AllocatePages() returned 0x%lx\n", __func__,
- (long)status);
- return (ENOMEM);
- }
-
- /*
- * Read the memory map and stash it after bootinfo. Align the
- * memory map on a 16-byte boundary (the bootinfo block is page
- * aligned).
- */
- *bi_addr = addr;
- mm = (void *)(addr + bisz);
- sz = (EFI_PAGE_SIZE * pages) - bisz;
- status = BS->GetMemoryMap(&sz, mm, &mapkey, &mmsz, &mmver);
- if (EFI_ERROR(status)) {
- printf("%s: GetMemoryMap() returned 0x%lx\n", __func__,
- (long)status);
- return (EINVAL);
- }
- bi->bi_memmap = (uint64_t)mm;
- bi->bi_memmap_size = sz;
- bi->bi_memdesc_size = mmsz;
- bi->bi_memdesc_version = mmver;
-
- bcopy(bi, (void *)(*bi_addr), sizeof(*bi));
- return (0);
-}
-
-int
-ldr_enter(const char *kernel)
-{
- EFI_STATUS status;
-
- status = BS->ExitBootServices(IH, mapkey);
- if (EFI_ERROR(status)) {
- printf("%s: ExitBootServices() returned 0x%lx\n", __func__,
- (long)status);
- return (EINVAL);
- }
-
- return (0);
-}
diff --git a/sys/boot/i386/efi/elf32_freebsd.c b/sys/boot/i386/efi/elf32_freebsd.c
deleted file mode 100644
index f193735..0000000
--- a/sys/boot/i386/efi/elf32_freebsd.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
- * All rights reserved.
- *
- * 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/exec.h>
-#include <sys/linker.h>
-#include <string.h>
-#include <machine/bootinfo.h>
-#include <machine/elf.h>
-#include <stand.h>
-
-#include "bootstrap.h"
-#include "../libi386/libi386.h"
-#include "../btx/lib/btxv86.h"
-
-extern void __exec(caddr_t addr, ...);
-
-
-static int elf32_exec(struct preloaded_file *amp);
-static int elf32_obj_exec(struct preloaded_file *amp);
-
-struct file_format i386_elf = { elf32_loadfile, elf32_exec };
-struct file_format i386_elf_obj = { elf32_obj_loadfile, elf32_obj_exec };
-
-/*
- * There is an ELF kernel and one or more ELF modules loaded.
- * We wish to start executing the kernel image, so make such
- * preparations as are required, and do so.
- */
-static int
-elf32_exec(struct preloaded_file *fp)
-{
- struct file_metadata *md;
- Elf_Ehdr *ehdr;
- vm_offset_t entry, bootinfop, modulep, kernend;
- int boothowto, err, bootdev;
-
- if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
- return(EFTYPE);
- ehdr = (Elf_Ehdr *)&(md->md_data);
-
- err = bi_load(fp->f_args, &boothowto, &bootdev, &bootinfop, &modulep, &kernend);
- if (err != 0)
- return(err);
- entry = ehdr->e_entry & 0xffffff;
-
- printf("Start @ 0x%lx ...\n", entry);
-
- ldr_enter(fp->f_name);
-
- dev_cleanup();
- __exec((void *)entry, boothowto, bootdev, 0, 0, 0, bootinfop, modulep, kernend);
-
- panic("exec returned");
-}
-
-static int
-elf32_obj_exec(struct preloaded_file *fp)
-{
- return (EFTYPE);
-}
diff --git a/sys/boot/i386/efi/ldscript.i386 b/sys/boot/i386/efi/ldscript.i386
deleted file mode 100644
index fdfda0a..0000000
--- a/sys/boot/i386/efi/ldscript.i386
+++ /dev/null
@@ -1,72 +0,0 @@
-/* $FreeBSD$ */
-OUTPUT_FORMAT("elf32-i386-freebsd", "elf32-i386-freebsd", "elf32-i386-freebsd")
-OUTPUT_ARCH(i386)
-ENTRY(_start)
-SECTIONS
-{
- /* Read-only sections, merged into text segment: */
- . = 0;
- ImageBase = .;
- . = SIZEOF_HEADERS;
- . = ALIGN(4096);
- .text : {
- *(.text .stub .text.* .gnu.linkonce.t.*)
- /* .gnu.warning sections are handled specially by elf32.em. */
- *(.gnu.warning)
- *(.plt)
- } =0x00300000010070000002000001000400
- . = ALIGN(4096);
- .data : {
- *(.rodata .rodata.* .gnu.linkonce.r.*)
- *(.rodata1)
- *(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
- *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)
- *(.opd)
- *(.data .data.* .gnu.linkonce.d.*)
- *(.data1)
- *(.plabel)
- *(.dynbss)
- *(.bss .bss.* .gnu.linkonce.b.*)
- *(COMMON)
- }
- . = ALIGN(4096);
- set_Xcommand_set : {
- __start_set_Xcommand_set = .;
- *(set_Xcommand_set)
- __stop_set_Xcommand_set = .;
- }
- . = ALIGN(4096);
- __gp = .;
- .sdata : {
- *(.got.plt .got)
- *(.sdata .sdata.* .gnu.linkonce.s.*)
- *(dynsbss)
- *(.sbss .sbss.* .gnu.linkonce.sb.*)
- *(.scommon)
- }
- . = ALIGN(4096);
- .dynamic : { *(.dynamic) }
- . = ALIGN(4096);
- .rel.dyn : {
- *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
- *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
- *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
- *(.rel.got)
- *(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*)
- *(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*)
- *(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*)
- *(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*)
- *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
- *(.rel.plt)
- *(.relset_*)
- *(.rel.dyn .rel.dyn.*)
- }
- . = ALIGN(4096);
- .reloc : { *(.reloc) }
- . = ALIGN(4096);
- .hash : { *(.hash) }
- . = ALIGN(4096);
- .dynsym : { *(.dynsym) }
- . = ALIGN(4096);
- .dynstr : { *(.dynstr) }
-}
diff --git a/sys/boot/i386/efi/reloc.c b/sys/boot/i386/efi/reloc.c
deleted file mode 100644
index 22c6642..0000000
--- a/sys/boot/i386/efi/reloc.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * Copyright (c) 2008-2010 Rui Paulo <rpaulo@FreeBSD.org>
- * All rights reserved.
- *
- * 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <elf.h>
-#include <efi.h>
-#include <bootstrap.h>
-
-#ifdef __i386__
-#define ElfW_Rel Elf32_Rel
-#define ElfW_Dyn Elf32_Dyn
-#define ELFW_R_TYPE ELF32_R_TYPE
-#elif __amd64__
-#define ElfW_Rel Elf64_Rel
-#define ElfW_Dyn Elf64_Dyn
-#define ELFW_R_TYPE ELF64_R_TYPE
-#endif
-
-/*
- * A simple relocator for IA32/AMD64 EFI binaries.
- */
-EFI_STATUS
-_reloc(unsigned long ImageBase, ElfW_Dyn *dynamic, EFI_HANDLE image_handle,
- EFI_SYSTEM_TABLE *system_table)
-{
- unsigned long relsz, relent;
- unsigned long *newaddr;
- ElfW_Rel *rel;
- ElfW_Dyn *dynp;
-
- /*
- * Find the relocation address, its size and the relocation entry.
- */
- relsz = 0;
- relent = 0;
- for (dynp = dynamic; dynp->d_tag != DT_NULL; dynp++) {
- switch (dynp->d_tag) {
- case DT_RELA:
- case DT_REL:
- rel = (ElfW_Rel *) ((unsigned long) dynp->d_un.d_ptr +
- ImageBase);
- break;
- case DT_RELSZ:
- case DT_RELASZ:
- relsz = dynp->d_un.d_val;
- break;
- case DT_RELENT:
- case DT_RELAENT:
- relent = dynp->d_un.d_val;
- break;
- default:
- break;
- }
- }
-
- /*
- * Perform the actual relocation.
- * XXX: We are reusing code for the amd64 version of this, but
- * we must make sure the relocation types are the same.
- */
- CTASSERT(R_386_NONE == R_X86_64_NONE);
- CTASSERT(R_386_RELATIVE == R_X86_64_RELATIVE);
- for (; relsz > 0; relsz -= relent) {
- switch (ELFW_R_TYPE(rel->r_info)) {
- case R_386_NONE:
- /* No relocation needs be performed. */
- break;
- case R_386_RELATIVE:
- /* Address relative to the base address. */
- newaddr = (unsigned long *)(ImageBase + rel->r_offset);
- *newaddr += ImageBase;
- break;
- default:
- /* XXX: do we need other relocations ? */
- break;
- }
- rel = (ElfW_Rel *) ((caddr_t) rel + relent);
- }
-
- return (EFI_SUCCESS);
-}
diff --git a/sys/boot/i386/efi/start.S b/sys/boot/i386/efi/start.S
deleted file mode 100644
index ea4597f..0000000
--- a/sys/boot/i386/efi/start.S
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * Copyright (c) 2008-2010 Rui Paulo <rpaulo@FreeBSD.org>
- * All rights reserved.
- *
- * 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$
- */
-
- .text
-
-#include <machine/asm.h>
-
-#define EFI_SUCCESS 0
-
-/*
- * EFI entry point.
- * _start(EFI_IMAGE image_handle, EFI_SYSTEM_TABLE *system_table);
- *
- * We calculate the base address along with _DYNAMIC, relocate us and finally
- * pass control to efi_main.
- */
-
-ENTRY(_start)
- pushl %ebp
- movl %esp, %ebp
-
- pushl 12(%ebp) /* image_handle */
- pushl 8(%ebp) /* system_table */
- call 0f
-0: popl %eax
- movl %eax, %ebx
- addl $ImageBase-0b, %eax
- addl $_DYNAMIC-0b, %ebx
- pushl %ebx /* dynamic */
- pushl %eax /* ImageBase */
- call _reloc
- cmpl $EFI_SUCCESS, %eax
- jne 1f
- popl %ebx /* remove ImageBase from the stack */
- popl %ebx /* remove dynamic from the stack */
- call efi_main
-1: leave
- ret
-END(_start)
-
- .data
- .section .reloc, "a"
- .long 0
- .long 10
- .word 0
diff --git a/sys/boot/i386/loader/Makefile b/sys/boot/i386/loader/Makefile
index 9f2f1b2..1ab909d3 100644
--- a/sys/boot/i386/loader/Makefile
+++ b/sys/boot/i386/loader/Makefile
@@ -108,12 +108,7 @@ FILESMODE_${LOADER}= ${BINMODE} -b
.PATH: ${.CURDIR}/../../forth
.include "${.CURDIR}/../../forth/Makefile.inc"
-.if !exists(${DESTDIR}/boot/loader.rc)
-FILES+= loader.rc
-.endif
-.if !exists(${DESTDIR}/boot/menu.rc)
-FILES+= menu.rc
-.endif
+FILES+= loader.rc menu.rc
.endif
# XXX crt0.o needs to be first for pxeboot(8) to work
diff --git a/sys/boot/pc98/loader/Makefile b/sys/boot/pc98/loader/Makefile
index 3eafed4..13b9520 100644
--- a/sys/boot/pc98/loader/Makefile
+++ b/sys/boot/pc98/loader/Makefile
@@ -89,12 +89,7 @@ FILESMODE_${LOADER}= ${BINMODE} -b
.PATH: ${.CURDIR}/../../forth
.include "${.CURDIR}/../../forth/Makefile.inc"
-.if !exists(${DESTDIR}/boot/loader.rc)
-FILES+= ${.CURDIR}/../../i386/loader/loader.rc
-.endif
-.if !exists(${DESTDIR}/boot/menu.rc)
-FILES+= menu.rc
-.endif
+FILES+= ${.CURDIR}/../../i386/loader/loader.rc menu.rc
# XXX crt0.o needs to be first for pxeboot(8) to work
OBJS= ${BTXCRT}
diff --git a/sys/boot/powerpc/ofw/Makefile b/sys/boot/powerpc/ofw/Makefile
index fbde1e7..83112d1 100644
--- a/sys/boot/powerpc/ofw/Makefile
+++ b/sys/boot/powerpc/ofw/Makefile
@@ -105,12 +105,6 @@ loader.help: help.common help.ofw
.PATH: ${.CURDIR}/../../forth
.include "${.CURDIR}/../../forth/Makefile.inc"
-.if !exists(${DESTDIR}/boot/loader.rc)
-FILES+= loader.rc
-.endif
-
-.if !exists(${DESTDIR}/boot/menu.rc)
-FILES+= menu.rc
-.endif
+FILES+= loader.rc menu.rc
.include <bsd.prog.mk>
diff --git a/sys/boot/powerpc/ps3/Makefile b/sys/boot/powerpc/ps3/Makefile
index a90a92c..4c67c15 100644
--- a/sys/boot/powerpc/ps3/Makefile
+++ b/sys/boot/powerpc/ps3/Makefile
@@ -116,12 +116,6 @@ loader.help: help.common help.ps3 ${.CURDIR}/../../fdt/help.fdt
.PATH: ${.CURDIR}/../../forth
.include "${.CURDIR}/../../forth/Makefile.inc"
-.if !exists(${DESTDIR}/boot/loader.rc)
-FILES+= loader.rc
-.endif
-
-.if !exists(${DESTDIR}/boot/menu.rc)
-FILES+= menu.rc
-.endif
+FILES+= loader.rc menu.rc
.include <bsd.prog.mk>
diff --git a/sys/boot/sparc64/loader/Makefile b/sys/boot/sparc64/loader/Makefile
index 06c9838..92e5a95 100644
--- a/sys/boot/sparc64/loader/Makefile
+++ b/sys/boot/sparc64/loader/Makefile
@@ -98,12 +98,6 @@ loader.help: help.common help.sparc64
.PATH: ${.CURDIR}/../../forth
.include "${.CURDIR}/../../forth/Makefile.inc"
-.if !exists(${DESTDIR}/boot/loader.rc)
-FILES+= loader.rc
-.endif
-
-.if !exists(${DESTDIR}/boot/menu.rc)
-FILES+= menu.rc
-.endif
+FILES+= loader.rc menu.rc
.include <bsd.prog.mk>
diff --git a/sys/bsm/audit.h b/sys/bsm/audit.h
index 625e816..078b333 100644
--- a/sys/bsm/audit.h
+++ b/sys/bsm/audit.h
@@ -26,7 +26,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit.h#10
* $FreeBSD$
*/
diff --git a/sys/bsm/audit_domain.h b/sys/bsm/audit_domain.h
index 76cd38f..22d2966 100644
--- a/sys/bsm/audit_domain.h
+++ b/sys/bsm/audit_domain.h
@@ -26,7 +26,6 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_domain.h#2
* $FreeBSD$
*/
diff --git a/sys/bsm/audit_errno.h b/sys/bsm/audit_errno.h
index d5a375f..939ddeb 100644
--- a/sys/bsm/audit_errno.h
+++ b/sys/bsm/audit_errno.h
@@ -26,7 +26,6 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_errno.h#7
* $FreeBSD$
*/
diff --git a/sys/bsm/audit_fcntl.h b/sys/bsm/audit_fcntl.h
index 15b5f51..8b5f1a5 100644
--- a/sys/bsm/audit_fcntl.h
+++ b/sys/bsm/audit_fcntl.h
@@ -26,7 +26,6 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_fcntl.h#2
* $FreeBSD$
*/
diff --git a/sys/bsm/audit_internal.h b/sys/bsm/audit_internal.h
index 8ba611f..3ec9896 100644
--- a/sys/bsm/audit_internal.h
+++ b/sys/bsm/audit_internal.h
@@ -30,7 +30,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#6
* $FreeBSD$
*/
diff --git a/sys/bsm/audit_kevents.h b/sys/bsm/audit_kevents.h
index 303d37f..3c16c73 100644
--- a/sys/bsm/audit_kevents.h
+++ b/sys/bsm/audit_kevents.h
@@ -26,7 +26,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_kevents.h#7
* $FreeBSD$
*/
@@ -34,7 +33,7 @@
#define _BSM_AUDIT_KEVENTS_H_
/*
- * The reserved event numbers for kernel events are 1...2047 and 43001..44900.
+ * The reserved event numbers for kernel events are 1...2047 and 43001..44999.
*/
#define AUE_IS_A_KEVENT(e) (((e) > 0 && (e) < 2048) || \
((e) > 43000 && (e) < 45000))
diff --git a/sys/bsm/audit_record.h b/sys/bsm/audit_record.h
index 7e6074f..63c5f50 100644
--- a/sys/bsm/audit_record.h
+++ b/sys/bsm/audit_record.h
@@ -26,7 +26,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_record.h#10
* $FreeBSD$
*/
diff --git a/sys/bsm/audit_socket_type.h b/sys/bsm/audit_socket_type.h
index 6b6bac1..1f580fc 100644
--- a/sys/bsm/audit_socket_type.h
+++ b/sys/bsm/audit_socket_type.h
@@ -26,7 +26,6 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_socket_type.h#1
* $FreeBSD$
*/
diff --git a/sys/cddl/compat/opensolaris/sys/nvpair.h b/sys/cddl/compat/opensolaris/sys/nvpair.h
new file mode 100644
index 0000000..c90ab70
--- /dev/null
+++ b/sys/cddl/compat/opensolaris/sys/nvpair.h
@@ -0,0 +1,263 @@
+/*-
+ * Copyright (c) 2014 Sandvine Inc.
+ * All rights reserved.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#ifndef _OPENSOLARIS_SYS_NVPAIR_H_
+#define _OPENSOLARIS_SYS_NVPAIR_H_
+
+#ifdef _KERNEL
+
+/*
+ * Some of the symbols in the Illumos nvpair library conflict with symbols
+ * provided by nv(9), so we use this preprocessor hack to avoid the conflict.
+ *
+ * This list was generated by:
+ * cat nv.h nv_impl.h nvlist_* nvpair_impl.h | \
+ * sed -nE 's/^[[:alnum:]_][[:alnum:]_ ]*[[:space:]]+[*]*([[:alnum:]_]+)\(.*$/#define \1 illumos_\1/p' | \
+ * sort -u
+ */
+#define nvlist_add_binary illumos_nvlist_add_binary
+#define nvlist_add_bool illumos_nvlist_add_bool
+#define nvlist_add_descriptor illumos_nvlist_add_descriptor
+#define nvlist_add_null illumos_nvlist_add_null
+#define nvlist_add_number illumos_nvlist_add_number
+#define nvlist_add_nvlist illumos_nvlist_add_nvlist
+#define nvlist_add_nvpair illumos_nvlist_add_nvpair
+#define nvlist_add_string illumos_nvlist_add_string
+#define nvlist_add_stringf illumos_nvlist_add_stringf
+#define nvlist_add_stringv illumos_nvlist_add_stringv
+#define nvlist_addf_binary illumos_nvlist_addf_binary
+#define nvlist_addf_bool illumos_nvlist_addf_bool
+#define nvlist_addf_descriptor illumos_nvlist_addf_descriptor
+#define nvlist_addf_null illumos_nvlist_addf_null
+#define nvlist_addf_number illumos_nvlist_addf_number
+#define nvlist_addf_nvlist illumos_nvlist_addf_nvlist
+#define nvlist_addf_string illumos_nvlist_addf_string
+#define nvlist_addv_binary illumos_nvlist_addv_binary
+#define nvlist_addv_bool illumos_nvlist_addv_bool
+#define nvlist_addv_descriptor illumos_nvlist_addv_descriptor
+#define nvlist_addv_null illumos_nvlist_addv_null
+#define nvlist_addv_number illumos_nvlist_addv_number
+#define nvlist_addv_nvlist illumos_nvlist_addv_nvlist
+#define nvlist_addv_string illumos_nvlist_addv_string
+#define nvlist_check_header illumos_nvlist_check_header
+#define nvlist_clone illumos_nvlist_clone
+#define nvlist_create illumos_nvlist_create
+#define nvlist_descriptors illumos_nvlist_descriptors
+#define nvlist_destroy illumos_nvlist_destroy
+#define nvlist_dump illumos_nvlist_dump
+#define nvlist_empty illumos_nvlist_empty
+#define nvlist_error illumos_nvlist_error
+#define nvlist_exists illumos_nvlist_exists
+#define nvlist_exists_binary illumos_nvlist_exists_binary
+#define nvlist_exists_bool illumos_nvlist_exists_bool
+#define nvlist_exists_descriptor illumos_nvlist_exists_descriptor
+#define nvlist_exists_null illumos_nvlist_exists_null
+#define nvlist_exists_number illumos_nvlist_exists_number
+#define nvlist_exists_nvlist illumos_nvlist_exists_nvlist
+#define nvlist_exists_string illumos_nvlist_exists_string
+#define nvlist_exists_type illumos_nvlist_exists_type
+#define nvlist_existsf illumos_nvlist_existsf
+#define nvlist_existsf_binary illumos_nvlist_existsf_binary
+#define nvlist_existsf_bool illumos_nvlist_existsf_bool
+#define nvlist_existsf_descriptor illumos_nvlist_existsf_descriptor
+#define nvlist_existsf_null illumos_nvlist_existsf_null
+#define nvlist_existsf_number illumos_nvlist_existsf_number
+#define nvlist_existsf_nvlist illumos_nvlist_existsf_nvlist
+#define nvlist_existsf_string illumos_nvlist_existsf_string
+#define nvlist_existsf_type illumos_nvlist_existsf_type
+#define nvlist_existsv illumos_nvlist_existsv
+#define nvlist_existsv_binary illumos_nvlist_existsv_binary
+#define nvlist_existsv_bool illumos_nvlist_existsv_bool
+#define nvlist_existsv_descriptor illumos_nvlist_existsv_descriptor
+#define nvlist_existsv_null illumos_nvlist_existsv_null
+#define nvlist_existsv_number illumos_nvlist_existsv_number
+#define nvlist_existsv_nvlist illumos_nvlist_existsv_nvlist
+#define nvlist_existsv_string illumos_nvlist_existsv_string
+#define nvlist_existsv_type illumos_nvlist_existsv_type
+#define nvlist_fdump illumos_nvlist_fdump
+#define nvlist_first_nvpair illumos_nvlist_first_nvpair
+#define nvlist_free illumos_nvlist_free
+#define nvlist_free_binary illumos_nvlist_free_binary
+#define nvlist_free_bool illumos_nvlist_free_bool
+#define nvlist_free_descriptor illumos_nvlist_free_descriptor
+#define nvlist_free_null illumos_nvlist_free_null
+#define nvlist_free_number illumos_nvlist_free_number
+#define nvlist_free_nvlist illumos_nvlist_free_nvlist
+#define nvlist_free_nvpair illumos_nvlist_free_nvpair
+#define nvlist_free_string illumos_nvlist_free_string
+#define nvlist_free_type illumos_nvlist_free_type
+#define nvlist_freef illumos_nvlist_freef
+#define nvlist_freef_binary illumos_nvlist_freef_binary
+#define nvlist_freef_bool illumos_nvlist_freef_bool
+#define nvlist_freef_descriptor illumos_nvlist_freef_descriptor
+#define nvlist_freef_null illumos_nvlist_freef_null
+#define nvlist_freef_number illumos_nvlist_freef_number
+#define nvlist_freef_nvlist illumos_nvlist_freef_nvlist
+#define nvlist_freef_string illumos_nvlist_freef_string
+#define nvlist_freef_type illumos_nvlist_freef_type
+#define nvlist_freev illumos_nvlist_freev
+#define nvlist_freev_binary illumos_nvlist_freev_binary
+#define nvlist_freev_bool illumos_nvlist_freev_bool
+#define nvlist_freev_descriptor illumos_nvlist_freev_descriptor
+#define nvlist_freev_null illumos_nvlist_freev_null
+#define nvlist_freev_number illumos_nvlist_freev_number
+#define nvlist_freev_nvlist illumos_nvlist_freev_nvlist
+#define nvlist_freev_string illumos_nvlist_freev_string
+#define nvlist_freev_type illumos_nvlist_freev_type
+#define nvlist_get_binary illumos_nvlist_get_binary
+#define nvlist_get_bool illumos_nvlist_get_bool
+#define nvlist_get_descriptor illumos_nvlist_get_descriptor
+#define nvlist_get_number illumos_nvlist_get_number
+#define nvlist_get_nvlist illumos_nvlist_get_nvlist
+#define nvlist_get_nvpair illumos_nvlist_get_nvpair
+#define nvlist_get_string illumos_nvlist_get_string
+#define nvlist_getf_binary illumos_nvlist_getf_binary
+#define nvlist_getf_bool illumos_nvlist_getf_bool
+#define nvlist_getf_descriptor illumos_nvlist_getf_descriptor
+#define nvlist_getf_number illumos_nvlist_getf_number
+#define nvlist_getf_nvlist illumos_nvlist_getf_nvlist
+#define nvlist_getf_string illumos_nvlist_getf_string
+#define nvlist_getv_binary illumos_nvlist_getv_binary
+#define nvlist_getv_bool illumos_nvlist_getv_bool
+#define nvlist_getv_descriptor illumos_nvlist_getv_descriptor
+#define nvlist_getv_number illumos_nvlist_getv_number
+#define nvlist_getv_nvlist illumos_nvlist_getv_nvlist
+#define nvlist_getv_string illumos_nvlist_getv_string
+#define nvlist_move_binary illumos_nvlist_move_binary
+#define nvlist_move_descriptor illumos_nvlist_move_descriptor
+#define nvlist_move_nvlist illumos_nvlist_move_nvlist
+#define nvlist_move_nvpair illumos_nvlist_move_nvpair
+#define nvlist_move_string illumos_nvlist_move_string
+#define nvlist_movef_binary illumos_nvlist_movef_binary
+#define nvlist_movef_descriptor illumos_nvlist_movef_descriptor
+#define nvlist_movef_nvlist illumos_nvlist_movef_nvlist
+#define nvlist_movef_string illumos_nvlist_movef_string
+#define nvlist_movev_binary illumos_nvlist_movev_binary
+#define nvlist_movev_descriptor illumos_nvlist_movev_descriptor
+#define nvlist_movev_nvlist illumos_nvlist_movev_nvlist
+#define nvlist_movev_string illumos_nvlist_movev_string
+#define nvlist_ndescriptors illumos_nvlist_ndescriptors
+#define nvlist_next illumos_nvlist_next
+#define nvlist_next_nvpair illumos_nvlist_next_nvpair
+#define nvlist_pack illumos_nvlist_pack
+#define nvlist_prev_nvpair illumos_nvlist_prev_nvpair
+#define nvlist_recv illumos_nvlist_recv
+#define nvlist_remove_nvpair illumos_nvlist_remove_nvpair
+#define nvlist_report_missing illumos_nvlist_report_missing
+#define nvlist_send illumos_nvlist_send
+#define nvlist_set_error illumos_nvlist_set_error
+#define nvlist_size illumos_nvlist_size
+#define nvlist_take_binary illumos_nvlist_take_binary
+#define nvlist_take_bool illumos_nvlist_take_bool
+#define nvlist_take_descriptor illumos_nvlist_take_descriptor
+#define nvlist_take_number illumos_nvlist_take_number
+#define nvlist_take_nvlist illumos_nvlist_take_nvlist
+#define nvlist_take_nvpair illumos_nvlist_take_nvpair
+#define nvlist_take_string illumos_nvlist_take_string
+#define nvlist_takef_binary illumos_nvlist_takef_binary
+#define nvlist_takef_bool illumos_nvlist_takef_bool
+#define nvlist_takef_descriptor illumos_nvlist_takef_descriptor
+#define nvlist_takef_number illumos_nvlist_takef_number
+#define nvlist_takef_nvlist illumos_nvlist_takef_nvlist
+#define nvlist_takef_string illumos_nvlist_takef_string
+#define nvlist_takev_binary illumos_nvlist_takev_binary
+#define nvlist_takev_bool illumos_nvlist_takev_bool
+#define nvlist_takev_descriptor illumos_nvlist_takev_descriptor
+#define nvlist_takev_number illumos_nvlist_takev_number
+#define nvlist_takev_nvlist illumos_nvlist_takev_nvlist
+#define nvlist_takev_string illumos_nvlist_takev_string
+#define nvlist_unpack illumos_nvlist_unpack
+#define nvlist_xfer illumos_nvlist_xfer
+#define nvlist_xpack illumos_nvlist_xpack
+#define nvlist_xunpack illumos_nvlist_xunpack
+#define nvpair_allocv illumos_nvpair_allocv
+#define nvpair_assert illumos_nvpair_assert
+#define nvpair_clone illumos_nvpair_clone
+#define nvpair_create_binary illumos_nvpair_create_binary
+#define nvpair_create_bool illumos_nvpair_create_bool
+#define nvpair_create_descriptor illumos_nvpair_create_descriptor
+#define nvpair_create_null illumos_nvpair_create_null
+#define nvpair_create_number illumos_nvpair_create_number
+#define nvpair_create_nvlist illumos_nvpair_create_nvlist
+#define nvpair_create_string illumos_nvpair_create_string
+#define nvpair_create_stringf illumos_nvpair_create_stringf
+#define nvpair_create_stringv illumos_nvpair_create_stringv
+#define nvpair_createf_binary illumos_nvpair_createf_binary
+#define nvpair_createf_bool illumos_nvpair_createf_bool
+#define nvpair_createf_descriptor illumos_nvpair_createf_descriptor
+#define nvpair_createf_null illumos_nvpair_createf_null
+#define nvpair_createf_number illumos_nvpair_createf_number
+#define nvpair_createf_nvlist illumos_nvpair_createf_nvlist
+#define nvpair_createf_string illumos_nvpair_createf_string
+#define nvpair_createv_binary illumos_nvpair_createv_binary
+#define nvpair_createv_bool illumos_nvpair_createv_bool
+#define nvpair_createv_descriptor illumos_nvpair_createv_descriptor
+#define nvpair_createv_null illumos_nvpair_createv_null
+#define nvpair_createv_number illumos_nvpair_createv_number
+#define nvpair_createv_nvlist illumos_nvpair_createv_nvlist
+#define nvpair_createv_string illumos_nvpair_createv_string
+#define nvpair_free illumos_nvpair_free
+#define nvpair_free_structure illumos_nvpair_free_structure
+#define nvpair_get_binary illumos_nvpair_get_binary
+#define nvpair_get_bool illumos_nvpair_get_bool
+#define nvpair_get_descriptor illumos_nvpair_get_descriptor
+#define nvpair_get_number illumos_nvpair_get_number
+#define nvpair_get_nvlist illumos_nvpair_get_nvlist
+#define nvpair_get_string illumos_nvpair_get_string
+#define nvpair_header_size illumos_nvpair_header_size
+#define nvpair_insert illumos_nvpair_insert
+#define nvpair_move_binary illumos_nvpair_move_binary
+#define nvpair_move_descriptor illumos_nvpair_move_descriptor
+#define nvpair_move_nvlist illumos_nvpair_move_nvlist
+#define nvpair_move_string illumos_nvpair_move_string
+#define nvpair_movef_binary illumos_nvpair_movef_binary
+#define nvpair_movef_descriptor illumos_nvpair_movef_descriptor
+#define nvpair_movef_nvlist illumos_nvpair_movef_nvlist
+#define nvpair_movef_string illumos_nvpair_movef_string
+#define nvpair_movev_binary illumos_nvpair_movev_binary
+#define nvpair_movev_descriptor illumos_nvpair_movev_descriptor
+#define nvpair_movev_nvlist illumos_nvpair_movev_nvlist
+#define nvpair_movev_string illumos_nvpair_movev_string
+#define nvpair_name illumos_nvpair_name
+#define nvpair_next illumos_nvpair_next
+#define nvpair_nvlist illumos_nvpair_nvlist
+#define nvpair_pack illumos_nvpair_pack
+#define nvpair_pack_descriptor illumos_nvpair_pack_descriptor
+#define nvpair_prev illumos_nvpair_prev
+#define nvpair_remove illumos_nvpair_remove
+#define nvpair_size illumos_nvpair_size
+#define nvpair_type illumos_nvpair_type
+#define nvpair_type_string illumos_nvpair_type_string
+#define nvpair_unpack illumos_nvpair_unpack
+#define nvpair_unpack_descriptor illumos_nvpair_unpack_descriptor
+
+#endif /* _KERNEL */
+
+#include_next <sys/nvpair.h>
+
+#endif
diff --git a/sys/cddl/contrib/opensolaris/common/nvpair/fnvpair.c b/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_fnvpair.c
index eb200a2..eb200a2 100644
--- a/sys/cddl/contrib/opensolaris/common/nvpair/fnvpair.c
+++ b/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_fnvpair.c
diff --git a/sys/cddl/contrib/opensolaris/common/nvpair/nvpair.c b/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c
index 7038f7f..7038f7f 100644
--- a/sys/cddl/contrib/opensolaris/common/nvpair/nvpair.c
+++ b/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c
diff --git a/sys/cddl/contrib/opensolaris/common/nvpair/nvpair_alloc_fixed.c b/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair_alloc_fixed.c
index 620171e..620171e 100644
--- a/sys/cddl/contrib/opensolaris/common/nvpair/nvpair_alloc_fixed.c
+++ b/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair_alloc_fixed.c
diff --git a/sys/conf/files b/sys/conf/files
index ec77e97..286a4f1 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -126,9 +126,9 @@ cddl/compat/opensolaris/kern/opensolaris_vm.c optional zfs compile-with "${ZF
cddl/compat/opensolaris/kern/opensolaris_zone.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/common/acl/acl_common.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/common/avl/avl.c optional zfs compile-with "${ZFS_C}"
-cddl/contrib/opensolaris/common/nvpair/fnvpair.c optional zfs compile-with "${ZFS_C}"
-cddl/contrib/opensolaris/common/nvpair/nvpair.c optional zfs compile-with "${ZFS_C}"
-cddl/contrib/opensolaris/common/nvpair/nvpair_alloc_fixed.c optional zfs compile-with "${ZFS_C}"
+cddl/contrib/opensolaris/common/nvpair/opensolaris_fnvpair.c optional zfs compile-with "${ZFS_C}"
+cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c optional zfs compile-with "${ZFS_C}"
+cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair_alloc_fixed.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/common/unicode/u8_textprep.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/common/zfs/zfeature_common.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/common/zfs/zfs_comutil.c optional zfs compile-with "${ZFS_C}"
@@ -3123,6 +3123,7 @@ kern/subr_clock.c standard
kern/subr_counter.c standard
kern/subr_devstat.c standard
kern/subr_disk.c standard
+kern/subr_dnvlist.c standard
kern/subr_eventhandler.c standard
kern/subr_fattime.c standard
kern/subr_firmware.c optional firmware
@@ -3136,6 +3137,8 @@ kern/subr_mbpool.c optional libmbpool
kern/subr_mchain.c optional libmchain
kern/subr_module.c standard
kern/subr_msgbuf.c standard
+kern/subr_nvlist.c standard
+kern/subr_nvpair.c standard
kern/subr_param.c standard
kern/subr_pcpu.c standard
kern/subr_pctrie.c standard
diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh
index 55ac59b..97bec5c 100644
--- a/sys/conf/newvers.sh
+++ b/sys/conf/newvers.sh
@@ -87,7 +87,15 @@ then
fi
touch version
-v=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`} t=`date`
+v=`cat version` u=${USER:-root} d=`pwd` h=${HOSTNAME:-`hostname`}
+if [ -n "$SOURCE_DATE_EPOCH" ]; then
+ if ! t=`date -r $SOURCE_DATE_EPOCH 2>/dev/null`; then
+ echo "Invalid SOURCE_DATE_EPOCH" >&2
+ exit 1
+ fi
+else
+ t=`date`
+fi
i=`${MAKE:-make} -V KERN_IDENT`
compiler_v=$($(${MAKE:-make} -V CC) -v 2>&1 | grep 'version')
diff --git a/sys/contrib/ipfilter/netinet/ip_nat.c b/sys/contrib/ipfilter/netinet/ip_nat.c
index 6ca938a..149f68e 100644
--- a/sys/contrib/ipfilter/netinet/ip_nat.c
+++ b/sys/contrib/ipfilter/netinet/ip_nat.c
@@ -5235,7 +5235,7 @@ ipf_nat_out(fin, nat, natadd, nflags)
uh->uh_ulen += fin->fin_plen;
uh->uh_ulen = htons(uh->uh_ulen);
#if !defined(_KERNEL) || defined(MENTAT) || defined(__sgi) || \
- defined(linux) || defined(BRIDGE_IPF) || defined(__FreeBSD)
+ defined(linux) || defined(BRIDGE_IPF) || defined(__FreeBSD__)
ipf_fix_outcksum(0, &ip->ip_sum, sumd, 0);
#endif
diff --git a/sys/dev/mlx5/device.h b/sys/dev/mlx5/device.h
index b9a8eec..88ca731 100644
--- a/sys/dev/mlx5/device.h
+++ b/sys/dev/mlx5/device.h
@@ -1042,6 +1042,7 @@ enum {
MLX5_ESW_VPORT_ADMIN_STATE_UP = 0x1,
MLX5_ESW_VPORT_ADMIN_STATE_AUTO = 0x2,
};
+
/* MLX5 DEV CAPs */
/* TODO: EAT.ME */
@@ -1219,4 +1220,36 @@ struct mlx5_ifc_mcia_reg_bits {
};
#define MLX5_CMD_OP_QUERY_EEPROM 0x93c
+
+struct mlx5_mini_cqe8 {
+ union {
+ u32 rx_hash_result;
+ u32 checksum;
+ struct {
+ u16 wqe_counter;
+ u8 s_wqe_opcode;
+ u8 reserved;
+ } s_wqe_info;
+ };
+ u32 byte_cnt;
+};
+
+enum {
+ MLX5_NO_INLINE_DATA,
+ MLX5_INLINE_DATA32_SEG,
+ MLX5_INLINE_DATA64_SEG,
+ MLX5_COMPRESSED,
+};
+
+enum mlx5_exp_cqe_zip_recv_type {
+ MLX5_CQE_FORMAT_HASH,
+ MLX5_CQE_FORMAT_CSUM,
+};
+
+#define MLX5E_CQE_FORMAT_MASK 0xc
+static inline int mlx5_get_cqe_format(const struct mlx5_cqe64 *cqe)
+{
+ return (cqe->op_own & MLX5E_CQE_FORMAT_MASK) >> 2;
+}
+
#endif /* MLX5_DEVICE_H */
diff --git a/sys/dev/mlx5/mlx5_en/en.h b/sys/dev/mlx5/mlx5_en/en.h
index 4203f5c..0db15bd 100644
--- a/sys/dev/mlx5/mlx5_en/en.h
+++ b/sys/dev/mlx5/mlx5_en/en.h
@@ -372,6 +372,7 @@ struct mlx5e_params {
u16 tx_cq_moderation_pkts;
u16 min_rx_wqes;
bool hw_lro_en;
+ bool cqe_zipping_en;
u32 lro_wqe_sz;
u16 rx_hash_log_tbl_sz;
};
@@ -392,7 +393,8 @@ struct mlx5e_params {
m(+1, u64 tx_coalesce_usecs, "tx_coalesce_usecs", "Limit in usec for joining tx packets") \
m(+1, u64 tx_coalesce_pkts, "tx_coalesce_pkts", "Maximum number of tx packets to join") \
m(+1, u64 tx_coalesce_mode, "tx_coalesce_mode", "0: EQE mode 1: CQE mode") \
- m(+1, u64 hw_lro, "hw_lro", "set to enable hw_lro")
+ m(+1, u64 hw_lro, "hw_lro", "set to enable hw_lro") \
+ m(+1, u64 cqe_zipping, "cqe_zipping", "0 : CQE zipping disabled")
#define MLX5E_PARAMS_NUM (0 MLX5E_PARAMS(MLX5E_STATS_COUNT))
@@ -698,7 +700,7 @@ enum mlx5e_link_mode {
MLX5E_56GBASE_R4 = 8,
MLX5E_10GBASE_CR = 12,
MLX5E_10GBASE_SR = 13,
- MLX5E_10GBASE_ER = 14,
+ MLX5E_10GBASE_LR = 14,
MLX5E_40GBASE_SR4 = 15,
MLX5E_40GBASE_LR4 = 16,
MLX5E_100GBASE_CR4 = 20,
@@ -787,5 +789,6 @@ void mlx5e_create_stats(struct sysctl_ctx_list *,
struct sysctl_oid_list *, const char *,
const char **, unsigned, u64 *);
void mlx5e_send_nop(struct mlx5e_sq *, u32, bool);
+int mlx5e_refresh_channel_params(struct mlx5e_priv *);
#endif /* _MLX5_EN_H_ */
diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c b/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c
index eede82f..e389a07 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c
@@ -58,19 +58,60 @@ mlx5e_ethtool_handler(SYSCTL_HANDLER_ARGS)
PRIV_LOCK(priv);
value = priv->params_ethtool.arg[arg2];
- error = sysctl_handle_64(oidp, &value, 0, req);
- if (error || req->newptr == NULL ||
- value == priv->params_ethtool.arg[arg2])
- goto done;
-
- /* assign new value */
- priv->params_ethtool.arg[arg2] = value;
+ if (req != NULL) {
+ error = sysctl_handle_64(oidp, &value, 0, req);
+ if (error || req->newptr == NULL ||
+ value == priv->params_ethtool.arg[arg2])
+ goto done;
+ /* assign new value */
+ priv->params_ethtool.arg[arg2] = value;
+ } else {
+ error = 0;
+ }
/* check if device is gone */
if (priv->gone) {
error = ENXIO;
goto done;
}
+ /* import RX coal time */
+ if (priv->params_ethtool.rx_coalesce_usecs < 1)
+ priv->params_ethtool.rx_coalesce_usecs = 0;
+ else if (priv->params_ethtool.rx_coalesce_usecs >
+ MLX5E_FLD_MAX(cqc, cq_period)) {
+ priv->params_ethtool.rx_coalesce_usecs =
+ MLX5E_FLD_MAX(cqc, cq_period);
+ }
+ priv->params.rx_cq_moderation_usec = priv->params_ethtool.rx_coalesce_usecs;
+
+ /* import RX coal pkts */
+ if (priv->params_ethtool.rx_coalesce_pkts < 1)
+ priv->params_ethtool.rx_coalesce_pkts = 0;
+ else if (priv->params_ethtool.rx_coalesce_pkts >
+ MLX5E_FLD_MAX(cqc, cq_max_count)) {
+ priv->params_ethtool.rx_coalesce_pkts =
+ MLX5E_FLD_MAX(cqc, cq_max_count);
+ }
+ priv->params.rx_cq_moderation_pkts = priv->params_ethtool.rx_coalesce_pkts;
+
+ /* import TX coal time */
+ if (priv->params_ethtool.tx_coalesce_usecs < 1)
+ priv->params_ethtool.tx_coalesce_usecs = 0;
+ else if (priv->params_ethtool.tx_coalesce_usecs >
+ MLX5E_FLD_MAX(cqc, cq_period)) {
+ priv->params_ethtool.tx_coalesce_usecs =
+ MLX5E_FLD_MAX(cqc, cq_period);
+ }
+ priv->params.tx_cq_moderation_usec = priv->params_ethtool.tx_coalesce_usecs;
+
+ /* import TX coal pkts */
+ if (priv->params_ethtool.tx_coalesce_pkts < 1)
+ priv->params_ethtool.tx_coalesce_pkts = 0;
+ else if (priv->params_ethtool.tx_coalesce_pkts >
+ MLX5E_FLD_MAX(cqc, cq_max_count)) {
+ priv->params_ethtool.tx_coalesce_pkts = MLX5E_FLD_MAX(cqc, cq_max_count);
+ }
+ priv->params.tx_cq_moderation_pkts = priv->params_ethtool.tx_coalesce_pkts;
if (&priv->params_ethtool.arg[arg2] == &priv->params_ethtool.rx_pauseframe_control ||
&priv->params_ethtool.arg[arg2] == &priv->params_ethtool.tx_pauseframe_control) {
@@ -88,9 +129,19 @@ mlx5e_ethtool_handler(SYSCTL_HANDLER_ARGS)
}
was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
- if (was_opened)
+ if (was_opened) {
+ u64 *xarg = priv->params_ethtool.arg + arg2;
+
+ if (xarg == &priv->params_ethtool.tx_coalesce_pkts ||
+ xarg == &priv->params_ethtool.rx_coalesce_pkts ||
+ xarg == &priv->params_ethtool.tx_coalesce_usecs ||
+ xarg == &priv->params_ethtool.rx_coalesce_usecs) {
+ /* avoid downing and upping the network interface */
+ error = mlx5e_refresh_channel_params(priv);
+ goto done;
+ }
mlx5e_close_locked(priv->ifp);
-
+ }
/* import TX queue size */
if (priv->params_ethtool.tx_queue_size <
(1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE)) {
@@ -141,45 +192,6 @@ mlx5e_ethtool_handler(SYSCTL_HANDLER_ARGS)
priv->params_ethtool.tx_coalesce_mode = 1;
priv->params.tx_cq_moderation_mode = priv->params_ethtool.tx_coalesce_mode;
- /* import RX coal time */
- if (priv->params_ethtool.rx_coalesce_usecs < 1)
- priv->params_ethtool.rx_coalesce_usecs = 0;
- else if (priv->params_ethtool.rx_coalesce_usecs >
- MLX5E_FLD_MAX(cqc, cq_period)) {
- priv->params_ethtool.rx_coalesce_usecs =
- MLX5E_FLD_MAX(cqc, cq_period);
- }
- priv->params.rx_cq_moderation_usec = priv->params_ethtool.rx_coalesce_usecs;
-
- /* import RX coal pkts */
- if (priv->params_ethtool.rx_coalesce_pkts < 1)
- priv->params_ethtool.rx_coalesce_pkts = 0;
- else if (priv->params_ethtool.rx_coalesce_pkts >
- MLX5E_FLD_MAX(cqc, cq_max_count)) {
- priv->params_ethtool.rx_coalesce_pkts =
- MLX5E_FLD_MAX(cqc, cq_max_count);
- }
- priv->params.rx_cq_moderation_pkts = priv->params_ethtool.rx_coalesce_pkts;
-
- /* import TX coal time */
- if (priv->params_ethtool.tx_coalesce_usecs < 1)
- priv->params_ethtool.tx_coalesce_usecs = 0;
- else if (priv->params_ethtool.tx_coalesce_usecs >
- MLX5E_FLD_MAX(cqc, cq_period)) {
- priv->params_ethtool.tx_coalesce_usecs =
- MLX5E_FLD_MAX(cqc, cq_period);
- }
- priv->params.tx_cq_moderation_usec = priv->params_ethtool.tx_coalesce_usecs;
-
- /* import TX coal pkts */
- if (priv->params_ethtool.tx_coalesce_pkts < 1)
- priv->params_ethtool.tx_coalesce_pkts = 0;
- else if (priv->params_ethtool.tx_coalesce_pkts >
- MLX5E_FLD_MAX(cqc, cq_max_count)) {
- priv->params_ethtool.tx_coalesce_pkts = MLX5E_FLD_MAX(cqc, cq_max_count);
- }
- priv->params.tx_cq_moderation_pkts = priv->params_ethtool.tx_coalesce_pkts;
-
/* we always agree to turn off HW LRO - but not always to turn on */
if (priv->params_ethtool.hw_lro) {
if (priv->params_ethtool.hw_lro != 1) {
@@ -200,6 +212,18 @@ mlx5e_ethtool_handler(SYSCTL_HANDLER_ARGS)
priv->params.hw_lro_en = false;
}
+ if (&priv->params_ethtool.arg[arg2] ==
+ &priv->params_ethtool.cqe_zipping) {
+ if (priv->params_ethtool.cqe_zipping &&
+ MLX5_CAP_GEN(priv->mdev, cqe_compression)) {
+ priv->params.cqe_zipping_en = true;
+ priv->params_ethtool.cqe_zipping = 1;
+ } else {
+ priv->params.cqe_zipping_en = false;
+ priv->params_ethtool.cqe_zipping = 0;
+ }
+ }
+
if (was_opened)
mlx5e_open_locked(priv->ifp);
done:
@@ -319,34 +343,33 @@ mlx5e_get_eeprom(struct mlx5e_priv *priv, struct mlx5e_eeprom *ee)
static void
mlx5e_print_eeprom(struct mlx5e_eeprom *eeprom)
{
- int i, j = 0;
- int row = 0;
+ int row;
+ int index_in_row;
+ int byte_to_write = 0;
+ int line_length = 16;
printf("\nOffset\t\tValues\n");
- printf("------\t\t------\n");
- while (row < eeprom->len) {
- printf("0x%04x\t\t", row);
- for (i = 0; i < 16; i++) {
- printf("%02x ", ((u8 *)eeprom->data)[j]);
- j++;
- row++;
+ printf("------\t\t------");
+ while (byte_to_write < eeprom->len) {
+ printf("\n0x%04X\t\t", byte_to_write);
+ for (index_in_row = 0; index_in_row < line_length; index_in_row++) {
+ printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]);
+ byte_to_write++;
}
- printf("\n");
}
if (eeprom->page_valid) {
row = MLX5E_EEPROM_HIGH_PAGE_OFFSET;
- printf("\nUpper Page 0x03\n");
+ printf("\n\nUpper Page 0x03\n");
printf("\nOffset\t\tValues\n");
- printf("------\t\t------\n");
+ printf("------\t\t------");
while (row < MLX5E_EEPROM_PAGE_LENGTH) {
- printf("0x%04x\t\t", row);
- for (i = 0; i < 16; i++) {
- printf("%02x ", ((u8 *)eeprom->data)[j]);
- j++;
+ printf("\n0x%04X\t\t", row);
+ for (index_in_row = 0; index_in_row < line_length; index_in_row++) {
+ printf("%02X ", ((u8 *)eeprom->data)[byte_to_write]);
+ byte_to_write++;
row++;
}
- printf("\n");
}
}
}
@@ -469,6 +492,7 @@ mlx5e_create_ethtool(struct mlx5e_priv *priv)
priv->params_ethtool.tx_coalesce_usecs = priv->params.tx_cq_moderation_usec;
priv->params_ethtool.tx_coalesce_pkts = priv->params.tx_cq_moderation_pkts;
priv->params_ethtool.hw_lro = priv->params.hw_lro_en;
+ priv->params_ethtool.cqe_zipping = priv->params.cqe_zipping_en;
/* create root node */
node = SYSCTL_ADD_NODE(&priv->sysctl_ctx,
@@ -484,10 +508,30 @@ mlx5e_create_ethtool(struct mlx5e_priv *priv)
CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU",
mlx5e_params_desc[2 * x + 1]);
} else {
+#if (__FreeBSD_version < 1100000)
+ char path[64];
+#endif
+ /*
+ * NOTE: In FreeBSD-11 and newer the
+ * CTLFLAG_RWTUN flag will take care of
+ * loading default sysctl value from the
+ * kernel environment, if any:
+ */
SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(node), OID_AUTO,
mlx5e_params_desc[2 * x], CTLTYPE_U64 | CTLFLAG_RWTUN |
CTLFLAG_MPSAFE, priv, x, &mlx5e_ethtool_handler, "QU",
mlx5e_params_desc[2 * x + 1]);
+
+#if (__FreeBSD_version < 1100000)
+ /* compute path for sysctl */
+ snprintf(path, sizeof(path), "dev.mce.%d.conf.%s",
+ device_get_unit(priv->mdev->pdev->dev.bsddev),
+ mlx5e_params_desc[2 * x]);
+
+ /* try to fetch tunable, if any */
+ if (TUNABLE_QUAD_FETCH(path, &priv->params_ethtool.arg[x]))
+ mlx5e_ethtool_handler(NULL, priv, x, NULL);
+#endif
}
}
diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
index 77aaf7b..82ea69d 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
@@ -106,8 +106,8 @@ static const struct {
.subtype = IFM_10G_SR,
.baudrate = IF_Gbps(10ULL),
},
- [MLX5E_10GBASE_ER] = {
- .subtype = IFM_10G_ER,
+ [MLX5E_10GBASE_LR] = {
+ .subtype = IFM_10G_LR,
.baudrate = IF_Gbps(10ULL),
},
[MLX5E_40GBASE_SR4] = {
@@ -1604,6 +1604,16 @@ mlx5e_build_rx_cq_param(struct mlx5e_priv *priv,
{
void *cqc = param->cqc;
+
+ /*
+ * TODO The sysctl to control on/off is a bool value for now, which means
+ * we only support CSUM, once HASH is implemnted we'll need to address that.
+ */
+ if (priv->params.cqe_zipping_en) {
+ MLX5_SET(cqc, cqc, mini_cqe_res_format, MLX5_CQE_FORMAT_CSUM);
+ MLX5_SET(cqc, cqc, cqe_compression_en, 1);
+ }
+
MLX5_SET(cqc, cqc, log_cq_size, priv->params.log_rq_size);
MLX5_SET(cqc, cqc, cq_period, priv->params.rx_cq_moderation_usec);
MLX5_SET(cqc, cqc, cq_max_count, priv->params.rx_cq_moderation_pkts);
@@ -1702,6 +1712,62 @@ mlx5e_close_channels(struct mlx5e_priv *priv)
}
static int
+mlx5e_refresh_sq_params(struct mlx5e_priv *priv, struct mlx5e_sq *sq)
+{
+ return (mlx5_core_modify_cq_moderation(priv->mdev, &sq->cq.mcq,
+ priv->params.tx_cq_moderation_usec,
+ priv->params.tx_cq_moderation_pkts));
+}
+
+static int
+mlx5e_refresh_rq_params(struct mlx5e_priv *priv, struct mlx5e_rq *rq)
+{
+ return (mlx5_core_modify_cq_moderation(priv->mdev, &rq->cq.mcq,
+ priv->params.rx_cq_moderation_usec,
+ priv->params.rx_cq_moderation_pkts));
+}
+
+static int
+mlx5e_refresh_channel_params_sub(struct mlx5e_priv *priv, struct mlx5e_channel *c)
+{
+ int err;
+ int i;
+
+ if (c == NULL)
+ return (EINVAL);
+
+ err = mlx5e_refresh_rq_params(priv, &c->rq);
+ if (err)
+ goto done;
+
+ for (i = 0; i != c->num_tc; i++) {
+ err = mlx5e_refresh_sq_params(priv, &c->sq[i]);
+ if (err)
+ goto done;
+ }
+done:
+ return (err);
+}
+
+int
+mlx5e_refresh_channel_params(struct mlx5e_priv *priv)
+{
+ int i;
+
+ if (priv->channel == NULL)
+ return (EINVAL);
+
+ for (i = 0; i < priv->params.num_channels; i++) {
+ int err;
+
+ err = mlx5e_refresh_channel_params_sub(priv, priv->channel[i]);
+ if (err)
+ return (err);
+ }
+ return (0);
+}
+
+static int
mlx5e_open_tis(struct mlx5e_priv *priv, int tc)
{
struct mlx5_core_dev *mdev = priv->mdev;
@@ -2288,6 +2354,7 @@ mlx5e_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
int size_read = 0;
int module_num;
int max_mtu;
+ uint8_t read_addr;
priv = ifp->if_softc;
@@ -2474,11 +2541,21 @@ out:
}
/*
- * Note that we ignore i2c.addr here. The driver hardcodes
- * the address to 0x50, while standard expects it to be 0xA0.
+ * Currently 0XA0 and 0xA2 are the only addresses permitted.
+ * The internal conversion is as follows:
*/
+ if (i2c.dev_addr == 0xA0)
+ read_addr = MLX5E_I2C_ADDR_LOW;
+ else if (i2c.dev_addr == 0xA2)
+ read_addr = MLX5E_I2C_ADDR_HIGH;
+ else {
+ if_printf(ifp, "Query eeprom failed, "
+ "Invalid Address: %X\n", i2c.dev_addr);
+ error = EINVAL;
+ goto err_i2c;
+ }
error = mlx5_query_eeprom(priv->mdev,
- MLX5E_I2C_ADDR_LOW, MLX5E_EEPROM_LOW_PAGE,
+ read_addr, MLX5E_EEPROM_LOW_PAGE,
(uint32_t)i2c.offset, (uint32_t)i2c.len, module_num,
(uint32_t *)i2c.data, &size_read);
if (error) {
@@ -2489,7 +2566,7 @@ out:
if (i2c.len > MLX5_EEPROM_MAX_BYTES) {
error = mlx5_query_eeprom(priv->mdev,
- MLX5E_I2C_ADDR_LOW, MLX5E_EEPROM_LOW_PAGE,
+ read_addr, MLX5E_EEPROM_LOW_PAGE,
(uint32_t)(i2c.offset + size_read),
(uint32_t)(i2c.len - size_read), module_num,
(uint32_t *)(i2c.data + size_read), &size_read);
@@ -2571,6 +2648,8 @@ mlx5e_build_ifp_priv(struct mlx5_core_dev *mdev,
priv->params.hw_lro_en = false;
priv->params.lro_wqe_sz = MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ;
+ priv->params.cqe_zipping_en = !!MLX5_CAP_GEN(mdev, cqe_compression);
+
priv->mdev = mdev;
priv->params.num_channels = num_comp_vectors;
priv->order_base_2_num_channels = order_base_2(num_comp_vectors);
diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c b/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c
index 87fc524..059b5ef 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c
@@ -248,6 +248,69 @@ mlx5e_build_rx_mbuf(struct mlx5_cqe64 *cqe,
}
}
+static inline void
+mlx5e_read_cqe_slot(struct mlx5e_cq *cq, u32 cc, void *data)
+{
+ memcpy(data, mlx5_cqwq_get_wqe(&cq->wq, (cc & cq->wq.sz_m1)),
+ sizeof(struct mlx5_cqe64));
+}
+
+static inline void
+mlx5e_write_cqe_slot(struct mlx5e_cq *cq, u32 cc, void *data)
+{
+ memcpy(mlx5_cqwq_get_wqe(&cq->wq, cc & cq->wq.sz_m1),
+ data, sizeof(struct mlx5_cqe64));
+}
+
+static inline void
+mlx5e_decompress_cqe(struct mlx5e_cq *cq, struct mlx5_cqe64 *title,
+ struct mlx5_mini_cqe8 *mini,
+ u16 wqe_counter, int i)
+{
+ title->byte_cnt = mini->byte_cnt;
+ title->wqe_counter = cpu_to_be16((wqe_counter + i) & cq->wq.sz_m1);
+ title->check_sum = mini->checksum;
+ title->op_own = (title->op_own & 0xf0) |
+ (((cq->wq.cc + i) >> cq->wq.log_sz) & 1);
+}
+
+#define MLX5E_MINI_ARRAY_SZ 8
+/* Make sure structs are not packet differently */
+CTASSERT(sizeof(struct mlx5_cqe64) ==
+ sizeof(struct mlx5_mini_cqe8) * MLX5E_MINI_ARRAY_SZ);
+static void
+mlx5e_decompress_cqes(struct mlx5e_cq *cq)
+{
+ struct mlx5_mini_cqe8 mini_array[MLX5E_MINI_ARRAY_SZ];
+ struct mlx5_cqe64 title;
+ u32 cqe_count;
+ u32 i = 0;
+ u16 title_wqe_counter;
+
+ mlx5e_read_cqe_slot(cq, cq->wq.cc, &title);
+ title_wqe_counter = be16_to_cpu(title.wqe_counter);
+ cqe_count = be32_to_cpu(title.byte_cnt);
+
+ /* Make sure we won't overflow */
+ KASSERT(cqe_count <= cq->wq.sz_m1,
+ ("%s: cqe_count %u > cq->wq.sz_m1 %u", __func__,
+ cqe_count, cq->wq.sz_m1));
+
+ mlx5e_read_cqe_slot(cq, cq->wq.cc + 1, mini_array);
+ while (true) {
+ mlx5e_decompress_cqe(cq, &title,
+ &mini_array[i % MLX5E_MINI_ARRAY_SZ],
+ title_wqe_counter, i);
+ mlx5e_write_cqe_slot(cq, cq->wq.cc + i, &title);
+ i++;
+
+ if (i == cqe_count)
+ break;
+ if (i % MLX5E_MINI_ARRAY_SZ == 0)
+ mlx5e_read_cqe_slot(cq, cq->wq.cc + i, mini_array);
+ }
+}
+
static int
mlx5e_poll_rx_cq(struct mlx5e_rq *rq, int budget)
{
@@ -268,6 +331,11 @@ mlx5e_poll_rx_cq(struct mlx5e_rq *rq, int budget)
if (!cqe)
break;
+ if (mlx5_get_cqe_format(cqe) == MLX5_COMPRESSED)
+ mlx5e_decompress_cqes(&rq->cq);
+
+ mlx5_cqwq_pop(&rq->cq.wq);
+
wqe_counter_be = cqe->wqe_counter;
wqe_counter = be16_to_cpu(wqe_counter_be);
wqe = mlx5_wq_ll_get_wqe(&rq->wq, wqe_counter);
diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_tx.c b/sys/dev/mlx5/mlx5_en/mlx5_en_tx.c
index cb08727..483a7e1 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_tx.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_tx.c
@@ -383,6 +383,8 @@ mlx5e_poll_tx_cq(struct mlx5e_sq *sq, int budget)
if (!cqe)
break;
+ mlx5_cqwq_pop(&sq->cq.wq);
+
ci = sqcc & sq->wq.sz_m1;
mb = sq->mbuf[ci].mbuf;
sq->mbuf[ci].mbuf = NULL; /* Safety clear */
diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_txrx.c b/sys/dev/mlx5/mlx5_en/mlx5_en_txrx.c
index 7836bfe..f46639d 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_txrx.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_txrx.c
@@ -37,8 +37,6 @@ mlx5e_get_cqe(struct mlx5e_cq *cq)
if ((cqe->op_own ^ mlx5_cqwq_get_wrap_cnt(&cq->wq)) & MLX5_CQE_OWNER_MASK)
return (NULL);
- mlx5_cqwq_pop(&cq->wq);
-
/* ensure cqe content is read after cqe ownership bit */
rmb();
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
index a9c33ae..e08237b 100644
--- a/sys/dev/pci/pci.c
+++ b/sys/dev/pci/pci.c
@@ -615,8 +615,6 @@ pci_read_device(device_t pcib, int d, int b, int s, int f, size_t size)
if (REG(PCIR_DEVVENDOR, 4) != 0xfffffffful) {
devlist_entry = malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
- if (devlist_entry == NULL)
- return (NULL);
cfg = &devlist_entry->cfg;
diff --git a/sys/dev/usb/controller/uhci.h b/sys/dev/usb/controller/uhci.h
index 8a6ce44..801952a 100644
--- a/sys/dev/usb/controller/uhci.h
+++ b/sys/dev/usb/controller/uhci.h
@@ -97,7 +97,7 @@ struct uhci_td {
#define UHCI_TD_GET_ENDPT(s) (((s) >> 15) & 0xf)
#define UHCI_TD_SET_DT(t) ((t) << 19)
#define UHCI_TD_GET_DT(s) (((s) >> 19) & 1)
-#define UHCI_TD_SET_MAXLEN(l) (((l)-1) << 21)
+#define UHCI_TD_SET_MAXLEN(l) (((l)-1U) << 21)
#define UHCI_TD_GET_MAXLEN(s) ((((s) >> 21) + 1) & 0x7ff)
#define UHCI_TD_MAXLEN_MASK 0xffe00000
volatile uint32_t td_buffer;
diff --git a/sys/dev/usb/serial/uftdi.c b/sys/dev/usb/serial/uftdi.c
index 02756ed..a35b62d 100644
--- a/sys/dev/usb/serial/uftdi.c
+++ b/sys/dev/usb/serial/uftdi.c
@@ -568,7 +568,7 @@ static const STRUCT_USB_HOST_ID uftdi_devs[] = {
UFTDI_DEV(KOBIL, CONV_B1, 0),
UFTDI_DEV(KOBIL, CONV_KAAN, 0),
UFTDI_DEV(LARSENBRUSGAARD, ALTITRACK, 0),
- UFTDI_DEV(MARVELL, SHEEVAPLUG, 0),
+ UFTDI_DEV(MARVELL, SHEEVAPLUG, UFTDI_JTAG_IFACE(0)),
UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0100, 0),
UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0101, 0),
UFTDI_DEV(MATRIXORBITAL, FTDI_RANGE_0102, 0),
diff --git a/sys/fs/ext2fs/ext2fs.h b/sys/fs/ext2fs/ext2fs.h
index 9985c45..7eabc47 100644
--- a/sys/fs/ext2fs/ext2fs.h
+++ b/sys/fs/ext2fs/ext2fs.h
@@ -187,6 +187,7 @@ struct csum {
#define EXT2F_INCOMPAT_COMP 0x0001
#define EXT2F_INCOMPAT_FTYPE 0x0002
+#define EXT2F_INCOMPAT_RECOVER 0x0004
#define EXT2F_INCOMPAT_META_BG 0x0010
#define EXT2F_INCOMPAT_EXTENTS 0x0040
#define EXT2F_INCOMPAT_64BIT 0x0080
@@ -208,6 +209,7 @@ struct csum {
*
* We do not support these EXT4 features but they are irrelevant
* for read-only support:
+ * - EXT2F_INCOMPAT_RECOVER
* - EXT2F_INCOMPAT_FLEX_BG
* - EXT2F_INCOMPAT_META_BG
*/
@@ -216,6 +218,7 @@ struct csum {
EXT2F_ROCOMPAT_EXTRA_ISIZE)
#define EXT2F_INCOMPAT_SUPP EXT2F_INCOMPAT_FTYPE
#define EXT4F_RO_INCOMPAT_SUPP (EXT2F_INCOMPAT_EXTENTS | \
+ EXT2F_INCOMPAT_RECOVER | \
EXT2F_INCOMPAT_FLEX_BG | \
EXT2F_INCOMPAT_META_BG )
diff --git a/sys/fs/nullfs/null_vnops.c b/sys/fs/nullfs/null_vnops.c
index 4762a3c..72b884f 100644
--- a/sys/fs/nullfs/null_vnops.c
+++ b/sys/fs/nullfs/null_vnops.c
@@ -568,14 +568,16 @@ static int
null_remove(struct vop_remove_args *ap)
{
int retval, vreleit;
- struct vnode *lvp;
+ struct vnode *lvp, *vp;
- if (vrefcnt(ap->a_vp) > 1) {
- lvp = NULLVPTOLOWERVP(ap->a_vp);
+ vp = ap->a_vp;
+ if (vrefcnt(vp) > 1) {
+ lvp = NULLVPTOLOWERVP(vp);
VREF(lvp);
vreleit = 1;
} else
vreleit = 0;
+ VTONULL(vp)->null_flags |= NULLV_DROP;
retval = null_bypass(&ap->a_gen);
if (vreleit != 0)
vrele(lvp);
diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index eaa3ee1..584b5da 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -783,6 +783,11 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
error = ENOEXEC;
goto ret;
}
+ if (interp != NULL) {
+ uprintf("Multiple PT_INTERP headers\n");
+ error = ENOEXEC;
+ goto ret;
+ }
interp_name_len = phdr[i].p_filesz;
if (phdr[i].p_offset > PAGE_SIZE ||
interp_name_len > PAGE_SIZE - phdr[i].p_offset) {
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index e051e3e..ac0152a 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -234,6 +234,7 @@ proc_init(void *mem, int size, int flags)
TAILQ_INIT(&p->p_threads); /* all threads in proc */
EVENTHANDLER_INVOKE(process_init, p);
p->p_stats = pstats_alloc();
+ p->p_pgrp = NULL;
SDT_PROBE3(proc, kernel, init, return, p, size, flags);
return (0);
}
diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c
index 3b03d6f..c2cceff 100644
--- a/sys/kern/link_elf.c
+++ b/sys/kern/link_elf.c
@@ -575,7 +575,7 @@ parse_dynamic(elf_file_t ef)
static int
parse_dpcpu(elf_file_t ef)
-{
+{
int count;
int error;
@@ -606,7 +606,7 @@ parse_dpcpu(elf_file_t ef)
#ifdef VIMAGE
static int
parse_vnet(elf_file_t ef)
-{
+{
int count;
int error;
@@ -872,7 +872,7 @@ link_elf_load_file(linker_class_t cls, const char* filename,
*/
base_offset = trunc_page(segs[0]->p_offset);
base_vaddr = trunc_page(segs[0]->p_vaddr);
- base_vlimit = round_page(segs[nsegs - 1]->p_vaddr +
+ base_vlimit = round_page(segs[nsegs - 1]->p_vaddr +
segs[nsegs - 1]->p_memsz);
mapsize = base_vlimit - base_vaddr;
@@ -1416,7 +1416,7 @@ link_elf_each_function_name(linker_file_t file,
elf_file_t ef = (elf_file_t)file;
const Elf_Sym *symp;
int i, error;
-
+
/* Exhaustive search */
for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
if (symp->st_value != 0 &&
@@ -1602,7 +1602,7 @@ link_elf_symtab_get(linker_file_t lf, const Elf_Sym **symtab)
return (ef->ddbsymcnt);
}
-
+
static long
link_elf_strtab_get(linker_file_t lf, caddr_t *strtab)
{
diff --git a/sys/kern/subr_dnvlist.c b/sys/kern/subr_dnvlist.c
new file mode 100644
index 0000000..9058520
--- /dev/null
+++ b/sys/kern/subr_dnvlist.c
@@ -0,0 +1,128 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifdef _KERNEL
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+
+#include <machine/stdarg.h>
+
+#else
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#endif
+
+#include <sys/nv.h>
+#include <sys/nv_impl.h>
+
+#include <sys/dnv.h>
+
+#define DNVLIST_GET(ftype, type) \
+ftype \
+dnvlist_get_##type(const nvlist_t *nvl, const char *name, ftype defval) \
+{ \
+ \
+ if (nvlist_exists_##type(nvl, name)) \
+ return (nvlist_get_##type(nvl, name)); \
+ else \
+ return (defval); \
+}
+
+DNVLIST_GET(bool, bool)
+DNVLIST_GET(uint64_t, number)
+DNVLIST_GET(const char *, string)
+DNVLIST_GET(const nvlist_t *, nvlist)
+#ifndef _KERNEL
+DNVLIST_GET(int, descriptor)
+#endif
+
+#undef DNVLIST_GET
+
+const void *
+dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep,
+ const void *defval, size_t defsize)
+{
+ const void *value;
+
+ if (nvlist_exists_binary(nvl, name))
+ value = nvlist_get_binary(nvl, name, sizep);
+ else {
+ if (sizep != NULL)
+ *sizep = defsize;
+ value = defval;
+ }
+ return (value);
+}
+
+#define DNVLIST_TAKE(ftype, type) \
+ftype \
+dnvlist_take_##type(nvlist_t *nvl, const char *name, ftype defval) \
+{ \
+ \
+ if (nvlist_exists_##type(nvl, name)) \
+ return (nvlist_take_##type(nvl, name)); \
+ else \
+ return (defval); \
+}
+
+DNVLIST_TAKE(bool, bool)
+DNVLIST_TAKE(uint64_t, number)
+DNVLIST_TAKE(char *, string)
+DNVLIST_TAKE(nvlist_t *, nvlist)
+#ifndef _KERNEL
+DNVLIST_TAKE(int, descriptor)
+#endif
+
+#undef DNVLIST_TAKE
+
+void *
+dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep,
+ void *defval, size_t defsize)
+{
+ void *value;
+
+ if (nvlist_exists_binary(nvl, name))
+ value = nvlist_take_binary(nvl, name, sizep);
+ else {
+ if (sizep != NULL)
+ *sizep = defsize;
+ value = defval;
+ }
+ return (value);
+}
+
diff --git a/sys/kern/subr_nvlist.c b/sys/kern/subr_nvlist.c
new file mode 100644
index 0000000..bc51018
--- /dev/null
+++ b/sys/kern/subr_nvlist.c
@@ -0,0 +1,1475 @@
+/*-
+ * Copyright (c) 2009-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/endian.h>
+#include <sys/queue.h>
+
+#ifdef _KERNEL
+
+#include <sys/errno.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/systm.h>
+
+#include <machine/stdarg.h>
+
+#else
+#include <sys/socket.h>
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#define _WITH_DPRINTF
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "msgio.h"
+#endif
+
+#ifdef HAVE_PJDLOG
+#include <pjdlog.h>
+#endif
+
+#include <sys/nv.h>
+#include <sys/nv_impl.h>
+#include <sys/nvlist_impl.h>
+#include <sys/nvpair_impl.h>
+
+#ifndef HAVE_PJDLOG
+#ifdef _KERNEL
+#define PJDLOG_ASSERT(...) MPASS(__VA_ARGS__)
+#define PJDLOG_RASSERT(expr, ...) KASSERT(expr, (__VA_ARGS__))
+#define PJDLOG_ABORT(...) panic(__VA_ARGS__)
+#else
+#include <assert.h>
+#define PJDLOG_ASSERT(...) assert(__VA_ARGS__)
+#define PJDLOG_RASSERT(expr, ...) assert(expr)
+#define PJDLOG_ABORT(...) do { \
+ fprintf(stderr, "%s:%u: ", __FILE__, __LINE__); \
+ fprintf(stderr, __VA_ARGS__); \
+ fprintf(stderr, "\n"); \
+ abort(); \
+} while (0)
+#endif
+#endif
+
+#define NV_FLAG_PRIVATE_MASK (NV_FLAG_BIG_ENDIAN)
+#define NV_FLAG_PUBLIC_MASK (NV_FLAG_IGNORE_CASE)
+#define NV_FLAG_ALL_MASK (NV_FLAG_PRIVATE_MASK | NV_FLAG_PUBLIC_MASK)
+
+#define NVLIST_MAGIC 0x6e766c /* "nvl" */
+struct nvlist {
+ int nvl_magic;
+ int nvl_error;
+ int nvl_flags;
+ nvpair_t *nvl_parent;
+ struct nvl_head nvl_head;
+};
+
+#define NVLIST_ASSERT(nvl) do { \
+ PJDLOG_ASSERT((nvl) != NULL); \
+ PJDLOG_ASSERT((nvl)->nvl_magic == NVLIST_MAGIC); \
+} while (0)
+
+#ifdef _KERNEL
+MALLOC_DEFINE(M_NVLIST, "nvlist", "kernel nvlist");
+#endif
+
+#define NVPAIR_ASSERT(nvp) nvpair_assert(nvp)
+
+#define NVLIST_HEADER_MAGIC 0x6c
+#define NVLIST_HEADER_VERSION 0x00
+struct nvlist_header {
+ uint8_t nvlh_magic;
+ uint8_t nvlh_version;
+ uint8_t nvlh_flags;
+ uint64_t nvlh_descriptors;
+ uint64_t nvlh_size;
+} __packed;
+
+nvlist_t *
+nvlist_create(int flags)
+{
+ nvlist_t *nvl;
+
+ PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
+
+ nvl = nv_malloc(sizeof(*nvl));
+ nvl->nvl_error = 0;
+ nvl->nvl_flags = flags;
+ nvl->nvl_parent = NULL;
+ TAILQ_INIT(&nvl->nvl_head);
+ nvl->nvl_magic = NVLIST_MAGIC;
+
+ return (nvl);
+}
+
+void
+nvlist_destroy(nvlist_t *nvl)
+{
+ nvpair_t *nvp;
+ int serrno;
+
+ if (nvl == NULL)
+ return;
+
+ SAVE_ERRNO(serrno);
+
+ NVLIST_ASSERT(nvl);
+
+ while ((nvp = nvlist_first_nvpair(nvl)) != NULL) {
+ nvlist_remove_nvpair(nvl, nvp);
+ nvpair_free(nvp);
+ }
+ nvl->nvl_magic = 0;
+ nv_free(nvl);
+
+ RESTORE_ERRNO(serrno);
+}
+
+void
+nvlist_set_error(nvlist_t *nvl, int error)
+{
+
+ PJDLOG_ASSERT(error != 0);
+
+ /*
+ * Check for error != 0 so that we don't do the wrong thing if somebody
+ * tries to abuse this API when asserts are disabled.
+ */
+ if (nvl != NULL && error != 0 && nvl->nvl_error == 0)
+ nvl->nvl_error = error;
+}
+
+int
+nvlist_error(const nvlist_t *nvl)
+{
+
+ if (nvl == NULL)
+ return (ENOMEM);
+
+ NVLIST_ASSERT(nvl);
+
+ return (nvl->nvl_error);
+}
+
+nvpair_t *
+nvlist_get_nvpair_parent(const nvlist_t *nvl)
+{
+
+ NVLIST_ASSERT(nvl);
+
+ return (nvl->nvl_parent);
+}
+
+const nvlist_t *
+nvlist_get_parent(const nvlist_t *nvl, void **cookiep)
+{
+ nvpair_t *nvp;
+
+ NVLIST_ASSERT(nvl);
+
+ nvp = nvl->nvl_parent;
+ if (cookiep != NULL)
+ *cookiep = nvp;
+ if (nvp == NULL)
+ return (NULL);
+
+ return (nvpair_nvlist(nvp));
+}
+
+void
+nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent)
+{
+
+ NVLIST_ASSERT(nvl);
+
+ nvl->nvl_parent = parent;
+}
+
+bool
+nvlist_empty(const nvlist_t *nvl)
+{
+
+ NVLIST_ASSERT(nvl);
+ PJDLOG_ASSERT(nvl->nvl_error == 0);
+
+ return (nvlist_first_nvpair(nvl) == NULL);
+}
+
+int
+nvlist_flags(const nvlist_t *nvl)
+{
+
+ NVLIST_ASSERT(nvl);
+ PJDLOG_ASSERT(nvl->nvl_error == 0);
+ PJDLOG_ASSERT((nvl->nvl_flags & ~(NV_FLAG_PUBLIC_MASK)) == 0);
+
+ return (nvl->nvl_flags);
+}
+
+static void
+nvlist_report_missing(int type, const char *name)
+{
+
+ PJDLOG_ABORT("Element '%s' of type %s doesn't exist.",
+ name, nvpair_type_string(type));
+}
+
+static nvpair_t *
+nvlist_find(const nvlist_t *nvl, int type, const char *name)
+{
+ nvpair_t *nvp;
+
+ NVLIST_ASSERT(nvl);
+ PJDLOG_ASSERT(nvl->nvl_error == 0);
+ PJDLOG_ASSERT(type == NV_TYPE_NONE ||
+ (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
+
+ for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
+ nvp = nvlist_next_nvpair(nvl, nvp)) {
+ if (type != NV_TYPE_NONE && nvpair_type(nvp) != type)
+ continue;
+ if ((nvl->nvl_flags & NV_FLAG_IGNORE_CASE) != 0) {
+ if (strcasecmp(nvpair_name(nvp), name) != 0)
+ continue;
+ } else {
+ if (strcmp(nvpair_name(nvp), name) != 0)
+ continue;
+ }
+ break;
+ }
+
+ if (nvp == NULL)
+ RESTORE_ERRNO(ENOENT);
+
+ return (nvp);
+}
+
+bool
+nvlist_exists_type(const nvlist_t *nvl, const char *name, int type)
+{
+
+ NVLIST_ASSERT(nvl);
+ PJDLOG_ASSERT(nvl->nvl_error == 0);
+ PJDLOG_ASSERT(type == NV_TYPE_NONE ||
+ (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
+
+ return (nvlist_find(nvl, type, name) != NULL);
+}
+
+void
+nvlist_free_type(nvlist_t *nvl, const char *name, int type)
+{
+ nvpair_t *nvp;
+
+ NVLIST_ASSERT(nvl);
+ PJDLOG_ASSERT(nvl->nvl_error == 0);
+ PJDLOG_ASSERT(type == NV_TYPE_NONE ||
+ (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST));
+
+ nvp = nvlist_find(nvl, type, name);
+ if (nvp != NULL)
+ nvlist_free_nvpair(nvl, nvp);
+ else
+ nvlist_report_missing(type, name);
+}
+
+nvlist_t *
+nvlist_clone(const nvlist_t *nvl)
+{
+ nvlist_t *newnvl;
+ nvpair_t *nvp, *newnvp;
+
+ NVLIST_ASSERT(nvl);
+
+ if (nvl->nvl_error != 0) {
+ RESTORE_ERRNO(nvl->nvl_error);
+ return (NULL);
+ }
+
+ newnvl = nvlist_create(nvl->nvl_flags & NV_FLAG_PUBLIC_MASK);
+ for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
+ nvp = nvlist_next_nvpair(nvl, nvp)) {
+ newnvp = nvpair_clone(nvp);
+ if (newnvp == NULL)
+ break;
+ nvlist_move_nvpair(newnvl, newnvp);
+ }
+ if (nvp != NULL) {
+ nvlist_destroy(newnvl);
+ return (NULL);
+ }
+ return (newnvl);
+}
+
+#ifndef _KERNEL
+static bool
+nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level)
+{
+
+ if (nvlist_error(nvl) != 0) {
+ dprintf(fd, "%*serror: %d\n", level * 4, "",
+ nvlist_error(nvl));
+ return (true);
+ }
+
+ return (false);
+}
+
+/*
+ * Dump content of nvlist.
+ */
+void
+nvlist_dump(const nvlist_t *nvl, int fd)
+{
+ const nvlist_t *tmpnvl;
+ nvpair_t *nvp, *tmpnvp;
+ void *cookie;
+ int level;
+
+ level = 0;
+ if (nvlist_dump_error_check(nvl, fd, level))
+ return;
+
+ nvp = nvlist_first_nvpair(nvl);
+ while (nvp != NULL) {
+ dprintf(fd, "%*s%s (%s):", level * 4, "", nvpair_name(nvp),
+ nvpair_type_string(nvpair_type(nvp)));
+ switch (nvpair_type(nvp)) {
+ case NV_TYPE_NULL:
+ dprintf(fd, " null\n");
+ break;
+ case NV_TYPE_BOOL:
+ dprintf(fd, " %s\n", nvpair_get_bool(nvp) ?
+ "TRUE" : "FALSE");
+ break;
+ case NV_TYPE_NUMBER:
+ dprintf(fd, " %ju (%jd) (0x%jx)\n",
+ (uintmax_t)nvpair_get_number(nvp),
+ (intmax_t)nvpair_get_number(nvp),
+ (uintmax_t)nvpair_get_number(nvp));
+ break;
+ case NV_TYPE_STRING:
+ dprintf(fd, " [%s]\n", nvpair_get_string(nvp));
+ break;
+ case NV_TYPE_NVLIST:
+ dprintf(fd, "\n");
+ tmpnvl = nvpair_get_nvlist(nvp);
+ if (nvlist_dump_error_check(tmpnvl, fd, level + 1))
+ break;
+ tmpnvp = nvlist_first_nvpair(tmpnvl);
+ if (tmpnvp != NULL) {
+ nvl = tmpnvl;
+ nvp = tmpnvp;
+ level++;
+ continue;
+ }
+ break;
+ case NV_TYPE_DESCRIPTOR:
+ dprintf(fd, " %d\n", nvpair_get_descriptor(nvp));
+ break;
+ case NV_TYPE_BINARY:
+ {
+ const unsigned char *binary;
+ unsigned int ii;
+ size_t size;
+
+ binary = nvpair_get_binary(nvp, &size);
+ dprintf(fd, " %zu ", size);
+ for (ii = 0; ii < size; ii++)
+ dprintf(fd, "%02hhx", binary[ii]);
+ dprintf(fd, "\n");
+ break;
+ }
+ default:
+ PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
+ }
+
+ while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
+ cookie = NULL;
+ nvl = nvlist_get_parent(nvl, &cookie);
+ if (nvl == NULL)
+ return;
+ nvp = cookie;
+ level--;
+ }
+ }
+}
+
+void
+nvlist_fdump(const nvlist_t *nvl, FILE *fp)
+{
+
+ fflush(fp);
+ nvlist_dump(nvl, fileno(fp));
+}
+#endif
+
+/*
+ * The function obtains size of the nvlist after nvlist_pack().
+ */
+size_t
+nvlist_size(const nvlist_t *nvl)
+{
+ const nvlist_t *tmpnvl;
+ const nvpair_t *nvp, *tmpnvp;
+ void *cookie;
+ size_t size;
+
+ NVLIST_ASSERT(nvl);
+ PJDLOG_ASSERT(nvl->nvl_error == 0);
+
+ size = sizeof(struct nvlist_header);
+ nvp = nvlist_first_nvpair(nvl);
+ while (nvp != NULL) {
+ size += nvpair_header_size();
+ size += strlen(nvpair_name(nvp)) + 1;
+ if (nvpair_type(nvp) == NV_TYPE_NVLIST) {
+ size += sizeof(struct nvlist_header);
+ size += nvpair_header_size() + 1;
+ tmpnvl = nvpair_get_nvlist(nvp);
+ PJDLOG_ASSERT(tmpnvl->nvl_error == 0);
+ tmpnvp = nvlist_first_nvpair(tmpnvl);
+ if (tmpnvp != NULL) {
+ nvl = tmpnvl;
+ nvp = tmpnvp;
+ continue;
+ }
+ } else {
+ size += nvpair_size(nvp);
+ }
+
+ while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
+ cookie = NULL;
+ nvl = nvlist_get_parent(nvl, &cookie);
+ if (nvl == NULL)
+ goto out;
+ nvp = cookie;
+ }
+ }
+
+out:
+ return (size);
+}
+
+#ifndef _KERNEL
+static int *
+nvlist_xdescriptors(const nvlist_t *nvl, int *descs, int level)
+{
+ const nvpair_t *nvp;
+
+ NVLIST_ASSERT(nvl);
+ PJDLOG_ASSERT(nvl->nvl_error == 0);
+ PJDLOG_ASSERT(level < 3);
+
+ for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
+ nvp = nvlist_next_nvpair(nvl, nvp)) {
+ switch (nvpair_type(nvp)) {
+ case NV_TYPE_DESCRIPTOR:
+ *descs = nvpair_get_descriptor(nvp);
+ descs++;
+ break;
+ case NV_TYPE_NVLIST:
+ descs = nvlist_xdescriptors(nvpair_get_nvlist(nvp),
+ descs, level + 1);
+ break;
+ }
+ }
+
+ return (descs);
+}
+#endif
+
+#ifndef _KERNEL
+int *
+nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp)
+{
+ size_t nitems;
+ int *fds;
+
+ nitems = nvlist_ndescriptors(nvl);
+ fds = nv_malloc(sizeof(fds[0]) * (nitems + 1));
+ if (fds == NULL)
+ return (NULL);
+ if (nitems > 0)
+ nvlist_xdescriptors(nvl, fds, 0);
+ fds[nitems] = -1;
+ if (nitemsp != NULL)
+ *nitemsp = nitems;
+ return (fds);
+}
+#endif
+
+static size_t
+nvlist_xndescriptors(const nvlist_t *nvl, int level)
+{
+#ifndef _KERNEL
+ const nvpair_t *nvp;
+ size_t ndescs;
+
+ NVLIST_ASSERT(nvl);
+ PJDLOG_ASSERT(nvl->nvl_error == 0);
+ PJDLOG_ASSERT(level < 3);
+
+ ndescs = 0;
+ for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
+ nvp = nvlist_next_nvpair(nvl, nvp)) {
+ switch (nvpair_type(nvp)) {
+ case NV_TYPE_DESCRIPTOR:
+ ndescs++;
+ break;
+ case NV_TYPE_NVLIST:
+ ndescs += nvlist_xndescriptors(nvpair_get_nvlist(nvp),
+ level + 1);
+ break;
+ }
+ }
+
+ return (ndescs);
+#else
+ return (0);
+#endif
+}
+
+size_t
+nvlist_ndescriptors(const nvlist_t *nvl)
+{
+
+ return (nvlist_xndescriptors(nvl, 0));
+}
+
+static unsigned char *
+nvlist_pack_header(const nvlist_t *nvl, unsigned char *ptr, size_t *leftp)
+{
+ struct nvlist_header nvlhdr;
+
+ NVLIST_ASSERT(nvl);
+
+ nvlhdr.nvlh_magic = NVLIST_HEADER_MAGIC;
+ nvlhdr.nvlh_version = NVLIST_HEADER_VERSION;
+ nvlhdr.nvlh_flags = nvl->nvl_flags;
+#if BYTE_ORDER == BIG_ENDIAN
+ nvlhdr.nvlh_flags |= NV_FLAG_BIG_ENDIAN;
+#endif
+ nvlhdr.nvlh_descriptors = nvlist_ndescriptors(nvl);
+ nvlhdr.nvlh_size = *leftp - sizeof(nvlhdr);
+ PJDLOG_ASSERT(*leftp >= sizeof(nvlhdr));
+ memcpy(ptr, &nvlhdr, sizeof(nvlhdr));
+ ptr += sizeof(nvlhdr);
+ *leftp -= sizeof(nvlhdr);
+
+ return (ptr);
+}
+
+void *
+nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
+{
+ unsigned char *buf, *ptr;
+ size_t left, size;
+ const nvlist_t *tmpnvl;
+ nvpair_t *nvp, *tmpnvp;
+ void *cookie;
+
+ NVLIST_ASSERT(nvl);
+
+ if (nvl->nvl_error != 0) {
+ RESTORE_ERRNO(nvl->nvl_error);
+ return (NULL);
+ }
+
+ size = nvlist_size(nvl);
+ buf = nv_malloc(size);
+ if (buf == NULL)
+ return (NULL);
+
+ ptr = buf;
+ left = size;
+
+ ptr = nvlist_pack_header(nvl, ptr, &left);
+
+ nvp = nvlist_first_nvpair(nvl);
+ while (nvp != NULL) {
+ NVPAIR_ASSERT(nvp);
+
+ nvpair_init_datasize(nvp);
+ ptr = nvpair_pack_header(nvp, ptr, &left);
+ if (ptr == NULL) {
+ nv_free(buf);
+ return (NULL);
+ }
+ switch (nvpair_type(nvp)) {
+ case NV_TYPE_NULL:
+ ptr = nvpair_pack_null(nvp, ptr, &left);
+ break;
+ case NV_TYPE_BOOL:
+ ptr = nvpair_pack_bool(nvp, ptr, &left);
+ break;
+ case NV_TYPE_NUMBER:
+ ptr = nvpair_pack_number(nvp, ptr, &left);
+ break;
+ case NV_TYPE_STRING:
+ ptr = nvpair_pack_string(nvp, ptr, &left);
+ break;
+ case NV_TYPE_NVLIST:
+ tmpnvl = nvpair_get_nvlist(nvp);
+ ptr = nvlist_pack_header(tmpnvl, ptr, &left);
+ if (ptr == NULL)
+ goto out;
+ tmpnvp = nvlist_first_nvpair(tmpnvl);
+ if (tmpnvp != NULL) {
+ nvl = tmpnvl;
+ nvp = tmpnvp;
+ continue;
+ }
+ ptr = nvpair_pack_nvlist_up(ptr, &left);
+ break;
+#ifndef _KERNEL
+ case NV_TYPE_DESCRIPTOR:
+ ptr = nvpair_pack_descriptor(nvp, ptr, fdidxp, &left);
+ break;
+#endif
+ case NV_TYPE_BINARY:
+ ptr = nvpair_pack_binary(nvp, ptr, &left);
+ break;
+ default:
+ PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
+ }
+ if (ptr == NULL) {
+ nv_free(buf);
+ return (NULL);
+ }
+ while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
+ cookie = NULL;
+ nvl = nvlist_get_parent(nvl, &cookie);
+ if (nvl == NULL)
+ goto out;
+ nvp = cookie;
+ ptr = nvpair_pack_nvlist_up(ptr, &left);
+ if (ptr == NULL)
+ goto out;
+ }
+ }
+
+out:
+ if (sizep != NULL)
+ *sizep = size;
+ return (buf);
+}
+
+void *
+nvlist_pack(const nvlist_t *nvl, size_t *sizep)
+{
+
+ NVLIST_ASSERT(nvl);
+
+ if (nvl->nvl_error != 0) {
+ RESTORE_ERRNO(nvl->nvl_error);
+ return (NULL);
+ }
+
+ if (nvlist_ndescriptors(nvl) > 0) {
+ RESTORE_ERRNO(EOPNOTSUPP);
+ return (NULL);
+ }
+
+ return (nvlist_xpack(nvl, NULL, sizep));
+}
+
+static bool
+nvlist_check_header(struct nvlist_header *nvlhdrp)
+{
+
+ if (nvlhdrp->nvlh_magic != NVLIST_HEADER_MAGIC) {
+ RESTORE_ERRNO(EINVAL);
+ return (false);
+ }
+ if ((nvlhdrp->nvlh_flags & ~NV_FLAG_ALL_MASK) != 0) {
+ RESTORE_ERRNO(EINVAL);
+ return (false);
+ }
+#if BYTE_ORDER == BIG_ENDIAN
+ if ((nvlhdrp->nvlh_flags & NV_FLAG_BIG_ENDIAN) == 0) {
+ nvlhdrp->nvlh_size = le64toh(nvlhdrp->nvlh_size);
+ nvlhdrp->nvlh_descriptors = le64toh(nvlhdrp->nvlh_descriptors);
+ }
+#else
+ if ((nvlhdrp->nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0) {
+ nvlhdrp->nvlh_size = be64toh(nvlhdrp->nvlh_size);
+ nvlhdrp->nvlh_descriptors = be64toh(nvlhdrp->nvlh_descriptors);
+ }
+#endif
+ return (true);
+}
+
+const unsigned char *
+nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
+ bool *isbep, size_t *leftp)
+{
+ struct nvlist_header nvlhdr;
+
+ if (*leftp < sizeof(nvlhdr))
+ goto failed;
+
+ memcpy(&nvlhdr, ptr, sizeof(nvlhdr));
+
+ if (!nvlist_check_header(&nvlhdr))
+ goto failed;
+
+ if (nvlhdr.nvlh_size != *leftp - sizeof(nvlhdr))
+ goto failed;
+
+ /*
+ * nvlh_descriptors might be smaller than nfds in embedded nvlists.
+ */
+ if (nvlhdr.nvlh_descriptors > nfds)
+ goto failed;
+
+ if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0)
+ goto failed;
+
+ nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK);
+
+ ptr += sizeof(nvlhdr);
+ if (isbep != NULL)
+ *isbep = (((int)nvlhdr.nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0);
+ *leftp -= sizeof(nvlhdr);
+
+ return (ptr);
+failed:
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+}
+
+nvlist_t *
+nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds)
+{
+ const unsigned char *ptr;
+ nvlist_t *nvl, *retnvl, *tmpnvl;
+ nvpair_t *nvp;
+ size_t left;
+ bool isbe;
+
+ left = size;
+ ptr = buf;
+
+ tmpnvl = NULL;
+ nvl = retnvl = nvlist_create(0);
+ if (nvl == NULL)
+ goto failed;
+
+ ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
+ if (ptr == NULL)
+ goto failed;
+
+ while (left > 0) {
+ ptr = nvpair_unpack(isbe, ptr, &left, &nvp);
+ if (ptr == NULL)
+ goto failed;
+ switch (nvpair_type(nvp)) {
+ case NV_TYPE_NULL:
+ ptr = nvpair_unpack_null(isbe, nvp, ptr, &left);
+ break;
+ case NV_TYPE_BOOL:
+ ptr = nvpair_unpack_bool(isbe, nvp, ptr, &left);
+ break;
+ case NV_TYPE_NUMBER:
+ ptr = nvpair_unpack_number(isbe, nvp, ptr, &left);
+ break;
+ case NV_TYPE_STRING:
+ ptr = nvpair_unpack_string(isbe, nvp, ptr, &left);
+ break;
+ case NV_TYPE_NVLIST:
+ ptr = nvpair_unpack_nvlist(isbe, nvp, ptr, &left, nfds,
+ &tmpnvl);
+ nvlist_set_parent(tmpnvl, nvp);
+ break;
+#ifndef _KERNEL
+ case NV_TYPE_DESCRIPTOR:
+ ptr = nvpair_unpack_descriptor(isbe, nvp, ptr, &left,
+ fds, nfds);
+ break;
+#endif
+ case NV_TYPE_BINARY:
+ ptr = nvpair_unpack_binary(isbe, nvp, ptr, &left);
+ break;
+ case NV_TYPE_NVLIST_UP:
+ if (nvl->nvl_parent == NULL)
+ goto failed;
+ nvl = nvpair_nvlist(nvl->nvl_parent);
+ continue;
+ default:
+ PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
+ }
+ if (ptr == NULL)
+ goto failed;
+ nvlist_move_nvpair(nvl, nvp);
+ if (tmpnvl != NULL) {
+ nvl = tmpnvl;
+ tmpnvl = NULL;
+ }
+ }
+
+ return (retnvl);
+failed:
+ nvlist_destroy(retnvl);
+ return (NULL);
+}
+
+nvlist_t *
+nvlist_unpack(const void *buf, size_t size)
+{
+
+ return (nvlist_xunpack(buf, size, NULL, 0));
+}
+
+#ifndef _KERNEL
+int
+nvlist_send(int sock, const nvlist_t *nvl)
+{
+ size_t datasize, nfds;
+ int *fds;
+ void *data;
+ int64_t fdidx;
+ int serrno, ret;
+
+ if (nvlist_error(nvl) != 0) {
+ errno = nvlist_error(nvl);
+ return (-1);
+ }
+
+ fds = nvlist_descriptors(nvl, &nfds);
+ if (fds == NULL)
+ return (-1);
+
+ ret = -1;
+ data = NULL;
+ fdidx = 0;
+
+ data = nvlist_xpack(nvl, &fdidx, &datasize);
+ if (data == NULL)
+ goto out;
+
+ if (buf_send(sock, data, datasize) == -1)
+ goto out;
+
+ if (nfds > 0) {
+ if (fd_send(sock, fds, nfds) == -1)
+ goto out;
+ }
+
+ ret = 0;
+out:
+ serrno = errno;
+ free(fds);
+ free(data);
+ errno = serrno;
+ return (ret);
+}
+
+nvlist_t *
+nvlist_recv(int sock)
+{
+ struct nvlist_header nvlhdr;
+ nvlist_t *nvl, *ret;
+ unsigned char *buf;
+ size_t nfds, size, i;
+ int serrno, *fds;
+
+ if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
+ return (NULL);
+
+ if (!nvlist_check_header(&nvlhdr))
+ return (NULL);
+
+ nfds = (size_t)nvlhdr.nvlh_descriptors;
+ size = sizeof(nvlhdr) + (size_t)nvlhdr.nvlh_size;
+
+ buf = malloc(size);
+ if (buf == NULL)
+ return (NULL);
+
+ memcpy(buf, &nvlhdr, sizeof(nvlhdr));
+
+ ret = NULL;
+ fds = NULL;
+
+ if (buf_recv(sock, buf + sizeof(nvlhdr), size - sizeof(nvlhdr)) == -1)
+ goto out;
+
+ if (nfds > 0) {
+ fds = malloc(nfds * sizeof(fds[0]));
+ if (fds == NULL)
+ goto out;
+ if (fd_recv(sock, fds, nfds) == -1)
+ goto out;
+ }
+
+ nvl = nvlist_xunpack(buf, size, fds, nfds);
+ if (nvl == NULL) {
+ for (i = 0; i < nfds; i++)
+ close(fds[i]);
+ goto out;
+ }
+
+ ret = nvl;
+out:
+ serrno = errno;
+ free(buf);
+ free(fds);
+ errno = serrno;
+
+ return (ret);
+}
+
+nvlist_t *
+nvlist_xfer(int sock, nvlist_t *nvl)
+{
+
+ if (nvlist_send(sock, nvl) < 0) {
+ nvlist_destroy(nvl);
+ return (NULL);
+ }
+ nvlist_destroy(nvl);
+ return (nvlist_recv(sock));
+}
+#endif
+
+nvpair_t *
+nvlist_first_nvpair(const nvlist_t *nvl)
+{
+
+ NVLIST_ASSERT(nvl);
+
+ return (TAILQ_FIRST(&nvl->nvl_head));
+}
+
+nvpair_t *
+nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
+{
+ nvpair_t *retnvp;
+
+ NVLIST_ASSERT(nvl);
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
+
+ retnvp = nvpair_next(nvp);
+ PJDLOG_ASSERT(retnvp == NULL || nvpair_nvlist(retnvp) == nvl);
+
+ return (retnvp);
+
+}
+
+nvpair_t *
+nvlist_prev_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
+{
+ nvpair_t *retnvp;
+
+ NVLIST_ASSERT(nvl);
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
+
+ retnvp = nvpair_prev(nvp);
+ PJDLOG_ASSERT(nvpair_nvlist(retnvp) == nvl);
+
+ return (retnvp);
+}
+
+const char *
+nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep)
+{
+ nvpair_t *nvp;
+
+ NVLIST_ASSERT(nvl);
+ PJDLOG_ASSERT(cookiep != NULL);
+
+ if (*cookiep == NULL)
+ nvp = nvlist_first_nvpair(nvl);
+ else
+ nvp = nvlist_next_nvpair(nvl, *cookiep);
+ if (nvp == NULL)
+ return (NULL);
+ if (typep != NULL)
+ *typep = nvpair_type(nvp);
+ *cookiep = nvp;
+ return (nvpair_name(nvp));
+}
+
+bool
+nvlist_exists(const nvlist_t *nvl, const char *name)
+{
+
+ return (nvlist_find(nvl, NV_TYPE_NONE, name) != NULL);
+}
+
+#define NVLIST_EXISTS(type, TYPE) \
+bool \
+nvlist_exists_##type(const nvlist_t *nvl, const char *name) \
+{ \
+ \
+ return (nvlist_find(nvl, NV_TYPE_##TYPE, name) != NULL); \
+}
+
+NVLIST_EXISTS(null, NULL)
+NVLIST_EXISTS(bool, BOOL)
+NVLIST_EXISTS(number, NUMBER)
+NVLIST_EXISTS(string, STRING)
+NVLIST_EXISTS(nvlist, NVLIST)
+#ifndef _KERNEL
+NVLIST_EXISTS(descriptor, DESCRIPTOR)
+#endif
+NVLIST_EXISTS(binary, BINARY)
+
+#undef NVLIST_EXISTS
+
+void
+nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
+{
+ nvpair_t *newnvp;
+
+ NVPAIR_ASSERT(nvp);
+
+ if (nvlist_error(nvl) != 0) {
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+ if (nvlist_exists(nvl, nvpair_name(nvp))) {
+ nvl->nvl_error = EEXIST;
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ newnvp = nvpair_clone(nvp);
+ if (newnvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvpair_insert(&nvl->nvl_head, newnvp, nvl);
+}
+
+void
+nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...)
+{
+ va_list valueap;
+
+ va_start(valueap, valuefmt);
+ nvlist_add_stringv(nvl, name, valuefmt, valueap);
+ va_end(valueap);
+}
+
+void
+nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt,
+ va_list valueap)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_create_stringv(name, valuefmt, valueap);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+void
+nvlist_add_null(nvlist_t *nvl, const char *name)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_create_null(name);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+void
+nvlist_add_bool(nvlist_t *nvl, const char *name, bool value)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_create_bool(name, value);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+void
+nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_create_number(name, value);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+void
+nvlist_add_string(nvlist_t *nvl, const char *name, const char *value)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_create_string(name, value);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+void
+nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_create_nvlist(name, value);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+#ifndef _KERNEL
+void
+nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ errno = nvlist_error(nvl);
+ return;
+ }
+
+ nvp = nvpair_create_descriptor(name, value);
+ if (nvp == NULL)
+ nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
+ else
+ nvlist_move_nvpair(nvl, nvp);
+}
+#endif
+
+void
+nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value,
+ size_t size)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_create_binary(name, value, size);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+void
+nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvpair_nvlist(nvp) == NULL);
+
+ if (nvlist_error(nvl) != 0) {
+ nvpair_free(nvp);
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+ if (nvlist_exists(nvl, nvpair_name(nvp))) {
+ nvpair_free(nvp);
+ nvl->nvl_error = EEXIST;
+ RESTORE_ERRNO(nvl->nvl_error);
+ return;
+ }
+
+ nvpair_insert(&nvl->nvl_head, nvp, nvl);
+}
+
+void
+nvlist_move_string(nvlist_t *nvl, const char *name, char *value)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ nv_free(value);
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_move_string(name, value);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+void
+nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ if (value != NULL && nvlist_get_nvpair_parent(value) != NULL)
+ nvlist_destroy(value);
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_move_nvlist(name, value);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+#ifndef _KERNEL
+void
+nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ close(value);
+ errno = nvlist_error(nvl);
+ return;
+ }
+
+ nvp = nvpair_move_descriptor(name, value);
+ if (nvp == NULL)
+ nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
+ else
+ nvlist_move_nvpair(nvl, nvp);
+}
+#endif
+
+void
+nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size)
+{
+ nvpair_t *nvp;
+
+ if (nvlist_error(nvl) != 0) {
+ nv_free(value);
+ RESTORE_ERRNO(nvlist_error(nvl));
+ return;
+ }
+
+ nvp = nvpair_move_binary(name, value, size);
+ if (nvp == NULL) {
+ nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+ RESTORE_ERRNO(nvl->nvl_error);
+ } else
+ nvlist_move_nvpair(nvl, nvp);
+}
+
+const nvpair_t *
+nvlist_get_nvpair(const nvlist_t *nvl, const char *name)
+{
+
+ return (nvlist_find(nvl, NV_TYPE_NONE, name));
+}
+
+#define NVLIST_GET(ftype, type, TYPE) \
+ftype \
+nvlist_get_##type(const nvlist_t *nvl, const char *name) \
+{ \
+ const nvpair_t *nvp; \
+ \
+ nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
+ if (nvp == NULL) \
+ nvlist_report_missing(NV_TYPE_##TYPE, name); \
+ return (nvpair_get_##type(nvp)); \
+}
+
+NVLIST_GET(bool, bool, BOOL)
+NVLIST_GET(uint64_t, number, NUMBER)
+NVLIST_GET(const char *, string, STRING)
+NVLIST_GET(const nvlist_t *, nvlist, NVLIST)
+#ifndef _KERNEL
+NVLIST_GET(int, descriptor, DESCRIPTOR)
+#endif
+
+#undef NVLIST_GET
+
+const void *
+nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep)
+{
+ nvpair_t *nvp;
+
+ nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
+ if (nvp == NULL)
+ nvlist_report_missing(NV_TYPE_BINARY, name);
+
+ return (nvpair_get_binary(nvp, sizep));
+}
+
+#define NVLIST_TAKE(ftype, type, TYPE) \
+ftype \
+nvlist_take_##type(nvlist_t *nvl, const char *name) \
+{ \
+ nvpair_t *nvp; \
+ ftype value; \
+ \
+ nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
+ if (nvp == NULL) \
+ nvlist_report_missing(NV_TYPE_##TYPE, name); \
+ value = (ftype)(intptr_t)nvpair_get_##type(nvp); \
+ nvlist_remove_nvpair(nvl, nvp); \
+ nvpair_free_structure(nvp); \
+ return (value); \
+}
+
+NVLIST_TAKE(bool, bool, BOOL)
+NVLIST_TAKE(uint64_t, number, NUMBER)
+NVLIST_TAKE(char *, string, STRING)
+NVLIST_TAKE(nvlist_t *, nvlist, NVLIST)
+#ifndef _KERNEL
+NVLIST_TAKE(int, descriptor, DESCRIPTOR)
+#endif
+
+#undef NVLIST_TAKE
+
+void *
+nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep)
+{
+ nvpair_t *nvp;
+ void *value;
+
+ nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
+ if (nvp == NULL)
+ nvlist_report_missing(NV_TYPE_BINARY, name);
+
+ value = (void *)(intptr_t)nvpair_get_binary(nvp, sizep);
+ nvlist_remove_nvpair(nvl, nvp);
+ nvpair_free_structure(nvp);
+ return (value);
+}
+
+void
+nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
+{
+
+ NVLIST_ASSERT(nvl);
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
+
+ nvpair_remove(&nvl->nvl_head, nvp, nvl);
+}
+
+void
+nvlist_free(nvlist_t *nvl, const char *name)
+{
+
+ nvlist_free_type(nvl, name, NV_TYPE_NONE);
+}
+
+#define NVLIST_FREE(type, TYPE) \
+void \
+nvlist_free_##type(nvlist_t *nvl, const char *name) \
+{ \
+ \
+ nvlist_free_type(nvl, name, NV_TYPE_##TYPE); \
+}
+
+NVLIST_FREE(null, NULL)
+NVLIST_FREE(bool, BOOL)
+NVLIST_FREE(number, NUMBER)
+NVLIST_FREE(string, STRING)
+NVLIST_FREE(nvlist, NVLIST)
+#ifndef _KERNEL
+NVLIST_FREE(descriptor, DESCRIPTOR)
+#endif
+NVLIST_FREE(binary, BINARY)
+
+#undef NVLIST_FREE
+
+void
+nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp)
+{
+
+ NVLIST_ASSERT(nvl);
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
+
+ nvlist_remove_nvpair(nvl, nvp);
+ nvpair_free(nvp);
+}
+
diff --git a/sys/kern/subr_nvpair.c b/sys/kern/subr_nvpair.c
new file mode 100644
index 0000000..2e11d799
--- /dev/null
+++ b/sys/kern/subr_nvpair.c
@@ -0,0 +1,1111 @@
+/*-
+ * Copyright (c) 2009-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/endian.h>
+#include <sys/queue.h>
+
+#ifdef _KERNEL
+
+#include <sys/errno.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/systm.h>
+
+#include <machine/stdarg.h>
+
+#else
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common_impl.h"
+#endif
+
+#ifdef HAVE_PJDLOG
+#include <pjdlog.h>
+#endif
+
+#include <sys/nv.h>
+#include <sys/nv_impl.h>
+#include <sys/nvlist_impl.h>
+#include <sys/nvpair_impl.h>
+
+#ifndef HAVE_PJDLOG
+#ifdef _KERNEL
+#define PJDLOG_ASSERT(...) MPASS(__VA_ARGS__)
+#define PJDLOG_RASSERT(expr, ...) KASSERT(expr, (__VA_ARGS__))
+#define PJDLOG_ABORT(...) panic(__VA_ARGS__)
+#else
+#include <assert.h>
+#define PJDLOG_ASSERT(...) assert(__VA_ARGS__)
+#define PJDLOG_RASSERT(expr, ...) assert(expr)
+#define PJDLOG_ABORT(...) abort()
+#endif
+#endif
+
+#define NVPAIR_MAGIC 0x6e7670 /* "nvp" */
+struct nvpair {
+ int nvp_magic;
+ char *nvp_name;
+ int nvp_type;
+ uint64_t nvp_data;
+ size_t nvp_datasize;
+ nvlist_t *nvp_list;
+ TAILQ_ENTRY(nvpair) nvp_next;
+};
+
+#define NVPAIR_ASSERT(nvp) do { \
+ PJDLOG_ASSERT((nvp) != NULL); \
+ PJDLOG_ASSERT((nvp)->nvp_magic == NVPAIR_MAGIC); \
+} while (0)
+
+struct nvpair_header {
+ uint8_t nvph_type;
+ uint16_t nvph_namesize;
+ uint64_t nvph_datasize;
+} __packed;
+
+
+void
+nvpair_assert(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+}
+
+nvlist_t *
+nvpair_nvlist(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+
+ return (nvp->nvp_list);
+}
+
+nvpair_t *
+nvpair_next(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_list != NULL);
+
+ return (TAILQ_NEXT(nvp, nvp_next));
+}
+
+nvpair_t *
+nvpair_prev(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_list != NULL);
+
+ return (TAILQ_PREV(nvp, nvl_head, nvp_next));
+}
+
+void
+nvpair_insert(struct nvl_head *head, nvpair_t *nvp, nvlist_t *nvl)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_list == NULL);
+ PJDLOG_ASSERT(!nvlist_exists(nvl, nvpair_name(nvp)));
+
+ TAILQ_INSERT_TAIL(head, nvp, nvp_next);
+ nvp->nvp_list = nvl;
+}
+
+static void
+nvpair_remove_nvlist(nvpair_t *nvp)
+{
+ nvlist_t *nvl;
+
+ /* XXX: DECONST is bad, mkay? */
+ nvl = __DECONST(nvlist_t *, nvpair_get_nvlist(nvp));
+ PJDLOG_ASSERT(nvl != NULL);
+ nvlist_set_parent(nvl, NULL);
+}
+
+void
+nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_list == nvl);
+
+ if (nvpair_type(nvp) == NV_TYPE_NVLIST)
+ nvpair_remove_nvlist(nvp);
+
+ TAILQ_REMOVE(head, nvp, nvp_next);
+ nvp->nvp_list = NULL;
+}
+
+nvpair_t *
+nvpair_clone(const nvpair_t *nvp)
+{
+ nvpair_t *newnvp;
+ const char *name;
+ const void *data;
+ size_t datasize;
+
+ NVPAIR_ASSERT(nvp);
+
+ name = nvpair_name(nvp);
+
+ switch (nvpair_type(nvp)) {
+ case NV_TYPE_NULL:
+ newnvp = nvpair_create_null(name);
+ break;
+ case NV_TYPE_BOOL:
+ newnvp = nvpair_create_bool(name, nvpair_get_bool(nvp));
+ break;
+ case NV_TYPE_NUMBER:
+ newnvp = nvpair_create_number(name, nvpair_get_number(nvp));
+ break;
+ case NV_TYPE_STRING:
+ newnvp = nvpair_create_string(name, nvpair_get_string(nvp));
+ break;
+ case NV_TYPE_NVLIST:
+ newnvp = nvpair_create_nvlist(name, nvpair_get_nvlist(nvp));
+ break;
+#ifndef _KERNEL
+ case NV_TYPE_DESCRIPTOR:
+ newnvp = nvpair_create_descriptor(name,
+ nvpair_get_descriptor(nvp));
+ break;
+#endif
+ case NV_TYPE_BINARY:
+ data = nvpair_get_binary(nvp, &datasize);
+ newnvp = nvpair_create_binary(name, data, datasize);
+ break;
+ default:
+ PJDLOG_ABORT("Unknown type: %d.", nvpair_type(nvp));
+ }
+
+ return (newnvp);
+}
+
+size_t
+nvpair_header_size(void)
+{
+
+ return (sizeof(struct nvpair_header));
+}
+
+size_t
+nvpair_size(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+
+ return (nvp->nvp_datasize);
+}
+
+unsigned char *
+nvpair_pack_header(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
+{
+ struct nvpair_header nvphdr;
+ size_t namesize;
+
+ NVPAIR_ASSERT(nvp);
+
+ nvphdr.nvph_type = nvp->nvp_type;
+ namesize = strlen(nvp->nvp_name) + 1;
+ PJDLOG_ASSERT(namesize > 0 && namesize <= UINT16_MAX);
+ nvphdr.nvph_namesize = namesize;
+ nvphdr.nvph_datasize = nvp->nvp_datasize;
+ PJDLOG_ASSERT(*leftp >= sizeof(nvphdr));
+ memcpy(ptr, &nvphdr, sizeof(nvphdr));
+ ptr += sizeof(nvphdr);
+ *leftp -= sizeof(nvphdr);
+
+ PJDLOG_ASSERT(*leftp >= namesize);
+ memcpy(ptr, nvp->nvp_name, namesize);
+ ptr += namesize;
+ *leftp -= namesize;
+
+ return (ptr);
+}
+
+unsigned char *
+nvpair_pack_null(const nvpair_t *nvp, unsigned char *ptr,
+ size_t *leftp __unused)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NULL);
+
+ return (ptr);
+}
+
+unsigned char *
+nvpair_pack_bool(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
+{
+ uint8_t value;
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BOOL);
+
+ value = (uint8_t)nvp->nvp_data;
+
+ PJDLOG_ASSERT(*leftp >= sizeof(value));
+ memcpy(ptr, &value, sizeof(value));
+ ptr += sizeof(value);
+ *leftp -= sizeof(value);
+
+ return (ptr);
+}
+
+unsigned char *
+nvpair_pack_number(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
+{
+ uint64_t value;
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NUMBER);
+
+ value = (uint64_t)nvp->nvp_data;
+
+ PJDLOG_ASSERT(*leftp >= sizeof(value));
+ memcpy(ptr, &value, sizeof(value));
+ ptr += sizeof(value);
+ *leftp -= sizeof(value);
+
+ return (ptr);
+}
+
+unsigned char *
+nvpair_pack_string(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_STRING);
+
+ PJDLOG_ASSERT(*leftp >= nvp->nvp_datasize);
+ memcpy(ptr, (const void *)(intptr_t)nvp->nvp_data, nvp->nvp_datasize);
+ ptr += nvp->nvp_datasize;
+ *leftp -= nvp->nvp_datasize;
+
+ return (ptr);
+}
+
+unsigned char *
+nvpair_pack_nvlist_up(unsigned char *ptr, size_t *leftp)
+{
+ struct nvpair_header nvphdr;
+ size_t namesize;
+ const char *name = "";
+
+ namesize = 1;
+ nvphdr.nvph_type = NV_TYPE_NVLIST_UP;
+ nvphdr.nvph_namesize = namesize;
+ nvphdr.nvph_datasize = 0;
+ PJDLOG_ASSERT(*leftp >= sizeof(nvphdr));
+ memcpy(ptr, &nvphdr, sizeof(nvphdr));
+ ptr += sizeof(nvphdr);
+ *leftp -= sizeof(nvphdr);
+
+ PJDLOG_ASSERT(*leftp >= namesize);
+ memcpy(ptr, name, namesize);
+ ptr += namesize;
+ *leftp -= namesize;
+
+ return (ptr);
+}
+
+#ifndef _KERNEL
+unsigned char *
+nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr, int64_t *fdidxp,
+ size_t *leftp)
+{
+ int64_t value;
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR);
+
+ value = (int64_t)nvp->nvp_data;
+ if (value != -1) {
+ /*
+ * If there is a real descriptor here, we change its number
+ * to position in the array of descriptors send via control
+ * message.
+ */
+ PJDLOG_ASSERT(fdidxp != NULL);
+
+ value = *fdidxp;
+ (*fdidxp)++;
+ }
+
+ PJDLOG_ASSERT(*leftp >= sizeof(value));
+ memcpy(ptr, &value, sizeof(value));
+ ptr += sizeof(value);
+ *leftp -= sizeof(value);
+
+ return (ptr);
+}
+#endif
+
+unsigned char *
+nvpair_pack_binary(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BINARY);
+
+ PJDLOG_ASSERT(*leftp >= nvp->nvp_datasize);
+ memcpy(ptr, (const void *)(intptr_t)nvp->nvp_data, nvp->nvp_datasize);
+ ptr += nvp->nvp_datasize;
+ *leftp -= nvp->nvp_datasize;
+
+ return (ptr);
+}
+
+void
+nvpair_init_datasize(nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+
+ if (nvp->nvp_type == NV_TYPE_NVLIST) {
+ if (nvp->nvp_data == 0) {
+ nvp->nvp_datasize = 0;
+ } else {
+ nvp->nvp_datasize =
+ nvlist_size((const nvlist_t *)(intptr_t)nvp->nvp_data);
+ }
+ }
+}
+
+const unsigned char *
+nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
+ size_t *leftp)
+{
+ struct nvpair_header nvphdr;
+
+ if (*leftp < sizeof(nvphdr))
+ goto failed;
+
+ memcpy(&nvphdr, ptr, sizeof(nvphdr));
+ ptr += sizeof(nvphdr);
+ *leftp -= sizeof(nvphdr);
+
+#if NV_TYPE_FIRST > 0
+ if (nvphdr.nvph_type < NV_TYPE_FIRST)
+ goto failed;
+#endif
+ if (nvphdr.nvph_type > NV_TYPE_LAST &&
+ nvphdr.nvph_type != NV_TYPE_NVLIST_UP) {
+ goto failed;
+ }
+
+#if BYTE_ORDER == BIG_ENDIAN
+ if (!isbe) {
+ nvphdr.nvph_namesize = le16toh(nvphdr.nvph_namesize);
+ nvphdr.nvph_datasize = le64toh(nvphdr.nvph_datasize);
+ }
+#else
+ if (isbe) {
+ nvphdr.nvph_namesize = be16toh(nvphdr.nvph_namesize);
+ nvphdr.nvph_datasize = be64toh(nvphdr.nvph_datasize);
+ }
+#endif
+
+ if (nvphdr.nvph_namesize > NV_NAME_MAX)
+ goto failed;
+ if (*leftp < nvphdr.nvph_namesize)
+ goto failed;
+ if (nvphdr.nvph_namesize < 1)
+ goto failed;
+ if (strnlen((const char *)ptr, nvphdr.nvph_namesize) !=
+ (size_t)(nvphdr.nvph_namesize - 1)) {
+ goto failed;
+ }
+
+ memcpy(nvp->nvp_name, ptr, nvphdr.nvph_namesize);
+ ptr += nvphdr.nvph_namesize;
+ *leftp -= nvphdr.nvph_namesize;
+
+ if (*leftp < nvphdr.nvph_datasize)
+ goto failed;
+
+ nvp->nvp_type = nvphdr.nvph_type;
+ nvp->nvp_data = 0;
+ nvp->nvp_datasize = nvphdr.nvph_datasize;
+
+ return (ptr);
+failed:
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+}
+
+const unsigned char *
+nvpair_unpack_null(bool isbe __unused, nvpair_t *nvp, const unsigned char *ptr,
+ size_t *leftp __unused)
+{
+
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NULL);
+
+ if (nvp->nvp_datasize != 0) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ return (ptr);
+}
+
+const unsigned char *
+nvpair_unpack_bool(bool isbe __unused, nvpair_t *nvp, const unsigned char *ptr,
+ size_t *leftp)
+{
+ uint8_t value;
+
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BOOL);
+
+ if (nvp->nvp_datasize != sizeof(value)) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+ if (*leftp < sizeof(value)) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ memcpy(&value, ptr, sizeof(value));
+ ptr += sizeof(value);
+ *leftp -= sizeof(value);
+
+ if (value != 0 && value != 1) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ nvp->nvp_data = (uint64_t)value;
+
+ return (ptr);
+}
+
+const unsigned char *
+nvpair_unpack_number(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
+ size_t *leftp)
+{
+
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NUMBER);
+
+ if (nvp->nvp_datasize != sizeof(uint64_t)) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+ if (*leftp < sizeof(uint64_t)) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ if (isbe)
+ nvp->nvp_data = be64dec(ptr);
+ else
+ nvp->nvp_data = le64dec(ptr);
+ ptr += sizeof(uint64_t);
+ *leftp -= sizeof(uint64_t);
+
+ return (ptr);
+}
+
+const unsigned char *
+nvpair_unpack_string(bool isbe __unused, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp)
+{
+
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_STRING);
+
+ if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ if (strnlen((const char *)ptr, nvp->nvp_datasize) !=
+ nvp->nvp_datasize - 1) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ nvp->nvp_data = (uint64_t)(uintptr_t)nv_strdup((const char *)ptr);
+ if (nvp->nvp_data == 0)
+ return (NULL);
+
+ ptr += nvp->nvp_datasize;
+ *leftp -= nvp->nvp_datasize;
+
+ return (ptr);
+}
+
+const unsigned char *
+nvpair_unpack_nvlist(bool isbe __unused, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp, size_t nfds, nvlist_t **child)
+{
+ nvlist_t *value;
+
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NVLIST);
+
+ if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ value = nvlist_create(0);
+ if (value == NULL)
+ return (NULL);
+
+ ptr = nvlist_unpack_header(value, ptr, nfds, NULL, leftp);
+ if (ptr == NULL)
+ return (NULL);
+
+ nvp->nvp_data = (uint64_t)(uintptr_t)value;
+ *child = value;
+
+ return (ptr);
+}
+
+#ifndef _KERNEL
+const unsigned char *
+nvpair_unpack_descriptor(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
+ size_t *leftp, const int *fds, size_t nfds)
+{
+ int64_t idx;
+
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR);
+
+ if (nvp->nvp_datasize != sizeof(idx)) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ if (*leftp < sizeof(idx)) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ if (isbe)
+ idx = be64dec(ptr);
+ else
+ idx = le64dec(ptr);
+
+ if (idx < 0) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ if ((size_t)idx >= nfds) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ nvp->nvp_data = (uint64_t)fds[idx];
+
+ ptr += sizeof(idx);
+ *leftp -= sizeof(idx);
+
+ return (ptr);
+}
+#endif
+
+const unsigned char *
+nvpair_unpack_binary(bool isbe __unused, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp)
+{
+ void *value;
+
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BINARY);
+
+ if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ value = nv_malloc(nvp->nvp_datasize);
+ if (value == NULL)
+ return (NULL);
+
+ memcpy(value, ptr, nvp->nvp_datasize);
+ ptr += nvp->nvp_datasize;
+ *leftp -= nvp->nvp_datasize;
+
+ nvp->nvp_data = (uint64_t)(uintptr_t)value;
+
+ return (ptr);
+}
+
+const unsigned char *
+nvpair_unpack(bool isbe, const unsigned char *ptr, size_t *leftp,
+ nvpair_t **nvpp)
+{
+ nvpair_t *nvp, *tmp;
+
+ nvp = nv_calloc(1, sizeof(*nvp) + NV_NAME_MAX);
+ if (nvp == NULL)
+ return (NULL);
+ nvp->nvp_name = (char *)(nvp + 1);
+
+ ptr = nvpair_unpack_header(isbe, nvp, ptr, leftp);
+ if (ptr == NULL)
+ goto failed;
+ tmp = nv_realloc(nvp, sizeof(*nvp) + strlen(nvp->nvp_name) + 1);
+ if (tmp == NULL)
+ goto failed;
+ nvp = tmp;
+
+ /* Update nvp_name after realloc(). */
+ nvp->nvp_name = (char *)(nvp + 1);
+ nvp->nvp_data = 0x00;
+ nvp->nvp_magic = NVPAIR_MAGIC;
+ *nvpp = nvp;
+ return (ptr);
+failed:
+ nv_free(nvp);
+ return (NULL);
+}
+
+int
+nvpair_type(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+
+ return (nvp->nvp_type);
+}
+
+const char *
+nvpair_name(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+
+ return (nvp->nvp_name);
+}
+
+static nvpair_t *
+nvpair_allocv(const char *name, int type, uint64_t data, size_t datasize)
+{
+ nvpair_t *nvp;
+ size_t namelen;
+
+ PJDLOG_ASSERT(type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST);
+
+ namelen = strlen(name);
+ if (namelen >= NV_NAME_MAX) {
+ RESTORE_ERRNO(ENAMETOOLONG);
+ return (NULL);
+ }
+
+ nvp = nv_calloc(1, sizeof(*nvp) + namelen + 1);
+ if (nvp != NULL) {
+ nvp->nvp_name = (char *)(nvp + 1);
+ memcpy(nvp->nvp_name, name, namelen);
+ nvp->nvp_name[namelen + 1] = '\0';
+ nvp->nvp_type = type;
+ nvp->nvp_data = data;
+ nvp->nvp_datasize = datasize;
+ nvp->nvp_magic = NVPAIR_MAGIC;
+ }
+
+ return (nvp);
+};
+
+nvpair_t *
+nvpair_create_stringf(const char *name, const char *valuefmt, ...)
+{
+ va_list valueap;
+ nvpair_t *nvp;
+
+ va_start(valueap, valuefmt);
+ nvp = nvpair_create_stringv(name, valuefmt, valueap);
+ va_end(valueap);
+
+ return (nvp);
+}
+
+nvpair_t *
+nvpair_create_stringv(const char *name, const char *valuefmt, va_list valueap)
+{
+ nvpair_t *nvp;
+ char *str;
+ int len;
+
+ len = nv_vasprintf(&str, valuefmt, valueap);
+ if (len < 0)
+ return (NULL);
+ nvp = nvpair_create_string(name, str);
+ if (nvp == NULL)
+ nv_free(str);
+ return (nvp);
+}
+
+nvpair_t *
+nvpair_create_null(const char *name)
+{
+
+ return (nvpair_allocv(name, NV_TYPE_NULL, 0, 0));
+}
+
+nvpair_t *
+nvpair_create_bool(const char *name, bool value)
+{
+
+ return (nvpair_allocv(name, NV_TYPE_BOOL, value ? 1 : 0,
+ sizeof(uint8_t)));
+}
+
+nvpair_t *
+nvpair_create_number(const char *name, uint64_t value)
+{
+
+ return (nvpair_allocv(name, NV_TYPE_NUMBER, value, sizeof(value)));
+}
+
+nvpair_t *
+nvpair_create_string(const char *name, const char *value)
+{
+ nvpair_t *nvp;
+ size_t size;
+ char *data;
+
+ if (value == NULL) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ data = nv_strdup(value);
+ if (data == NULL)
+ return (NULL);
+ size = strlen(value) + 1;
+
+ nvp = nvpair_allocv(name, NV_TYPE_STRING, (uint64_t)(uintptr_t)data,
+ size);
+ if (nvp == NULL)
+ nv_free(data);
+
+ return (nvp);
+}
+
+nvpair_t *
+nvpair_create_nvlist(const char *name, const nvlist_t *value)
+{
+ nvlist_t *nvl;
+ nvpair_t *nvp;
+
+ if (value == NULL) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ nvl = nvlist_clone(value);
+ if (nvl == NULL)
+ return (NULL);
+
+ nvp = nvpair_allocv(name, NV_TYPE_NVLIST, (uint64_t)(uintptr_t)nvl, 0);
+ if (nvp == NULL)
+ nvlist_destroy(nvl);
+ else
+ nvlist_set_parent(nvl, nvp);
+
+ return (nvp);
+}
+
+#ifndef _KERNEL
+nvpair_t *
+nvpair_create_descriptor(const char *name, int value)
+{
+ nvpair_t *nvp;
+
+ if (value < 0 || !fd_is_valid(value)) {
+ errno = EBADF;
+ return (NULL);
+ }
+
+ value = fcntl(value, F_DUPFD_CLOEXEC, 0);
+ if (value < 0)
+ return (NULL);
+
+ nvp = nvpair_allocv(name, NV_TYPE_DESCRIPTOR, (uint64_t)value,
+ sizeof(int64_t));
+ if (nvp == NULL)
+ close(value);
+
+ return (nvp);
+}
+#endif
+
+nvpair_t *
+nvpair_create_binary(const char *name, const void *value, size_t size)
+{
+ nvpair_t *nvp;
+ void *data;
+
+ if (value == NULL || size == 0) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ data = nv_malloc(size);
+ if (data == NULL)
+ return (NULL);
+ memcpy(data, value, size);
+
+ nvp = nvpair_allocv(name, NV_TYPE_BINARY, (uint64_t)(uintptr_t)data,
+ size);
+ if (nvp == NULL)
+ nv_free(data);
+
+ return (nvp);
+}
+
+nvpair_t *
+nvpair_move_string(const char *name, char *value)
+{
+ nvpair_t *nvp;
+ int serrno;
+
+ if (value == NULL) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ nvp = nvpair_allocv(name, NV_TYPE_STRING, (uint64_t)(uintptr_t)value,
+ strlen(value) + 1);
+ if (nvp == NULL) {
+ SAVE_ERRNO(serrno);
+ nv_free(value);
+ RESTORE_ERRNO(serrno);
+ }
+
+ return (nvp);
+}
+
+nvpair_t *
+nvpair_move_nvlist(const char *name, nvlist_t *value)
+{
+ nvpair_t *nvp;
+
+ if (value == NULL || nvlist_get_nvpair_parent(value) != NULL) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ if (nvlist_error(value) != 0) {
+ RESTORE_ERRNO(nvlist_error(value));
+ nvlist_destroy(value);
+ return (NULL);
+ }
+
+ nvp = nvpair_allocv(name, NV_TYPE_NVLIST, (uint64_t)(uintptr_t)value,
+ 0);
+ if (nvp == NULL)
+ nvlist_destroy(value);
+ else
+ nvlist_set_parent(value, nvp);
+
+ return (nvp);
+}
+
+#ifndef _KERNEL
+nvpair_t *
+nvpair_move_descriptor(const char *name, int value)
+{
+ nvpair_t *nvp;
+ int serrno;
+
+ if (value < 0 || !fd_is_valid(value)) {
+ errno = EBADF;
+ return (NULL);
+ }
+
+ nvp = nvpair_allocv(name, NV_TYPE_DESCRIPTOR, (uint64_t)value,
+ sizeof(int64_t));
+ if (nvp == NULL) {
+ serrno = errno;
+ close(value);
+ errno = serrno;
+ }
+
+ return (nvp);
+}
+#endif
+
+nvpair_t *
+nvpair_move_binary(const char *name, void *value, size_t size)
+{
+ nvpair_t *nvp;
+ int serrno;
+
+ if (value == NULL || size == 0) {
+ RESTORE_ERRNO(EINVAL);
+ return (NULL);
+ }
+
+ nvp = nvpair_allocv(name, NV_TYPE_BINARY, (uint64_t)(uintptr_t)value,
+ size);
+ if (nvp == NULL) {
+ SAVE_ERRNO(serrno);
+ nv_free(value);
+ RESTORE_ERRNO(serrno);
+ }
+
+ return (nvp);
+}
+
+bool
+nvpair_get_bool(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+
+ return (nvp->nvp_data == 1);
+}
+
+uint64_t
+nvpair_get_number(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+
+ return (nvp->nvp_data);
+}
+
+const char *
+nvpair_get_string(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_STRING);
+
+ return ((const char *)(intptr_t)nvp->nvp_data);
+}
+
+const nvlist_t *
+nvpair_get_nvlist(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NVLIST);
+
+ return ((const nvlist_t *)(intptr_t)nvp->nvp_data);
+}
+
+#ifndef _KERNEL
+int
+nvpair_get_descriptor(const nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR);
+
+ return ((int)nvp->nvp_data);
+}
+#endif
+
+const void *
+nvpair_get_binary(const nvpair_t *nvp, size_t *sizep)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BINARY);
+
+ if (sizep != NULL)
+ *sizep = nvp->nvp_datasize;
+ return ((const void *)(intptr_t)nvp->nvp_data);
+}
+
+void
+nvpair_free(nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_list == NULL);
+
+ nvp->nvp_magic = 0;
+ switch (nvp->nvp_type) {
+#ifndef _KERNEL
+ case NV_TYPE_DESCRIPTOR:
+ close((int)nvp->nvp_data);
+ break;
+#endif
+ case NV_TYPE_NVLIST:
+ nvlist_destroy((nvlist_t *)(intptr_t)nvp->nvp_data);
+ break;
+ case NV_TYPE_STRING:
+ nv_free((char *)(intptr_t)nvp->nvp_data);
+ break;
+ case NV_TYPE_BINARY:
+ nv_free((void *)(intptr_t)nvp->nvp_data);
+ break;
+ }
+ nv_free(nvp);
+}
+
+void
+nvpair_free_structure(nvpair_t *nvp)
+{
+
+ NVPAIR_ASSERT(nvp);
+ PJDLOG_ASSERT(nvp->nvp_list == NULL);
+
+ nvp->nvp_magic = 0;
+ nv_free(nvp);
+}
+
+const char *
+nvpair_type_string(int type)
+{
+
+ switch (type) {
+ case NV_TYPE_NULL:
+ return ("NULL");
+ case NV_TYPE_BOOL:
+ return ("BOOL");
+ case NV_TYPE_NUMBER:
+ return ("NUMBER");
+ case NV_TYPE_STRING:
+ return ("STRING");
+ case NV_TYPE_NVLIST:
+ return ("NVLIST");
+ case NV_TYPE_DESCRIPTOR:
+ return ("DESCRIPTOR");
+ case NV_TYPE_BINARY:
+ return ("BINARY");
+ default:
+ return ("<UNKNOWN>");
+ }
+}
+
diff --git a/sys/modules/zfs/Makefile b/sys/modules/zfs/Makefile
index 5c363f9..53e8d34 100644
--- a/sys/modules/zfs/Makefile
+++ b/sys/modules/zfs/Makefile
@@ -17,9 +17,9 @@ SRCS+= acl_common.c
.PATH: ${SUNW}/common/avl
SRCS+= avl.c
.PATH: ${SUNW}/common/nvpair
-SRCS+= nvpair.c
-SRCS+= nvpair_alloc_fixed.c
-SRCS+= fnvpair.c
+SRCS+= opensolaris_nvpair.c
+SRCS+= opensolaris_nvpair_alloc_fixed.c
+SRCS+= opensolaris_fnvpair.c
.PATH: ${.CURDIR}/../../cddl/contrib/opensolaris/common/unicode
SRCS+= u8_textprep.c
diff --git a/sys/ofed/include/linux/compiler.h b/sys/ofed/include/linux/compiler.h
index 9b1a5ad..c7a3d28 100644
--- a/sys/ofed/include/linux/compiler.h
+++ b/sys/ofed/include/linux/compiler.h
@@ -2,7 +2,8 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
+ * Copyright (c) 2015 François Tigeot
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -62,5 +63,28 @@
#define typeof(x) __typeof(x)
#define uninitialized_var(x) x = x
+#define __read_mostly __attribute__((__section__(".data.read_mostly")))
+#define __always_unused __unused
+#define __must_check __result_use_check
+
+#define __printf(a,b) __printflike(a,b)
+
+#define barrier() __asm__ __volatile__("": : :"memory")
+
+#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
+
+#define WRITE_ONCE(x,v) do { \
+ barrier(); \
+ ACCESS_ONCE(x) = (v); \
+ barrier(); \
+} while (0)
+
+#define READ_ONCE(x) ({ \
+ __typeof(x) __var; \
+ barrier(); \
+ __var = ACCESS_ONCE(x); \
+ barrier(); \
+ __var; \
+})
#endif /* _LINUX_COMPILER_H_ */
diff --git a/sys/ofed/include/linux/file.h b/sys/ofed/include/linux/file.h
index b76a408..1f72822 100644
--- a/sys/ofed/include/linux/file.h
+++ b/sys/ofed/include/linux/file.h
@@ -2,7 +2,7 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -119,6 +119,21 @@ get_unused_fd(void)
return fd;
}
+static inline int
+get_unused_fd_flags(int flags)
+{
+ struct file *file;
+ int error;
+ int fd;
+
+ error = falloc(curthread, &file, &fd, flags);
+ if (error)
+ return -error;
+ /* drop the extra reference */
+ fdrop(file, curthread);
+ return fd;
+}
+
static inline struct linux_file *
alloc_file(int mode, const struct file_operations *fops)
{
diff --git a/sys/ofed/include/linux/kobject.h b/sys/ofed/include/linux/kobject.h
index 159f071..437d32f 100644
--- a/sys/ofed/include/linux/kobject.h
+++ b/sys/ofed/include/linux/kobject.h
@@ -87,29 +87,7 @@ kobject_get(struct kobject *kobj)
return kobj;
}
-static inline int
-kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args)
-{
- char *old;
- char *name;
-
- old = kobj->name;
-
- if (old && !fmt)
- return 0;
-
- name = kzalloc(MAXPATHLEN, GFP_KERNEL);
- if (!name)
- return -ENOMEM;
- vsnprintf(name, MAXPATHLEN, fmt, args);
- kobj->name = name;
- kfree(old);
- for (; *name != '\0'; name++)
- if (*name == '/')
- *name = '!';
- return (0);
-}
-
+int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list);
int kobject_add(struct kobject *kobj, struct kobject *parent,
const char *fmt, ...);
diff --git a/sys/ofed/include/linux/linux_compat.c b/sys/ofed/include/linux/linux_compat.c
index e9cc0c6..ef44c6d 100644
--- a/sys/ofed/include/linux/linux_compat.c
+++ b/sys/ofed/include/linux/linux_compat.c
@@ -64,6 +64,8 @@
#include <vm/vm_pager.h>
+#include <linux/workqueue.h>
+
MALLOC_DEFINE(M_KMALLOC, "linux", "Linux kmalloc compat");
#include <linux/rbtree.h>
@@ -90,7 +92,50 @@ panic_cmp(struct rb_node *one, struct rb_node *two)
}
RB_GENERATE(linux_root, rb_node, __entry, panic_cmp);
-
+
+int
+kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args)
+{
+ va_list tmp_va;
+ int len;
+ char *old;
+ char *name;
+ char dummy;
+
+ old = kobj->name;
+
+ if (old && fmt == NULL)
+ return (0);
+
+ /* compute length of string */
+ va_copy(tmp_va, args);
+ len = vsnprintf(&dummy, 0, fmt, tmp_va);
+ va_end(tmp_va);
+
+ /* account for zero termination */
+ len++;
+
+ /* check for error */
+ if (len < 1)
+ return (-EINVAL);
+
+ /* allocate memory for string */
+ name = kzalloc(len, GFP_KERNEL);
+ if (name == NULL)
+ return (-ENOMEM);
+ vsnprintf(name, len, fmt, args);
+ kobj->name = name;
+
+ /* free old string */
+ kfree(old);
+
+ /* filter new string */
+ for (; *name != '\0'; name++)
+ if (*name == '/')
+ *name = '!';
+ return (0);
+}
+
int
kobject_set_name(struct kobject *kobj, const char *fmt, ...)
{
@@ -882,6 +927,50 @@ linux_completion_done(struct completion *c)
return (isdone);
}
+void
+linux_delayed_work_fn(void *arg)
+{
+ struct delayed_work *work;
+
+ work = arg;
+ taskqueue_enqueue(work->work.taskqueue, &work->work.work_task);
+}
+
+void
+linux_work_fn(void *context, int pending)
+{
+ struct work_struct *work;
+
+ work = context;
+ work->fn(work);
+}
+
+void
+linux_flush_fn(void *context, int pending)
+{
+}
+
+struct workqueue_struct *
+linux_create_workqueue_common(const char *name, int cpus)
+{
+ struct workqueue_struct *wq;
+
+ wq = kmalloc(sizeof(*wq), M_WAITOK);
+ wq->taskqueue = taskqueue_create(name, M_WAITOK,
+ taskqueue_thread_enqueue, &wq->taskqueue);
+ atomic_set(&wq->draining, 0);
+ taskqueue_start_threads(&wq->taskqueue, cpus, PWAIT, "%s", name);
+
+ return (wq);
+}
+
+void
+destroy_workqueue(struct workqueue_struct *wq)
+{
+ taskqueue_free(wq->taskqueue);
+ kfree(wq);
+}
+
static void
linux_compat_init(void *arg)
{
diff --git a/sys/boot/i386/efi/exec.c b/sys/ofed/include/linux/srcu.h
index 579f559..c20215b 100644
--- a/sys/boot/i386/efi/exec.c
+++ b/sys/ofed/include/linux/srcu.h
@@ -1,13 +1,13 @@
/*-
- * Copyright (c) 2010 Rui Paulo <rpaulo@FreeBSD.org>
+ * Copyright (c) 2015 Mellanox Technologies, Ltd.
* All rights reserved.
*
* 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.
+ * notice unmodified, 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.
@@ -22,28 +22,51 @@
* 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$
*/
+#ifndef _LINUX_SRCU_H_
+#define _LINUX_SRCU_H_
+
+#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/sx.h>
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+struct srcu_struct {
+ struct sx sx;
+};
-#include <stand.h>
-#include <machine/elf.h>
-#include "../btx/lib/btxv86.h"
+static inline int
+init_srcu_struct(struct srcu_struct *srcu)
+{
+ sx_init(&srcu->sx, "SleepableRCU");
+ return (0);
+}
-#include "../../common/bootstrap.h"
+static inline void
+cleanup_srcu_struct(struct srcu_struct *srcu)
+{
+ sx_destroy(&srcu->sx);
+}
-uint32_t __base;
-struct __v86 __v86;
+static inline int
+srcu_read_lock(struct srcu_struct *srcu)
+{
+ sx_slock(&srcu->sx);
+ return (0);
+}
-void
-__v86int()
+static inline void
+srcu_read_unlock(struct srcu_struct *srcu, int key)
{
- printf("%s\n", __func__);
- exit(1);
+ sx_sunlock(&srcu->sx);
}
-void
-__exec(caddr_t addr, ...)
+static inline void
+synchronize_srcu(struct srcu_struct *srcu)
{
+ sx_xlock(&srcu->sx);
+ sx_xunlock(&srcu->sx);
}
+
+#endif /* _LINUX_SRCU_H_ */
diff --git a/sys/ofed/include/linux/types.h b/sys/ofed/include/linux/types.h
index 9fff0ec..b5def55 100644
--- a/sys/ofed/include/linux/types.h
+++ b/sys/ofed/include/linux/types.h
@@ -36,8 +36,6 @@
#include <linux/compiler.h>
#include <asm/types.h>
-#define __read_mostly __attribute__((__section__(".data.read_mostly")))
-
#ifndef __bitwise__
#ifdef __CHECKER__
#define __bitwise__ __attribute__((bitwise))
diff --git a/sys/ofed/include/linux/workqueue.h b/sys/ofed/include/linux/workqueue.h
index 38cd2fe..41ca80f 100644
--- a/sys/ofed/include/linux/workqueue.h
+++ b/sys/ofed/include/linux/workqueue.h
@@ -2,7 +2,7 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,10 +34,13 @@
#include <linux/timer.h>
#include <linux/slab.h>
+#include <asm/atomic.h>
+
#include <sys/taskqueue.h>
struct workqueue_struct {
struct taskqueue *taskqueue;
+ atomic_t draining;
};
struct work_struct {
@@ -46,11 +49,19 @@ struct work_struct {
void (*fn)(struct work_struct *);
};
+typedef __typeof(((struct work_struct *)0)->fn) work_func_t;
+
struct delayed_work {
struct work_struct work;
struct callout timer;
};
+extern void linux_work_fn(void *, int);
+extern void linux_flush_fn(void *, int);
+extern void linux_delayed_work_fn(void *);
+extern struct workqueue_struct *linux_create_workqueue_common(const char *, int);
+extern void destroy_workqueue(struct workqueue_struct *);
+
static inline struct delayed_work *
to_delayed_work(struct work_struct *work)
{
@@ -58,21 +69,11 @@ to_delayed_work(struct work_struct *work)
return container_of(work, struct delayed_work, work);
}
-
-static inline void
-_work_fn(void *context, int pending)
-{
- struct work_struct *work;
-
- work = context;
- work->fn(work);
-}
-
#define INIT_WORK(work, func) \
do { \
(work)->fn = (func); \
(work)->taskqueue = NULL; \
- TASK_INIT(&(work)->work_task, 0, _work_fn, (work)); \
+ TASK_INIT(&(work)->work_task, 0, linux_work_fn, (work)); \
} while (0)
#define INIT_DELAYED_WORK(_work, func) \
@@ -81,7 +82,7 @@ do { \
callout_init(&(_work)->timer, CALLOUT_MPSAFE); \
} while (0)
-#define INIT_DEFERRABLE_WORK INIT_DELAYED_WORK
+#define INIT_DEFERRABLE_WORK(...) INIT_DELAYED_WORK(__VA_ARGS__)
#define schedule_work(work) \
do { \
@@ -91,20 +92,15 @@ do { \
#define flush_scheduled_work() flush_taskqueue(taskqueue_thread)
-static inline int queue_work (struct workqueue_struct *q, struct work_struct *work)
+static inline int
+queue_work(struct workqueue_struct *wq, struct work_struct *work)
{
- (work)->taskqueue = (q)->taskqueue;
- /* Return opposite val to align with Linux logic */
- return !taskqueue_enqueue((q)->taskqueue, &(work)->work_task);
-}
-
-static inline void
-_delayed_work_fn(void *arg)
-{
- struct delayed_work *work;
-
- work = arg;
- taskqueue_enqueue(work->work.taskqueue, &work->work.work_task);
+ work->taskqueue = wq->taskqueue;
+ /* Check for draining */
+ if (atomic_read(&wq->draining) != 0)
+ return (!work->work_task.ta_pending);
+ /* Return opposite value to align with Linux logic */
+ return (!taskqueue_enqueue(wq->taskqueue, &work->work_task));
}
static inline int
@@ -113,57 +109,44 @@ queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work,
{
int pending;
- pending = work->work.work_task.ta_pending;
work->work.taskqueue = wq->taskqueue;
- if (delay != 0)
- callout_reset(&work->timer, delay, _delayed_work_fn, work);
- else
- _delayed_work_fn((void *)work);
-
+ if (atomic_read(&wq->draining) != 0) {
+ pending = work->work.work_task.ta_pending;
+ } else if (delay != 0) {
+ pending = work->work.work_task.ta_pending;
+ callout_reset(&work->timer, delay, linux_delayed_work_fn, work);
+ } else {
+ callout_stop(&work->timer);
+ pending = taskqueue_enqueue(work->work.taskqueue,
+ &work->work.work_task);
+ }
return (!pending);
}
-static inline bool schedule_delayed_work(struct delayed_work *dwork,
- unsigned long delay)
-{
- struct workqueue_struct wq;
- wq.taskqueue = taskqueue_thread;
- return queue_delayed_work(&wq, dwork, delay);
-}
-
-static inline struct workqueue_struct *
-_create_workqueue_common(char *name, int cpus)
+static inline bool
+schedule_delayed_work(struct delayed_work *dwork,
+ unsigned long delay)
{
- struct workqueue_struct *wq;
+ struct workqueue_struct wq;
- wq = kmalloc(sizeof(*wq), M_WAITOK);
- wq->taskqueue = taskqueue_create((name), M_WAITOK,
- taskqueue_thread_enqueue, &wq->taskqueue);
- taskqueue_start_threads(&wq->taskqueue, cpus, PWAIT, "%s", name);
-
- return (wq);
+ wq.taskqueue = taskqueue_thread;
+ atomic_set(&wq.draining, 0);
+ return (queue_delayed_work(&wq, dwork, delay));
}
-
#define create_singlethread_workqueue(name) \
- _create_workqueue_common(name, 1)
+ linux_create_workqueue_common(name, 1)
#define create_workqueue(name) \
- _create_workqueue_common(name, MAXCPU)
+ linux_create_workqueue_common(name, MAXCPU)
-static inline void
-destroy_workqueue(struct workqueue_struct *wq)
-{
- taskqueue_free(wq->taskqueue);
- kfree(wq);
-}
+#define alloc_ordered_workqueue(name, flags) \
+ linux_create_workqueue_common(name, 1)
-#define flush_workqueue(wq) flush_taskqueue((wq)->taskqueue)
+#define alloc_workqueue(name, flags, max_active) \
+ linux_create_workqueue_common(name, max_active)
-static inline void
-_flush_fn(void *context, int pending)
-{
-}
+#define flush_workqueue(wq) flush_taskqueue((wq)->taskqueue)
static inline void
flush_taskqueue(struct taskqueue *tq)
@@ -171,12 +154,20 @@ flush_taskqueue(struct taskqueue *tq)
struct task flushtask;
PHOLD(curproc);
- TASK_INIT(&flushtask, 0, _flush_fn, NULL);
+ TASK_INIT(&flushtask, 0, linux_flush_fn, NULL);
taskqueue_enqueue(tq, &flushtask);
taskqueue_drain(tq, &flushtask);
PRELE(curproc);
}
+static inline void
+drain_workqueue(struct workqueue_struct *wq)
+{
+ atomic_inc(&wq->draining);
+ flush_taskqueue(wq->taskqueue);
+ atomic_dec(&wq->draining);
+}
+
static inline int
cancel_work_sync(struct work_struct *work)
{
@@ -213,7 +204,7 @@ cancel_delayed_work_sync(struct delayed_work *work)
static inline bool
mod_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork,
- unsigned long delay)
+ unsigned long delay)
{
cancel_delayed_work(dwork);
queue_delayed_work(wq, dwork, delay);
diff --git a/sys/security/audit/bsm_domain.c b/sys/security/audit/bsm_domain.c
index cb5939f..8119956 100644
--- a/sys/security/audit/bsm_domain.c
+++ b/sys/security/audit/bsm_domain.c
@@ -25,8 +25,6 @@
* 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.
- *
- * P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_domain.c#3
*/
#include <sys/cdefs.h>
diff --git a/sys/security/audit/bsm_errno.c b/sys/security/audit/bsm_errno.c
index e2e1961..bb746b5 100644
--- a/sys/security/audit/bsm_errno.c
+++ b/sys/security/audit/bsm_errno.c
@@ -25,8 +25,6 @@
* 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.
- *
- * P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#22
*/
#include <sys/cdefs.h>
diff --git a/sys/security/audit/bsm_fcntl.c b/sys/security/audit/bsm_fcntl.c
index 1e7e68f..5d27a3a 100644
--- a/sys/security/audit/bsm_fcntl.c
+++ b/sys/security/audit/bsm_fcntl.c
@@ -25,8 +25,6 @@
* 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.
- *
- * P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_fcntl.c#2
*/
#include <sys/cdefs.h>
diff --git a/sys/security/audit/bsm_socket_type.c b/sys/security/audit/bsm_socket_type.c
index c049179..94c361c 100644
--- a/sys/security/audit/bsm_socket_type.c
+++ b/sys/security/audit/bsm_socket_type.c
@@ -25,8 +25,6 @@
* 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.
- *
- * P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_socket_type.c#1
*/
#include <sys/cdefs.h>
diff --git a/sys/security/audit/bsm_token.c b/sys/security/audit/bsm_token.c
index 763d597..84f4fce 100644
--- a/sys/security/audit/bsm_token.c
+++ b/sys/security/audit/bsm_token.c
@@ -29,8 +29,6 @@
* 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.
- *
- * P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#99
*/
#include <sys/cdefs.h>
diff --git a/sys/sys/copyright.h b/sys/sys/copyright.h
index 3e1b2b5..5c96e4b 100644
--- a/sys/sys/copyright.h
+++ b/sys/sys/copyright.h
@@ -1,5 +1,5 @@
/*-
- * Copyright (C) 1992-2015 The FreeBSD Project. All rights reserved.
+ * Copyright (C) 1992-2016 The FreeBSD Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,7 +30,7 @@
/* FreeBSD */
#define COPYRIGHT_FreeBSD \
- "Copyright (c) 1992-2015 The FreeBSD Project.\n"
+ "Copyright (c) 1992-2016 The FreeBSD Project.\n"
/* Foundation */
#define TRADEMARK_Foundation \
diff --git a/sys/sys/dnv.h b/sys/sys/dnv.h
new file mode 100644
index 0000000..8337d78
--- /dev/null
+++ b/sys/sys/dnv.h
@@ -0,0 +1,116 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#ifndef _DNV_H_
+#define _DNV_H_
+
+#include <sys/cdefs.h>
+
+#ifndef _KERNEL
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#endif
+
+#ifndef _NVLIST_T_DECLARED
+#define _NVLIST_T_DECLARED
+struct nvlist;
+
+typedef struct nvlist nvlist_t;
+#endif
+
+__BEGIN_DECLS
+
+/*
+ * The dnvlist_get functions returns value associated with the given name.
+ * If it returns a pointer, the pointer represents internal buffer and should
+ * not be freed by the caller.
+ * If no element of the given name and type exists, the function will return
+ * provided default value.
+ */
+
+bool dnvlist_get_bool(const nvlist_t *nvl, const char *name, bool defval);
+uint64_t dnvlist_get_number(const nvlist_t *nvl, const char *name, uint64_t defval);
+const char *dnvlist_get_string(const nvlist_t *nvl, const char *name, const char *defval);
+const nvlist_t *dnvlist_get_nvlist(const nvlist_t *nvl, const char *name, const nvlist_t *defval);
+int dnvlist_get_descriptor(const nvlist_t *nvl, const char *name, int defval);
+const void *dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep, const void *defval, size_t defsize);
+
+#ifndef _KERNEL
+bool dnvlist_getf_bool(const nvlist_t *nvl, bool defval, const char *namefmt, ...) __printflike(3, 4);
+uint64_t dnvlist_getf_number(const nvlist_t *nvl, uint64_t defval, const char *namefmt, ...) __printflike(3, 4);
+const char *dnvlist_getf_string(const nvlist_t *nvl, const char *defval, const char *namefmt, ...) __printflike(3, 4);
+const nvlist_t *dnvlist_getf_nvlist(const nvlist_t *nvl, const nvlist_t *defval, const char *namefmt, ...) __printflike(3, 4);
+int dnvlist_getf_descriptor(const nvlist_t *nvl, int defval, const char *namefmt, ...) __printflike(3, 4);
+const void *dnvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const void *defval, size_t defsize, const char *namefmt, ...) __printflike(5, 6);
+
+bool dnvlist_getv_bool(const nvlist_t *nvl, bool defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+uint64_t dnvlist_getv_number(const nvlist_t *nvl, uint64_t defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+const char *dnvlist_getv_string(const nvlist_t *nvl, const char *defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+const nvlist_t *dnvlist_getv_nvlist(const nvlist_t *nvl, const nvlist_t *defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+int dnvlist_getv_descriptor(const nvlist_t *nvl, int defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+const void *dnvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const void *defval, size_t defsize, const char *namefmt, va_list nameap) __printflike(5, 0);
+#endif
+
+/*
+ * The dnvlist_take functions returns value associated with the given name and
+ * remove corresponding nvpair.
+ * If it returns a pointer, the caller has to free it.
+ * If no element of the given name and type exists, the function will return
+ * provided default value.
+ */
+
+bool dnvlist_take_bool(nvlist_t *nvl, const char *name, bool defval);
+uint64_t dnvlist_take_number(nvlist_t *nvl, const char *name, uint64_t defval);
+char *dnvlist_take_string(nvlist_t *nvl, const char *name, char *defval);
+nvlist_t *dnvlist_take_nvlist(nvlist_t *nvl, const char *name, nvlist_t *defval);
+int dnvlist_take_descriptor(nvlist_t *nvl, const char *name, int defval);
+void *dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep, void *defval, size_t defsize);
+
+#ifndef _KERNEL
+bool dnvlist_takef_bool(nvlist_t *nvl, bool defval, const char *namefmt, ...) __printflike(3, 4);
+uint64_t dnvlist_takef_number(nvlist_t *nvl, uint64_t defval, const char *namefmt, ...) __printflike(3, 4);
+char *dnvlist_takef_string(nvlist_t *nvl, char *defval, const char *namefmt, ...) __printflike(3, 4);
+nvlist_t *dnvlist_takef_nvlist(nvlist_t *nvl, nvlist_t *defval, const char *namefmt, ...) __printflike(3, 4);
+int dnvlist_takef_descriptor(nvlist_t *nvl, int defval, const char *namefmt, ...) __printflike(3, 4);
+void *dnvlist_takef_binary(nvlist_t *nvl, size_t *sizep, void *defval, size_t defsize, const char *namefmt, ...) __printflike(5, 6);
+
+bool dnvlist_takev_bool(nvlist_t *nvl, bool defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+uint64_t dnvlist_takev_number(nvlist_t *nvl, uint64_t defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+char *dnvlist_takev_string(nvlist_t *nvl, char *defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+nvlist_t *dnvlist_takev_nvlist(nvlist_t *nvl, nvlist_t *defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+int dnvlist_takev_descriptor(nvlist_t *nvl, int defval, const char *namefmt, va_list nameap) __printflike(3, 0);
+void *dnvlist_takev_binary(nvlist_t *nvl, size_t *sizep, void *defval, size_t defsize, const char *namefmt, va_list nameap) __printflike(5, 0);
+#endif
+
+__END_DECLS
+
+#endif /* !_DNV_H_ */
diff --git a/sys/sys/nv.h b/sys/sys/nv.h
new file mode 100644
index 0000000..5c342dc
--- /dev/null
+++ b/sys/sys/nv.h
@@ -0,0 +1,200 @@
+/*-
+ * Copyright (c) 2009-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#ifndef _NV_H_
+#define _NV_H_
+
+#include <sys/cdefs.h>
+
+#ifndef _KERNEL
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#endif
+
+#ifndef _NVLIST_T_DECLARED
+#define _NVLIST_T_DECLARED
+struct nvlist;
+
+typedef struct nvlist nvlist_t;
+#endif
+
+#define NV_NAME_MAX 2048
+
+#define NV_TYPE_NONE 0
+
+#define NV_TYPE_NULL 1
+#define NV_TYPE_BOOL 2
+#define NV_TYPE_NUMBER 3
+#define NV_TYPE_STRING 4
+#define NV_TYPE_NVLIST 5
+#define NV_TYPE_DESCRIPTOR 6
+#define NV_TYPE_BINARY 7
+
+/*
+ * Perform case-insensitive lookups of provided names.
+ */
+#define NV_FLAG_IGNORE_CASE 0x01
+
+#if defined(_KERNEL) && defined(MALLOC_DECLARE)
+MALLOC_DECLARE(M_NVLIST);
+#endif
+
+__BEGIN_DECLS
+
+nvlist_t *nvlist_create(int flags);
+void nvlist_destroy(nvlist_t *nvl);
+int nvlist_error(const nvlist_t *nvl);
+bool nvlist_empty(const nvlist_t *nvl);
+int nvlist_flags(const nvlist_t *nvl);
+void nvlist_set_error(nvlist_t *nvl, int error);
+
+nvlist_t *nvlist_clone(const nvlist_t *nvl);
+
+#ifndef _KERNEL
+void nvlist_dump(const nvlist_t *nvl, int fd);
+void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
+#endif
+
+size_t nvlist_size(const nvlist_t *nvl);
+void *nvlist_pack(const nvlist_t *nvl, size_t *sizep);
+nvlist_t *nvlist_unpack(const void *buf, size_t size);
+
+int nvlist_send(int sock, const nvlist_t *nvl);
+nvlist_t *nvlist_recv(int sock);
+nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl);
+
+const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
+
+const nvlist_t *nvlist_get_parent(const nvlist_t *nvl, void **cookiep);
+
+/*
+ * The nvlist_exists functions check if the given name (optionally of the given
+ * type) exists on nvlist.
+ */
+
+bool nvlist_exists(const nvlist_t *nvl, const char *name);
+bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
+
+bool nvlist_exists_null(const nvlist_t *nvl, const char *name);
+bool nvlist_exists_bool(const nvlist_t *nvl, const char *name);
+bool nvlist_exists_number(const nvlist_t *nvl, const char *name);
+bool nvlist_exists_string(const nvlist_t *nvl, const char *name);
+bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
+#ifndef _KERNEL
+bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
+#endif
+bool nvlist_exists_binary(const nvlist_t *nvl, const char *name);
+
+/*
+ * The nvlist_add functions add the given name/value pair.
+ * If a pointer is provided, nvlist_add will internally allocate memory for the
+ * given data (in other words it won't consume provided buffer).
+ */
+
+void nvlist_add_null(nvlist_t *nvl, const char *name);
+void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
+void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
+void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
+void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4);
+#ifdef _VA_LIST_DECLARED
+void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0);
+#endif
+void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value);
+#ifndef _KERNEL
+void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
+#endif
+void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size);
+
+/*
+ * The nvlist_move functions add the given name/value pair.
+ * The functions consumes provided buffer.
+ */
+
+void nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
+void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
+#ifndef _KERNEL
+void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
+#endif
+void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size);
+
+/*
+ * The nvlist_get functions returns value associated with the given name.
+ * If it returns a pointer, the pointer represents internal buffer and should
+ * not be freed by the caller.
+ */
+
+bool nvlist_get_bool(const nvlist_t *nvl, const char *name);
+uint64_t nvlist_get_number(const nvlist_t *nvl, const char *name);
+const char *nvlist_get_string(const nvlist_t *nvl, const char *name);
+const nvlist_t *nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
+#ifndef _KERNEL
+int nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
+#endif
+const void *nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
+
+/*
+ * The nvlist_take functions returns value associated with the given name and
+ * remove the given entry from the nvlist.
+ * The caller is responsible for freeing received data.
+ */
+
+bool nvlist_take_bool(nvlist_t *nvl, const char *name);
+uint64_t nvlist_take_number(nvlist_t *nvl, const char *name);
+char *nvlist_take_string(nvlist_t *nvl, const char *name);
+nvlist_t *nvlist_take_nvlist(nvlist_t *nvl, const char *name);
+#ifndef _KERNEL
+int nvlist_take_descriptor(nvlist_t *nvl, const char *name);
+#endif
+void *nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
+
+/*
+ * The nvlist_free functions removes the given name/value pair from the nvlist
+ * and frees memory associated with it.
+ */
+
+void nvlist_free(nvlist_t *nvl, const char *name);
+void nvlist_free_type(nvlist_t *nvl, const char *name, int type);
+
+void nvlist_free_null(nvlist_t *nvl, const char *name);
+void nvlist_free_bool(nvlist_t *nvl, const char *name);
+void nvlist_free_number(nvlist_t *nvl, const char *name);
+void nvlist_free_string(nvlist_t *nvl, const char *name);
+void nvlist_free_nvlist(nvlist_t *nvl, const char *name);
+#ifndef _KERNEL
+void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
+#endif
+void nvlist_free_binary(nvlist_t *nvl, const char *name);
+
+__END_DECLS
+
+#endif /* !_NV_H_ */
diff --git a/sys/sys/nv_impl.h b/sys/sys/nv_impl.h
new file mode 100644
index 0000000..b0e3c5c
--- /dev/null
+++ b/sys/sys/nv_impl.h
@@ -0,0 +1,131 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#ifndef _NV_IMPL_H_
+#define _NV_IMPL_H_
+
+#ifndef _NVPAIR_T_DECLARED
+#define _NVPAIR_T_DECLARED
+struct nvpair;
+
+typedef struct nvpair nvpair_t;
+#endif
+
+#define NV_TYPE_NVLIST_UP 255
+
+#define NV_TYPE_FIRST NV_TYPE_NULL
+#define NV_TYPE_LAST NV_TYPE_BINARY
+
+#define NV_FLAG_BIG_ENDIAN 0x80
+
+#ifdef _KERNEL
+#define nv_malloc(size) malloc((size), M_NVLIST, M_NOWAIT)
+#define nv_calloc(n, size) malloc((n) * (size), M_NVLIST, \
+ M_NOWAIT | M_ZERO)
+#define nv_realloc(buf, size) realloc((buf), (size), M_NVLIST, \
+ M_NOWAIT)
+#define nv_free(buf) free((buf), M_NVLIST)
+#define nv_strdup(buf) strdup((buf), M_NVLIST)
+#define nv_vasprintf(ptr, ...) vasprintf(ptr, M_NVLIST, __VA_ARGS__)
+
+#define SAVE_ERRNO(var) ((void)(var))
+#define RESTORE_ERRNO(var) ((void)(var))
+
+#define ERRNO_OR_DEFAULT(default) (default)
+
+#else
+
+#define nv_malloc(size) malloc((size))
+#define nv_calloc(n, size) calloc((n), (size))
+#define nv_realloc(buf, size) realloc((buf), (size))
+#define nv_free(buf) free((buf))
+#define nv_strdup(buf) strdup((buf))
+#define nv_vasprintf(ptr, ...) vasprintf(ptr, __VA_ARGS__)
+
+#define SAVE_ERRNO(var) (var) = errno
+#define RESTORE_ERRNO(var) errno = (var)
+
+#define ERRNO_OR_DEFAULT(default) (errno == 0 ? (default) : errno)
+
+#endif
+
+int *nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp);
+size_t nvlist_ndescriptors(const nvlist_t *nvl);
+
+nvpair_t *nvlist_first_nvpair(const nvlist_t *nvl);
+nvpair_t *nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t *nvp);
+nvpair_t *nvlist_prev_nvpair(const nvlist_t *nvl, const nvpair_t *nvp);
+
+void nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp);
+
+void nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp);
+
+void nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent);
+
+const nvpair_t *nvlist_get_nvpair(const nvlist_t *nvl, const char *name);
+
+nvpair_t *nvlist_take_nvpair(nvlist_t *nvl, const char *name);
+
+/* Function removes the given nvpair from the nvlist. */
+void nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp);
+
+void nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp);
+
+int nvpair_type(const nvpair_t *nvp);
+const char *nvpair_name(const nvpair_t *nvp);
+
+nvpair_t *nvpair_clone(const nvpair_t *nvp);
+
+nvpair_t *nvpair_create_null(const char *name);
+nvpair_t *nvpair_create_bool(const char *name, bool value);
+nvpair_t *nvpair_create_number(const char *name, uint64_t value);
+nvpair_t *nvpair_create_string(const char *name, const char *value);
+nvpair_t *nvpair_create_stringf(const char *name, const char *valuefmt, ...) __printflike(2, 3);
+nvpair_t *nvpair_create_stringv(const char *name, const char *valuefmt, va_list valueap) __printflike(2, 0);
+nvpair_t *nvpair_create_nvlist(const char *name, const nvlist_t *value);
+nvpair_t *nvpair_create_descriptor(const char *name, int value);
+nvpair_t *nvpair_create_binary(const char *name, const void *value, size_t size);
+
+nvpair_t *nvpair_move_string(const char *name, char *value);
+nvpair_t *nvpair_move_nvlist(const char *name, nvlist_t *value);
+nvpair_t *nvpair_move_descriptor(const char *name, int value);
+nvpair_t *nvpair_move_binary(const char *name, void *value, size_t size);
+
+bool nvpair_get_bool(const nvpair_t *nvp);
+uint64_t nvpair_get_number(const nvpair_t *nvp);
+const char *nvpair_get_string(const nvpair_t *nvp);
+const nvlist_t *nvpair_get_nvlist(const nvpair_t *nvp);
+int nvpair_get_descriptor(const nvpair_t *nvp);
+const void *nvpair_get_binary(const nvpair_t *nvp, size_t *sizep);
+
+void nvpair_free(nvpair_t *nvp);
+
+#endif /* !_NV_IMPL_H_ */
diff --git a/sys/sys/nvlist_impl.h b/sys/sys/nvlist_impl.h
new file mode 100644
index 0000000..a59a90e
--- /dev/null
+++ b/sys/sys/nvlist_impl.h
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#ifndef _NVLIST_IMPL_H_
+#define _NVLIST_IMPL_H_
+
+#ifndef _KERNEL
+#include <stdint.h>
+#endif
+
+#include "nv.h"
+
+void *nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep);
+nvlist_t *nvlist_xunpack(const void *buf, size_t size, const int *fds,
+ size_t nfds);
+
+nvpair_t *nvlist_get_nvpair_parent(const nvlist_t *nvl);
+const unsigned char *nvlist_unpack_header(nvlist_t *nvl,
+ const unsigned char *ptr, size_t nfds, bool *isbep, size_t *leftp);
+
+#endif /* !_NVLIST_IMPL_H_ */
diff --git a/sys/sys/nvpair_impl.h b/sys/sys/nvpair_impl.h
new file mode 100644
index 0000000..121c8ab
--- /dev/null
+++ b/sys/sys/nvpair_impl.h
@@ -0,0 +1,94 @@
+/*-
+ * Copyright (c) 2009-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHORS 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 AUTHORS 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$
+ */
+
+#ifndef _NVPAIR_IMPL_H_
+#define _NVPAIR_IMPL_H_
+
+#include <sys/queue.h>
+
+#ifndef _KERNEL
+#include <stdint.h>
+#endif
+
+#include "nv.h"
+
+TAILQ_HEAD(nvl_head, nvpair);
+
+void nvpair_assert(const nvpair_t *nvp);
+nvlist_t *nvpair_nvlist(const nvpair_t *nvp);
+nvpair_t *nvpair_next(const nvpair_t *nvp);
+nvpair_t *nvpair_prev(const nvpair_t *nvp);
+void nvpair_insert(struct nvl_head *head, nvpair_t *nvp, nvlist_t *nvl);
+void nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl);
+size_t nvpair_header_size(void);
+size_t nvpair_size(const nvpair_t *nvp);
+const unsigned char *nvpair_unpack(bool isbe, const unsigned char *ptr,
+ size_t *leftp, nvpair_t **nvpp);
+void nvpair_free_structure(nvpair_t *nvp);
+void nvpair_init_datasize(nvpair_t *nvp);
+const char *nvpair_type_string(int type);
+
+/* Pack functions. */
+unsigned char *nvpair_pack_header(const nvpair_t *nvp, unsigned char *ptr,
+ size_t *leftp);
+unsigned char *nvpair_pack_null(const nvpair_t *nvp, unsigned char *ptr,
+ size_t *leftp);
+unsigned char *nvpair_pack_bool(const nvpair_t *nvp, unsigned char *ptr,
+ size_t *leftp);
+unsigned char *nvpair_pack_number(const nvpair_t *nvp, unsigned char *ptr,
+ size_t *leftp);
+unsigned char *nvpair_pack_string(const nvpair_t *nvp, unsigned char *ptr,
+ size_t *leftp);
+unsigned char *nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr,
+ int64_t *fdidxp, size_t *leftp);
+unsigned char *nvpair_pack_binary(const nvpair_t *nvp, unsigned char *ptr,
+ size_t *leftp);
+unsigned char *nvpair_pack_nvlist_up(unsigned char *ptr, size_t *leftp);
+
+/* Unpack data functions. */
+const unsigned char *nvpair_unpack_header(bool isbe, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp);
+const unsigned char *nvpair_unpack_null(bool isbe, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp);
+const unsigned char *nvpair_unpack_bool(bool isbe, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp);
+const unsigned char *nvpair_unpack_number(bool isbe, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp);
+const unsigned char *nvpair_unpack_string(bool isbe, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp);
+const unsigned char *nvpair_unpack_nvlist(bool isbe, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp, size_t nvlist, nvlist_t **child);
+const unsigned char *nvpair_unpack_descriptor(bool isbe, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds);
+const unsigned char *nvpair_unpack_binary(bool isbe, nvpair_t *nvp,
+ const unsigned char *ptr, size_t *leftp);
+
+#endif /* !_NVPAIR_IMPL_H_ */
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 3b188ca..5b441bc 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -558,7 +558,7 @@ struct proc {
int p_osrel; /* (x) osreldate for the
binary (from ELF note, if any) */
char p_comm[MAXCOMLEN + 1]; /* (b) Process name. */
- struct pgrp *p_pgrp; /* (c + e) Pointer to process group. */
+ void *p_pad0;
struct sysentvec *p_sysent; /* (b) Syscall dispatch info. */
struct pargs *p_args; /* (c) Process arguments. */
rlim_t p_cpulimit; /* (c) Current CPU limit in seconds. */
@@ -604,6 +604,7 @@ struct proc {
pid_t p_reapsubtree; /* (e) Pid of the direct child of the
reaper which spawned
our subtree. */
+ struct pgrp *p_pgrp; /* (c + e) Pointer to process group. */
};
#define p_session p_pgrp->pg_session
diff --git a/sys/x86/include/specialreg.h b/sys/x86/include/specialreg.h
index 1de4f1f..5e7658b 100644
--- a/sys/x86/include/specialreg.h
+++ b/sys/x86/include/specialreg.h
@@ -334,6 +334,7 @@
#define CPUID_STDEXT_BMI1 0x00000008
#define CPUID_STDEXT_HLE 0x00000010
#define CPUID_STDEXT_AVX2 0x00000020
+#define CPUID_STDEXT_FDP_EXC 0x00000040
#define CPUID_STDEXT_SMEP 0x00000080
#define CPUID_STDEXT_BMI2 0x00000100
#define CPUID_STDEXT_ERMS 0x00000200
diff --git a/sys/x86/x86/identcpu.c b/sys/x86/x86/identcpu.c
index 62a39f2..1544509 100644
--- a/sys/x86/x86/identcpu.c
+++ b/sys/x86/x86/identcpu.c
@@ -894,6 +894,8 @@ printcpuinfo(void)
"\005HLE"
/* Advanced Vector Instructions 2 */
"\006AVX2"
+ /* FDP_EXCPTN_ONLY */
+ "\007FDPEXC"
/* Supervisor Mode Execution Prot. */
"\010SMEP"
/* Bit Manipulation Instructions */
diff --git a/tests/sys/Makefile b/tests/sys/Makefile
index 015040d..4e653be 100644
--- a/tests/sys/Makefile
+++ b/tests/sys/Makefile
@@ -10,6 +10,7 @@ TESTS_SUBDIRS+= fifo
TESTS_SUBDIRS+= file
TESTS_SUBDIRS+= kern
TESTS_SUBDIRS+= kqueue
+TESTS_SUBDIRS+= mac
TESTS_SUBDIRS+= mqueue
TESTS_SUBDIRS+= netinet
TESTS_SUBDIRS+= opencrypto
diff --git a/tests/sys/aio/aio_kqueue_test.c b/tests/sys/aio/aio_kqueue_test.c
index 14e4729..97c2c38f 100644
--- a/tests/sys/aio/aio_kqueue_test.c
+++ b/tests/sys/aio/aio_kqueue_test.c
@@ -62,7 +62,10 @@ main (int argc, char *argv[])
struct kevent ke, kq_returned;
struct timespec ts;
char buffer[32768];
- int cancel, error, failed = 0, fd, kq, pending, result, run;
+#ifdef DEBUG
+ int cancel, error;
+#endif
+ int failed = 0, fd, kq, pending, result, run;
int tmp_file = 0;
unsigned i, j;
@@ -96,19 +99,19 @@ main (int argc, char *argv[])
if (iocb[i] == NULL)
err(1, "calloc");
}
-
- pending = 0;
+
+ pending = 0;
for (i = 0; i < nitems(iocb); i++) {
pending++;
iocb[i]->aio_nbytes = sizeof(buffer);
iocb[i]->aio_buf = buffer;
iocb[i]->aio_fildes = fd;
iocb[i]->aio_offset = iocb[i]->aio_nbytes * i * run;
-
+
iocb[i]->aio_sigevent.sigev_notify_kqueue = kq;
iocb[i]->aio_sigevent.sigev_value.sival_ptr = iocb[i];
iocb[i]->aio_sigevent.sigev_notify = SIGEV_KEVENT;
-
+
result = aio_write(iocb[i]);
if (result != 0) {
perror("aio_write");
@@ -133,7 +136,9 @@ main (int argc, char *argv[])
}
}
}
+#ifdef DEBUG
cancel = nitems(iocb) - pending;
+#endif
i = 0;
while (pending) {
@@ -144,34 +149,36 @@ main (int argc, char *argv[])
bzero(&kq_returned, sizeof(ke));
ts.tv_sec = 0;
ts.tv_nsec = 1;
- result = kevent(kq, NULL, 0,
+ result = kevent(kq, NULL, 0,
&kq_returned, 1, &ts);
+#ifdef DEBUG
error = errno;
+#endif
if (result < 0)
perror("kevent error: ");
kq_iocb = kq_returned.udata;
#ifdef DEBUG
printf("kevent %d %d errno %d return.ident %p "
- "return.data %p return.udata %p %p\n",
- i, result, error,
- kq_returned.ident, kq_returned.data,
- kq_returned.udata,
+ "return.data %p return.udata %p %p\n",
+ i, result, error,
+ kq_returned.ident, kq_returned.data,
+ kq_returned.udata,
kq_iocb);
#endif
-
+
if (kq_iocb)
break;
#ifdef DEBUG
printf("Try again left %d out of %d %d\n",
pending, nitems(iocb), cancel);
#endif
- }
-
+ }
+
for (j = 0; j < nitems(iocb) && iocb[j] != kq_iocb;
j++) ;
#ifdef DEBUG
printf("kq_iocb %p\n", kq_iocb);
-
+
printf("Error Result for %d is %d pending %d\n",
j, result, pending);
#endif
@@ -192,7 +199,7 @@ main (int argc, char *argv[])
iocb[j] = NULL;
pending--;
i++;
- }
+ }
for (i = 0; i < nitems(iocb); i++)
free(iocb[i]);
diff --git a/tests/sys/aio/lio_kqueue_test.c b/tests/sys/aio/lio_kqueue_test.c
index 5cc87b3..e69b9c9 100644
--- a/tests/sys/aio/lio_kqueue_test.c
+++ b/tests/sys/aio/lio_kqueue_test.c
@@ -42,6 +42,7 @@
#include <sys/time.h>
#include <aio.h>
#include <fcntl.h>
+#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -57,26 +58,26 @@
#define MAX_RUNS 300
int
-main(int argc, char *argv[]){
+main(int argc, char *argv[])
+{
int fd;
struct aiocb *iocb[MAX_IOCBS];
- struct aiocb **lio[LIO_MAX], **lio_element, **kq_lio;
+ struct aiocb **lio[LIO_MAX], **kq_lio;
int i, result, run, error, j, k;
char buffer[32768];
- int kq = kqueue();
+ int kq;
struct kevent ke, kq_returned;
struct timespec ts;
struct sigevent sig;
time_t time1, time2;
- char *file, pathname[sizeof(PATH_TEMPLATE)-1];
+ char *file, pathname[sizeof(PATH_TEMPLATE)];
int tmp_file = 0, failed = 0;
PLAIN_REQUIRE_KERNEL_MODULE("aio", 0);
- if (kq < 0) {
- perror("No kqeueue\n");
- exit(1);
- }
+ kq = kqueue();
+ if (kq < 0)
+ err(1, "kqeueue(2) failed");
if (argc == 1) {
strcpy(pathname, PATH_TEMPLATE);
@@ -87,34 +88,29 @@ main(int argc, char *argv[]){
file = argv[1];
fd = open(file, O_RDWR|O_CREAT, 0666);
}
- if (fd < 0){
- fprintf(stderr, "Can't open %s\n", argv[1]);
- perror("");
- exit(1);
- }
+ if (fd < 0)
+ err(1, "can't open %s", argv[1]);
#ifdef DEBUG
printf("Hello kq %d fd %d\n", kq, fd);
#endif
- for (run = 0; run < MAX_RUNS; run++){
+ for (run = 0; run < MAX_RUNS; run++) {
#ifdef DEBUG
printf("Run %d\n", run);
#endif
for (j = 0; j < LIO_MAX; j++) {
- lio[j] = (struct aiocb **)
+ lio[j] =
malloc(sizeof(struct aiocb *) * MAX_IOCBS/LIO_MAX);
- for(i = 0; i < MAX_IOCBS / LIO_MAX; i++) {
+ for (i = 0; i < MAX_IOCBS / LIO_MAX; i++) {
k = (MAX_IOCBS / LIO_MAX * j) + i;
- lio_element = lio[j];
- lio[j][i] = iocb[k] = (struct aiocb *)
- malloc(sizeof(struct aiocb));
- bzero(iocb[k], sizeof(struct aiocb));
+ lio[j][i] = iocb[k] =
+ calloc(1, sizeof(struct aiocb));
iocb[k]->aio_nbytes = sizeof(buffer);
iocb[k]->aio_buf = buffer;
iocb[k]->aio_fildes = fd;
- iocb[k]->aio_offset
- = iocb[k]->aio_nbytes * k * (run + 1);
+ iocb[k]->aio_offset
+ = iocb[k]->aio_nbytes * k * (run + 1);
#ifdef DEBUG
printf("hello iocb[k] %d\n",
@@ -131,27 +127,26 @@ main(int argc, char *argv[]){
error = errno;
time(&time2);
#ifdef DEBUG
- printf("Time %d %d %d result -> %d\n",
+ printf("Time %d %d %d result -> %d\n",
time1, time2, time2-time1, result);
#endif
if (result != 0) {
errno = error;
- perror("list_listio");
- printf("FAIL: Result %d iteration %d\n",result, j);
- exit(1);
+ err(1, "FAIL: Result %d iteration %d\n",
+ result, j);
}
#ifdef DEBUG
printf("write %d is at %p\n", j, lio[j]);
#endif
}
- for(i = 0; i < LIO_MAX; i++) {
- for(j = LIO_MAX - 1; j >=0; j--) {
+ for (i = 0; i < LIO_MAX; i++) {
+ for (j = LIO_MAX - 1; j >=0; j--) {
if (lio[j])
break;
}
- for(;;) {
+ for (;;) {
bzero(&ke, sizeof(ke));
bzero(&kq_returned, sizeof(ke));
ts.tv_sec = 0;
@@ -159,9 +154,9 @@ main(int argc, char *argv[]){
#ifdef DEBUG
printf("FOO lio %d -> %p\n", j, lio[j]);
#endif
- EV_SET(&ke, (uintptr_t)lio[j],
+ EV_SET(&ke, (uintptr_t)lio[j],
EVFILT_LIO, EV_ONESHOT, 0, 0, iocb[j]);
- result = kevent(kq, NULL, 0,
+ result = kevent(kq, NULL, 0,
&kq_returned, 1, &ts);
error = errno;
if (result < 0) {
@@ -170,14 +165,14 @@ main(int argc, char *argv[]){
kq_lio = kq_returned.udata;
#ifdef DEBUG
printf("kevent %d %d errno %d return.ident %p "
- "return.data %p return.udata %p %p\n",
- i, result, error,
- kq_returned.ident, kq_returned.data,
- kq_returned.udata,
+ "return.data %p return.udata %p %p\n",
+ i, result, error,
+ kq_returned.ident, kq_returned.data,
+ kq_returned.udata,
lio[j]);
#endif
- if(kq_lio)
+ if (kq_lio)
break;
#ifdef DEBUG
printf("Try again\n");
@@ -189,25 +184,21 @@ main(int argc, char *argv[]){
#endif
for (j = 0; j < LIO_MAX; j++) {
- if (lio[j] == kq_lio) {
+ if (lio[j] == kq_lio)
break;
- }
- }
- if (j == LIO_MAX) {
- printf("FAIL:\n");
- exit(1);
}
+ if (j == LIO_MAX)
+ errx(1, "FAIL: ");
#ifdef DEBUG
printf("Error Result for %d is %d\n", j, result);
#endif
if (result < 0) {
printf("FAIL: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result);
- failed = 1;
- } else {
+ failed++;
+ } else
printf("PASS: run %d, operation %d result %d \n", run, LIO_MAX - i -1, result);
- }
- for(k = 0; k < MAX_IOCBS / LIO_MAX; k++){
+ for (k = 0; k < MAX_IOCBS / LIO_MAX; k++) {
result = aio_return(kq_lio[k]);
#ifdef DEBUG
printf("Return Resulto for %d %d is %d\n", j, k, result);
@@ -224,9 +215,8 @@ main(int argc, char *argv[]){
printf("\n");
#endif
- for(k = 0; k < MAX_IOCBS / LIO_MAX; k++) {
+ for (k = 0; k < MAX_IOCBS / LIO_MAX; k++)
free(lio[j][k]);
- }
free(lio[j]);
lio[j] = NULL;
}
@@ -235,15 +225,12 @@ main(int argc, char *argv[]){
printf("Done\n");
#endif
- if (tmp_file) {
+ if (tmp_file)
unlink(pathname);
- }
- if (failed) {
- printf("FAIL: Atleast one\n");
- exit(1);
- } else {
- printf("PASS: All\n");
- exit(0);
- }
+ if (failed)
+ errx(1, "FAIL: %d testcases failed", failed);
+ else
+ errx(0, "PASS: All\n");
+
}
diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
index 03b4a5c..296bbed 100644
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -9,6 +9,7 @@ TESTSDIR= ${TESTSBASE}/sys/kern
ATF_TESTS_C+= kern_descrip_test
ATF_TESTS_C+= ptrace_test
ATF_TESTS_C+= unix_seqpacket_test
+ATF_TESTS_C+= unix_passfd_test
TEST_METADATA.unix_seqpacket_test+= timeout="15"
LDADD.ptrace_test+= -lpthread
diff --git a/tests/sys/kern/pipe/pipe_overcommit1_test.c b/tests/sys/kern/pipe/pipe_overcommit1_test.c
index f8f881d..4e40be7 100644
--- a/tests/sys/kern/pipe/pipe_overcommit1_test.c
+++ b/tests/sys/kern/pipe/pipe_overcommit1_test.c
@@ -40,12 +40,11 @@
int
main(void)
{
- int pipes[10000], returnval;
+ int pipes[10000];
unsigned int i;
- for (i = 0; i < nitems(pipes); i++) {
- returnval = pipe(&pipes[i]);
- }
+ for (i = 0; i < nitems(pipes); i++)
+ (void)pipe(&pipes[i]);
printf("PASS\n");
exit(0);
diff --git a/tests/sys/kern/ptrace_test.c b/tests/sys/kern/ptrace_test.c
index 1731698..1be1144 100644
--- a/tests/sys/kern/ptrace_test.c
+++ b/tests/sys/kern/ptrace_test.c
@@ -1017,7 +1017,7 @@ ATF_TC_BODY(ptrace__new_child_pl_syscall_code_thread, tc)
{
struct ptrace_lwpinfo pl;
pid_t fpid, wpid;
- lwpid_t main;
+ lwpid_t mainlwp;
int status;
ATF_REQUIRE((fpid = fork()) != -1);
@@ -1040,7 +1040,7 @@ ATF_TC_BODY(ptrace__new_child_pl_syscall_code_thread, tc)
ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
sizeof(pl)) != -1);
- main = pl.pl_lwpid;
+ mainlwp = pl.pl_lwpid;
/*
* Continue the child ignoring the SIGSTOP and tracing all
@@ -1065,7 +1065,7 @@ ATF_TC_BODY(ptrace__new_child_pl_syscall_code_thread, tc)
sizeof(pl)) != -1);
ATF_REQUIRE((pl.pl_flags & PL_FLAG_SCX) != 0);
ATF_REQUIRE(pl.pl_syscall_code != 0);
- if (pl.pl_lwpid != main)
+ if (pl.pl_lwpid != mainlwp)
/* New thread seen. */
break;
diff --git a/tests/sys/kern/unix_passfd_test.c b/tests/sys/kern/unix_passfd_test.c
new file mode 100644
index 0000000..12568389
--- /dev/null
+++ b/tests/sys/kern/unix_passfd_test.c
@@ -0,0 +1,396 @@
+/*-
+ * Copyright (c) 2005 Robert N. M. Watson
+ * Copyright (c) 2015 Mark Johnston
+ * All rights reserved.
+ *
+ * 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$
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/sysctl.h>
+#include <sys/un.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+/*
+ * UNIX domain sockets allow file descriptors to be passed via "ancillary
+ * data", or control messages. This regression test is intended to exercise
+ * this facility, both performing some basic tests that it operates, and also
+ * causing some kernel edge cases to execute, such as garbage collection when
+ * there are cyclic file descriptor references. Right now we test only with
+ * stream sockets, but ideally we'd also test with datagram sockets.
+ */
+
+static void
+domainsocketpair(int *fdp)
+{
+
+ ATF_REQUIRE_MSG(socketpair(PF_UNIX, SOCK_STREAM, 0, fdp) != -1,
+ "socketpair(PF_UNIX, SOCK_STREAM) failed: %s", strerror(errno));
+}
+
+static void
+closesocketpair(int *fdp)
+{
+
+ close(fdp[0]);
+ close(fdp[1]);
+}
+
+static void
+devnull(int *fdp)
+{
+ int fd;
+
+ fd = open("/dev/null", O_RDONLY);
+ ATF_REQUIRE_MSG(fd != -1, "open failed: %s", strerror(errno));
+ *fdp = fd;
+}
+
+static void
+tempfile(int *fdp)
+{
+ char path[PATH_MAX];
+ int fd;
+
+ snprintf(path, PATH_MAX, "%s/unix_passfd.XXXXXXXXXXXXXXX",
+ getenv("TMPDIR") == NULL ? "/tmp" : getenv("TMPDIR"));
+ fd = mkstemp(path);
+ ATF_REQUIRE_MSG(fd != -1, "mkstemp(%s) failed", path);
+ (void)unlink(path);
+ *fdp = fd;
+}
+
+static void
+dofstat(int fd, struct stat *sb)
+{
+
+ ATF_REQUIRE_MSG(fstat(fd, sb) == 0,
+ "fstat failed: %s", strerror(errno));
+}
+
+static void
+samefile(struct stat *sb1, struct stat *sb2)
+{
+
+ ATF_REQUIRE_MSG(sb1->st_dev == sb2->st_dev, "different device");
+ ATF_REQUIRE_MSG(sb1->st_ino == sb2->st_ino, "different inode");
+}
+
+static void
+sendfd_payload(int sockfd, int send_fd, void *payload, size_t paylen)
+{
+ struct iovec iovec;
+ char message[CMSG_SPACE(sizeof(int))];
+ struct cmsghdr *cmsghdr;
+ struct msghdr msghdr;
+ ssize_t len;
+
+ bzero(&msghdr, sizeof(msghdr));
+ bzero(&message, sizeof(message));
+
+ msghdr.msg_control = message;
+ msghdr.msg_controllen = sizeof(message);
+
+ iovec.iov_base = payload;
+ iovec.iov_len = paylen;
+
+ msghdr.msg_iov = &iovec;
+ msghdr.msg_iovlen = 1;
+
+ cmsghdr = (struct cmsghdr *)(void*)message;
+ cmsghdr->cmsg_len = CMSG_LEN(sizeof(int));
+ cmsghdr->cmsg_level = SOL_SOCKET;
+ cmsghdr->cmsg_type = SCM_RIGHTS;
+ memcpy(CMSG_DATA(cmsghdr), &send_fd, sizeof(int));
+
+ len = sendmsg(sockfd, &msghdr, 0);
+ ATF_REQUIRE_MSG(len != -1, "sendmsg failed: %s", strerror(errno));
+ ATF_REQUIRE_MSG((size_t)len == paylen,
+ "sendmsg: %zd messages sent; expected: %zu; %s", len, paylen,
+ strerror(errno));
+}
+
+static void
+sendfd(int sockfd, int send_fd)
+{
+ char ch = 0;
+
+ return (sendfd_payload(sockfd, send_fd, &ch, sizeof(ch)));
+}
+
+static void
+recvfd_payload(int sockfd, int *recv_fd, void *buf, size_t buflen)
+{
+ struct cmsghdr *cmsghdr;
+ char message[CMSG_SPACE(SOCKCREDSIZE(CMGROUP_MAX)) + sizeof(int)];
+ struct msghdr msghdr;
+ struct iovec iovec;
+ ssize_t len;
+
+ bzero(&msghdr, sizeof(msghdr));
+
+ msghdr.msg_control = message;
+ msghdr.msg_controllen = sizeof(message);
+
+ iovec.iov_base = buf;
+ iovec.iov_len = buflen;
+
+ msghdr.msg_iov = &iovec;
+ msghdr.msg_iovlen = 1;
+
+ len = recvmsg(sockfd, &msghdr, 0);
+ ATF_REQUIRE_MSG(len != -1, "recvmsg failed: %s", strerror(errno));
+ ATF_REQUIRE_MSG((size_t)len == buflen,
+ "recvmsg: %zd bytes received; expected %zd", len, buflen);
+
+ cmsghdr = CMSG_FIRSTHDR(&msghdr);
+ ATF_REQUIRE_MSG(cmsghdr != NULL,
+ "recvmsg: did not receive control message");
+ *recv_fd = -1;
+ for (; cmsghdr != NULL; cmsghdr = CMSG_NXTHDR(&msghdr, cmsghdr)) {
+ if (cmsghdr->cmsg_level == SOL_SOCKET &&
+ cmsghdr->cmsg_type == SCM_RIGHTS &&
+ cmsghdr->cmsg_len == CMSG_LEN(sizeof(int))) {
+ memcpy(recv_fd, CMSG_DATA(cmsghdr), sizeof(int));
+ ATF_REQUIRE(*recv_fd != -1);
+ }
+ }
+ ATF_REQUIRE_MSG(*recv_fd != -1,
+ "recvmsg: did not receive single-fd message");
+}
+
+static void
+recvfd(int sockfd, int *recv_fd)
+{
+ char ch = 0;
+
+ return (recvfd_payload(sockfd, recv_fd, &ch, sizeof(ch)));
+}
+
+/*
+ * Put a temporary file into a UNIX domain socket, then take it out and make
+ * sure it's the same file. First time around, don't close the reference
+ * after sending.
+ */
+ATF_TC_WITHOUT_HEAD(simple_send_fd);
+ATF_TC_BODY(simple_send_fd, tc)
+{
+ struct stat getfd_stat, putfd_stat;
+ int fd[2], getfd, putfd;
+
+ domainsocketpair(fd);
+ tempfile(&putfd);
+ dofstat(putfd, &putfd_stat);
+ sendfd(fd[0], putfd);
+ recvfd(fd[1], &getfd);
+ dofstat(getfd, &getfd_stat);
+ samefile(&putfd_stat, &getfd_stat);
+ close(putfd);
+ close(getfd);
+ closesocketpair(fd);
+}
+
+/*
+ * Same as simple_send_fd, only close the file reference after sending, so that
+ * the only reference is the descriptor in the UNIX domain socket buffer.
+ */
+ATF_TC_WITHOUT_HEAD(send_and_close);
+ATF_TC_BODY(send_and_close, tc)
+{
+ struct stat getfd_stat, putfd_stat;
+ int fd[2], getfd, putfd;
+
+ domainsocketpair(fd);
+ tempfile(&putfd);
+ dofstat(putfd, &putfd_stat);
+ sendfd(fd[0], putfd);
+ close(putfd);
+ recvfd(fd[1], &getfd);
+ dofstat(getfd, &getfd_stat);
+ samefile(&putfd_stat, &getfd_stat);
+ close(getfd);
+ closesocketpair(fd);
+}
+
+/*
+ * Put a temporary file into a UNIX domain socket, then close both endpoints
+ * causing garbage collection to kick off.
+ */
+ATF_TC_WITHOUT_HEAD(send_and_cancel);
+ATF_TC_BODY(send_and_cancel, tc)
+{
+ int fd[2], putfd;
+
+ domainsocketpair(fd);
+ tempfile(&putfd);
+ sendfd(fd[0], putfd);
+ close(putfd);
+ closesocketpair(fd);
+}
+
+/*
+ * Send two files. Then receive them. Make sure they are returned in the
+ * right order, and both get there.
+ */
+ATF_TC_WITHOUT_HEAD(two_files);
+ATF_TC_BODY(two_files, tc)
+{
+ struct stat getfd_1_stat, getfd_2_stat, putfd_1_stat, putfd_2_stat;
+ int fd[2], getfd_1, getfd_2, putfd_1, putfd_2;
+
+ domainsocketpair(fd);
+ tempfile(&putfd_1);
+ tempfile(&putfd_2);
+ dofstat(putfd_1, &putfd_1_stat);
+ dofstat(putfd_2, &putfd_2_stat);
+ sendfd(fd[0], putfd_1);
+ sendfd(fd[0], putfd_2);
+ close(putfd_1);
+ close(putfd_2);
+ recvfd(fd[1], &getfd_1);
+ recvfd(fd[1], &getfd_2);
+ dofstat(getfd_1, &getfd_1_stat);
+ dofstat(getfd_2, &getfd_2_stat);
+ samefile(&putfd_1_stat, &getfd_1_stat);
+ samefile(&putfd_2_stat, &getfd_2_stat);
+ close(getfd_1);
+ close(getfd_2);
+ closesocketpair(fd);
+}
+
+/*
+ * Big bundling test. Send an endpoint of the UNIX domain socket over itself,
+ * closing the door behind it.
+ */
+ATF_TC_WITHOUT_HEAD(bundle);
+ATF_TC_BODY(bundle, tc)
+{
+ int fd[2], getfd;
+
+ domainsocketpair(fd);
+
+ sendfd(fd[0], fd[0]);
+ close(fd[0]);
+ recvfd(fd[1], &getfd);
+ close(getfd);
+ close(fd[1]);
+}
+
+/*
+ * Big bundling test part two: Send an endpoint of the UNIX domain socket over
+ * itself, close the door behind it, and never remove it from the other end.
+ */
+ATF_TC_WITHOUT_HEAD(bundle_cancel);
+ATF_TC_BODY(bundle_cancel, tc)
+{
+ int fd[2];
+
+ domainsocketpair(fd);
+ sendfd(fd[0], fd[0]);
+ sendfd(fd[1], fd[0]);
+ closesocketpair(fd);
+}
+
+/*
+ * Test for PR 151758: Send an character device over the UNIX domain socket
+ * and then close both sockets to orphan the device.
+ */
+ATF_TC_WITHOUT_HEAD(devfs_orphan);
+ATF_TC_BODY(devfs_orphan, tc)
+{
+ int fd[2], putfd;
+
+ domainsocketpair(fd);
+ devnull(&putfd);
+ sendfd(fd[0], putfd);
+ close(putfd);
+ closesocketpair(fd);
+}
+
+#define LOCAL_SENDSPACE_SYSCTL "net.local.stream.sendspace"
+
+/*
+ * Test for PR 181741. Receiver sets LOCAL_CREDS, and kernel prepends a
+ * control message to the data. Sender sends large payload.
+ * Payload + SCM_RIGHTS + LOCAL_CREDS hit socket buffer limit, and receiver
+ * receives truncated data.
+ */
+ATF_TC_WITHOUT_HEAD(rights_creds_payload);
+ATF_TC_BODY(rights_creds_payload, tc)
+{
+ const int on = 1;
+ u_long sendspace;
+ size_t len;
+ void *buf;
+ int fd[2], getfd, putfd, rc;
+
+ atf_tc_expect_fail("PR 181741: Packet loss when 'control' messages "
+ "are present with large data");
+
+ len = sizeof(sendspace);
+ rc = sysctlbyname(LOCAL_SENDSPACE_SYSCTL, &sendspace,
+ &len, NULL, 0);
+ ATF_REQUIRE_MSG(rc != -1,
+ "sysctl %s failed: %s", LOCAL_SENDSPACE_SYSCTL, strerror(errno));
+
+ buf = calloc(1, sendspace);
+ ATF_REQUIRE(buf != NULL);
+
+ domainsocketpair(fd);
+ rc = setsockopt(fd[1], 0, LOCAL_CREDS, &on, sizeof(on));
+ ATF_REQUIRE_MSG(rc != -1, "setsockopt(LOCAL_CREDS) failed: %s",
+ strerror(errno));
+ tempfile(&putfd);
+ sendfd_payload(fd[0], putfd, buf, sendspace);
+ recvfd_payload(fd[1], &getfd, buf, sendspace);
+ close(putfd);
+ close(getfd);
+ closesocketpair(fd);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, simple_send_fd);
+ ATF_TP_ADD_TC(tp, send_and_close);
+ ATF_TP_ADD_TC(tp, send_and_cancel);
+ ATF_TP_ADD_TC(tp, two_files);
+ ATF_TP_ADD_TC(tp, bundle);
+ ATF_TP_ADD_TC(tp, bundle_cancel);
+ ATF_TP_ADD_TC(tp, devfs_orphan);
+ ATF_TP_ADD_TC(tp, rights_creds_payload);
+
+ return (atf_no_error());
+}
diff --git a/tests/sys/kern/unix_seqpacket_test.c b/tests/sys/kern/unix_seqpacket_test.c
index 58d6c19..4d157dc 100644
--- a/tests/sys/kern/unix_seqpacket_test.c
+++ b/tests/sys/kern/unix_seqpacket_test.c
@@ -47,7 +47,7 @@ static void
do_socketpair(int *sv)
{
int s;
-
+
s = socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sv);
ATF_REQUIRE_EQ(0, s);
ATF_REQUIRE(sv[0] >= 0);
@@ -59,7 +59,7 @@ static void
do_socketpair_nonblocking(int *sv)
{
int s;
-
+
s = socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sv);
ATF_REQUIRE_EQ(0, s);
ATF_REQUIRE(sv[0] >= 0);
@@ -69,7 +69,7 @@ do_socketpair_nonblocking(int *sv)
ATF_REQUIRE(-1 != fcntl(sv[1], F_SETFL, O_NONBLOCK));
}
-/*
+/*
* Returns a pair of sockets made the hard way: bind, listen, connect & accept
* @return const char* The path to the socket
*/
@@ -91,7 +91,6 @@ mk_pair_of_sockets(int *sv)
err = bind(s, (struct sockaddr *)&sun, sizeof(sun));
err = listen(s, -1);
ATF_CHECK_EQ(0, err);
- ATF_CHECK_EQ(0, err);
/* Create the other socket */
s2 = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
@@ -101,7 +100,7 @@ mk_pair_of_sockets(int *sv)
perror("connect");
atf_tc_fail("connect(2) failed");
}
-
+
/* Accept it */
s1 = accept(s, NULL, NULL);
if (s1 == -1) {
@@ -111,6 +110,9 @@ mk_pair_of_sockets(int *sv)
sv[0] = s1;
sv[1] = s2;
+
+ close(s);
+
return (path);
}
@@ -148,8 +150,11 @@ test_eagain(size_t sndbufsize, size_t rcvbufsize)
for(i=0; i < numpkts; i++) {
ssize = send(sv[0], sndbuf, pktsize, MSG_EOR);
if (ssize == -1) {
- if (errno == EAGAIN)
+ if (errno == EAGAIN) {
+ close(sv[0]);
+ close(sv[1]);
atf_tc_pass();
+ }
else {
perror("send");
atf_tc_fail("send returned < 0 but not EAGAIN");
@@ -199,6 +204,8 @@ test_sendrecv_symmetric_buffers(size_t bufsize, int blocking) {
}
ATF_CHECK_EQ_MSG(pktsize, rsize, "expected %zd=send(...) but got %zd",
pktsize, rsize);
+ close(sv[0]);
+ close(sv[1]);
}
static void
@@ -232,7 +239,7 @@ test_pipe_simulator(size_t sndbufsize, size_t rcvbufsize)
memset(sndbuf, num_sent, pktsize);
ssize = send(sv[0], sndbuf, pktsize, MSG_EOR);
if (ssize < 0) {
- /*
+ /*
* XXX: This is bug-compatible with the kernel.
* The kernel returns EMSGSIZE when it should
* return EAGAIN
@@ -268,12 +275,14 @@ test_pipe_simulator(size_t sndbufsize, size_t rcvbufsize)
pktsize, rsize);
memset(comparebuf, num_received, pktsize);
ATF_CHECK_EQ_MSG(0, memcmp(comparebuf, rcvbuf,
- pktsize),
+ pktsize),
"Received data miscompare");
num_received++;
}
}
}
+ close(sv[0]);
+ close(sv[1]);
}
typedef struct {
@@ -324,7 +333,7 @@ test_pipe_reader(void* args)
"expected %zd=send(...) but got %zd",
td->pktsize, rsize);
d = memcmp(comparebuf, rcvbuf, td->pktsize);
- ATF_CHECK_EQ_MSG(0, d,
+ ATF_CHECK_EQ_MSG(0, d,
"Received data miscompare on packet %d", i);
}
return (0);
@@ -360,7 +369,7 @@ test_pipe(size_t sndbufsize, size_t rcvbufsize)
reader_data.so = sv[1];
ATF_REQUIRE_EQ(0, pthread_create(&writer, NULL, test_pipe_writer,
(void*)&writer_data));
- /*
+ /*
* Give the writer time to start writing, and hopefully block, before
* starting the reader. This increases the likelihood of the test case
* failing due to PR kern/185812
@@ -372,6 +381,8 @@ test_pipe(size_t sndbufsize, size_t rcvbufsize)
/* Join the children */
ATF_REQUIRE_EQ(0, pthread_join(writer, NULL));
ATF_REQUIRE_EQ(0, pthread_join(reader, NULL));
+ close(sv[0]);
+ close(sv[1]);
}
@@ -386,7 +397,8 @@ ATF_TC_BODY(create_socket, tc)
int s;
s = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
- ATF_CHECK(s >= 0);
+ ATF_REQUIRE(s >= 0);
+ close(s);
}
/* Create SEQPACKET sockets using socketpair(2) */
@@ -401,6 +413,8 @@ ATF_TC_BODY(create_socketpair, tc)
ATF_CHECK(sv[0] >= 0);
ATF_CHECK(sv[1] >= 0);
ATF_CHECK(sv[0] != sv[1]);
+ close(sv[0]);
+ close(sv[1]);
}
/* Call listen(2) without first calling bind(2). It should fail */
@@ -414,6 +428,7 @@ ATF_TC_BODY(listen_unbound, tc)
r = listen(s, -1);
/* expect listen to fail since we haven't called bind(2) */
ATF_CHECK(r != 0);
+ close(s);
}
/* Bind the socket to a file */
@@ -434,6 +449,7 @@ ATF_TC_BODY(bind, tc)
strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
r = bind(s, (struct sockaddr *)&sun, sizeof(sun));
ATF_CHECK_EQ(0, r);
+ close(s);
}
/* listen(2) a socket that is already bound(2) should succeed */
@@ -456,6 +472,7 @@ ATF_TC_BODY(listen_bound, tc)
l = listen(s, -1);
ATF_CHECK_EQ(0, r);
ATF_CHECK_EQ(0, l);
+ close(s);
}
/* connect(2) can make a connection */
@@ -487,6 +504,8 @@ ATF_TC_BODY(connect, tc)
perror("connect");
atf_tc_fail("connect(2) failed");
}
+ close(s);
+ close(s2);
}
/* accept(2) can receive a connection */
@@ -496,6 +515,8 @@ ATF_TC_BODY(accept, tc)
int sv[2];
mk_pair_of_sockets(sv);
+ close(sv[0]);
+ close(sv[1]);
}
@@ -511,6 +532,7 @@ ATF_TC_BODY(fcntl_nonblock, tc)
perror("fcntl");
atf_tc_fail("fcntl failed");
}
+ close(s);
}
/* Resize the send and receive buffers */
@@ -539,7 +561,7 @@ ATF_TC_BODY(resize_buffers, tc)
ATF_CHECK_EQ(0, getsockopt(s, SOL_SOCKET, SO_SNDBUF, &xs, &sl));
ATF_CHECK_EQ(0, getsockopt(s, SOL_SOCKET, SO_RCVBUF, &xr, &sl));
printf("After changing SNDBUF | %7d | %7d |\n", xs, xr);
-
+
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)) != 0){
perror("setsockopt");
atf_tc_fail("setsockopt(SO_RCVBUF) failed");
@@ -547,6 +569,7 @@ ATF_TC_BODY(resize_buffers, tc)
ATF_CHECK_EQ(0, getsockopt(s, SOL_SOCKET, SO_SNDBUF, &xs, &sl));
ATF_CHECK_EQ(0, getsockopt(s, SOL_SOCKET, SO_RCVBUF, &xr, &sl));
printf("After changing RCVBUF | %7d | %7d |\n", xs, xr);
+ close(s);
}
/*
@@ -603,6 +626,8 @@ ATF_TC_BODY(resize_connected_buffers, tc)
ATF_CHECK_EQ(0, getsockopt(sv[1], SOL_SOCKET, SO_RCVBUF, &rr, &sl));
printf("After changing Left's RCVBUF | %7d | %7d | %7d | %7d |\n",
ls, lr, rs, rr);
+ close(sv[0]);
+ close(sv[1]);
}
@@ -632,6 +657,8 @@ ATF_TC_BODY(send_recv, tc)
rsize = recv(sv[1], recv_buf, bufsize, MSG_WAITALL);
ATF_CHECK_EQ(datalen, rsize);
+ close(sv[0]);
+ close(sv[1]);
}
/* sendto(2) and recvfrom(2) a single short record
@@ -676,7 +703,7 @@ ATF_TC_BODY(sendto_recvfrom, tc)
}
ATF_CHECK_EQ(datalen, rsize);
- /*
+ /*
* FreeBSD does not currently provide the source address for SEQ_PACKET
* AF_UNIX sockets, and POSIX does not require it, so these two checks
* are disabled. If FreeBSD gains that feature in the future, then
@@ -684,9 +711,11 @@ ATF_TC_BODY(sendto_recvfrom, tc)
*/
/* ATF_CHECK_EQ(PF_LOCAL, from.ss_family); */
/* ATF_CHECK_STREQ(path, ((struct sockaddr_un*)&from)->sun_path); */
+ close(sv[0]);
+ close(sv[1]);
}
-/*
+/*
* send(2) and recv(2) a single short record with sockets created the
* traditional way, involving bind, listen, connect, and accept
*/
@@ -714,6 +743,8 @@ ATF_TC_BODY(send_recv_with_connect, tc)
rsize = recv(sv[1], recv_buf, bufsize, MSG_WAITALL);
ATF_CHECK_EQ(datalen, rsize);
+ close(sv[0]);
+ close(sv[1]);
}
/* send(2) should fail on a shutdown socket */
@@ -721,16 +752,17 @@ ATF_TC_WITHOUT_HEAD(shutdown_send);
ATF_TC_BODY(shutdown_send, tc)
{
int s;
- const char *data = "data";
+ const char data[] = "data";
ssize_t ssize;
s = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
- ATF_CHECK(s >= 0);
+ ATF_REQUIRE(s >= 0);
ATF_CHECK_EQ(0, shutdown(s, SHUT_RDWR));
/* USE MSG_NOSIGNAL so we don't get SIGPIPE */
ssize = send(s, data, sizeof(data), MSG_EOR | MSG_NOSIGNAL);
ATF_CHECK_EQ(EPIPE, errno);
ATF_CHECK_EQ(-1, ssize);
+ close(s);
}
/* send(2) should cause SIGPIPE on a shutdown socket */
@@ -738,15 +770,16 @@ ATF_TC_WITHOUT_HEAD(shutdown_send_sigpipe);
ATF_TC_BODY(shutdown_send_sigpipe, tc)
{
int s;
- const char *data = "data";
+ const char data[] = "data";
ssize_t ssize;
s = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
- ATF_CHECK(s >= 0);
+ ATF_REQUIRE(s >= 0);
ATF_CHECK_EQ(0, shutdown(s, SHUT_RDWR));
ATF_REQUIRE(SIG_ERR != signal(SIGPIPE, shutdown_send_sigpipe_handler));
ssize = send(s, data, sizeof(data), MSG_EOR);
ATF_CHECK_EQ(1, got_sigpipe);
+ close(s);
}
/* nonblocking send(2) and recv(2) a single short record */
@@ -780,9 +813,11 @@ ATF_TC_BODY(send_recv_nonblocking, tc)
rsize = recv(sv[1], recv_buf, bufsize, MSG_WAITALL);
ATF_CHECK_EQ(datalen, rsize);
+ close(sv[0]);
+ close(sv[1]);
}
-/*
+/*
* We should get EMSGSIZE if we try to send a message larger than the socket
* buffer, with blocking sockets
*/
@@ -807,9 +842,11 @@ ATF_TC_BODY(emsgsize, tc)
ssize = send(sv[0], sndbuf, pktsize, MSG_EOR);
ATF_CHECK_EQ(EMSGSIZE, errno);
ATF_CHECK_EQ(-1, ssize);
+ close(sv[0]);
+ close(sv[1]);
}
-/*
+/*
* We should get EMSGSIZE if we try to send a message larger than the socket
* buffer, with nonblocking sockets
*/
@@ -834,10 +871,12 @@ ATF_TC_BODY(emsgsize_nonblocking, tc)
ssize = send(sv[0], sndbuf, pktsize, MSG_EOR);
ATF_CHECK_EQ(EMSGSIZE, errno);
ATF_CHECK_EQ(-1, ssize);
+ close(sv[0]);
+ close(sv[1]);
}
-/*
+/*
* We should get EAGAIN if we try to send a message larger than the socket
* buffer, with nonblocking sockets. Test with several different sockbuf sizes
*/
@@ -863,7 +902,7 @@ ATF_TC_BODY(eagain_128k_128k, tc)
}
-/*
+/*
* nonblocking send(2) and recv(2) of several records, which should collectively
* fill up the send buffer but not the receive buffer
*/
@@ -888,7 +927,7 @@ ATF_TC_BODY(rcvbuf_oversized, tc)
ATF_REQUIRE_EQ(0, setsockopt(sv[1], SOL_SOCKET, SO_RCVBUF, &rcvbufsize,
sizeof(rcvbufsize)));
- /*
+ /*
* Send and receive packets that are collectively greater than the send
* buffer, but less than the receive buffer
*/
@@ -916,7 +955,7 @@ ATF_TC_BODY(rcvbuf_oversized, tc)
"expected %zd=send(...) but got %zd", pktsize, rsize);
/* Verify the contents */
- ATF_CHECK_EQ_MSG(0, memcmp(sndbuf, recv_buf, pktsize),
+ ATF_CHECK_EQ_MSG(0, memcmp(sndbuf, recv_buf, pktsize),
"Received data miscompare");
}
@@ -924,9 +963,11 @@ ATF_TC_BODY(rcvbuf_oversized, tc)
rsize = recv(sv[1], recv_buf, pktsize, MSG_WAITALL);
ATF_CHECK_EQ(EAGAIN, errno);
ATF_CHECK_EQ(-1, rsize);
+ close(sv[0]);
+ close(sv[1]);
}
-/*
+/*
* Simulate the behavior of a blocking pipe. The sender will send until his
* buffer fills up, then we'll simulate a scheduler switch that will allow the
* receiver to read until his buffer empties. Repeat the process until the
@@ -957,7 +998,7 @@ ATF_TC_BODY(pipe_simulator_128k_128k, tc)
test_pipe_simulator(131072, 131072);
}
-/*
+/*
* Test blocking I/O by passing data between two threads. The total amount of
* data will be >> buffer size to force blocking. Repeat the test with multiple
* send and receive buffer sizes
diff --git a/tests/sys/mac/Makefile b/tests/sys/mac/Makefile
new file mode 100644
index 0000000..ae2c491
--- /dev/null
+++ b/tests/sys/mac/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+TESTSDIR= ${TESTSBASE}/sys/mac
+
+TESTS_SUBDIRS+= bsdextended
+TESTS_SUBDIRS+= portacl
+
+.include <bsd.test.mk>
diff --git a/tests/sys/mac/bsdextended/Makefile b/tests/sys/mac/bsdextended/Makefile
new file mode 100644
index 0000000..39a778b
--- /dev/null
+++ b/tests/sys/mac/bsdextended/Makefile
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+TESTSDIR= ${TESTSBASE}/sys/mac/bsdextended
+
+TAP_TESTS_C+= ugidfw_test
+TAP_TESTS_SH+= matches_test
+
+DPADD.ugidfw_test+= ${LIBUGIDFW}
+LDADD.ugidfw_test+= -lugidfw
+
+TEST_METADATA.matches_test+= required_user="root"
+TEST_METADATA.ugidfw_test+= required_user="root"
+
+.include <bsd.test.mk>
diff --git a/tests/sys/mac/bsdextended/matches_test.sh b/tests/sys/mac/bsdextended/matches_test.sh
new file mode 100644
index 0000000..5aff413
--- /dev/null
+++ b/tests/sys/mac/bsdextended/matches_test.sh
@@ -0,0 +1,353 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+uidrange="60000:100000"
+gidrange="60000:100000"
+uidinrange="nobody"
+uidoutrange="daemon"
+gidinrange="nobody" # We expect $uidinrange in this group
+gidoutrange="daemon" # We expect $uidinrange in this group
+
+test_num=1
+pass()
+{
+ echo "ok $test_num # $@"
+ : $(( test_num += 1 ))
+}
+
+fail()
+{
+ echo "not ok $test_num # $@"
+ : $(( test_num += 1 ))
+}
+
+#
+# Setup
+#
+
+: ${TMPDIR=/tmp}
+if [ $(id -u) -ne 0 ]; then
+ echo "1..0 # SKIP test must be run as root"
+ exit 0
+fi
+if ! sysctl -N security.mac.bsdextended >/dev/null 2>&1; then
+ echo "1..0 # SKIP mac_bsdextended(4) support isn't available"
+ exit 0
+fi
+if ! playground=$(mktemp -d $TMPDIR/tmp.XXXXXXX); then
+ echo "1..0 # SKIP failed to create temporary directory"
+ exit 0
+fi
+trap "rmdir $playground" EXIT INT TERM
+if ! mdmfs -s 25m md $playground; then
+ echo "1..0 # SKIP failed to mount md device"
+ exit 0
+fi
+chmod a+rwx $playground
+md_device=$(mount -p | grep "$playground" | awk '{ gsub(/^\/dev\//, "", $1); print $1 }')
+trap "umount -f $playground; mdconfig -d -u $md_device; rmdir $playground" EXIT INT TERM
+if [ -z "$md_device" ]; then
+ mount -p | grep $playground
+ echo "1..0 # SKIP md device not properly attached to the system"
+fi
+
+ugidfw remove 1
+
+file1=$playground/test-$uidinrange
+file2=$playground/test-$uidoutrange
+cat > $playground/test-script.sh <<'EOF'
+#!/bin/sh
+: > $1
+EOF
+if [ $? -ne 0 ]; then
+ echo "1..0 # SKIP failed to create test script"
+ exit 0
+fi
+echo "1..30"
+
+command1="sh $playground/test-script.sh $file1"
+command2="sh $playground/test-script.sh $file2"
+
+desc="$uidinrange file"
+if su -m $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+chown "$uidinrange":"$gidinrange" $file1
+chmod a+w $file1
+
+desc="$uidoutrange file"
+if $command2; then
+ pass $desc
+else
+ fail $desc
+fi
+
+chown "$uidoutrange":"$gidoutrange" $file2
+chmod a+w $file2
+
+#
+# No rules
+#
+desc="no rules $uidinrange"
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+desc="no rules $uidoutrange"
+if su -fm $uidoutrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+#
+# Subject Match on uid
+#
+ugidfw set 1 subject uid $uidrange object mode rasx
+desc="subject uid in range"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="subject uid out range"
+if su -fm $uidoutrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+#
+# Subject Match on gid
+#
+ugidfw set 1 subject gid $gidrange object mode rasx
+
+desc="subject gid in range"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="subject gid out range"
+if su -fm $uidoutrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+#
+# Subject Match on jail
+#
+rm -f $playground/test-jail
+
+desc="subject matching jailid"
+jailid=`jail -i / localhost 127.0.0.1 /usr/sbin/daemon -f /bin/sh -c "(sleep 5; touch $playground/test-jail) &"`
+ugidfw set 1 subject jailid $jailid object mode rasx
+sleep 10
+
+if [ -f $playground/test-jail ]; then
+ fail "TODO $desc: this testcase fails (see bug # 205481)"
+else
+ pass $desc
+fi
+
+rm -f $playground/test-jail
+desc="subject nonmatching jailid"
+jailid=`jail -i / localhost 127.0.0.1 /usr/sbin/daemon -f /bin/sh -c "(sleep 5; touch $playground/test-jail) &"`
+sleep 10
+if [ -f $playground/test-jail ]; then
+ pass $desc
+else
+ fail $desc
+fi
+
+#
+# Object uid
+#
+ugidfw set 1 subject object uid $uidrange mode rasx
+
+desc="object uid in range"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="object uid out range"
+if su -fm $uidinrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
+ugidfw set 1 subject object uid $uidrange mode rasx
+
+desc="object uid in range (different subject)"
+if su -fm $uidoutrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="object uid out range (different subject)"
+if su -fm $uidoutrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+#
+# Object gid
+#
+ugidfw set 1 subject object gid $uidrange mode rasx
+
+desc="object gid in range"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="object gid out range"
+if su -fm $uidinrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
+desc="object gid in range (different subject)"
+if su -fm $uidoutrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="object gid out range (different subject)"
+if su -fm $uidoutrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+#
+# Object filesys
+#
+ugidfw set 1 subject uid $uidrange object filesys / mode rasx
+desc="object out of filesys"
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+ugidfw set 1 subject uid $uidrange object filesys $playground mode rasx
+desc="object in filesys"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+#
+# Object suid
+#
+ugidfw set 1 subject uid $uidrange object suid mode rasx
+desc="object notsuid"
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+chmod u+s $file1
+desc="object suid"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+chmod u-s $file1
+
+#
+# Object sgid
+#
+ugidfw set 1 subject uid $uidrange object sgid mode rasx
+desc="object notsgid"
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+chmod g+s $file1
+desc="object sgid"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+chmod g-s $file1
+
+#
+# Object uid matches subject
+#
+ugidfw set 1 subject uid $uidrange object uid_of_subject mode rasx
+
+desc="object uid notmatches subject"
+if su -fm $uidinrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+desc="object uid matches subject"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+#
+# Object gid matches subject
+#
+ugidfw set 1 subject uid $uidrange object gid_of_subject mode rasx
+
+desc="object gid notmatches subject"
+if su -fm $uidinrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+desc="object gid matches subject"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+#
+# Object type
+#
+desc="object not type"
+ugidfw set 1 subject uid $uidrange object type dbclsp mode rasx
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+desc="object type"
+ugidfw set 1 subject uid $uidrange object type r mode rasx
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
diff --git a/tests/sys/mac/bsdextended/ugidfw_test.c b/tests/sys/mac/bsdextended/ugidfw_test.c
new file mode 100644
index 0000000..aab8553
--- /dev/null
+++ b/tests/sys/mac/bsdextended/ugidfw_test.c
@@ -0,0 +1,252 @@
+/*-
+ * Copyright (c) 2005 McAfee, Inc.
+ * All rights reserved.
+ *
+ * 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$
+ */
+
+#include <sys/param.h>
+#include <sys/mac.h>
+#include <sys/mount.h>
+
+#include <security/mac_bsdextended/mac_bsdextended.h>
+
+#include <err.h>
+#include <errno.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ugidfw.h>
+#include <unistd.h>
+
+/*
+ * Starting point for a regression test for mac_bsdextended(4) and the
+ * supporting libugidfw(3).
+ */
+
+/*
+ * This section of the regression test passes some test cases through the
+ * rule<->string routines to confirm they work approximately as desired.
+ */
+
+/*
+ * List of users and groups we must check exists before we can begin, since
+ * they are used in the string test rules. We use users and groups that will
+ * always exist in a default install used for regression testing.
+ */
+static const char *test_users[] = {
+ "root",
+ "daemon",
+ "operator",
+ "bin",
+};
+
+static const char *test_groups[] = {
+ "wheel",
+ "daemon",
+ "operator",
+ "bin",
+};
+
+int test_num;
+
+/*
+ * List of test strings that must go in (and come out) of libugidfw intact.
+ */
+static const char *test_strings[] = {
+ /* Variations on subject and object uids. */
+ "subject uid root object uid root mode n",
+ "subject uid root object uid daemon mode n",
+ "subject uid daemon object uid root mode n",
+ "subject uid daemon object uid daemon mode n",
+ /* Variations on mode. */
+ "subject uid root object uid root mode a",
+ "subject uid root object uid root mode r",
+ "subject uid root object uid root mode s",
+ "subject uid root object uid root mode w",
+ "subject uid root object uid root mode x",
+ "subject uid root object uid root mode arswx",
+ /* Variations on subject and object gids. */
+ "subject gid wheel object gid wheel mode n",
+ "subject gid wheel object gid daemon mode n",
+ "subject gid daemon object gid wheel mode n",
+ "subject gid daemon object gid daemon mode n",
+ /* Subject uids and subject gids. */
+ "subject uid bin gid daemon object uid operator gid wheel mode n",
+ /* Not */
+ "subject not uid operator object uid bin mode n",
+ "subject uid bin object not uid operator mode n",
+ "subject not uid daemon object not uid operator mode n",
+ /* Ranges */
+ "subject uid root:operator object gid wheel:bin mode n",
+ /* Jail ID */
+ "subject jailid 1 object uid root mode n",
+ /* Filesys */
+ "subject uid root object filesys / mode n",
+ "subject uid root object filesys /dev mode n",
+ /* S/UGID */
+ "subject not uid root object sgid mode n",
+ "subject not uid root object sgid mode n",
+ /* Matching uid/gid */
+ "subject not uid root:operator object not uid_of_subject mode n",
+ "subject not gid wheel:bin object not gid_of_subject mode n",
+ /* Object types */
+ "subject uid root object type a mode a",
+ "subject uid root object type r mode a",
+ "subject uid root object type d mode a",
+ "subject uid root object type b mode a",
+ "subject uid root object type c mode a",
+ "subject uid root object type l mode a",
+ "subject uid root object type s mode a",
+ "subject uid root object type rbc mode a",
+ "subject uid root object type dls mode a",
+ /* Empty rules always match */
+ "subject object mode a",
+ /* Partial negations */
+ "subject ! uid root object mode n",
+ "subject ! gid wheel object mode n",
+ "subject ! jailid 2 object mode n",
+ "subject object ! uid root mode n",
+ "subject object ! gid wheel mode n",
+ "subject object ! filesys / mode n",
+ "subject object ! suid mode n",
+ "subject object ! sgid mode n",
+ "subject object ! uid_of_subject mode n",
+ "subject object ! gid_of_subject mode n",
+ "subject object ! type d mode n",
+ /* All out nonsense */
+ "subject uid root ! gid wheel:bin ! jailid 1 "
+ "object ! uid root:daemon gid daemon filesys / suid sgid uid_of_subject gid_of_subject ! type r "
+ "mode rsx",
+};
+
+static void
+test_libugidfw_strings(void)
+{
+ struct mac_bsdextended_rule rule;
+ char errorstr[256];
+ char rulestr[256];
+ int error, i;
+
+ for (i = 0; i < nitems(test_users); i++, test_num++) {
+ if (getpwnam(test_users[i]) == NULL)
+ printf("not ok %d # test_libugidfw_strings: getpwnam(%s) "
+ "failed: %s\n", test_num, test_users[i], strerror(errno));
+ else
+ printf("ok %d\n", test_num);
+ }
+
+ for (i = 0; i < nitems(test_groups); i++, test_num++) {
+ if (getgrnam(test_groups[i]) == NULL)
+ printf("not ok %d # test_libugidfw_strings: getgrnam(%s) "
+ "failed: %s\n", test_num, test_groups[i], strerror(errno));
+ else
+ printf("ok %d\n", test_num);
+ }
+
+ for (i = 0; i < nitems(test_strings); i++) {
+ error = bsde_parse_rule_string(test_strings[i], &rule,
+ sizeof(errorstr), errorstr);
+ if (error == -1)
+ printf("not ok %d # bsde_parse_rule_string: '%s' (%d) "
+ "failed: %s\n", test_num, test_strings[i], i, errorstr);
+ else
+ printf("ok %d\n", test_num);
+ test_num++;
+
+ error = bsde_rule_to_string(&rule, rulestr, sizeof(rulestr));
+ if (error < 0)
+ printf("not ok %d # bsde_rule_to_string: rule for '%s' "
+ "returned %d\n", test_num, test_strings[i], error);
+ else
+ printf("ok %d\n", test_num);
+ test_num++;
+
+ if (strcmp(test_strings[i], rulestr) != 0)
+ printf("not ok %d # test_libugidfw: '%s' in, '%s' "
+ "out\n", test_num, test_strings[i], rulestr);
+ else
+ printf("ok %d\n", test_num);
+ test_num++;
+ }
+}
+
+int
+main(void)
+{
+ char errorstr[256];
+ int count, slots;
+
+ test_num = 1;
+
+ /* Print an error if a non-root user attemps to run the tests. */
+ if (getuid() != 0) {
+ printf("1..0 # SKIP you must be root\n");
+ return (0);
+ }
+
+ switch (mac_is_present("bsdextended")) {
+ case -1:
+ printf("1..0 # SKIP mac_is_present failed: %s\n",
+ strerror(errno));
+ return (0);
+ case 1:
+ break;
+ case 0:
+ default:
+ printf("1..0 # SKIP mac_bsdextended not loaded\n");
+ return (0);
+ }
+
+ printf("1..%lu\n", nitems(test_users) + nitems(test_groups) +
+ 3 * nitems(test_strings) + 2);
+
+ test_libugidfw_strings();
+
+ /*
+ * Some simple up-front checks to see if we're able to query the
+ * policy for basic state. We want the rule count to be 0 before
+ * starting, but "slots" is a property of prior runs and so we ignore
+ * the return value.
+ */
+ count = bsde_get_rule_count(sizeof(errorstr), errorstr);
+ if (count == -1)
+ printf("not ok %d # bsde_get_rule_count: %s\n", test_num,
+ errorstr);
+ else
+ printf("ok %d\n", test_num);
+
+ test_num++;
+
+ slots = bsde_get_rule_slots(sizeof(errorstr), errorstr);
+ if (slots == -1)
+ printf("not ok %d # bsde_get_rule_slots: %s\n", test_num,
+ errorstr);
+ else
+ printf("ok %d\n", test_num);
+
+ return (0);
+}
diff --git a/tests/sys/mac/portacl/LICENSE b/tests/sys/mac/portacl/LICENSE
new file mode 100644
index 0000000..c95c149
--- /dev/null
+++ b/tests/sys/mac/portacl/LICENSE
@@ -0,0 +1,27 @@
+$FreeBSD$
+
+License for all mac_portacl regression tests:
+
+Copyright (c) 2009 Pawel Jakub Dawidek <pjd@FreeBSD.org>
+All rights reserved.
+
+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 AUTHORS 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 AUTHORS 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.
diff --git a/tests/sys/mac/portacl/Makefile b/tests/sys/mac/portacl/Makefile
new file mode 100644
index 0000000..129d486
--- /dev/null
+++ b/tests/sys/mac/portacl/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+TESTSDIR= ${TESTSBASE}/sys/mac/portacl
+BINDIR= ${TESTSDIR}
+
+FILES+= misc.sh
+
+TAP_TESTS_SH+= nobody_test
+TAP_TESTS_SH+= root_test
+
+.for t in ${TAP_TESTS_SH}
+TEST_METADATA.$t+= required_user="root"
+TEST_METADATA.$t+= timeout="450"
+.endfor
+
+.include <bsd.test.mk>
diff --git a/tests/sys/mac/portacl/misc.sh b/tests/sys/mac/portacl/misc.sh
new file mode 100755
index 0000000..5a9e67b
--- /dev/null
+++ b/tests/sys/mac/portacl/misc.sh
@@ -0,0 +1,106 @@
+#!/bin/sh
+# $FreeBSD$
+
+sysctl security.mac.portacl >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+ echo "1..0 # SKIP MAC_PORTACL is unavailable."
+ exit 0
+fi
+if [ $(id -u) -ne 0 ]; then
+ echo "1..0 # SKIP testcases must be run as root"
+ exit 0
+fi
+
+ntest=1
+
+check_bind() {
+ local host idtype name proto port udpflag
+
+ host="127.0.0.1"
+
+ idtype=${1}
+ name=${2}
+ proto=${3}
+ port=${4}
+
+ [ "${proto}" = "udp" ] && udpflag="-u"
+
+ out=$(
+ case "${idtype}" in
+ uid|gid)
+ ( echo -n | su -m ${name} -c "nc ${udpflag} -l -w 10 $host $port" 2>&1 ) &
+ ;;
+ jail)
+ kill $$
+ ;;
+ *)
+ kill $$
+ esac
+ sleep 0.3
+ echo | nc ${udpflag} -w 10 $host $port >/dev/null 2>&1
+ wait
+ )
+ case "${out}" in
+ "nc: Permission denied"*|"nc: Operation not permitted"*)
+ echo fl
+ ;;
+ "")
+ echo ok
+ ;;
+ *)
+ echo ${out}
+ ;;
+ esac
+}
+
+bind_test() {
+ local expect_without_rule expect_with_rule idtype name proto port
+
+ expect_without_rule=${1}
+ expect_with_rule=${2}
+ idtype=${3}
+ name=${4}
+ proto=${5}
+ port=${6}
+
+ sysctl security.mac.portacl.rules= >/dev/null
+ out=$(check_bind ${idtype} ${name} ${proto} ${port})
+ if [ "${out}" = "${expect_without_rule}" ]; then
+ echo "ok ${ntest}"
+ elif [ "${out}" = "ok" -o "${out}" = "fl" ]; then
+ echo "not ok ${ntest} # '${out}' != '${expect_without_rule}'"
+ else
+ echo "not ok ${ntest} # unexpected output: '${out}'"
+ fi
+ : $(( ntest += 1 ))
+
+ if [ "${idtype}" = "uid" ]; then
+ idstr=$(id -u ${name})
+ elif [ "${idtype}" = "gid" ]; then
+ idstr=$(id -g ${name})
+ else
+ idstr=${name}
+ fi
+ sysctl security.mac.portacl.rules=${idtype}:${idstr}:${proto}:${port} >/dev/null
+ out=$(check_bind ${idtype} ${name} ${proto} ${port})
+ if [ "${out}" = "${expect_with_rule}" ]; then
+ echo "ok ${ntest}"
+ elif [ "${out}" = "ok" -o "${out}" = "fl" ]; then
+ echo "not ok ${ntest} # '${out}' != '${expect_with_rule}'"
+ else
+ echo "not ok ${ntest} # unexpected output: '${out}'"
+ fi
+ : $(( ntest += 1 ))
+
+ sysctl security.mac.portacl.rules= >/dev/null
+}
+
+reserved_high=$(sysctl -n net.inet.ip.portrange.reservedhigh)
+suser_exempt=$(sysctl -n security.mac.portacl.suser_exempt)
+port_high=$(sysctl -n security.mac.portacl.port_high)
+
+restore_settings() {
+ sysctl -n net.inet.ip.portrange.reservedhigh=${reserved_high} >/dev/null
+ sysctl -n security.mac.portacl.suser_exempt=${suser_exempt} >/dev/null
+ sysctl -n security.mac.portacl.port_high=${port_high} >/dev/null
+}
diff --git a/tests/sys/mac/portacl/nobody_test.sh b/tests/sys/mac/portacl/nobody_test.sh
new file mode 100755
index 0000000..7d8dbd6
--- /dev/null
+++ b/tests/sys/mac/portacl/nobody_test.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+# $FreeBSD$
+
+dir=`dirname $0`
+. ${dir}/misc.sh
+
+echo "1..64"
+
+# security.mac.portacl.suser_exempt value doesn't affect unprivileged users
+# behaviour.
+# mac_portacl has no impact on ports <= net.inet.ip.portrange.reservedhigh.
+
+trap restore_settings EXIT INT TERM
+
+sysctl security.mac.portacl.suser_exempt=1 >/dev/null
+sysctl net.inet.ip.portrange.reservedhigh=78 >/dev/null
+
+bind_test fl fl uid nobody tcp 77
+bind_test ok ok uid nobody tcp 7777
+bind_test fl fl uid nobody udp 77
+bind_test ok ok uid nobody udp 7777
+
+bind_test fl fl gid nobody tcp 77
+bind_test ok ok gid nobody tcp 7777
+bind_test fl fl gid nobody udp 77
+bind_test ok ok gid nobody udp 7777
+
+sysctl security.mac.portacl.suser_exempt=0 >/dev/null
+
+bind_test fl fl uid nobody tcp 77
+bind_test ok ok uid nobody tcp 7777
+bind_test fl fl uid nobody udp 77
+bind_test ok ok uid nobody udp 7777
+
+bind_test fl fl gid nobody tcp 77
+bind_test ok ok gid nobody tcp 7777
+bind_test fl fl gid nobody udp 77
+bind_test ok ok gid nobody udp 7777
+
+# Verify if security.mac.portacl.port_high works.
+
+sysctl security.mac.portacl.port_high=7778 >/dev/null
+
+bind_test fl fl uid nobody tcp 77
+bind_test fl ok uid nobody tcp 7777
+bind_test fl fl uid nobody udp 77
+bind_test fl ok uid nobody udp 7777
+
+bind_test fl fl gid nobody tcp 77
+bind_test fl ok gid nobody tcp 7777
+bind_test fl fl gid nobody udp 77
+bind_test fl ok gid nobody udp 7777
+
+# Verify if mac_portacl rules work.
+
+sysctl net.inet.ip.portrange.reservedhigh=76 >/dev/null
+sysctl security.mac.portacl.port_high=7776 >/dev/null
+
+bind_test fl ok uid nobody tcp 77
+bind_test ok ok uid nobody tcp 7777
+bind_test fl ok uid nobody udp 77
+bind_test ok ok uid nobody udp 7777
+
+bind_test fl ok gid nobody tcp 77
+bind_test ok ok gid nobody tcp 7777
+bind_test fl ok gid nobody udp 77
+bind_test ok ok gid nobody udp 7777
diff --git a/tests/sys/mac/portacl/root_test.sh b/tests/sys/mac/portacl/root_test.sh
new file mode 100755
index 0000000..9ed452f
--- /dev/null
+++ b/tests/sys/mac/portacl/root_test.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+# $FreeBSD$
+
+dir=`dirname $0`
+. ${dir}/misc.sh
+
+echo "1..48"
+
+# Verify if security.mac.portacl.suser_exempt=1 really exempts super-user.
+
+trap restore_settings EXIT INT TERM
+
+sysctl security.mac.portacl.suser_exempt=1 >/dev/null
+
+bind_test ok ok uid root tcp 77
+bind_test ok ok uid root tcp 7777
+bind_test ok ok uid root udp 77
+bind_test ok ok uid root udp 7777
+
+bind_test ok ok gid root tcp 77
+bind_test ok ok gid root tcp 7777
+bind_test ok ok gid root udp 77
+bind_test ok ok gid root udp 7777
+
+# Verify if security.mac.portacl.suser_exempt=0 really doesn't exempt super-user.
+
+sysctl security.mac.portacl.suser_exempt=0 >/dev/null
+
+bind_test fl ok uid root tcp 77
+bind_test ok ok uid root tcp 7777
+bind_test fl ok uid root udp 77
+bind_test ok ok uid root udp 7777
+
+bind_test fl ok gid root tcp 77
+bind_test ok ok gid root tcp 7777
+bind_test fl ok gid root udp 77
+bind_test ok ok gid root udp 7777
+
+# Verify if security.mac.portacl.port_high works for super-user.
+
+sysctl security.mac.portacl.port_high=7778 >/dev/null
+
+bind_test fl ok uid root tcp 77
+bind_test fl ok uid root tcp 7777
+bind_test fl ok uid root udp 77
+bind_test fl ok uid root udp 7777
+
+bind_test fl ok gid root tcp 77
+bind_test fl ok gid root tcp 7777
+bind_test fl ok gid root udp 77
+bind_test fl ok gid root udp 7777
diff --git a/tools/regression/lib/msun/Makefile b/tools/regression/lib/msun/Makefile
index dbf582f..8b301cb 100644
--- a/tools/regression/lib/msun/Makefile
+++ b/tools/regression/lib/msun/Makefile
@@ -1,10 +1,8 @@
# $FreeBSD$
-TESTS= test-cexp test-conj test-csqrt test-ctrig \
- test-exponential test-fenv test-fma \
- test-fmaxmin test-ilogb test-invtrig test-invctrig \
- test-logarithm test-lrint \
- test-lround test-nan test-nearbyint test-next test-rem test-trig
+TESTS= test-ctrig \
+ test-exponential test-fma \
+ test-lround test-nearbyint test-next test-rem test-trig
CFLAGS+= -O0 -lm -Wno-unknown-pragmas
.PHONY: tests
diff --git a/tools/regression/lib/msun/test-cexp.t b/tools/regression/lib/msun/test-cexp.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-cexp.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-conj.t b/tools/regression/lib/msun/test-conj.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-conj.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-csqrt.t b/tools/regression/lib/msun/test-csqrt.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-csqrt.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-fenv.t b/tools/regression/lib/msun/test-fenv.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-fenv.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-fmaxmin.t b/tools/regression/lib/msun/test-fmaxmin.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-fmaxmin.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-ilogb.t b/tools/regression/lib/msun/test-ilogb.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-ilogb.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-logarithm.t b/tools/regression/lib/msun/test-logarithm.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-logarithm.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-lrint.t b/tools/regression/lib/msun/test-lrint.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-lrint.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-nan.t b/tools/regression/lib/msun/test-nan.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-nan.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-nearbyint.t b/tools/regression/lib/msun/test-nearbyint.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-nearbyint.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-next.t b/tools/regression/lib/msun/test-next.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-next.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-rem.t b/tools/regression/lib/msun/test-rem.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-rem.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/lib/msun/test-trig.t b/tools/regression/lib/msun/test-trig.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/lib/msun/test-trig.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/mac/mac_bsdextended/test_matches.sh b/tools/regression/mac/mac_bsdextended/test_matches.sh
index 99d6b62..5aff413 100644
--- a/tools/regression/mac/mac_bsdextended/test_matches.sh
+++ b/tools/regression/mac/mac_bsdextended/test_matches.sh
@@ -10,158 +10,344 @@ uidoutrange="daemon"
gidinrange="nobody" # We expect $uidinrange in this group
gidoutrange="daemon" # We expect $uidinrange in this group
-playground="/stuff/nobody/" # Must not be on root fs
+test_num=1
+pass()
+{
+ echo "ok $test_num # $@"
+ : $(( test_num += 1 ))
+}
+
+fail()
+{
+ echo "not ok $test_num # $@"
+ : $(( test_num += 1 ))
+}
#
# Setup
#
-rm -f $playground/test*
+
+: ${TMPDIR=/tmp}
+if [ $(id -u) -ne 0 ]; then
+ echo "1..0 # SKIP test must be run as root"
+ exit 0
+fi
+if ! sysctl -N security.mac.bsdextended >/dev/null 2>&1; then
+ echo "1..0 # SKIP mac_bsdextended(4) support isn't available"
+ exit 0
+fi
+if ! playground=$(mktemp -d $TMPDIR/tmp.XXXXXXX); then
+ echo "1..0 # SKIP failed to create temporary directory"
+ exit 0
+fi
+trap "rmdir $playground" EXIT INT TERM
+if ! mdmfs -s 25m md $playground; then
+ echo "1..0 # SKIP failed to mount md device"
+ exit 0
+fi
+chmod a+rwx $playground
+md_device=$(mount -p | grep "$playground" | awk '{ gsub(/^\/dev\//, "", $1); print $1 }')
+trap "umount -f $playground; mdconfig -d -u $md_device; rmdir $playground" EXIT INT TERM
+if [ -z "$md_device" ]; then
+ mount -p | grep $playground
+ echo "1..0 # SKIP md device not properly attached to the system"
+fi
+
ugidfw remove 1
file1=$playground/test-$uidinrange
file2=$playground/test-$uidoutrange
-cat <<EOF> $playground/test-script.pl
-if (open(F, ">" . shift)) { exit 0; } else { exit 1; }
+cat > $playground/test-script.sh <<'EOF'
+#!/bin/sh
+: > $1
EOF
-command1="perl $playground/test-script.pl $file1"
-command2="perl $playground/test-script.pl $file2"
+if [ $? -ne 0 ]; then
+ echo "1..0 # SKIP failed to create test script"
+ exit 0
+fi
+echo "1..30"
+
+command1="sh $playground/test-script.sh $file1"
+command2="sh $playground/test-script.sh $file2"
+
+desc="$uidinrange file"
+if su -m $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
-echo -n "$uidinrange file: "
-su -m $uidinrange -c "$command1 && echo good"
chown "$uidinrange":"$gidinrange" $file1
chmod a+w $file1
-echo -n "$uidoutrange file: "
-$command2 && echo good
+desc="$uidoutrange file"
+if $command2; then
+ pass $desc
+else
+ fail $desc
+fi
+
chown "$uidoutrange":"$gidoutrange" $file2
chmod a+w $file2
#
# No rules
#
-echo -n "no rules $uidinrange: "
-su -fm $uidinrange -c "$command1 && echo good"
-echo -n "no rules $uidoutrange: "
-su -fm $uidoutrange -c "$command1 && echo good"
+desc="no rules $uidinrange"
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+desc="no rules $uidoutrange"
+if su -fm $uidoutrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
#
# Subject Match on uid
#
ugidfw set 1 subject uid $uidrange object mode rasx
-echo -n "subject uid in range: "
-su -fm $uidinrange -c "$command1 || echo good"
-echo -n "subject uid out range: "
-su -fm $uidoutrange -c "$command1 && echo good"
+desc="subject uid in range"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="subject uid out range"
+if su -fm $uidoutrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
#
# Subject Match on gid
#
ugidfw set 1 subject gid $gidrange object mode rasx
-echo -n "subject gid in range: "
-su -fm $uidinrange -c "$command1 || echo good"
-echo -n "subject gid out range: "
-su -fm $uidoutrange -c "$command1 && echo good"
+
+desc="subject gid in range"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="subject gid out range"
+if su -fm $uidoutrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
#
# Subject Match on jail
#
-echo -n "subject matching jailid: "
rm -f $playground/test-jail
-jailid=`jail -i / localhost 127.0.0.1 /usr/sbin/daemon -f /bin/sh -c "(sleep 3; touch $playground/test-jail) &"`
+
+desc="subject matching jailid"
+jailid=`jail -i / localhost 127.0.0.1 /usr/sbin/daemon -f /bin/sh -c "(sleep 5; touch $playground/test-jail) &"`
ugidfw set 1 subject jailid $jailid object mode rasx
-sleep 6
-if [ ! -f $playground/test-jail ] ; then echo good ; fi
+sleep 10
+
+if [ -f $playground/test-jail ]; then
+ fail "TODO $desc: this testcase fails (see bug # 205481)"
+else
+ pass $desc
+fi
-echo -n "subject nonmatching jailid: "
rm -f $playground/test-jail
-jailid=`jail -i / localhost 127.0.0.1 /usr/sbin/daemon -f /bin/sh -c "(sleep 3; touch $playground/test-jail) &"`
-sleep 6
-if [ -f $playground/test-jail ] ; then echo good ; fi
+desc="subject nonmatching jailid"
+jailid=`jail -i / localhost 127.0.0.1 /usr/sbin/daemon -f /bin/sh -c "(sleep 5; touch $playground/test-jail) &"`
+sleep 10
+if [ -f $playground/test-jail ]; then
+ pass $desc
+else
+ fail $desc
+fi
#
# Object uid
#
ugidfw set 1 subject object uid $uidrange mode rasx
-echo -n "object uid in range: "
-su -fm $uidinrange -c "$command1 || echo good"
-echo -n "object uid out range: "
-su -fm $uidinrange -c "$command2 && echo good"
+
+desc="object uid in range"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="object uid out range"
+if su -fm $uidinrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
ugidfw set 1 subject object uid $uidrange mode rasx
-echo -n "object uid in range (differennt subject): "
-su -fm $uidoutrange -c "$command1 || echo good"
-echo -n "object uid out range (differennt subject): "
-su -fm $uidoutrange -c "$command2 && echo good"
+
+desc="object uid in range (different subject)"
+if su -fm $uidoutrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="object uid out range (different subject)"
+if su -fm $uidoutrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
#
# Object gid
#
ugidfw set 1 subject object gid $uidrange mode rasx
-echo -n "object gid in range: "
-su -fm $uidinrange -c "$command1 || echo good"
-echo -n "object gid out range: "
-su -fm $uidinrange -c "$command2 && echo good"
-echo -n "object gid in range (differennt subject): "
-su -fm $uidoutrange -c "$command1 || echo good"
-echo -n "object gid out range (differennt subject): "
-su -fm $uidoutrange -c "$command2 && echo good"
+
+desc="object gid in range"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="object gid out range"
+if su -fm $uidinrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
+desc="object gid in range (different subject)"
+if su -fm $uidoutrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
+
+desc="object gid out range (different subject)"
+if su -fm $uidoutrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
#
# Object filesys
#
ugidfw set 1 subject uid $uidrange object filesys / mode rasx
-echo -n "object out of filesys: "
-su -fm $uidinrange -c "$command1 && echo good"
+desc="object out of filesys"
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
ugidfw set 1 subject uid $uidrange object filesys $playground mode rasx
-echo -n "object in filesys: "
-su -fm $uidinrange -c "$command1 || echo good"
+desc="object in filesys"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
#
# Object suid
#
ugidfw set 1 subject uid $uidrange object suid mode rasx
-echo -n "object notsuid: "
-su -fm $uidinrange -c "$command1 && echo good"
+desc="object notsuid"
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
chmod u+s $file1
-echo -n "object suid: "
-su -fm $uidinrange -c "$command1 || echo good"
+desc="object suid"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
chmod u-s $file1
#
# Object sgid
#
ugidfw set 1 subject uid $uidrange object sgid mode rasx
-echo -n "object notsgid: "
-su -fm $uidinrange -c "$command1 && echo good"
+desc="object notsgid"
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+
chmod g+s $file1
-echo -n "object sgid: "
-su -fm $uidinrange -c "$command1 || echo good"
+desc="object sgid"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
chmod g-s $file1
#
# Object uid matches subject
#
ugidfw set 1 subject uid $uidrange object uid_of_subject mode rasx
-echo -n "object uid notmatches subject: "
-su -fm $uidinrange -c "$command2 && echo good"
-echo -n "object uid matches subject: "
-su -fm $uidinrange -c "$command1 || echo good"
+
+desc="object uid notmatches subject"
+if su -fm $uidinrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+desc="object uid matches subject"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
#
# Object gid matches subject
#
ugidfw set 1 subject uid $uidrange object gid_of_subject mode rasx
-echo -n "object gid notmatches subject: "
-su -fm $uidinrange -c "$command2 && echo good"
-echo -n "object gid matches subject: "
-su -fm $uidinrange -c "$command1 || echo good"
+
+desc="object gid notmatches subject"
+if su -fm $uidinrange -c "$command2"; then
+ pass $desc
+else
+ fail $desc
+fi
+
+desc="object gid matches subject"
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
#
# Object type
#
+desc="object not type"
ugidfw set 1 subject uid $uidrange object type dbclsp mode rasx
-echo -n "object not type: "
-su -fm $uidinrange -c "$command1 && echo good"
-ugidfw set 1 subject uid $uidrange object type r mode rasx
-echo -n "object type: "
-su -fm $uidinrange -c "$command1 || echo good"
+if su -fm $uidinrange -c "$command1"; then
+ pass $desc
+else
+ fail $desc
+fi
+desc="object type"
+ugidfw set 1 subject uid $uidrange object type r mode rasx
+if su -fm $uidinrange -c "$command1"; then
+ fail $desc
+else
+ pass $desc
+fi
diff --git a/tools/regression/mac/mac_bsdextended/test_ugidfw.c b/tools/regression/mac/mac_bsdextended/test_ugidfw.c
index 63e25f0..7c1dc2a 100644
--- a/tools/regression/mac/mac_bsdextended/test_ugidfw.c
+++ b/tools/regression/mac/mac_bsdextended/test_ugidfw.c
@@ -33,24 +33,19 @@
#include <security/mac_bsdextended/mac_bsdextended.h>
#include <err.h>
+#include <errno.h>
#include <grp.h>
#include <pwd.h>
-#include <ugidfw.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <ugidfw.h>
+#include <unistd.h>
/*
* Starting point for a regression test for mac_bsdextended(4) and the
* supporting libugidfw(3).
*/
-void
-usage(void)
-{
-
- fprintf(stderr, "test_ugidfw\n");
- exit(-1);
-}
/*
* This section of the regression test passes some test cases through the
@@ -68,7 +63,6 @@ static const char *test_users[] = {
"operator",
"bin",
};
-static const int test_users_len = sizeof(test_users) / sizeof(char *);
static const char *test_groups[] = {
"wheel",
@@ -76,7 +70,8 @@ static const char *test_groups[] = {
"operator",
"bin",
};
-static const int test_groups_len = sizeof(test_groups) / sizeof(char *);
+
+int test_num;
/*
* List of test strings that must go in (and come out) of libugidfw intact.
@@ -147,7 +142,6 @@ static const char *test_strings[] = {
"object ! uid root:daemon gid daemon filesys / suid sgid uid_of_subject gid_of_subject ! type r "
"mode rsx",
};
-static const int test_strings_len = sizeof(test_strings) / sizeof(char *);
static void
test_libugidfw_strings(void)
@@ -155,52 +149,68 @@ test_libugidfw_strings(void)
struct mac_bsdextended_rule rule;
char errorstr[256];
char rulestr[256];
- int i, error;
+ int error, i;
- for (i = 0; i < test_users_len; i++) {
+ for (i = 0; i < nitems(test_users); i++, test_num++) {
if (getpwnam(test_users[i]) == NULL)
- err(-1, "test_libugidfw_strings: getpwnam: %s",
- test_users[i]);
+ printf("not ok %d # test_libugidfw_strings: getpwnam(%s) "
+ "failed: %s\n", test_num, test_users[i], strerror(errno));
+ else
+ printf("ok %d\n", test_num);
}
- for (i = 0; i < test_groups_len; i++) {
+ for (i = 0; i < nitems(test_groups); i++, test_num++) {
if (getgrnam(test_groups[i]) == NULL)
- err(-1, "test_libugidfw_strings: getgrnam: %s",
- test_groups[i]);
+ printf("not ok %d # test_libugidfw_strings: getgrnam(%s) "
+ "failed: %s\n", test_num, test_groups[i], strerror(errno));
+ else
+ printf("ok %d\n", test_num);
}
- for (i = 0; i < test_strings_len; i++) {
+ for (i = 0; i < nitems(test_strings); i++) {
error = bsde_parse_rule_string(test_strings[i], &rule,
sizeof(errorstr), errorstr);
if (error == -1)
- errx(-1, "bsde_parse_rule_string: '%s' (%d): %s",
- test_strings[i], i, errorstr);
+ printf("not ok %d # bsde_parse_rule_string: '%s' (%d) "
+ "failed: %s\n", test_num, test_strings[i], i, errorstr);
+ else
+ printf("ok %d\n", test_num);
+ test_num++;
+
error = bsde_rule_to_string(&rule, rulestr, sizeof(rulestr));
if (error < 0)
- errx(-1, "bsde_rule_to_string: rule for '%s' "
- "returned %d", test_strings[i], error);
+ printf("not ok %d # bsde_rule_to_string: rule for '%s' "
+ "returned %d\n", test_num, test_strings[i], error);
+ else
+ printf("ok %d\n", test_num);
+ test_num++;
if (strcmp(test_strings[i], rulestr) != 0)
- errx(-1, "test_libugidfw: '%s' in, '%s' out",
- test_strings[i], rulestr);
+ printf("not ok %d # test_libugidfw: '%s' in, '%s' "
+ "out\n", test_num, test_strings[i], rulestr);
+ else
+ printf("ok %d\n", test_num);
+ test_num++;
}
}
int
-main(int argc, char *argv[])
+main(void)
{
char errorstr[256];
int count, slots;
- if (argc != 1)
- usage();
+ test_num = 1;
/* Print an error if a non-root user attemps to run the tests. */
if (getuid() != 0) {
- fprintf(stderr, "Error! Only root may run this utility\n");
- return (EXIT_FAILURE);
+ printf("1..0 # SKIP you must be root\n");
+ return (0);
}
+ printf("1..%lu\n", nitems(test_users) + nitems(test_groups) +
+ 3 * nitems(test_strings) + 2);
+
/*
* We can test some parts of the library without the MAC Framework
* and policy loaded, so run those tests before calling
@@ -210,12 +220,15 @@ main(int argc, char *argv[])
switch (mac_is_present("bsdextended")) {
case -1:
- err(-1, "mac_is_present");
+ printf("1..0 # SKIP mac_is_present failed: %s\n",
+ strerror(errno));
+ return (0);
case 1:
break;
case 0:
default:
- errx(-1, "mac_bsdextended not loaded");
+ printf("1..0 # SKIP mac_bsdextended not loaded\n");
+ return (0);
}
/*
@@ -226,13 +239,19 @@ main(int argc, char *argv[])
*/
count = bsde_get_rule_count(sizeof(errorstr), errorstr);
if (count == -1)
- errx(-1, "bsde_get_rule_count: %s", errorstr);
- if (count != 0)
- errx(-1, "bsde_get_rule_count: %d rules", count);
+ printf("not ok %d # bsde_get_rule_count: %s\n", test_num,
+ errorstr);
+ else
+ printf("ok %d\n", test_num);
+
+ test_num++;
slots = bsde_get_rule_slots(sizeof(errorstr), errorstr);
if (slots == -1)
- errx(-1, "bsde_get_rule_slots: %s", errorstr);
+ printf("not ok %d # bsde_get_rule_slots: %s\n", test_num,
+ errorstr);
+ else
+ printf("ok %d\n", test_num);
return (0);
}
diff --git a/tools/regression/sockets/unix_passfd/Makefile b/tools/regression/sockets/unix_passfd/Makefile
deleted file mode 100644
index 600b7b1..0000000
--- a/tools/regression/sockets/unix_passfd/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= unix_passfd
-MAN=
-WARNS?= 3
-
-.include <bsd.prog.mk>
diff --git a/tools/regression/sockets/unix_passfd/unix_passfd.c b/tools/regression/sockets/unix_passfd/unix_passfd.c
deleted file mode 100644
index 07ef589..0000000
--- a/tools/regression/sockets/unix_passfd/unix_passfd.c
+++ /dev/null
@@ -1,389 +0,0 @@
-/*-
- * Copyright (c) 2005 Robert N. M. Watson
- * All rights reserved.
- *
- * 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$
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/sysctl.h>
-#include <sys/un.h>
-
-#include <err.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-/*
- * UNIX domain sockets allow file descriptors to be passed via "ancillary
- * data", or control messages. This regression test is intended to exercise
- * this facility, both performing some basic tests that it operates, and also
- * causing some kernel edge cases to execute, such as garbage collection when
- * there are cyclic file descriptor references. Right now we test only with
- * stream sockets, but ideally we'd also test with datagram sockets.
- */
-
-static void
-domainsocketpair(const char *test, int *fdp)
-{
-
- if (socketpair(PF_UNIX, SOCK_STREAM, 0, fdp) < 0)
- err(-1, "%s: socketpair(PF_UNIX, SOCK_STREAM)", test);
-}
-
-static void
-closesocketpair(int *fdp)
-{
-
- close(fdp[0]);
- close(fdp[1]);
-}
-
-static void
-devnull(const char *test, int *fdp)
-{
- int fd;
-
- fd = open("/dev/null", O_RDONLY);
- if (fd < 0)
- err(-1, "%s: open(/dev/null)", test);
- *fdp = fd;
-}
-
-static void
-tempfile(const char *test, int *fdp)
-{
- char path[PATH_MAX];
- int fd;
-
- snprintf(path, PATH_MAX, "/tmp/unix_passfd.XXXXXXXXXXXXXXX");
- fd = mkstemp(path);
- if (fd < 0)
- err(-1, "%s: mkstemp(%s)", test, path);
- (void)unlink(path);
- *fdp = fd;
-}
-
-static void
-dofstat(const char *test, int fd, struct stat *sb)
-{
-
- if (fstat(fd, sb) < 0)
- err(-1, "%s: fstat", test);
-}
-
-static void
-samefile(const char *test, struct stat *sb1, struct stat *sb2)
-{
-
- if (sb1->st_dev != sb2->st_dev)
- errx(-1, "%s: samefile: different device", test);
- if (sb1->st_ino != sb2->st_ino)
- errx(-1, "%s: samefile: different inode", test);
-}
-
-static void
-sendfd_payload(const char *test, int sockfd, int sendfd,
- void *payload, size_t paylen)
-{
- struct iovec iovec;
- char message[CMSG_SPACE(sizeof(int))];
- struct cmsghdr *cmsghdr;
- struct msghdr msghdr;
- ssize_t len;
-
- bzero(&msghdr, sizeof(msghdr));
- bzero(&message, sizeof(message));
-
- msghdr.msg_control = message;
- msghdr.msg_controllen = sizeof(message);
-
- iovec.iov_base = payload;
- iovec.iov_len = paylen;
-
- msghdr.msg_iov = &iovec;
- msghdr.msg_iovlen = 1;
-
- cmsghdr = (struct cmsghdr *)message;
- cmsghdr->cmsg_len = CMSG_LEN(sizeof(int));
- cmsghdr->cmsg_level = SOL_SOCKET;
- cmsghdr->cmsg_type = SCM_RIGHTS;
- *(int *)CMSG_DATA(cmsghdr) = sendfd;
-
- len = sendmsg(sockfd, &msghdr, 0);
- if (len < 0)
- err(-1, "%s: sendmsg", test);
- if ((size_t)len != paylen)
- errx(-1, "%s: sendmsg: %zd bytes sent", test, len);
-}
-
-static void
-sendfd(const char *test, int sockfd, int sendfd)
-{
- char ch;
-
- return (sendfd_payload(test, sockfd, sendfd, &ch, sizeof(ch)));
-}
-
-static void
-recvfd_payload(const char *test, int sockfd, int *recvfd,
- void *buf, size_t buflen)
-{
- struct cmsghdr *cmsghdr;
- char message[CMSG_SPACE(SOCKCREDSIZE(CMGROUP_MAX)) + sizeof(int)];
- struct msghdr msghdr;
- struct iovec iovec;
- ssize_t len;
-
- bzero(&msghdr, sizeof(msghdr));
-
- msghdr.msg_control = message;
- msghdr.msg_controllen = sizeof(message);
-
- iovec.iov_base = buf;
- iovec.iov_len = buflen;
-
- msghdr.msg_iov = &iovec;
- msghdr.msg_iovlen = 1;
-
- len = recvmsg(sockfd, &msghdr, 0);
- if (len < 0)
- err(-1, "%s: recvmsg", test);
- if ((size_t)len != buflen)
- errx(-1, "%s: recvmsg: %zd bytes received", test, len);
-
- cmsghdr = CMSG_FIRSTHDR(&msghdr);
- if (cmsghdr == NULL)
- errx(-1, "%s: recvmsg: did not receive control message", test);
- *recvfd = -1;
- for (; cmsghdr != NULL; cmsghdr = CMSG_NXTHDR(&msghdr, cmsghdr)) {
- if (cmsghdr->cmsg_level == SOL_SOCKET &&
- cmsghdr->cmsg_type == SCM_RIGHTS &&
- cmsghdr->cmsg_len == CMSG_LEN(sizeof(int))) {
- *recvfd = *(int *)CMSG_DATA(cmsghdr);
- if (*recvfd == -1)
- errx(-1, "%s: recvmsg: received fd -1", test);
- }
- }
- if (*recvfd == -1)
- errx(-1, "%s: recvmsg: did not receive single-fd message",
- test);
-}
-
-static void
-recvfd(const char *test, int sockfd, int *recvfd)
-{
- char ch;
-
- return (recvfd_payload(test, sockfd, recvfd, &ch, sizeof(ch)));
-}
-
-int
-main(void)
-{
- struct stat putfd_1_stat, putfd_2_stat, getfd_1_stat, getfd_2_stat;
- int fd[2], putfd_1, putfd_2, getfd_1, getfd_2;
- const char *test;
-
- /*
- * First test: put a temporary file into a UNIX domain socket, then
- * take it out and make sure it's the same file. First time around,
- * don't close the reference after sending.
- */
- test = "test1-simplesendfd";
- printf("beginning %s\n", test);
-
- domainsocketpair(test, fd);
- tempfile(test, &putfd_1);
- dofstat(test, putfd_1, &putfd_1_stat);
- sendfd(test, fd[0], putfd_1);
- recvfd(test, fd[1], &getfd_1);
- dofstat(test, getfd_1, &getfd_1_stat);
- samefile(test, &putfd_1_stat, &getfd_1_stat);
- close(putfd_1);
- close(getfd_1);
- closesocketpair(fd);
-
- printf("%s passed\n", test);
-
- /*
- * Second test: same as first, only close the file reference after
- * sending, so that the only reference is the descriptor in the UNIX
- * domain socket buffer.
- */
- test = "test2-sendandclose";
- printf("beginning %s\n", test);
-
- domainsocketpair(test, fd);
- tempfile(test, &putfd_1);
- dofstat(test, putfd_1, &putfd_1_stat);
- sendfd(test, fd[0], putfd_1);
- close(putfd_1);
- recvfd(test, fd[1], &getfd_1);
- dofstat(test, getfd_1, &getfd_1_stat);
- samefile(test, &putfd_1_stat, &getfd_1_stat);
- close(getfd_1);
- closesocketpair(fd);
-
- printf("%s passed\n", test);
-
- /*
- * Third test: put a temporary file into a UNIX domain socket, then
- * close both endpoints causing garbage collection to kick off.
- */
- test = "test3-sendandcancel";
- printf("beginning %s\n", test);
-
- domainsocketpair(test, fd);
- tempfile(test, &putfd_1);
- sendfd(test, fd[0], putfd_1);
- close(putfd_1);
- closesocketpair(fd);
-
- printf("%s passed\n", test);
-
- /*
- * Send two files. Then receive them. Make sure they are returned
- * in the right order, and both get there.
- */
-
- test = "test4-twofile";
- printf("beginning %s\n", test);
-
- domainsocketpair(test, fd);
- tempfile(test, &putfd_1);
- tempfile(test, &putfd_2);
- dofstat(test, putfd_1, &putfd_1_stat);
- dofstat(test, putfd_2, &putfd_2_stat);
- sendfd(test, fd[0], putfd_1);
- sendfd(test, fd[0], putfd_2);
- close(putfd_1);
- close(putfd_2);
- recvfd(test, fd[1], &getfd_1);
- recvfd(test, fd[1], &getfd_2);
- dofstat(test, getfd_1, &getfd_1_stat);
- dofstat(test, getfd_2, &getfd_2_stat);
- samefile(test, &putfd_1_stat, &getfd_1_stat);
- samefile(test, &putfd_2_stat, &getfd_2_stat);
- close(getfd_1);
- close(getfd_2);
- closesocketpair(fd);
-
- printf("%s passed\n", test);
-
- /*
- * Big bundling test. Send an endpoint of the UNIX domain socket
- * over itself, closing the door behind it.
- */
-
- test = "test5-bundle";
- printf("beginning %s\n", test);
-
- domainsocketpair(test, fd);
-
- sendfd(test, fd[0], fd[0]);
- close(fd[0]);
- recvfd(test, fd[1], &getfd_1);
- close(getfd_1);
- close(fd[1]);
-
- printf("%s passed\n", test);
-
- /*
- * Big bundling test part two: Send an endpoint of the UNIX domain
- * socket over itself, close the door behind it, and never remove it
- * from the other end.
- */
-
- test = "test6-bundlecancel";
- printf("beginning %s\n", test);
-
- domainsocketpair(test, fd);
- sendfd(test, fd[0], fd[0]);
- sendfd(test, fd[1], fd[0]);
- closesocketpair(fd);
-
- printf("%s passed\n", test);
-
- /*
- * Test for PR 151758: Send an character device over the UNIX
- * domain socket and then close both sockets to orphan the
- * device.
- */
-
- test = "test7-devfsorphan";
- printf("beginning %s\n", test);
-
- domainsocketpair(test, fd);
- devnull(test, &putfd_1);
- sendfd(test, fd[0], putfd_1);
- close(putfd_1);
- closesocketpair(fd);
-
- printf("%s passed\n", test);
-
- /*
- * Test for PR 181741. Receiver sets LOCAL_CREDS, and kernel
- * prepends a control message to the data. Sender sends large
- * payload. Payload + SCM_RIGHTS + LOCAL_CREDS hit socket buffer
- * limit, and receiver receives truncated data.
- */
- test = "test8-rights+creds+payload";
- printf("beginning %s\n", test);
-
- {
- const int on = 1;
- u_long sendspace;
- size_t len;
- void *buf;
-
- len = sizeof(sendspace);
- if (sysctlbyname("net.local.stream.sendspace", &sendspace,
- &len, NULL, 0) < 0)
- err(-1, "%s: sysctlbyname(net.local.stream.sendspace)",
- test);
-
- if ((buf = malloc(sendspace)) == NULL)
- err(-1, "%s: malloc", test);
-
- domainsocketpair(test, fd);
- if (setsockopt(fd[1], 0, LOCAL_CREDS, &on, sizeof(on)) < 0)
- err(-1, "%s: setsockopt(LOCAL_CREDS)", test);
- tempfile(test, &putfd_1);
- sendfd_payload(test, fd[0], putfd_1, buf, sendspace);
- recvfd_payload(test, fd[1], &getfd_1, buf, sendspace);
- close(putfd_1);
- close(getfd_1);
- closesocketpair(fd);
- }
-
- printf("%s passed\n", test);
-
- return (0);
-}
diff --git a/usr.bin/bmake/Makefile b/usr.bin/bmake/Makefile
index 82decdb..008a413 100644
--- a/usr.bin/bmake/Makefile
+++ b/usr.bin/bmake/Makefile
@@ -14,10 +14,10 @@ CFLAGS+= -I${.CURDIR}
CLEANDIRS+= FreeBSD
CLEANFILES+= bootstrap
-# $Id: Makefile,v 1.48 2015/12/02 00:36:42 sjg Exp $
+# $Id: Makefile,v 1.49 2015/12/20 22:54:40 sjg Exp $
# Base version on src date
-MAKE_VERSION= 20151201
+MAKE_VERSION= 20151220
PROG?= ${.CURDIR:T}
diff --git a/usr.bin/calendar/parsedata.c b/usr.bin/calendar/parsedata.c
index 4586973..1a19164 100644
--- a/usr.bin/calendar/parsedata.c
+++ b/usr.bin/calendar/parsedata.c
@@ -274,7 +274,7 @@ determinestyle(char *date, int *flags,
/* If both the month and date are specified as numbers */
if (isonlydigits(p1, 1) && isonlydigits(p2, 0)) {
- /* Now who wants to be this ambigious? :-( */
+ /* Now who wants to be this ambiguous? :-( */
int m, d;
if (strchr(p2, '*') != NULL)
diff --git a/usr.bin/colldef/parse.y b/usr.bin/colldef/parse.y
index 9f8f8a8..9867608 100644
--- a/usr.bin/colldef/parse.y
+++ b/usr.bin/colldef/parse.y
@@ -134,17 +134,17 @@ order : ORDER order_list {
strcpy(__collate_version, COLLATE_VERSION1_2);
if (fwrite(__collate_version, sizeof(__collate_version), 1, fp) != 1)
err(EX_IOERR,
- "IO error writting collate version to destination file %s",
+ "I/O error writing collate version to destination file %s",
out_file);
u32 = htonl(chain_index);
if (fwrite(&u32, sizeof(u32), 1, fp) != 1)
err(EX_IOERR,
- "IO error writting chains number to destination file %s",
+ "I/O error writing chains number to destination file %s",
out_file);
if (fwrite(__collate_substitute_table,
sizeof(__collate_substitute_table), 1, fp) != 1)
err(EX_IOERR,
- "IO error writting substitute table to destination file %s",
+ "I/O error writing substitution table to destination file %s",
out_file);
for (ch = 0; ch < UCHAR_MAX + 1; ch++) {
__collate_char_pri_table[ch].prim =
@@ -155,7 +155,7 @@ order : ORDER order_list {
if (fwrite(__collate_char_pri_table,
sizeof(__collate_char_pri_table), 1, fp) != 1)
err(EX_IOERR,
- "IO error writting char table to destination file %s",
+ "I/O error writing char table to destination file %s",
out_file);
for (ch = 0; ch < chain_index; ch++) {
__collate_chain_pri_table[ch].prim =
@@ -167,10 +167,10 @@ order : ORDER order_list {
sizeof(*__collate_chain_pri_table), chain_index, fp) !=
(size_t)chain_index)
err(EX_IOERR,
- "IO error writting chain table to destination file %s",
+ "I/O error writing chain table to destination file %s",
out_file);
if (fclose(fp) != 0)
- err(EX_IOERR, "IO error closing destination file %s",
+ err(EX_IOERR, "I/O error closing destination file %s",
out_file);
exit(EX_OK);
}
diff --git a/usr.bin/dtc/dtb.hh b/usr.bin/dtc/dtb.hh
index 2c5f39e..a246e96 100644
--- a/usr.bin/dtc/dtb.hh
+++ b/usr.bin/dtc/dtb.hh
@@ -224,7 +224,7 @@ class asm_writer : public output_writer
uint32_t bytes_written;
/**
- * Writes a C string directly to the ouput as-is. This is mainly used
+ * Writes a C string directly to the output as-is. This is mainly used
* for writing directives.
*/
void write_string(const char *c);
diff --git a/usr.bin/indent/indent.1 b/usr.bin/indent/indent.1
index fe8f1ae..3a6f893 100644
--- a/usr.bin/indent/indent.1
+++ b/usr.bin/indent/indent.1
@@ -523,7 +523,7 @@ The
utility understands a substantial amount about the syntax of C, but it
has a `forgiving' parser.
It attempts to cope with the usual sorts of
-incomplete and misformed syntax.
+incomplete and malformed syntax.
In particular, the use of macros like:
.Pp
.Dl #define forever for(;;)
diff --git a/usr.bin/locale/locale.c b/usr.bin/locale/locale.c
index ee9bf84..e0fe7be 100644
--- a/usr.bin/locale/locale.c
+++ b/usr.bin/locale/locale.c
@@ -466,10 +466,10 @@ showlocale(void)
&& strcmp(lang, vval)) {
/*
* Appropriate environment variable set, its value
- * is valid and not overriden by LC_ALL
+ * is valid and not overridden by LC_ALL
*
* XXX: possible side effect: if both LANG and
- * overriden environment variable are set into same
+ * overridden environment variable are set into same
* value, then it'll be assumed as 'implied'
*/
printf("%s=%s\n", lcinfo[i].name, vval);
diff --git a/usr.bin/mkimg/mkimg.1 b/usr.bin/mkimg/mkimg.1
index 1fecdd2..246a397 100644
--- a/usr.bin/mkimg/mkimg.1
+++ b/usr.bin/mkimg/mkimg.1
@@ -289,7 +289,7 @@ utility as follows:
.Dl % mkimg -s mbr -b /boot/mbr -p freebsd:-'mkimg -s bsd -b /boot/boot \
-p freebsd-ufs:=root-file-system.ufs -p freebsd-swap::1G' -o mbr-bsd.img
.Pp
-To accomodate the need to have partitions named or numbered in a certain
+To accommodate the need to have partitions named or numbered in a certain
way, the
.Nm
utility allows for the specification of empty partitions.
diff --git a/usr.bin/mt/mt.c b/usr.bin/mt/mt.c
index 745766c..6069ec7 100644
--- a/usr.bin/mt/mt.c
+++ b/usr.bin/mt/mt.c
@@ -1343,7 +1343,7 @@ mt_param(int argc, char **argv, int mtfd, char *xml_str,
break;
case 'p':
if (param_name != NULL) {
- warnx("Only one paramter name may be "
+ warnx("Only one parameter name may be "
"specified");
retval = 1;
goto bailout;
@@ -1355,7 +1355,7 @@ mt_param(int argc, char **argv, int mtfd, char *xml_str,
break;
case 's':
if (param_value != NULL) {
- warnx("Only one paramter value may be "
+ warnx("Only one parameter value may be "
"specified");
retval = 1;
goto bailout;
diff --git a/usr.bin/netstat/flowtable.c b/usr.bin/netstat/flowtable.c
index a3d5dd5..392cc0b 100644
--- a/usr.bin/netstat/flowtable.c
+++ b/usr.bin/netstat/flowtable.c
@@ -28,12 +28,14 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
-#include <sys/sysctl.h>
+
#include <net/flowtable.h>
-#include <err.h>
+
#include <stdint.h>
#include <stdio.h>
+
#include "netstat.h"
/*
@@ -67,17 +69,18 @@ void
flowtable_stats(void)
{
struct flowtable_stat stat;
- size_t len = sizeof(stat);
if (!live)
return;
- if (sysctlbyname("net.flowtable.ip4.stat", &stat, &len, NULL, 0) == 0) {
+ if (fetch_stats("net.flowtable.ip4.stat", 0, &stat,
+ sizeof(stat), NULL) == 0) {
printf("flowtable for IPv4:\n");
print_stats(&stat);
}
- if (sysctlbyname("net.flowtable.ip6.stat", &stat, &len, NULL, 0) == 0) {
+ if (fetch_stats("net.flowtable.ip6.stat", 0, &stat,
+ sizeof(stat), NULL) == 0) {
printf("flowtable for IPv6:\n");
print_stats(&stat);
}
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index 4b802d4..c1ed499 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
-#include <sys/sysctl.h>
#include <sys/time.h>
#define _IFI_OQDROPS
@@ -117,20 +116,11 @@ pfsync_acts_stats(const char *fmt, uint64_t *a)
void
pfsync_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct pfsyncstats pfsyncstat, zerostat;
- size_t len = sizeof(struct pfsyncstats);
-
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.pfsync.stats", &pfsyncstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- if (errno != ENOENT)
- warn("sysctl: net.pfsync.stats");
- return;
- }
- } else
- kread(off, &pfsyncstat, len);
+ struct pfsyncstats pfsyncstat;
+
+ if (fetch_stats("net.pfsync.stats", off, &pfsyncstat,
+ sizeof(pfsyncstat), kread) != 0)
+ return;
printf("%s:\n", name);
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index f8ff31b..8013ebe 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -593,8 +593,7 @@ protopr(u_long off, const char *name, int af1, int proto)
void
tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct tcpstat tcpstat, zerostat;
- size_t len = sizeof tcpstat;
+ struct tcpstat tcpstat;
#ifdef INET6
if (tcp_done != 0)
@@ -603,16 +602,9 @@ tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
tcp_done = 1;
#endif
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.tcp.stats");
- return;
- }
- } else
- kread_counters(off, &tcpstat, len);
+ if (fetch_stats("net.inet.tcp.stats", off, &tcpstat,
+ sizeof(tcpstat), kread_counters) != 0)
+ return;
printf ("%s:\n", name);
@@ -755,8 +747,7 @@ tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
void
udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct udpstat udpstat, zerostat;
- size_t len = sizeof udpstat;
+ struct udpstat udpstat;
uint64_t delivered;
#ifdef INET6
@@ -766,16 +757,9 @@ udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
udp_done = 1;
#endif
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.udp.stats", &udpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.udp.stats");
- return;
- }
- } else
- kread_counters(off, &udpstat, len);
+ if (fetch_stats("net.inet.udp.stats", off, &udpstat,
+ sizeof(udpstat), kread_counters) != 0)
+ return;
printf("%s:\n", name);
#define p(f, m) if (udpstat.f || sflag <= 1) \
@@ -815,23 +799,11 @@ udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
void
carp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct carpstats carpstat, zerostat;
- size_t len = sizeof(struct carpstats);
+ struct carpstats carpstat;
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.carp.stats", &carpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- if (errno != ENOENT)
- warn("sysctl: net.inet.carp.stats");
- return;
- }
- } else {
- if (off == 0)
- return;
- kread_counters(off, &carpstat, len);
- }
+ if (fetch_stats("net.inet.carp.stats", off, &carpstat,
+ sizeof(carpstat), kread_counters) != 0)
+ return;
printf("%s:\n", name);
@@ -866,19 +838,11 @@ carp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
void
ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct ipstat ipstat, zerostat;
- size_t len = sizeof ipstat;
+ struct ipstat ipstat;
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.ip.stats", &ipstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.ip.stats");
- return;
- }
- } else
- kread_counters(off, &ipstat, len);
+ if (fetch_stats("net.inet.ip.stats", off, &ipstat,
+ sizeof(ipstat), kread_counters) != 0)
+ return;
printf("%s:\n", name);
@@ -930,19 +894,11 @@ ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
void
arp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct arpstat arpstat, zerostat;
- size_t len = sizeof(arpstat);
+ struct arpstat arpstat;
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.link.ether.arp.stats", &arpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.link.ether.arp.stats");
- return;
- }
- } else
- kread_counters(off, &arpstat, len);
+ if (fetch_stats("net.link.ether.arp.stats", off, &arpstat,
+ sizeof(arpstat), kread_counters) != 0)
+ return;
printf("%s:\n", name);
@@ -1015,21 +971,13 @@ static const char *icmpnames[ICMP_MAXTYPE + 1] = {
void
icmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct icmpstat icmpstat, zerostat;
- int i, first;
+ struct icmpstat icmpstat;
size_t len;
+ int i, first;
- len = sizeof icmpstat;
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.icmp.stats", &icmpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.icmp.stats");
- return;
- }
- } else
- kread_counters(off, &icmpstat, len);
+ if (fetch_stats("net.inet.icmp.stats", off, &icmpstat,
+ sizeof(icmpstat), kread_counters) != 0)
+ return;
printf("%s:\n", name);
@@ -1138,43 +1086,11 @@ igmp_stats_live_old(const char *name)
void
igmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct igmpstat igmpstat, zerostat;
- size_t len;
-
-#ifndef BURN_BRIDGES
- if (live) {
- /*
- * Detect if we are being run against a pre-IGMPv3 kernel.
- * We cannot do this for a core file as the legacy
- * struct igmpstat has no size field, nor does it
- * export it in any readily-available symbols.
- */
- len = 0;
- if (sysctlbyname("net.inet.igmp.stats", NULL, &len, NULL,
- 0) < 0) {
- warn("sysctl: net.inet.igmp.stats");
- return;
- }
- if (len < sizeof(igmpstat)) {
- igmp_stats_live_old(name);
- return;
- }
- }
-#endif /* !BURN_BRIDGES */
+ struct igmpstat igmpstat;
- len = sizeof(igmpstat);
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.igmp.stats", &igmpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- warn("sysctl: net.inet.igmp.stats");
- return;
- }
- } else {
- len = sizeof(igmpstat);
- kread(off, &igmpstat, len);
- }
+ if (fetch_stats("net.inet.igmp.stats", 0, &igmpstat,
+ sizeof(igmpstat), kread) != 0)
+ return;
if (igmpstat.igps_version != IGPS_VERSION_3) {
warnx("%s: version mismatch (%d != %d)", __func__,
@@ -1221,23 +1137,11 @@ void
pim_stats(u_long off __unused, const char *name, int af1 __unused,
int proto __unused)
{
- struct pimstat pimstat, zerostat;
- size_t len = sizeof pimstat;
+ struct pimstat pimstat;
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.pim.stats", &pimstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- if (errno != ENOENT)
- warn("sysctl: net.inet.pim.stats");
- return;
- }
- } else {
- if (off == 0)
- return;
- kread_counters(off, &pimstat, len);
- }
+ if (fetch_stats("net.inet.pim.stats", off, &pimstat,
+ sizeof(pimstat), kread_counters) != 0)
+ return;
printf("%s:\n", name);
diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c
index 96fdcaf..4e175fc 100644
--- a/usr.bin/netstat/inet6.c
+++ b/usr.bin/netstat/inet6.c
@@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$");
#include <sys/ioctl.h>
#include <sys/mbuf.h>
#include <sys/protosw.h>
-#include <sys/sysctl.h>
#include <net/route.h>
#include <net/if.h>
@@ -360,23 +359,12 @@ static const char *srcrule_str[] = {
void
ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct ip6stat ip6stat, zerostat;
+ struct ip6stat ip6stat;
int first, i;
- size_t len;
- len = sizeof ip6stat;
- if (live) {
- memset(&ip6stat, 0, len);
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet6.ip6.stats", &ip6stat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- if (errno != ENOENT)
- warn("sysctl: net.inet6.ip6.stats");
- return;
- }
- } else
- kread_counters(off, &ip6stat, len);
+ if (fetch_stats("net.inet6.ip6.stats", off, &ip6stat,
+ sizeof(ip6stat), kread_counters) != 0)
+ return;
printf("%s:\n", name);
@@ -842,23 +830,12 @@ static const char *icmp6names[] = {
void
icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct icmp6stat icmp6stat, zerostat;
+ struct icmp6stat icmp6stat;
int i, first;
- size_t len;
- len = sizeof icmp6stat;
- if (live) {
- memset(&icmp6stat, 0, len);
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet6.icmp6.stats", &icmp6stat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- if (errno != ENOENT)
- warn("sysctl: net.inet6.icmp6.stats");
- return;
- }
- } else
- kread_counters(off, &icmp6stat, len);
+ if (fetch_stats("net.inet6.icmp6.stats", off, &icmp6stat,
+ sizeof(icmp6stat), kread_counters) != 0)
+ return;
printf("%s:\n", name);
@@ -999,23 +976,11 @@ icmp6_ifstats(char *ifname)
void
pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct pim6stat pim6stat, zerostat;
- size_t len = sizeof pim6stat;
+ struct pim6stat pim6stat;
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet6.pim.stats", &pim6stat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- if (errno != ENOENT)
- warn("sysctl: net.inet6.pim.stats");
- return;
- }
- } else {
- if (off == 0)
- return;
- kread(off, &pim6stat, len);
- }
+ if (fetch_stats("net.inet6.pim.stats", off, &pim6stat,
+ sizeof(pim6stat), kread) != 0)
+ return;
printf("%s:\n", name);
@@ -1037,22 +1002,12 @@ pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
void
rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct rip6stat rip6stat, zerostat;
+ struct rip6stat rip6stat;
u_quad_t delivered;
- size_t len;
- len = sizeof(rip6stat);
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet6.ip6.rip6stats", &rip6stat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- if (errno != ENOENT)
- warn("sysctl: net.inet6.ip6.rip6stats");
- return;
- }
- } else
- kread_counters(off, &rip6stat, len);
+ if (fetch_stats("net.inet6.ip6.rip6stats", off, &rip6stat,
+ sizeof(rip6stat), kread_counters) != 0)
+ return;
printf("%s:\n", name);
diff --git a/usr.bin/netstat/ipsec.c b/usr.bin/netstat/ipsec.c
index af1b234..801008f 100644
--- a/usr.bin/netstat/ipsec.c
+++ b/usr.bin/netstat/ipsec.c
@@ -202,10 +202,17 @@ ipsec_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
struct ipsecstat ipsecstat;
- if (off == 0)
- return;
+ if (strcmp(name, "ipsec6") == 0) {
+ if (fetch_stats("net.inet6.ipsec6.ipsecstats", off,&ipsecstat,
+ sizeof(ipsecstat), kread_counters) != 0)
+ return;
+ } else {
+ if (fetch_stats("net.inet.ipsec.ipsecstats", off, &ipsecstat,
+ sizeof(ipsecstat), kread_counters) != 0)
+ return;
+ }
+
printf ("%s:\n", name);
- kread_counters(off, (char *)&ipsecstat, sizeof(ipsecstat));
print_ipsecstats(&ipsecstat);
}
@@ -288,10 +295,10 @@ ah_stats(u_long off, const char *name, int family __unused, int proto __unused)
{
struct ahstat ahstat;
- if (off == 0)
+ if (fetch_stats("net.inet.ah.stats", off, &ahstat,
+ sizeof(ahstat), kread_counters) != 0)
return;
printf ("%s:\n", name);
- kread_counters(off, (char *)&ahstat, sizeof(ahstat));
print_ahstats(&ahstat);
}
@@ -335,10 +342,10 @@ esp_stats(u_long off, const char *name, int family __unused, int proto __unused)
{
struct espstat espstat;
- if (off == 0)
+ if (fetch_stats("net.inet.esp.stats", off, &espstat,
+ sizeof(espstat), kread_counters) != 0)
return;
printf ("%s:\n", name);
- kread_counters(off, (char *)&espstat, sizeof(espstat));
print_espstats(&espstat);
}
@@ -380,10 +387,10 @@ ipcomp_stats(u_long off, const char *name, int family __unused,
{
struct ipcompstat ipcompstat;
- if (off == 0)
+ if (fetch_stats("net.inet.ipcomp.stats", off, &ipcompstat,
+ sizeof(ipcompstat), kread_counters) != 0)
return;
printf ("%s:\n", name);
- kread_counters(off, (char *)&ipcompstat, sizeof(ipcompstat));
print_ipcompstats(&ipcompstat);
}
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 6a1ab18..8ef9783 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
+#include <sys/sysctl.h>
#include <netinet/in.h>
@@ -202,13 +203,13 @@ struct protox {
igmp_stats, NULL, "igmp", 1, IPPROTO_IGMP },
#ifdef IPSEC
{ -1, N_IPSECSTAT, 1, NULL, /* keep as compat */
- ipsec_stats, NULL, "ipsec", 0, 0},
+ ipsec_stats, NULL, "ipsec", 1, 0},
{ -1, N_AHSTAT, 1, NULL,
- ah_stats, NULL, "ah", 0, 0},
+ ah_stats, NULL, "ah", 1, 0},
{ -1, N_ESPSTAT, 1, NULL,
- esp_stats, NULL, "esp", 0, 0},
+ esp_stats, NULL, "esp", 1, 0},
{ -1, N_IPCOMPSTAT, 1, NULL,
- ipcomp_stats, NULL, "ipcomp", 0, 0},
+ ipcomp_stats, NULL, "ipcomp", 1, 0},
#endif
{ N_RIPCBINFO, N_PIMSTAT, 1, protopr,
pim_stats, NULL, "pim", 1, IPPROTO_PIM },
@@ -240,7 +241,7 @@ struct protox ip6protox[] = {
#endif
#ifdef IPSEC
{ -1, N_IPSEC6STAT, 1, NULL,
- ipsec_stats, NULL, "ipsec6", 0, 0 },
+ ipsec_stats, NULL, "ipsec6", 1, 0 },
#endif
#ifdef notyet
{ -1, N_PIM6STAT, 1, NULL,
@@ -643,6 +644,29 @@ main(int argc, char *argv[])
exit(0);
}
+int
+fetch_stats(const char *sysctlname, u_long off, void *stats, size_t len,
+ int (*kreadfn)(u_long, void *, size_t))
+{
+ int error;
+
+ if (live) {
+ memset(stats, 0, len);
+ if (zflag)
+ error = sysctlbyname(sysctlname, NULL, NULL, stats,
+ len);
+ else
+ error = sysctlbyname(sysctlname, stats, &len, NULL, 0);
+ if (error == -1 && errno != ENOENT)
+ warn("sysctl %s", sysctlname);
+ } else {
+ if (off == 0)
+ return (1);
+ error = kreadfn(off, stats, len);
+ }
+ return (error);
+}
+
/*
* Print out protocol statistics or control blocks (per sflag).
* If the interface was not specifically requested, and the symbol
diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c
index ebd843f..74c2285 100644
--- a/usr.bin/netstat/mbuf.c
+++ b/usr.bin/netstat/mbuf.c
@@ -294,25 +294,20 @@ mbpr(void *kvmd, u_long mbaddr)
"(%juk/9k/16k)\n", jumbop_failures, jumbo9_failures,
jumbo16_failures, jumbop_size / 1024);
- if (live) {
- mlen = sizeof(nsfbufs);
- if (!sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL,
- 0) &&
- !sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused,
- &mlen, NULL, 0) &&
- !sysctlbyname("kern.ipc.nsfbufspeak", &nsfbufspeak,
- &mlen, NULL, 0))
- printf("%d/%d/%d sfbufs in use (current/peak/max)\n",
- nsfbufsused, nsfbufspeak, nsfbufs);
- mlen = sizeof(sfstat);
- if (sysctlbyname("kern.ipc.sfstat", &sfstat, &mlen, NULL, 0)) {
- warn("kern.ipc.sfstat");
- goto out;
- }
- } else {
- if (kread_counters(mbaddr, (char *)&sfstat, sizeof sfstat) != 0)
- goto out;
- }
+ mlen = sizeof(nsfbufs);
+ if (live &&
+ sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL, 0) == 0 &&
+ sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused, &mlen,
+ NULL, 0) == 0 &&
+ sysctlbyname("kern.ipc.nsfbufspeak", &nsfbufspeak, &mlen,
+ NULL, 0) == 0)
+ printf("%d/%d/%d sfbufs in use (current/peak/max)\n",
+ nsfbufsused, nsfbufspeak, nsfbufs);
+
+ if (fetch_stats("kern.ipc.sfstat", mbaddr, &sfstat, sizeof(sfstat),
+ kread_counters) != 0)
+ goto out;
+
printf("%ju requests for sfbufs denied\n",
(uintmax_t)sfstat.sf_allocfail);
printf("%ju requests for sfbufs delayed\n",
diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c
index 3ec716d..c53ffc1 100644
--- a/usr.bin/netstat/mroute.c
+++ b/usr.bin/netstat/mroute.c
@@ -370,7 +370,6 @@ mrt_stats()
{
struct mrtstat mrtstat;
u_long mstaddr;
- size_t len = sizeof(mrtstat);
kresolve_list(mrl);
mstaddr = mrl[N_MRTSTAT].n_value;
@@ -380,14 +379,9 @@ mrt_stats()
return;
}
- if (live) {
- if (sysctlbyname("net.inet.ip.mrtstat", &mrtstat, &len, NULL,
- 0) < 0) {
- warn("sysctl: net.inet.ip.mrtstat failed.");
- return;
- }
- } else
- kread_counters(mstaddr, &mrtstat, len);
+ if (fetch_stats("net.inet.ip.mrtstat", mstaddr, &mrtstat,
+ sizeof(mrtstat), kread_counters) != 0)
+ return;
printf("IPv4 multicast forwarding:\n");
diff --git a/usr.bin/netstat/mroute6.c b/usr.bin/netstat/mroute6.c
index ac31f5e..7cde3a7 100644
--- a/usr.bin/netstat/mroute6.c
+++ b/usr.bin/netstat/mroute6.c
@@ -246,7 +246,6 @@ mrt6_stats()
{
struct mrt6stat mrtstat;
u_long mstaddr;
- size_t len = sizeof mrtstat;
kresolve_list(mrl);
mstaddr = mrl[N_MRT6STAT].n_value;
@@ -255,15 +254,9 @@ mrt6_stats()
fprintf(stderr, "No IPv6 MROUTING kernel support.\n");
return;
}
-
- if (live) {
- if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len,
- NULL, 0) < 0) {
- warn("sysctl: net.inet6.ip6.mrt6stat");
- return;
- }
- } else
- kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
+ if (fetch_stats("net.inet6.ip6.mrt6stat", 0, &mrtstat,
+ sizeof(mrtstat), kread_counters) != 0)
+ return;
printf("IPv6 multicast forwarding:\n");
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index d2e9d32..086b60c 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -60,6 +60,8 @@ extern int unit; /* unit number for above */
extern int live; /* true if we are examining a live system */
struct nlist;
+int fetch_stats(const char *sysctlname, u_long addr, void *stats,
+ size_t len, int (*kreadfn)(u_long, void *, size_t));
int kread(u_long addr, void *buf, size_t size);
uint64_t kread_counter(u_long addr);
int kread_counters(u_long addr, void *buf, size_t size);
diff --git a/usr.bin/netstat/sctp.c b/usr.bin/netstat/sctp.c
index a2ef7d568..687d039 100644
--- a/usr.bin/netstat/sctp.c
+++ b/usr.bin/netstat/sctp.c
@@ -607,20 +607,11 @@ sctp_statesprint(uint32_t state)
void
sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
{
- struct sctpstat sctpstat, zerostat;
- size_t len = sizeof(sctpstat);
-
- if (live) {
- if (zflag)
- memset(&zerostat, 0, len);
- if (sysctlbyname("net.inet.sctp.stats", &sctpstat, &len,
- zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
- if (errno != ENOENT)
- warn("sysctl: net.inet.sctp.stats");
- return;
- }
- } else
- kread(off, &sctpstat, len);
+ struct sctpstat sctpstat;
+
+ if (fetch_stats("net.inet.sctp.stats", off, &sctpstat,
+ sizeof(sctpstat), kread) != 0)
+ return;
printf ("%s:\n", name);
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index 5fadf62..357c364 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -499,7 +499,7 @@ another_hunk(void)
LINENUM fillcnt; /* #lines of missing ptrn or repl */
LINENUM fillsrc; /* index of first line to copy */
LINENUM filldst; /* index of first missing line */
- bool ptrn_spaces_eaten; /* ptrn was slightly misformed */
+ bool ptrn_spaces_eaten; /* ptrn was slightly malformed */
bool repl_could_be_missing; /* no + or ! lines in this hunk */
bool repl_missing; /* we are now backtracking */
off_t repl_backtrack_position; /* file pos of first repl line */
diff --git a/usr.bin/pr/egetopt.c b/usr.bin/pr/egetopt.c
index 4b41b4a..22a093a 100644
--- a/usr.bin/pr/egetopt.c
+++ b/usr.bin/pr/egetopt.c
@@ -76,7 +76,7 @@ egetopt(int nargc, char * const *nargv, const char *ostr)
{
static char *place = emsg; /* option letter processing */
char *oli; /* option letter list index */
- static int delim; /* which option delimeter */
+ static int delim; /* which option delimiter */
char *p;
static char savec = '\0';
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index c7fbe21..68cbbc5 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -364,7 +364,7 @@ nonsel: /* Now parse the command */
}
/*
- * Get a delimited string. P points to the delimeter of the string; d points
+ * Get a delimited string. P points to the delimiter of the string; d points
* to a buffer area. Newline and delimiter escapes are processed; other
* escapes are ignored.
*
diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c
index d1ec0d3..8a8afc0 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -365,7 +365,7 @@ gather_sctp(void)
htons(xinpcb->local_port));
break;
default:
- errx(1, "adress family %d not supported",
+ errx(1, "address family %d not supported",
xladdr->address.sa.sa_family);
}
laddr->next = NULL;
@@ -457,7 +457,7 @@ gather_sctp(void)
htons(xstcb->local_port));
break;
default:
- errx(1, "adress family %d not supported",
+ errx(1, "address family %d not supported",
xladdr->address.sa.sa_family);
}
laddr->next = NULL;
@@ -499,7 +499,7 @@ gather_sctp(void)
htons(xstcb->remote_port));
break;
default:
- errx(1, "adress family %d not supported",
+ errx(1, "address family %d not supported",
xraddr->address.sa.sa_family);
}
faddr->next = NULL;
diff --git a/usr.bin/vgrind/regexp.c b/usr.bin/vgrind/regexp.c
index cd57835..04d3a83 100644
--- a/usr.bin/vgrind/regexp.c
+++ b/usr.bin/vgrind/regexp.c
@@ -318,7 +318,7 @@ expconv()
/*
- * The following routine recognises an irregular expresion
+ * The following routine recognises an irregular expression
* with the following special characters:
*
* \? - means last match was optional
diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c
index 03ff0c0..af427ef 100644
--- a/usr.sbin/bhyve/pci_emul.c
+++ b/usr.sbin/bhyve/pci_emul.c
@@ -295,7 +295,7 @@ pci_emul_msix_tread(struct pci_devinst *pi, uint64_t offset, int size)
/*
* The PCI standard only allows 4 and 8 byte accesses to the MSI-X
- * table but we also allow 1 byte access to accomodate reads from
+ * table but we also allow 1 byte access to accommodate reads from
* ddb.
*/
if (size != 1 && size != 4 && size != 8)
diff --git a/usr.sbin/bsdconfig/bsdconfig b/usr.sbin/bsdconfig/bsdconfig
index 62699f2..993865c 100755
--- a/usr.sbin/bsdconfig/bsdconfig
+++ b/usr.sbin/bsdconfig/bsdconfig
@@ -131,7 +131,7 @@ usage()
# determine if we can use more than one column to display commands.
#
local x=$longest_cmd ncols=1
- x=$(( $x + 8 )) # Accomodate leading tab character
+ x=$(( $x + 8 )) # Accommodate leading tab character
x=$(( $x + 3 + $longest_cmd )) # Preload end of next column
while [ $x -lt $max_width ]; do
ncols=$(( $ncols + 1 ))
diff --git a/usr.sbin/bsdconfig/console/INDEX b/usr.sbin/bsdconfig/console/INDEX
index 21a5ffd..e298f34 100644
--- a/usr.sbin/bsdconfig/console/INDEX
+++ b/usr.sbin/bsdconfig/console/INDEX
@@ -46,6 +46,13 @@ menu_help="Customize system console behavior"
# can be i18n'ed but `command' is the name of a script.
#
menu_selection="console|console"
+menu_selection="vt_font|font"
+menu_selection="vt_keymap|keymap"
+menu_selection="vt_repeat|repeat"
+menu_selection="vt_saver|saver"
+menu_selection="vt_screenmap|screenmap"
+menu_selection="vt_ttys|ttys"
+# For backward compatibility
menu_selection="syscons_font|font"
menu_selection="syscons_keymap|keymap"
menu_selection="syscons_repeat|repeat"
diff --git a/usr.sbin/bsdconfig/share/sysrc.subr b/usr.sbin/bsdconfig/share/sysrc.subr
index d863ba0..346bf10 100644
--- a/usr.sbin/bsdconfig/share/sysrc.subr
+++ b/usr.sbin/bsdconfig/share/sysrc.subr
@@ -1,6 +1,6 @@
if [ ! "$_SYSRC_SUBR" ]; then _SYSRC_SUBR=1
#
-# Copyright (c) 2006-2012 Devin Teske
+# Copyright (c) 2006-2015 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -204,6 +204,100 @@ f_sysrc_get()
)
}
+# f_sysrc_service_configs [-a|-p] $name [$var_to_set]
+#
+# Get a list of optional `rc.conf.d' entries sourced by system `rc.d' script
+# $name (see rc.subr(8) for additional information on `rc.conf.d'). If $name
+# exists in `/etc/rc.d' or $local_startup directories and is an rc(8) script
+# the result is a space separated list of `rc.conf.d' entries sourced by the
+# $name `rc.d' script. Otherwise, if $name exists as a binary `rc.d' script,
+# the result is ``/etc/rc.conf.d/$name /usr/local/etc/rc.conf.d/$name''. The
+# result is NULL if $name does not exist.
+#
+# If $var_to_set is missing or NULL, output is to standard out. Returns success
+# if $name was found, failure otherwise.
+#
+# If `-a' flag is given and $var_to_set is non-NULL, append result to value of
+# $var_to_set rather than overwriting current contents.
+#
+# If `-p' flag is given and $var_to_set is non-NULL, prepend result to value of
+# $var_to_set rather than overwriting current contents.
+#
+# NB: The `-a' and `-p' option flags are mutually exclusive.
+#
+f_sysrc_service_configs()
+{
+ local OPTIND=1 OPTARG __flag __append= __prepend=
+ local __local_startup __dir __spath __stype __names=
+
+ while getopts ap __flag; do
+ case "$__flag" in
+ a) __append=1 __prepend= ;;
+ p) __prepend=1 __append= ;;
+ esac
+ done
+ shift $(( $OPTIND - 1 ))
+
+ [ $# -gt 0 ] || return $FAILURE
+ local __sname="$1" __var_to_set="$2"
+
+ __local_startup=$( f_sysrc_get local_startup )
+ for __dir in /etc/rc.d $__local_startup; do
+ __spath="$__dir/$__sname"
+ [ -f "$__spath" -a -x "$__spath" ] || __spath= continue
+ break
+ done
+ [ "$__spath" ] || return $FAILURE
+
+ __stype=$( file -b "$__spath" 2> /dev/null )
+ case "$__stype" in
+ *"shell script"*)
+ __names=$( exec 9<&1 1>&- 2>&-
+ last_name=
+ print_name() {
+ local name="$1"
+ [ "$name" = "$last_name" ] && return
+ echo "$name" >&9
+ last_name="$name"
+ }
+ eval "$( awk '{
+ gsub(/load_rc_config /, "print_name ")
+ gsub(/run_rc_command /, ": ")
+ print
+ }' "$__spath" )"
+ ) ;;
+ *)
+ __names="$__sname"
+ esac
+
+ local __name __test_path __configs=
+ for __name in $__names; do
+ for __dir in /etc/rc.d $__local_startup; do
+ __test_path="${__dir%/rc.d}/rc.conf.d/$__name"
+ [ -d "$__test_path" ] ||
+ __configs="$__configs $__test_path" continue
+ for __test_path in "$__test_path"/*; do
+ [ -f "$__test_path" ] || continue
+ __configs="$__configs $__test_path"
+ done
+ done
+ done
+ __configs="${__configs# }"
+
+ if [ "$__var_to_set" ]; then
+ local __cur=
+ [ "$__append" -o "$__prepend" ] &&
+ f_getvar "$__var_to_set" __cur
+ [ "$__append" ] && __configs="$__cur{$__cur:+ }$__configs"
+ [ "$__prepend" ] && __configs="$__configs${__cur:+ }$__cur"
+ setvar "$__var_to_set" "$__configs"
+ else
+ echo "$__configs"
+ fi
+
+ return $SUCCESS
+}
+
# f_sysrc_get_default $varname
#
# Get a system configuration default setting from the default rc.conf(5) file
diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h
index 93b2086..703d053 100644
--- a/usr.sbin/config/config.h
+++ b/usr.sbin/config/config.h
@@ -50,7 +50,7 @@ struct file_list {
int f_type; /* type */
u_char f_flags; /* see below */
char *f_compilewith; /* special make rule if present */
- char *f_depends; /* additional dependancies */
+ char *f_depends; /* additional dependencies */
char *f_clean; /* File list to add to clean rule */
char *f_warn; /* warning message */
const char *f_objprefix; /* prefix string for object name */
diff --git a/usr.sbin/cron/cron/do_command.c b/usr.sbin/cron/cron/do_command.c
index fee4131..1ad8395 100644
--- a/usr.sbin/cron/cron/do_command.c
+++ b/usr.sbin/cron/cron/do_command.c
@@ -161,8 +161,10 @@ child_process(e, u)
/* create some pipes to talk to our future child
*/
- pipe(stdin_pipe); /* child's stdin */
- pipe(stdout_pipe); /* child's stdout */
+ if (pipe(stdin_pipe) != 0 || pipe(stdout_pipe) != 0) {
+ log_it("CRON", getpid(), "error", "can't pipe");
+ exit(ERROR_EXIT);
+ }
/* since we are a forked process, we can diddle the command string
* we were passed -- nobody else is going to use it again, right?
diff --git a/usr.sbin/cron/cron/popen.c b/usr.sbin/cron/cron/popen.c
index 428de2e..57b1f77 100644
--- a/usr.sbin/cron/cron/popen.c
+++ b/usr.sbin/cron/cron/popen.c
@@ -82,9 +82,8 @@ cron_popen(program, type, e)
if (!pids) {
if ((fds = getdtablesize()) <= 0)
return(NULL);
- if (!(pids = (PID_T *)malloc((u_int)(fds * sizeof(PID_T)))))
+ if (!(pids = calloc(fds, sizeof(PID_T))))
return(NULL);
- bzero((char *)pids, fds * sizeof(PID_T));
}
if (pipe(pdes) < 0)
return(NULL);
diff --git a/usr.sbin/cron/crontab/crontab.c b/usr.sbin/cron/crontab/crontab.c
index 1ac81b0..f2e97a7 100644
--- a/usr.sbin/cron/crontab/crontab.c
+++ b/usr.sbin/cron/crontab/crontab.c
@@ -558,7 +558,7 @@ replace_cmd() {
case FALSE:
e = load_entry(tmp, check_error, pw, envp);
if (e)
- free(e);
+ free_entry(e);
break;
case TRUE:
break;
diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c
index 55a2603..d0013bf 100644
--- a/usr.sbin/ctld/ctld.c
+++ b/usr.sbin/ctld/ctld.c
@@ -2012,7 +2012,7 @@ conf_apply(struct conf *oldconf, struct conf *newconf)
}
/*
- * Go through the new portals, opening the sockets as neccessary.
+ * Go through the new portals, opening the sockets as necessary.
*/
TAILQ_FOREACH(newpg, &newconf->conf_portal_groups, pg_next) {
if (newpg->pg_foreign)
diff --git a/usr.sbin/fwcontrol/fwmpegts.c b/usr.sbin/fwcontrol/fwmpegts.c
index 4f84789..ae9a52b 100644
--- a/usr.sbin/fwcontrol/fwmpegts.c
+++ b/usr.sbin/fwcontrol/fwmpegts.c
@@ -119,7 +119,7 @@ bandwidth (R):
2) 1.5 < R < 3 Mbps: db0/db1 or db2/db3 or db4/db5 or db6/db7 is payload,
3) 3 < R < 6 Mbps: db0/db1/db2/db3 or db4/db5/db6/db7 is payload,
4) R > 6 Mbps: all db0..db7 contain the payload.
-Curently, only case (4) is supported in fwmpegts.c
+Currently, only case (4) is supported in fwmpegts.c
Each packet may contain N MPEG TS data blocks with timestamp header,
which are (4+188)B long. Experimentally, the N ranges from 0 through 3.
diff --git a/usr.sbin/jail/command.c b/usr.sbin/jail/command.c
index d424d1c..a170b30 100644
--- a/usr.sbin/jail/command.c
+++ b/usr.sbin/jail/command.c
@@ -762,7 +762,7 @@ add_proc(struct cfjail *j, pid_t pid)
if (j->timeout.tv_sec == 0)
requeue(j, &sleeping);
else {
- /* File the jail in the sleep queue acording to its timeout. */
+ /* File the jail in the sleep queue according to its timeout. */
TAILQ_REMOVE(j->queue, j, tq);
TAILQ_FOREACH(tj, &sleeping, tq) {
if (!tj->timeout.tv_sec ||
diff --git a/usr.sbin/jail/jailp.h b/usr.sbin/jail/jailp.h
index d2c929e..4498f4b 100644
--- a/usr.sbin/jail/jailp.h
+++ b/usr.sbin/jail/jailp.h
@@ -41,7 +41,7 @@
#define DF_SEEN 0x01 /* Dependency has been followed */
#define DF_LIGHT 0x02 /* Implied dependency on jail existence only */
-#define DF_NOFAIL 0x04 /* Don't propigate failed jails */
+#define DF_NOFAIL 0x04 /* Don't propagate failed jails */
#define PF_VAR 0x01 /* This is a variable, not a true parameter */
#define PF_APPEND 0x02 /* Append to existing parameter list */
diff --git a/usr.sbin/jail/jailparse.y b/usr.sbin/jail/jailparse.y
index 2df337f..d085eb8 100644
--- a/usr.sbin/jail/jailparse.y
+++ b/usr.sbin/jail/jailparse.y
@@ -103,7 +103,7 @@ param_l :
/*
* Parameters have a name and an optional list of value strings,
- * which may have "+=" or "=" preceeding them.
+ * which may have "+=" or "=" preceding them.
*/
param : name
{
diff --git a/usr.sbin/jls/jls.c b/usr.sbin/jls/jls.c
index b1e28fb..fbd1694 100644
--- a/usr.sbin/jls/jls.c
+++ b/usr.sbin/jls/jls.c
@@ -220,7 +220,7 @@ main(int argc, char **argv)
putchar('\n');
}
- /* Fetch the jail(s) and print the paramters. */
+ /* Fetch the jail(s) and print the parameters. */
if (jid != 0 || jname != NULL) {
if (print_jail(pflags, jflags) < 0)
errx(1, "%s", jail_errmsg);
diff --git a/usr.sbin/kbdmap/kbdmap.c b/usr.sbin/kbdmap/kbdmap.c
index 08c0d77..4f983a5 100644
--- a/usr.sbin/kbdmap/kbdmap.c
+++ b/usr.sbin/kbdmap/kbdmap.c
@@ -57,6 +57,7 @@ static const char *dir;
static const char *menu = "";
static int x11;
+static int using_vt;
static int show;
static int verbose;
static int print;
@@ -150,7 +151,7 @@ add_keymap(const char *desc, int mark, const char *keym)
* Return 0 if syscons is in use (to select legacy defaults).
*/
static int
-check_newcons(void)
+check_vt(void)
{
size_t len;
char term[3];
@@ -159,7 +160,7 @@ check_newcons(void)
if (sysctlbyname("kern.vty", &term, &len, NULL, 0) != 0 ||
strcmp(term, "vt") != 0)
return 0;
- return -1;
+ return 1;
}
/*
@@ -256,7 +257,7 @@ get_font(void)
static void
vidcontrol(const char *fnt)
{
- char *tmp, *p, *q;
+ char *tmp, *p, *q, *cmd;
char ch;
int i;
@@ -264,6 +265,13 @@ vidcontrol(const char *fnt)
if (x11)
return;
+ if (using_vt) {
+ asprintf(&cmd, "vidcontrol -f %s", fnt);
+ system(cmd);
+ free(cmd);
+ return;
+ }
+
tmp = strdup(fnt);
/* Extract font size */
@@ -281,7 +289,6 @@ vidcontrol(const char *fnt)
if (sscanf(p, "%dx%d%c", &i, &i, &ch) != 2)
fprintf(stderr, "Which font size? %s\n", fnt);
else {
- char *cmd;
asprintf(&cmd, "vidcontrol -f %s %s", p, fnt);
if (verbose)
fprintf(stderr, "%s\n", cmd);
@@ -832,7 +839,8 @@ main(int argc, char **argv)
sleep(2);
}
- if (check_newcons() == 0) {
+ using_vt = check_vt();
+ if (using_vt == 0) {
keymapdir = DEFAULT_SC_KEYMAP_DIR;
fontdir = DEFAULT_SC_FONT_DIR;
font_default = DEFAULT_SC_FONT;
diff --git a/usr.sbin/mailwrapper/mailwrapper.8 b/usr.sbin/mailwrapper/mailwrapper.8
index 6e498f6..79eceb1 100644
--- a/usr.sbin/mailwrapper/mailwrapper.8
+++ b/usr.sbin/mailwrapper/mailwrapper.8
@@ -31,7 +31,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd August 7, 2006
+.Dd August 27, 2014
.Dt MAILWRAPPER 8
.Os
.Sh NAME
@@ -109,6 +109,8 @@ utility is designed to replace
and to invoke an appropriate MTA instead of
.Xr sendmail 8
based on configuration information placed in
+.Pa ${LOCALBASE}/etc/mail/mailer.conf
+falling back on
.Pa /etc/mail/mailer.conf .
This permits the administrator to configure which MTA is to be invoked on
the system at run time.
@@ -126,6 +128,8 @@ should be turned off in
Configuration for
.Nm
is kept in
+.Pa ${LOCALBASE}/etc/mail/mailer.conf
+or
.Pa /etc/mail/mailer.conf .
.Pa /usr/sbin/sendmail
is typically set up as a symbolic link to
diff --git a/usr.sbin/mailwrapper/mailwrapper.c b/usr.sbin/mailwrapper/mailwrapper.c
index 1b52a64..96c9190 100644
--- a/usr.sbin/mailwrapper/mailwrapper.c
+++ b/usr.sbin/mailwrapper/mailwrapper.c
@@ -35,6 +35,8 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/param.h>
+
#include <err.h>
#include <stdio.h>
#include <string.h>
@@ -87,6 +89,8 @@ main(int argc, char *argv[], char *envp[])
FILE *config;
char *line, *cp, *from, *to, *ap;
const char *progname;
+ char localmailerconf[MAXPATHLEN];
+ const char *mailerconf;
size_t len, lineno = 0;
int i;
struct arglist al;
@@ -98,11 +102,18 @@ main(int argc, char *argv[], char *envp[])
initarg(&al);
addarg(&al, argv[0]);
- if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL) {
+ snprintf(localmailerconf, MAXPATHLEN, "%s/etc/mail/mailer.conf",
+ getenv("LOCALBASE") ? getenv("LOCALBASE") : "/usr/local");
+
+ mailerconf = localmailerconf;
+ if ((config = fopen(localmailerconf, "r")) == NULL)
+ mailerconf = _PATH_MAILERCONF;
+
+ if (config == NULL && ((config = fopen(mailerconf, "r")) == NULL)) {
addarg(&al, NULL);
openlog(getprogname(), LOG_PID, LOG_MAIL);
syslog(LOG_INFO, "cannot open %s, using %s as default MTA",
- _PATH_MAILERCONF, _PATH_DEFAULTMTA);
+ mailerconf, _PATH_DEFAULTMTA);
closelog();
execve(_PATH_DEFAULTMTA, al.argv, envp);
err(EX_OSERR, "cannot exec %s", _PATH_DEFAULTMTA);
@@ -112,7 +123,7 @@ main(int argc, char *argv[], char *envp[])
for (;;) {
if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) {
if (feof(config))
- errx(EX_CONFIG, "no mapping in %s", _PATH_MAILERCONF);
+ errx(EX_CONFIG, "no mapping in %s", mailerconf);
err(EX_CONFIG, "cannot parse line %lu", (u_long)lineno);
}
@@ -157,6 +168,6 @@ main(int argc, char *argv[], char *envp[])
/*NOTREACHED*/
parse_error:
errx(EX_CONFIG, "parse error in %s at line %lu",
- _PATH_MAILERCONF, (u_long)lineno);
+ mailerconf, (u_long)lineno);
/*NOTREACHED*/
}
diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c
index dcee66f..e05e52a 100644
--- a/usr.sbin/makefs/cd9660.c
+++ b/usr.sbin/makefs/cd9660.c
@@ -163,7 +163,7 @@ static cd9660node *cd9660_create_special_directory(u_char, cd9660node *);
/*
- * Allocate and initalize a cd9660node
+ * Allocate and initialize a cd9660node
* @returns struct cd9660node * Pointer to new node, or NULL on error
*/
static cd9660node *
diff --git a/usr.sbin/makefs/makefs.c b/usr.sbin/makefs/makefs.c
index bca9722..b9491e8 100644
--- a/usr.sbin/makefs/makefs.c
+++ b/usr.sbin/makefs/makefs.c
@@ -113,7 +113,7 @@ main(int argc, char *argv[])
start_time.tv_sec = start.tv_sec;
start_time.tv_nsec = start.tv_usec * 1000;
- while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:o:pr:s:S:t:xZ")) != -1) {
+ while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:o:pR:s:S:t:xZ")) != -1) {
switch (ch) {
case 'B':
diff --git a/usr.sbin/mfiutil/mfiutil.8 b/usr.sbin/mfiutil/mfiutil.8
index 6ff652f..8a810ca 100644
--- a/usr.sbin/mfiutil/mfiutil.8
+++ b/usr.sbin/mfiutil/mfiutil.8
@@ -607,25 +607,25 @@ Scan for foreign configurations and display the number found. The
argument for the commands below takes the form of a number from 0 to the total
configurations found.
.It Cm foreign clear Op config
-Clear the specifed foreign
+Clear the specified foreign
.Ar config
or all if no
.Ar config
argument is provided.
.It Cm foreign diag Op config
-Display a diagnostic display of the specifed foreign
+Display a diagnostic display of the specified foreign
.Ar config
or all if no
.Ar config
argument is provided.
.It Cm foreign preview Op config
-Preview the specifed foreign
+Preview the specified foreign
.Ar config
after import or all if no
.Ar config
argument is provided.
.It Cm foreign import Op config
-Import the specifed foreign
+Import the specified foreign
.Ar config
or all if no
.Ar config
diff --git a/usr.sbin/nandsim/nandsim.8 b/usr.sbin/nandsim/nandsim.8
index 5b318a2..30a3151 100644
--- a/usr.sbin/nandsim/nandsim.8
+++ b/usr.sbin/nandsim/nandsim.8
@@ -177,7 +177,7 @@ list all blocks marked as bad on a given chip.
.El
.It Ic log
Prints activity log of the specified controller to stdout; if
-controller number is not specifed, logs for all available
+controller number is not specified, logs for all available
controllers are printed.
.It Ic stats
Print statistics of the selected controller, chip and page.
diff --git a/usr.sbin/nandsim/nandsim.c b/usr.sbin/nandsim/nandsim.c
index 082085f..bd3d080 100644
--- a/usr.sbin/nandsim/nandsim.c
+++ b/usr.sbin/nandsim/nandsim.c
@@ -421,7 +421,7 @@ cmdmod(int gargc __unused, char **gargv)
if (gargc >= 4) {
if (strcmp(gargv[2], "--loglevel") == 0 || strcmp(gargv[2],
"-l") == 0) {
- /* Set loglevel (ctrl:chip pair independant) */
+ /* Set loglevel (ctrl:chip pair independent) */
mods.field = SIM_MOD_LOG_LEVEL;
if (convert_arguint(gargv[3], &mods.new_value) != 0)
diff --git a/usr.sbin/nandsim/nandsim_cfgparse.c b/usr.sbin/nandsim/nandsim_cfgparse.c
index a965034..a9b5eb1 100644
--- a/usr.sbin/nandsim/nandsim_cfgparse.c
+++ b/usr.sbin/nandsim/nandsim_cfgparse.c
@@ -349,7 +349,7 @@ create_ctrls(struct rcfile *f, struct sim_ctrl **ctrls, int *cnt)
/*
* ECC layout have to end up with 0xffff, so
* we're filling buffer with 0xff. If ecc_layout is
- * defined in config file, values will be overriden.
+ * defined in config file, values will be overridden.
*/
memset((void *)&ctrl_conf.ecc_layout, 0xff,
sizeof(ctrl_conf.ecc_layout));
@@ -411,7 +411,7 @@ create_chips(struct rcfile *f, struct sim_chip **chips, int *cnt)
/*
* Bad block map have to end up with 0xffff, so
* we're filling array with 0xff. If bad block map is
- * defined in config file, values will be overriden.
+ * defined in config file, values will be overridden.
*/
memset((void *)&chip_conf.bad_block_map, 0xff,
sizeof(chip_conf.bad_block_map));
diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c
index ce3c4e0..ada1822 100644
--- a/usr.sbin/ndp/ndp.c
+++ b/usr.sbin/ndp/ndp.c
@@ -679,7 +679,7 @@ again:;
printf("%-*.*s %-*.*s %*.*s", addrwidth, addrwidth, host_buf,
llwidth, llwidth, ether_str(sdl), ifwidth, ifwidth, ifname);
- /* Print neighbor discovery specific informations */
+ /* Print neighbor discovery specific information */
nbi = getnbrinfo(&sin->sin6_addr, sdl->sdl_index, 1);
if (nbi) {
if (nbi->expire > now.tv_sec) {
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index 24e4882..f405bf8 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -1913,7 +1913,7 @@ do_sigwork(struct sigwork_entry *swork)
/*
* Compute the pause between consecutive signals. Use a longer
* sleep time if we will be sending two signals to the same
- * deamon or process-group.
+ * daemon or process-group.
*/
secs = 0;
nextsig = SLIST_NEXT(swork, sw_nextp);
diff --git a/usr.sbin/pmcstudy/eval_expr.c b/usr.sbin/pmcstudy/eval_expr.c
index c225391..d8999a9 100644
--- a/usr.sbin/pmcstudy/eval_expr.c
+++ b/usr.sbin/pmcstudy/eval_expr.c
@@ -444,7 +444,7 @@ parse_expression(char *str)
* val OP val <or>
* val OP ( <recursively>
* d) A final optional step (not implemented yet) would be
- * to insert the mathimatical precedence paran's. For
+ * to insert the mathematical precedence paran's. For
* the start we will just do the left to right evaluation and
* then later we can add this guy to add paran's to make it
* mathimatically correct... i.e instead of 1 + 2 * 3 we
diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c
index 5cd2272..5c25a09 100644
--- a/usr.sbin/ppp/ip.c
+++ b/usr.sbin/ppp/ip.c
@@ -473,7 +473,7 @@ FilterCheck(const unsigned char *packet,
ncpaddr_ntoa(&srcaddr), sport, dstip, dport);
}
return 1;
- } /* Explict match. Deny this packet */
+ } /* Explicit match. Deny this packet */
}
} else {
n++;
diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8
index 7358a48..87adf3a 100644
--- a/usr.sbin/ppp/ppp.8
+++ b/usr.sbin/ppp/ppp.8
@@ -5412,7 +5412,7 @@ and
.Dq default
can be used for
.Ar dest
-to sepcify the default route, and
+to specify the default route, and
.Dq 0.0.0.0
is understood to be the same as
.Dq default
@@ -5463,7 +5463,7 @@ and
.Dq default
can be used for
.Ar dest
-to sepcify the default route, and
+to specify the default route, and
.Dq ::
is understood to be the same as
.Dq default
diff --git a/usr.sbin/pw/pw_conf.c b/usr.sbin/pw/pw_conf.c
index e9606b4..d30c80e 100644
--- a/usr.sbin/pw/pw_conf.c
+++ b/usr.sbin/pw/pw_conf.c
@@ -313,7 +313,7 @@ read_userconfig(char const * file)
? NULL : newstr(q);
break;
case _UC_EXTRAGROUPS:
- for (i = 0; q != NULL; q = strtok(NULL, toks)) {
+ while ((q = strtok(NULL, toks)) != NULL) {
if (config.groups == NULL)
config.groups = sl_init();
sl_add(config.groups, newstr(q));
diff --git a/usr.sbin/pw/pw_group.c b/usr.sbin/pw/pw_group.c
index 67beab9..289a4c8 100644
--- a/usr.sbin/pw/pw_group.c
+++ b/usr.sbin/pw/pw_group.c
@@ -664,6 +664,11 @@ pw_group_mod(int argc, char **argv, char *arg1)
grp_add_members(&grp, newmembers);
}
+ if (dryrun) {
+ print_group(grp, pretty);
+ return (EXIT_SUCCESS);
+ }
+
if ((rc = chggrent(name, grp)) != 0) {
if (rc == -1)
errx(EX_IOERR, "group '%s' not available (NIS?)",
diff --git a/usr.sbin/pw/pw_vpw.c b/usr.sbin/pw/pw_vpw.c
index a23c66e..2d1c75b 100644
--- a/usr.sbin/pw/pw_vpw.c
+++ b/usr.sbin/pw/pw_vpw.c
@@ -70,7 +70,6 @@ vnextpwent(char const *nam, uid_t uid, int doclose)
pw = NULL;
line = NULL;
linecap = 0;
- linelen = 0;
if (pwd_fp != NULL || (pwd_fp = fopen(getpwpath(_MASTERPASSWD), "r")) != NULL) {
while ((linelen = getline(&line, &linecap, pwd_fp)) > 0) {
@@ -153,7 +152,6 @@ vnextgrent(char const *nam, gid_t gid, int doclose)
gr = NULL;
line = NULL;
linecap = 0;
- linelen = 0;
if (grp_fp != NULL || (grp_fp = fopen(getgrpath(_GROUP), "r")) != NULL) {
while ((linelen = getline(&line, &linecap, grp_fp)) > 0) {
diff --git a/usr.sbin/rtsold/rtsold.h b/usr.sbin/rtsold/rtsold.h
index 56b4185..f19fb3c 100644
--- a/usr.sbin/rtsold/rtsold.h
+++ b/usr.sbin/rtsold/rtsold.h
@@ -67,7 +67,7 @@ struct ifinfo {
int active; /* interface status */
int probeinterval; /* interval of probe timer (if necessary) */
int probetimer; /* rest of probe timer */
- int mediareqok; /* wheter the IF supports SIOCGIFMEDIA */
+ int mediareqok; /* whether the IF supports SIOCGIFMEDIA */
int otherconfig; /* need a separate protocol for the "other"
* configuration */
int state;
diff --git a/usr.sbin/uefisign/magic.h b/usr.sbin/uefisign/magic.h
index 4c3ad4e..85f2c55 100644
--- a/usr.sbin/uefisign/magic.h
+++ b/usr.sbin/uefisign/magic.h
@@ -50,7 +50,7 @@ static const char *magic_fmt =
"a = FORMAT:HEX,BITSTRING:00\n"
/*
* Well, there should be some other struct here, "SPCLink", but it doesn't
- * appear to be neccessary for UEFI, and I have no idea how to synthesize it,
+ * appear to be necessary for UEFI, and I have no idea how to synthesize it,
* as it uses the CHOICE type.
*/
"\n"
diff --git a/usr.sbin/uefisign/pe.c b/usr.sbin/uefisign/pe.c
index f4695b4..768ba5a 100644
--- a/usr.sbin/uefisign/pe.c
+++ b/usr.sbin/uefisign/pe.c
@@ -304,7 +304,7 @@ parse_directory(struct executable *x, off_t off,
* Note that most software does not care about the checksum at all; perhaps
* we could just set it to 0 instead.
*
- * XXX: Endianess?
+ * XXX: Endianness?
*/
static uint32_t
compute_checksum(const struct executable *x)
diff --git a/usr.sbin/ypbind/ypbind.c b/usr.sbin/ypbind/ypbind.c
index 700365f..293d437 100644
--- a/usr.sbin/ypbind/ypbind.c
+++ b/usr.sbin/ypbind/ypbind.c
@@ -392,7 +392,7 @@ main(int argc, char *argv[])
if (flock(yplockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK)
errx(1, "another ypbind is already running. Aborting");
- /* XXX domainname will be overriden if we use restricted mode */
+ /* XXX domainname will be overridden if we use restricted mode */
yp_get_default_domain(&domain_name);
if (domain_name[0] == '\0')
errx(1, "domainname not set. Aborting");
diff --git a/usr.sbin/ypserv/ypinit.sh b/usr.sbin/ypserv/ypinit.sh
index a55e4cb..5008bcf 100644
--- a/usr.sbin/ypserv/ypinit.sh
+++ b/usr.sbin/ypserv/ypinit.sh
@@ -235,7 +235,7 @@ then
for MAP in ${YPMAPLIST}
do
- echo "Transfering ${MAP}..."
+ echo "Transferring ${MAP}..."
if ! ${YPXFR} -p ${YP_DIR} -h ${MASTER} -c -d ${DOMAIN} ${MAP}; then
echo "Can't transfer map ${MAP}." 1>&2
ERROR_EXISTS="YES"
OpenPOWER on IntegriCloud