From 2387390ada842a67547463464e0def253594c4f5 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Fri, 13 Mar 2015 00:28:35 +0100 Subject: [PATCH] Update libnv to the latest version from FreeBSD head --- Makefile.am | 11 +- Makefile.in | 149 ++- aclocal.m4 | 67 +- configure | 13 +- external/libnv/Makefile | 15 +- external/libnv/nv.3 | 42 +- external/libnv/{dnvlist.c => subr_dnvlist.c} | 106 +- external/libnv/{nvlist.c => subr_nvlist.c} | 664 ++++++---- external/libnv/{nvpair.c => subr_nvpair.c} | 198 ++- external/libnv/{ => sys}/dnv.h | 12 +- external/libnv/{ => sys}/nv.h | 51 +- external/libnv/{ => sys}/nv_impl.h | 41 +- external/libnv/{ => sys}/nvlist_impl.h | 6 +- external/libnv/{ => sys}/nvpair_impl.h | 22 +- external/libnv/tests/dnv_tests.cc | 577 ++++++++ external/libnv/tests/nv_tests.cc | 1254 ++++++++++++++++++ external/libnv/tests/nvlist_send_recv_test.c | 23 +- 17 files changed, 2783 insertions(+), 468 deletions(-) rename external/libnv/{dnvlist.c => subr_dnvlist.c} (76%) rename external/libnv/{nvlist.c => subr_nvlist.c} (76%) rename external/libnv/{nvpair.c => subr_nvpair.c} (87%) rename external/libnv/{ => sys}/dnv.h (97%) rename external/libnv/{ => sys}/nv.h (93%) rename external/libnv/{ => sys}/nv_impl.h (85%) rename external/libnv/{ => sys}/nvlist_impl.h (91%) rename external/libnv/{ => sys}/nvpair_impl.h (83%) create mode 100644 external/libnv/tests/dnv_tests.cc create mode 100644 external/libnv/tests/nv_tests.cc diff --git a/Makefile.am b/Makefile.am index ffe6096719..e4e05c9808 100644 --- a/Makefile.am +++ b/Makefile.am @@ -143,10 +143,11 @@ libucl_a_CFLAGS= -I$(top_srcdir)/external/libucl/uthash \ -I$(top_srcdir)/external/libucl/include \ -I$(top_srcdir)/external/libucl/src \ -Wno-unused-parameter -Wno-pointer-sign -libnv_a_SOURCES= external/libnv/dnvlist.c \ +libnv_a_CFLAGS= -I$(top_srcdir)/external/libnv/ +libnv_a_SOURCES= external/libnv/subr_dnvlist.c \ external/libnv/msgio.c \ - external/libnv/nvlist.c \ - external/libnv/nvpair.c + external/libnv/subr_nvlist.c \ + external/libnv/subr_nvpair.c poudriered_SOURCES= src/poudriered/poudriered.c poudriered_CFLAGS= -DPREFIX=\"$(prefix)\" \ -I$(top_srcdir)/external/libucl/include @@ -155,14 +156,14 @@ poudriered_LDADD= libucl.a \ -lutil jexecd_SOURCES= src/libexec/poudriere/jexecd/jexecd.c -jexecd_CFLAGS= -I$(top_srcdir)/external/libnv +jexecd_CFLAGS= -I$(top_srcdir)/external/libnv/sys jexecd_LDADD= libnv.a \ -lsbuf \ -lutil \ -ljail rexec_SOURCES= src/libexec/poudriere/rexec/rexec.c -rexec_CFLAGS= -I$(top_srcdir)/external/libnv +rexec_CFLAGS= -I$(top_srcdir)/external/libnv/sys rexec_LDADD= libnv.a cached_SOURCES= src/libexec/poudriere/cached/cached.c diff --git a/Makefile.in b/Makefile.in index 9f808f0c28..cd2e7fc4d4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.14 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2014 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -19,7 +19,17 @@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ @@ -85,20 +95,17 @@ pkglibexec_PROGRAMS = cpdup$(EXEEXT) dirempty$(EXEEXT) \ rename$(EXEEXT) timeout$(EXEEXT) timestamp$(EXEEXT) \ tsort$(EXEEXT) jexecd$(EXEEXT) rexec$(EXEEXT) cached$(EXEEXT) subdir = . -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(top_srcdir)/configure $(am__configure_deps) \ - $(top_srcdir)/src/config.h.in \ - $(top_srcdir)/src/etc/rc.d/poudriered.in $(dist_bin_SCRIPTS) \ - $(dist_rc_SCRIPTS) depcomp $(dist_man_MANS) \ - $(dist_assets_DATA) $(dist_awk_DATA) $(dist_btcss_DATA) \ - $(dist_btfonts_DATA) $(dist_btjs_DATA) $(dist_dtcss_DATA) \ - $(dist_dtimages_DATA) $(dist_dtjs_DATA) $(dist_html_DATA) \ - $(dist_pkgdata_DATA) $(dist_include_HEADERS) compile \ - install-sh missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ + $(am__configure_deps) $(dist_bin_SCRIPTS) $(dist_rc_SCRIPTS) \ + $(dist_assets_DATA) $(dist_awk_DATA) $(dist_btcss_DATA) \ + $(dist_btfonts_DATA) $(dist_btjs_DATA) $(dist_dtcss_DATA) \ + $(dist_dtimages_DATA) $(dist_dtjs_DATA) $(dist_html_DATA) \ + $(dist_pkgdata_DATA) $(dist_include_HEADERS) \ + $(am__DIST_COMMON) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d @@ -115,9 +122,10 @@ am__v_AR_1 = libnv_a_AR = $(AR) $(ARFLAGS) libnv_a_LIBADD = am__dirstamp = $(am__leading_dot)dirstamp -am_libnv_a_OBJECTS = external/libnv/dnvlist.$(OBJEXT) \ - external/libnv/msgio.$(OBJEXT) external/libnv/nvlist.$(OBJEXT) \ - external/libnv/nvpair.$(OBJEXT) +am_libnv_a_OBJECTS = external/libnv/libnv_a-subr_dnvlist.$(OBJEXT) \ + external/libnv/libnv_a-msgio.$(OBJEXT) \ + external/libnv/libnv_a-subr_nvlist.$(OBJEXT) \ + external/libnv/libnv_a-subr_nvpair.$(OBJEXT) libnv_a_OBJECTS = $(am_libnv_a_OBJECTS) libucl_a_AR = $(AR) $(ARFLAGS) libucl_a_LIBADD = @@ -302,6 +310,10 @@ ETAGS = etags CTAGS = ctags CSCOPE = cscope AM_RECURSIVE_TARGETS = cscope +am__DIST_COMMON = $(dist_man_MANS) $(srcdir)/Makefile.in \ + $(top_srcdir)/src/config.h.in \ + $(top_srcdir)/src/etc/rc.d/poudriered.in compile depcomp \ + install-sh missing DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) @@ -537,10 +549,11 @@ libucl_a_CFLAGS = -I$(top_srcdir)/external/libucl/uthash \ -I$(top_srcdir)/external/libucl/src \ -Wno-unused-parameter -Wno-pointer-sign -libnv_a_SOURCES = external/libnv/dnvlist.c \ +libnv_a_CFLAGS = -I$(top_srcdir)/external/libnv/ +libnv_a_SOURCES = external/libnv/subr_dnvlist.c \ external/libnv/msgio.c \ - external/libnv/nvlist.c \ - external/libnv/nvpair.c + external/libnv/subr_nvlist.c \ + external/libnv/subr_nvpair.c poudriered_SOURCES = src/poudriered/poudriered.c poudriered_CFLAGS = -DPREFIX=\"$(prefix)\" \ @@ -551,14 +564,14 @@ poudriered_LDADD = libucl.a \ -lutil jexecd_SOURCES = src/libexec/poudriere/jexecd/jexecd.c -jexecd_CFLAGS = -I$(top_srcdir)/external/libnv +jexecd_CFLAGS = -I$(top_srcdir)/external/libnv/sys jexecd_LDADD = libnv.a \ -lsbuf \ -lutil \ -ljail rexec_SOURCES = src/libexec/poudriere/rexec/rexec.c -rexec_CFLAGS = -I$(top_srcdir)/external/libnv +rexec_CFLAGS = -I$(top_srcdir)/external/libnv/sys rexec_LDADD = libnv.a cached_SOURCES = src/libexec/poudriere/cached/cached.c cached_CFLAGS = -I$(top_srcdir)/external/uthash @@ -582,7 +595,6 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ @@ -627,13 +639,17 @@ external/libnv/$(am__dirstamp): external/libnv/$(DEPDIR)/$(am__dirstamp): @$(MKDIR_P) external/libnv/$(DEPDIR) @: > external/libnv/$(DEPDIR)/$(am__dirstamp) -external/libnv/dnvlist.$(OBJEXT): external/libnv/$(am__dirstamp) \ +external/libnv/libnv_a-subr_dnvlist.$(OBJEXT): \ + external/libnv/$(am__dirstamp) \ external/libnv/$(DEPDIR)/$(am__dirstamp) -external/libnv/msgio.$(OBJEXT): external/libnv/$(am__dirstamp) \ +external/libnv/libnv_a-msgio.$(OBJEXT): \ + external/libnv/$(am__dirstamp) \ external/libnv/$(DEPDIR)/$(am__dirstamp) -external/libnv/nvlist.$(OBJEXT): external/libnv/$(am__dirstamp) \ +external/libnv/libnv_a-subr_nvlist.$(OBJEXT): \ + external/libnv/$(am__dirstamp) \ external/libnv/$(DEPDIR)/$(am__dirstamp) -external/libnv/nvpair.$(OBJEXT): external/libnv/$(am__dirstamp) \ +external/libnv/libnv_a-subr_nvpair.$(OBJEXT): \ + external/libnv/$(am__dirstamp) \ external/libnv/$(DEPDIR)/$(am__dirstamp) libnv.a: $(libnv_a_OBJECTS) $(libnv_a_DEPENDENCIES) $(EXTRA_libnv_a_DEPENDENCIES) @@ -976,10 +992,10 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@external/libnv/$(DEPDIR)/dnvlist.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@external/libnv/$(DEPDIR)/msgio.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@external/libnv/$(DEPDIR)/nvlist.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@external/libnv/$(DEPDIR)/nvpair.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@external/libnv/$(DEPDIR)/libnv_a-msgio.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@external/libnv/$(DEPDIR)/libnv_a-subr_dnvlist.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@external/libnv/$(DEPDIR)/libnv_a-subr_nvlist.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@external/libnv/$(DEPDIR)/libnv_a-subr_nvpair.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@external/libucl/src/$(DEPDIR)/libucl_a-ucl_emitter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@external/libucl/src/$(DEPDIR)/libucl_a-ucl_emitter_streamline.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@external/libucl/src/$(DEPDIR)/libucl_a-ucl_emitter_utils.Po@am__quote@ @@ -1021,6 +1037,62 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` +external/libnv/libnv_a-subr_dnvlist.o: external/libnv/subr_dnvlist.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -MT external/libnv/libnv_a-subr_dnvlist.o -MD -MP -MF external/libnv/$(DEPDIR)/libnv_a-subr_dnvlist.Tpo -c -o external/libnv/libnv_a-subr_dnvlist.o `test -f 'external/libnv/subr_dnvlist.c' || echo '$(srcdir)/'`external/libnv/subr_dnvlist.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/libnv/$(DEPDIR)/libnv_a-subr_dnvlist.Tpo external/libnv/$(DEPDIR)/libnv_a-subr_dnvlist.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/libnv/subr_dnvlist.c' object='external/libnv/libnv_a-subr_dnvlist.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -c -o external/libnv/libnv_a-subr_dnvlist.o `test -f 'external/libnv/subr_dnvlist.c' || echo '$(srcdir)/'`external/libnv/subr_dnvlist.c + +external/libnv/libnv_a-subr_dnvlist.obj: external/libnv/subr_dnvlist.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -MT external/libnv/libnv_a-subr_dnvlist.obj -MD -MP -MF external/libnv/$(DEPDIR)/libnv_a-subr_dnvlist.Tpo -c -o external/libnv/libnv_a-subr_dnvlist.obj `if test -f 'external/libnv/subr_dnvlist.c'; then $(CYGPATH_W) 'external/libnv/subr_dnvlist.c'; else $(CYGPATH_W) '$(srcdir)/external/libnv/subr_dnvlist.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/libnv/$(DEPDIR)/libnv_a-subr_dnvlist.Tpo external/libnv/$(DEPDIR)/libnv_a-subr_dnvlist.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/libnv/subr_dnvlist.c' object='external/libnv/libnv_a-subr_dnvlist.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -c -o external/libnv/libnv_a-subr_dnvlist.obj `if test -f 'external/libnv/subr_dnvlist.c'; then $(CYGPATH_W) 'external/libnv/subr_dnvlist.c'; else $(CYGPATH_W) '$(srcdir)/external/libnv/subr_dnvlist.c'; fi` + +external/libnv/libnv_a-msgio.o: external/libnv/msgio.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -MT external/libnv/libnv_a-msgio.o -MD -MP -MF external/libnv/$(DEPDIR)/libnv_a-msgio.Tpo -c -o external/libnv/libnv_a-msgio.o `test -f 'external/libnv/msgio.c' || echo '$(srcdir)/'`external/libnv/msgio.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/libnv/$(DEPDIR)/libnv_a-msgio.Tpo external/libnv/$(DEPDIR)/libnv_a-msgio.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/libnv/msgio.c' object='external/libnv/libnv_a-msgio.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -c -o external/libnv/libnv_a-msgio.o `test -f 'external/libnv/msgio.c' || echo '$(srcdir)/'`external/libnv/msgio.c + +external/libnv/libnv_a-msgio.obj: external/libnv/msgio.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -MT external/libnv/libnv_a-msgio.obj -MD -MP -MF external/libnv/$(DEPDIR)/libnv_a-msgio.Tpo -c -o external/libnv/libnv_a-msgio.obj `if test -f 'external/libnv/msgio.c'; then $(CYGPATH_W) 'external/libnv/msgio.c'; else $(CYGPATH_W) '$(srcdir)/external/libnv/msgio.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/libnv/$(DEPDIR)/libnv_a-msgio.Tpo external/libnv/$(DEPDIR)/libnv_a-msgio.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/libnv/msgio.c' object='external/libnv/libnv_a-msgio.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -c -o external/libnv/libnv_a-msgio.obj `if test -f 'external/libnv/msgio.c'; then $(CYGPATH_W) 'external/libnv/msgio.c'; else $(CYGPATH_W) '$(srcdir)/external/libnv/msgio.c'; fi` + +external/libnv/libnv_a-subr_nvlist.o: external/libnv/subr_nvlist.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -MT external/libnv/libnv_a-subr_nvlist.o -MD -MP -MF external/libnv/$(DEPDIR)/libnv_a-subr_nvlist.Tpo -c -o external/libnv/libnv_a-subr_nvlist.o `test -f 'external/libnv/subr_nvlist.c' || echo '$(srcdir)/'`external/libnv/subr_nvlist.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/libnv/$(DEPDIR)/libnv_a-subr_nvlist.Tpo external/libnv/$(DEPDIR)/libnv_a-subr_nvlist.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/libnv/subr_nvlist.c' object='external/libnv/libnv_a-subr_nvlist.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -c -o external/libnv/libnv_a-subr_nvlist.o `test -f 'external/libnv/subr_nvlist.c' || echo '$(srcdir)/'`external/libnv/subr_nvlist.c + +external/libnv/libnv_a-subr_nvlist.obj: external/libnv/subr_nvlist.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -MT external/libnv/libnv_a-subr_nvlist.obj -MD -MP -MF external/libnv/$(DEPDIR)/libnv_a-subr_nvlist.Tpo -c -o external/libnv/libnv_a-subr_nvlist.obj `if test -f 'external/libnv/subr_nvlist.c'; then $(CYGPATH_W) 'external/libnv/subr_nvlist.c'; else $(CYGPATH_W) '$(srcdir)/external/libnv/subr_nvlist.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/libnv/$(DEPDIR)/libnv_a-subr_nvlist.Tpo external/libnv/$(DEPDIR)/libnv_a-subr_nvlist.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/libnv/subr_nvlist.c' object='external/libnv/libnv_a-subr_nvlist.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -c -o external/libnv/libnv_a-subr_nvlist.obj `if test -f 'external/libnv/subr_nvlist.c'; then $(CYGPATH_W) 'external/libnv/subr_nvlist.c'; else $(CYGPATH_W) '$(srcdir)/external/libnv/subr_nvlist.c'; fi` + +external/libnv/libnv_a-subr_nvpair.o: external/libnv/subr_nvpair.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -MT external/libnv/libnv_a-subr_nvpair.o -MD -MP -MF external/libnv/$(DEPDIR)/libnv_a-subr_nvpair.Tpo -c -o external/libnv/libnv_a-subr_nvpair.o `test -f 'external/libnv/subr_nvpair.c' || echo '$(srcdir)/'`external/libnv/subr_nvpair.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/libnv/$(DEPDIR)/libnv_a-subr_nvpair.Tpo external/libnv/$(DEPDIR)/libnv_a-subr_nvpair.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/libnv/subr_nvpair.c' object='external/libnv/libnv_a-subr_nvpair.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -c -o external/libnv/libnv_a-subr_nvpair.o `test -f 'external/libnv/subr_nvpair.c' || echo '$(srcdir)/'`external/libnv/subr_nvpair.c + +external/libnv/libnv_a-subr_nvpair.obj: external/libnv/subr_nvpair.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -MT external/libnv/libnv_a-subr_nvpair.obj -MD -MP -MF external/libnv/$(DEPDIR)/libnv_a-subr_nvpair.Tpo -c -o external/libnv/libnv_a-subr_nvpair.obj `if test -f 'external/libnv/subr_nvpair.c'; then $(CYGPATH_W) 'external/libnv/subr_nvpair.c'; else $(CYGPATH_W) '$(srcdir)/external/libnv/subr_nvpair.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/libnv/$(DEPDIR)/libnv_a-subr_nvpair.Tpo external/libnv/$(DEPDIR)/libnv_a-subr_nvpair.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/libnv/subr_nvpair.c' object='external/libnv/libnv_a-subr_nvpair.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnv_a_CFLAGS) $(CFLAGS) -c -o external/libnv/libnv_a-subr_nvpair.obj `if test -f 'external/libnv/subr_nvpair.c'; then $(CYGPATH_W) 'external/libnv/subr_nvpair.c'; else $(CYGPATH_W) '$(srcdir)/external/libnv/subr_nvpair.c'; fi` + external/libucl/src/libucl_a-ucl_emitter.o: external/libucl/src/ucl_emitter.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libucl_a_CFLAGS) $(CFLAGS) -MT external/libucl/src/libucl_a-ucl_emitter.o -MD -MP -MF external/libucl/src/$(DEPDIR)/libucl_a-ucl_emitter.Tpo -c -o external/libucl/src/libucl_a-ucl_emitter.o `test -f 'external/libucl/src/ucl_emitter.c' || echo '$(srcdir)/'`external/libucl/src/ucl_emitter.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/libucl/src/$(DEPDIR)/libucl_a-ucl_emitter.Tpo external/libucl/src/$(DEPDIR)/libucl_a-ucl_emitter.Po @@ -1710,15 +1782,15 @@ dist-xz: distdir $(am__post_remove_distdir) dist-tarZ: distdir - @echo WARNING: "Support for shar distribution archives is" \ - "deprecated." >&2 + @echo WARNING: "Support for distribution archives compressed with" \ + "legacy program 'compress' is deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z $(am__post_remove_distdir) dist-shar: distdir - @echo WARNING: "Support for distribution archives compressed with" \ - "legacy program 'compress' is deprecated." >&2 + @echo WARNING: "Support for shar distribution archives is" \ + "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz $(am__post_remove_distdir) @@ -1754,16 +1826,17 @@ distcheck: dist esac chmod -R a-w $(distdir) chmod u+w $(distdir) - mkdir $(distdir)/_build $(distdir)/_inst + mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst chmod a-w $(distdir) test -d $(distdir)/_build || exit 0; \ dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ && am__cwd=`pwd` \ - && $(am__cd) $(distdir)/_build \ - && ../configure --srcdir=.. --prefix="$$dc_install_base" \ + && $(am__cd) $(distdir)/_build/sub \ + && ../../configure \ $(AM_DISTCHECK_CONFIGURE_FLAGS) \ $(DISTCHECK_CONFIGURE_FLAGS) \ + --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ && $(MAKE) $(AM_MAKEFLAGS) dvi \ && $(MAKE) $(AM_MAKEFLAGS) check \ @@ -2008,6 +2081,8 @@ uninstall-man: uninstall-man8 uninstall-hookDATA uninstall-man uninstall-man8 \ uninstall-pkglibexecPROGRAMS uninstall-sysconfDATA +.PRECIOUS: Makefile + .PHONY: gen-make-wiki gen-man-wiki: diff --git a/aclocal.m4 b/aclocal.m4 index b85f6aed76..e81142640d 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.14 -*- Autoconf -*- +# generated automatically by aclocal 1.15 -*- Autoconf -*- -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2014 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -20,7 +20,7 @@ You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically 'autoreconf'.])]) -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -32,10 +32,10 @@ To do so, use the procedure documented by the package, typically 'autoreconf'.]) # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], -[am__api_version='1.14' +[am__api_version='1.15' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.14], [], +m4_if([$1], [1.15], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -51,14 +51,14 @@ m4_define([_AM_AUTOCONF_VERSION], []) # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.14])dnl +[AM_AUTOMAKE_VERSION([1.15])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -103,15 +103,14 @@ _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # configured tree to be moved without reconfiguration. AC_DEFUN([AM_AUX_DIR_EXPAND], -[dnl Rely on autoconf to set up CDPATH properly. -AC_PREREQ([2.50])dnl -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` +[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` ]) # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -142,7 +141,7 @@ AC_CONFIG_COMMANDS_PRE( Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -333,7 +332,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -409,7 +408,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -499,8 +498,8 @@ AC_REQUIRE([AC_PROG_MKDIR_P])dnl # # AC_SUBST([mkdir_p], ['$(MKDIR_P)']) -# We need awk for the "check" target. The system "awk" is bad on -# some platforms. +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AM_SET_LEADING_DOT])dnl @@ -573,7 +572,11 @@ to "yes", and re-run configure. END AC_MSG_ERROR([Your 'rm' program is bad, sorry.]) fi -fi]) +fi +dnl The trailing newline in this macro's definition is deliberate, for +dnl backward compatibility and to allow trailing 'dnl'-style comments +dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841. +]) dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further @@ -602,7 +605,7 @@ for _am_header in $config_headers :; do done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -613,7 +616,7 @@ echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_co # Define $install_sh. AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl -if test x"${install_sh}" != xset; then +if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; @@ -623,7 +626,7 @@ if test x"${install_sh}" != xset; then fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -645,7 +648,7 @@ AC_SUBST([am__leading_dot])]) # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -680,7 +683,7 @@ AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles]) # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -730,7 +733,7 @@ rm -f confinc confmf # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -769,7 +772,7 @@ fi # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -798,7 +801,7 @@ AC_DEFUN([_AM_SET_OPTIONS], AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -845,7 +848,7 @@ AC_LANG_POP([C])]) # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -864,7 +867,7 @@ AC_DEFUN([AM_RUN_LOG], # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -945,7 +948,7 @@ AC_CONFIG_COMMANDS_PRE( rm -f conftest.file ]) -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1005,7 +1008,7 @@ AC_SUBST([AM_BACKSLASH])dnl _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1033,7 +1036,7 @@ fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1052,7 +1055,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2014 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, diff --git a/configure b/configure index 143a583c14..e385ca37f2 100755 --- a/configure +++ b/configure @@ -2080,7 +2080,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -am__api_version='1.14' +am__api_version='1.15' ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do @@ -2281,8 +2281,8 @@ test "$program_suffix" != NONE && ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` if test x"${MISSING+set}" != xset; then case $am_aux_dir in @@ -2301,7 +2301,7 @@ else $as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi -if test x"${install_sh}" != xset; then +if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; @@ -2629,8 +2629,8 @@ MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} # mkdir_p='$(MKDIR_P)' -# We need awk for the "check" target. The system "awk" is bad on -# some platforms. +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. # Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AMTAR='$${TAR-tar}' @@ -2687,6 +2687,7 @@ END as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5 fi fi + # Check whether --enable-silent-rules was given. if test "${enable_silent_rules+set}" = set; then : enableval=$enable_silent_rules; diff --git a/external/libnv/Makefile b/external/libnv/Makefile index d05fe2024d..c8179d9e0e 100644 --- a/external/libnv/Makefile +++ b/external/libnv/Makefile @@ -1,4 +1,4 @@ -# $FreeBSD: head/lib/libnv/Makefile 271241 2014-09-07 22:56:57Z ngie $ +# $FreeBSD: head/lib/libnv/Makefile 279439 2015-03-01 00:34:27Z rstone $ SHLIBDIR?= /lib @@ -7,10 +7,13 @@ SHLIBDIR?= /lib LIB= nv SHLIB_MAJOR= 0 -SRCS= dnvlist.c +.PATH: ${.CURDIR}/../../sys/kern ${.CURDIR}/../../sys/sys +CFLAGS+=-I${.CURDIR}/../../sys -I${.CURDIR} + +SRCS= subr_dnvlist.c SRCS+= msgio.c -SRCS+= nvlist.c -SRCS+= nvpair.c +SRCS+= subr_nvlist.c +SRCS+= subr_nvpair.c INCS= dnv.h INCS+= nv.h @@ -22,6 +25,7 @@ MLINKS+=nv.3 libnv.3 \ MLINKS+=nv.3 nvlist_create.3 \ nv.3 nvlist_destroy.3 \ nv.3 nvlist_error.3 \ + nv.3 nvlist_set_error.3 \ nv.3 nvlist_empty.3 \ nv.3 nvlist_clone.3 \ nv.3 nvlist_dump.3 \ @@ -61,6 +65,7 @@ MLINKS+=nv.3 nvlist_create.3 \ nv.3 nvlist_get_nvlist.3 \ nv.3 nvlist_get_descriptor.3 \ nv.3 nvlist_get_binary.3 \ + nv.3 nvlist_get_parent.3 \ nv.3 nvlist_take_bool.3 \ nv.3 nvlist_take_number.3 \ nv.3 nvlist_take_string.3 \ @@ -149,7 +154,7 @@ MLINKS+=nv.3 nvlist_existsv.3 \ nv.3 nvlist_takev_nvlist.3 \ nv.3 nvlist_takev_descriptor.3 \ nv.3 nvlist_takev_binary.3 \ - nv.3 nvlist_freef.3 \ + nv.3 nvlist_freev.3 \ nv.3 nvlist_freev_type.3 \ nv.3 nvlist_freev_null.3 \ nv.3 nvlist_freev_bool.3 \ diff --git a/external/libnv/nv.3 b/external/libnv/nv.3 index 0340326e8a..dd9a661a78 100644 --- a/external/libnv/nv.3 +++ b/external/libnv/nv.3 @@ -26,15 +26,16 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: head/lib/libnv/nv.3 272102 2014-09-25 10:59:01Z pjd $ +.\" $FreeBSD: head/lib/libnv/nv.3 279434 2015-03-01 00:22:23Z rstone $ .\" -.Dd September 25, 2014 +.Dd January 30, 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_exists , .Nm nvlist_free , @@ -63,6 +64,8 @@ .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" .\" @@ -151,7 +154,7 @@ .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" +.Fn nvlist_get_parent "const nvlist_t *nvl" "void **cookiep" .\" .Ft bool .Fn nvlist_take_bool "nvlist_t *nvl" "const char *name" @@ -248,8 +251,17 @@ the 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 -functions returns +function returns .Dv true if the given nvlist is empty and .Dv false @@ -588,6 +600,28 @@ while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) { 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 , diff --git a/external/libnv/dnvlist.c b/external/libnv/subr_dnvlist.c similarity index 76% rename from external/libnv/dnvlist.c rename to external/libnv/subr_dnvlist.c index 97d02ee7c7..01618a0471 100644 --- a/external/libnv/dnvlist.c +++ b/external/libnv/subr_dnvlist.c @@ -28,30 +28,48 @@ */ #include -__FBSDID("$FreeBSD: head/lib/libnv/dnvlist.c 258065 2013-11-12 19:39:14Z pjd $"); +__FBSDID("$FreeBSD: head/sys/kern/subr_dnvlist.c 279439 2015-03-01 00:34:27Z rstone $"); +#ifdef _KERNEL + +#include +#include +#include +#include +#include + +#include + +#else #include #include #include +#include +#endif -#include "nv.h" -#include "nv_impl.h" +#include +#include -#include "dnv.h" +#include #define DNVLIST_GET(ftype, type) \ ftype \ dnvlist_get_##type(const nvlist_t *nvl, const char *name, ftype defval) \ { \ \ - return (dnvlist_getf_##type(nvl, defval, "%s", name)); \ + 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 @@ -59,10 +77,19 @@ const void * dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep, const void *defval, size_t defsize) { + const void *value; - return (dnvlist_getf_binary(nvl, sizep, defval, defsize, "%s", name)); + if (nvlist_exists_binary(nvl, name)) + value = nvlist_get_binary(nvl, name, sizep); + else { + if (sizep != NULL) + *sizep = defsize; + value = defval; + } + return (value); } +#ifndef _KERNEL #define DNVLIST_GETF(ftype, type) \ ftype \ dnvlist_getf_##type(const nvlist_t *nvl, ftype defval, \ @@ -106,15 +133,14 @@ ftype \ dnvlist_getv_##type(const nvlist_t *nvl, ftype defval, \ const char *namefmt, va_list nameap) \ { \ - va_list cnameap; \ + char *name; \ ftype value; \ \ - va_copy(cnameap, nameap); \ - if (nvlist_existsv_##type(nvl, namefmt, cnameap)) \ - value = nvlist_getv_##type(nvl, namefmt, nameap); \ - else \ - value = defval; \ - va_end(cnameap); \ + vasprintf(&name, namefmt, nameap); \ + if (name == NULL) \ + return (defval); \ + value = dnvlist_get_##type(nvl, name, defval); \ + free(name); \ return (value); \ } @@ -130,34 +156,40 @@ const void * dnvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const void *defval, size_t defsize, const char *namefmt, va_list nameap) { - va_list cnameap; + char *name; const void *value; - va_copy(cnameap, nameap); - if (nvlist_existsv_binary(nvl, namefmt, cnameap)) { - value = nvlist_getv_binary(nvl, sizep, namefmt, nameap); + nv_vasprintf(&name, namefmt, nameap); + if (name != NULL) { + value = dnvlist_get_binary(nvl, name, sizep, defval, defsize); + nv_free(name); } else { if (sizep != NULL) *sizep = defsize; value = defval; } - va_end(cnameap); return (value); } +#endif #define DNVLIST_TAKE(ftype, type) \ ftype \ dnvlist_take_##type(nvlist_t *nvl, const char *name, ftype defval) \ { \ \ - return (dnvlist_takef_##type(nvl, defval, "%s", name)); \ + 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 @@ -165,10 +197,19 @@ void * dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep, void *defval, size_t defsize) { + void *value; - return (dnvlist_takef_binary(nvl, sizep, defval, defsize, "%s", name)); + if (nvlist_exists_binary(nvl, name)) + value = nvlist_take_binary(nvl, name, sizep); + else { + if (sizep != NULL) + *sizep = defsize; + value = defval; + } + return (value); } +#ifndef _KERNEL #define DNVLIST_TAKEF(ftype, type) \ ftype \ dnvlist_takef_##type(nvlist_t *nvl, ftype defval, \ @@ -212,15 +253,14 @@ ftype \ dnvlist_takev_##type(nvlist_t *nvl, ftype defval, const char *namefmt, \ va_list nameap) \ { \ - va_list cnameap; \ + char *name; \ ftype value; \ \ - va_copy(cnameap, nameap); \ - if (nvlist_existsv_##type(nvl, namefmt, cnameap)) \ - value = nvlist_takev_##type(nvl, namefmt, nameap); \ - else \ - value = defval; \ - va_end(cnameap); \ + vasprintf(&name, namefmt, nameap); \ + if (name == NULL) \ + return (defval); \ + value = dnvlist_take_##type(nvl, name, defval); \ + free(name); \ return (value); \ } @@ -236,17 +276,19 @@ void * dnvlist_takev_binary(nvlist_t *nvl, size_t *sizep, void *defval, size_t defsize, const char *namefmt, va_list nameap) { - va_list cnameap; + char *name; void *value; - va_copy(cnameap, nameap); - if (nvlist_existsv_binary(nvl, namefmt, cnameap)) { - value = nvlist_takev_binary(nvl, sizep, namefmt, nameap); + nv_vasprintf(&name, namefmt, nameap); + if (name != NULL) { + value = dnvlist_take_binary(nvl, name, sizep, defval, defsize); + nv_free(name); } else { if (sizep != NULL) *sizep = defsize; value = defval; } - va_end(cnameap); + return (value); } +#endif diff --git a/external/libnv/nvlist.c b/external/libnv/subr_nvlist.c similarity index 76% rename from external/libnv/nvlist.c rename to external/libnv/subr_nvlist.c index 6012c488a1..d42f8357b5 100644 --- a/external/libnv/nvlist.c +++ b/external/libnv/subr_nvlist.c @@ -28,11 +28,23 @@ */ #include -__FBSDID("$FreeBSD: head/lib/libnv/nvlist.c 271579 2014-09-14 09:30:09Z pjd $"); +__FBSDID("$FreeBSD: head/sys/kern/subr_nvlist.c 279439 2015-03-01 00:34:27Z rstone $"); #include #include #include + +#ifdef _KERNEL + +#include +#include +#include +#include +#include + +#include + +#else #include #include @@ -45,17 +57,24 @@ __FBSDID("$FreeBSD: head/lib/libnv/nvlist.c 271579 2014-09-14 09:30:09Z pjd $"); #include #include +#include "msgio.h" +#endif + #ifdef HAVE_PJDLOG #include #endif -#include "msgio.h" -#include "nv.h" -#include "nv_impl.h" -#include "nvlist_impl.h" -#include "nvpair_impl.h" +#include +#include +#include +#include #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 #define PJDLOG_ASSERT(...) assert(__VA_ARGS__) #define PJDLOG_RASSERT(expr, ...) assert(expr) @@ -66,6 +85,7 @@ __FBSDID("$FreeBSD: head/lib/libnv/nvlist.c 271579 2014-09-14 09:30:09Z pjd $"); abort(); \ } while (0) #endif +#endif #define NV_FLAG_PRIVATE_MASK (NV_FLAG_BIG_ENDIAN) #define NV_FLAG_PUBLIC_MASK (NV_FLAG_IGNORE_CASE) @@ -85,6 +105,10 @@ struct nvlist { 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 @@ -104,7 +128,7 @@ nvlist_create(int flags) PJDLOG_ASSERT((flags & ~(NV_FLAG_PUBLIC_MASK)) == 0); - nvl = malloc(sizeof(*nvl)); + nvl = nv_malloc(sizeof(*nvl)); nvl->nvl_error = 0; nvl->nvl_flags = flags; nvl->nvl_parent = NULL; @@ -123,7 +147,7 @@ nvlist_destroy(nvlist_t *nvl) if (nvl == NULL) return; - serrno = errno; + SAVE_ERRNO(serrno); NVLIST_ASSERT(nvl); @@ -132,9 +156,23 @@ nvlist_destroy(nvlist_t *nvl) nvpair_free(nvp); } nvl->nvl_magic = 0; - free(nvl); + nv_free(nvl); - errno = serrno; + 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 @@ -159,15 +197,19 @@ nvlist_get_nvpair_parent(const nvlist_t *nvl) } const nvlist_t * -nvlist_get_parent(const nvlist_t *nvl) +nvlist_get_parent(const nvlist_t *nvl, void **cookiep) { + nvpair_t *nvp; NVLIST_ASSERT(nvl); - if (nvl->nvl_parent == NULL) + nvp = nvl->nvl_parent; + if (cookiep != NULL) + *cookiep = nvp; + if (nvp == NULL) return (NULL); - return (nvpair_nvlist(nvl->nvl_parent)); + return (nvpair_nvlist(nvp)); } void @@ -190,29 +232,23 @@ nvlist_empty(const nvlist_t *nvl) } static void -nvlist_report_missing(int type, const char *namefmt, va_list nameap) +nvlist_report_missing(int type, const char *name) { - char *name; - vasprintf(&name, namefmt, nameap); PJDLOG_ABORT("Element '%s' of type %s doesn't exist.", - name != NULL ? name : "N/A", nvpair_type_string(type)); + name, nvpair_type_string(type)); } static nvpair_t * -nvlist_findv(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap) +nvlist_find(const nvlist_t *nvl, int type, const char *name) { nvpair_t *nvp; - char *name; NVLIST_ASSERT(nvl); PJDLOG_ASSERT(nvl->nvl_error == 0); PJDLOG_ASSERT(type == NV_TYPE_NONE || (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST)); - if (vasprintf(&name, namefmt, nameap) < 0) - return (NULL); - for (nvp = nvlist_first_nvpair(nvl); nvp != NULL; nvp = nvlist_next_nvpair(nvl, nvp)) { if (type != NV_TYPE_NONE && nvpair_type(nvp) != type) @@ -227,10 +263,8 @@ nvlist_findv(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap) break; } - free(name); - if (nvp == NULL) - errno = ENOENT; + RESTORE_ERRNO(ENOENT); return (nvp); } @@ -239,9 +273,15 @@ bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type) { - return (nvlist_existsf_type(nvl, type, "%s", name)); + 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); } +#ifndef _KERNEL bool nvlist_existsf_type(const nvlist_t *nvl, int type, const char *namefmt, ...) { @@ -259,22 +299,37 @@ bool nvlist_existsv_type(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap) { + char *name; + bool exists; - NVLIST_ASSERT(nvl); - PJDLOG_ASSERT(nvl->nvl_error == 0); - PJDLOG_ASSERT(type == NV_TYPE_NONE || - (type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST)); + nv_vasprintf(&name, namefmt, nameap); + if (name == NULL) + return (false); - return (nvlist_findv(nvl, type, namefmt, nameap) != NULL); + exists = nvlist_exists_type(nvl, name, type); + nv_free(name); + return (exists); } +#endif 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)); - nvlist_freef_type(nvl, type, "%s", name); + nvp = nvlist_find(nvl, type, name); + if (nvp != NULL) + nvlist_free_nvpair(nvl, nvp); + else + nvlist_report_missing(type, name); } +#ifndef _KERNEL void nvlist_freef_type(nvlist_t *nvl, int type, const char *namefmt, ...) { @@ -288,22 +343,15 @@ nvlist_freef_type(nvlist_t *nvl, int type, const char *namefmt, ...) void nvlist_freev_type(nvlist_t *nvl, int type, const char *namefmt, va_list nameap) { - va_list cnameap; - 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)); + char *name; - va_copy(cnameap, nameap); - nvp = nvlist_findv(nvl, type, namefmt, cnameap); - va_end(cnameap); - if (nvp != NULL) - nvlist_free_nvpair(nvl, nvp); - else - nvlist_report_missing(type, namefmt, nameap); + nv_vasprintf(&name, namefmt, nameap); + if (name == NULL) + nvlist_report_missing(type, ""); + nvlist_free_type(nvl, name, type); + nv_free(name); } +#endif nvlist_t * nvlist_clone(const nvlist_t *nvl) @@ -314,7 +362,7 @@ nvlist_clone(const nvlist_t *nvl) NVLIST_ASSERT(nvl); if (nvl->nvl_error != 0) { - errno = nvl->nvl_error; + RESTORE_ERRNO(nvl->nvl_error); return (NULL); } @@ -333,6 +381,7 @@ nvlist_clone(const nvlist_t *nvl) return (newnvl); } +#ifndef _KERNEL static bool nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level) { @@ -352,7 +401,9 @@ nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level) void nvlist_dump(const nvlist_t *nvl, int fd) { - nvpair_t *nvp; + const nvlist_t *tmpnvl; + nvpair_t *nvp, *tmpnvp; + void *cookie; int level; level = 0; @@ -382,14 +433,17 @@ nvlist_dump(const nvlist_t *nvl, int fd) break; case NV_TYPE_NVLIST: dprintf(fd, "\n"); - nvl = nvpair_get_nvlist(nvp); - if (nvlist_dump_error_check(nvl, fd, level + 1)) { - nvl = nvlist_get_parent(nvl); + 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; } - level += 1; - nvp = nvlist_first_nvpair(nvl); - continue; + break; case NV_TYPE_DESCRIPTOR: dprintf(fd, " %d\n", nvpair_get_descriptor(nvp)); break; @@ -411,11 +465,12 @@ nvlist_dump(const nvlist_t *nvl, int fd) } while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) { - nvp = nvlist_get_nvpair_parent(nvl); - if (nvp == NULL) + cookie = NULL; + nvl = nvlist_get_parent(nvl, &cookie); + if (nvl == NULL) return; - nvl = nvlist_get_parent(nvl); - level --; + nvp = cookie; + level--; } } } @@ -427,6 +482,7 @@ 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(). @@ -434,7 +490,9 @@ nvlist_fdump(const nvlist_t *nvl, FILE *fp) size_t nvlist_size(const nvlist_t *nvl) { - const nvpair_t *nvp; + const nvlist_t *tmpnvl; + const nvpair_t *nvp, *tmpnvp; + void *cookie; size_t size; NVLIST_ASSERT(nvl); @@ -448,19 +506,24 @@ nvlist_size(const nvlist_t *nvl) if (nvpair_type(nvp) == NV_TYPE_NVLIST) { size += sizeof(struct nvlist_header); size += nvpair_header_size() + 1; - nvl = nvpair_get_nvlist(nvp); - PJDLOG_ASSERT(nvl->nvl_error == 0); - nvp = nvlist_first_nvpair(nvl); - continue; + 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) { - nvp = nvlist_get_nvpair_parent(nvl); - if (nvp == NULL) + cookie = NULL; + nvl = nvlist_get_parent(nvl, &cookie); + if (nvl == NULL) goto out; - nvl = nvlist_get_parent(nvl); + nvp = cookie; } } @@ -468,6 +531,7 @@ nvlist_size(const nvlist_t *nvl) return (size); } +#ifndef _KERNEL static int * nvlist_xdescriptors(const nvlist_t *nvl, int *descs, int level) { @@ -493,7 +557,9 @@ nvlist_xdescriptors(const nvlist_t *nvl, int *descs, int level) return (descs); } +#endif +#ifndef _KERNEL int * nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp) { @@ -501,7 +567,7 @@ nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp) int *fds; nitems = nvlist_ndescriptors(nvl); - fds = malloc(sizeof(fds[0]) * (nitems + 1)); + fds = nv_malloc(sizeof(fds[0]) * (nitems + 1)); if (fds == NULL) return (NULL); if (nitems > 0) @@ -511,10 +577,12 @@ nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp) *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; @@ -537,6 +605,9 @@ nvlist_xndescriptors(const nvlist_t *nvl, int level) } return (ndescs); +#else + return (0); +#endif } size_t @@ -574,17 +645,19 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) { unsigned char *buf, *ptr; size_t left, size; - nvpair_t *nvp; + const nvlist_t *tmpnvl; + nvpair_t *nvp, *tmpnvp; + void *cookie; NVLIST_ASSERT(nvl); if (nvl->nvl_error != 0) { - errno = nvl->nvl_error; + RESTORE_ERRNO(nvl->nvl_error); return (NULL); } size = nvlist_size(nvl); - buf = malloc(size); + buf = nv_malloc(size); if (buf == NULL) return (NULL); @@ -600,7 +673,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) nvpair_init_datasize(nvp); ptr = nvpair_pack_header(nvp, ptr, &left); if (ptr == NULL) { - free(buf); + nv_free(buf); return (NULL); } switch (nvpair_type(nvp)) { @@ -617,13 +690,23 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) ptr = nvpair_pack_string(nvp, ptr, &left); break; case NV_TYPE_NVLIST: - nvl = nvpair_get_nvlist(nvp); - nvp = nvlist_first_nvpair(nvl); - ptr = nvlist_pack_header(nvl, ptr, &left); - continue; + 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; @@ -631,17 +714,18 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep) PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp)); } if (ptr == NULL) { - free(buf); + nv_free(buf); return (NULL); } while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) { - nvp = nvlist_get_nvpair_parent(nvl); - if (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; - nvl = nvlist_get_parent(nvl); } } @@ -658,12 +742,12 @@ nvlist_pack(const nvlist_t *nvl, size_t *sizep) NVLIST_ASSERT(nvl); if (nvl->nvl_error != 0) { - errno = nvl->nvl_error; + RESTORE_ERRNO(nvl->nvl_error); return (NULL); } if (nvlist_ndescriptors(nvl) > 0) { - errno = EOPNOTSUPP; + RESTORE_ERRNO(EOPNOTSUPP); return (NULL); } @@ -675,11 +759,11 @@ nvlist_check_header(struct nvlist_header *nvlhdrp) { if (nvlhdrp->nvlh_magic != NVLIST_HEADER_MAGIC) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (false); } if ((nvlhdrp->nvlh_flags & ~NV_FLAG_ALL_MASK) != 0) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (false); } #if BYTE_ORDER == BIG_ENDIAN @@ -698,7 +782,7 @@ nvlist_check_header(struct nvlist_header *nvlhdrp) const unsigned char * nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds, - int *flagsp, size_t *leftp) + bool *isbep, size_t *leftp) { struct nvlist_header nvlhdr; @@ -725,12 +809,13 @@ nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds, nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK); ptr += sizeof(nvlhdr); - *flagsp = (int)nvlhdr.nvlh_flags; + if (isbep != NULL) + *isbep = (((int)nvlhdr.nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0); *leftp -= sizeof(nvlhdr); return (ptr); failed: - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } @@ -741,7 +826,7 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds) nvlist_t *nvl, *retnvl, *tmpnvl; nvpair_t *nvp; size_t left; - int flags; + bool isbe; left = size; ptr = buf; @@ -751,44 +836,45 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds) if (nvl == NULL) goto failed; - ptr = nvlist_unpack_header(nvl, ptr, nfds, &flags, &left); + ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left); if (ptr == NULL) goto failed; while (left > 0) { - ptr = nvpair_unpack(flags, ptr, &left, &nvp); + ptr = nvpair_unpack(isbe, ptr, &left, &nvp); if (ptr == NULL) goto failed; switch (nvpair_type(nvp)) { case NV_TYPE_NULL: - ptr = nvpair_unpack_null(flags, nvp, ptr, &left); + ptr = nvpair_unpack_null(isbe, nvp, ptr, &left); break; case NV_TYPE_BOOL: - ptr = nvpair_unpack_bool(flags, nvp, ptr, &left); + ptr = nvpair_unpack_bool(isbe, nvp, ptr, &left); break; case NV_TYPE_NUMBER: - ptr = nvpair_unpack_number(flags, nvp, ptr, &left); + ptr = nvpair_unpack_number(isbe, nvp, ptr, &left); break; case NV_TYPE_STRING: - ptr = nvpair_unpack_string(flags, nvp, ptr, &left); + ptr = nvpair_unpack_string(isbe, nvp, ptr, &left); break; case NV_TYPE_NVLIST: - ptr = nvpair_unpack_nvlist(&flags, nvp, ptr, &left, - nfds, &tmpnvl); + 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(flags, nvp, ptr, &left, + ptr = nvpair_unpack_descriptor(isbe, nvp, ptr, &left, fds, nfds); break; +#endif case NV_TYPE_BINARY: - ptr = nvpair_unpack_binary(flags, nvp, ptr, &left); + 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); - flags = nvl->nvl_flags; continue; default: PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp)); @@ -815,6 +901,7 @@ 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) { @@ -924,6 +1011,7 @@ nvlist_xfer(int sock, nvlist_t *nvl) nvlist_destroy(nvl); return (nvlist_recv(sock)); } +#endif nvpair_t * nvlist_first_nvpair(const nvlist_t *nvl) @@ -989,27 +1077,30 @@ bool nvlist_exists(const nvlist_t *nvl, const char *name) { - return (nvlist_existsf(nvl, "%s", name)); + return (nvlist_find(nvl, NV_TYPE_NONE, name) != NULL); } -#define NVLIST_EXISTS(type) \ +#define NVLIST_EXISTS(type, TYPE) \ bool \ nvlist_exists_##type(const nvlist_t *nvl, const char *name) \ { \ \ - return (nvlist_existsf_##type(nvl, "%s", name)); \ + return (nvlist_find(nvl, NV_TYPE_##TYPE, name) != NULL); \ } -NVLIST_EXISTS(null) -NVLIST_EXISTS(bool) -NVLIST_EXISTS(number) -NVLIST_EXISTS(string) -NVLIST_EXISTS(nvlist) -NVLIST_EXISTS(descriptor) -NVLIST_EXISTS(binary) +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 +#ifndef _KERNEL bool nvlist_existsf(const nvlist_t *nvl, const char *namefmt, ...) { @@ -1040,7 +1131,9 @@ NVLIST_EXISTSF(bool) NVLIST_EXISTSF(number) NVLIST_EXISTSF(string) NVLIST_EXISTSF(nvlist) +#ifndef _KERNEL NVLIST_EXISTSF(descriptor) +#endif NVLIST_EXISTSF(binary) #undef NVLIST_EXISTSF @@ -1048,29 +1141,44 @@ NVLIST_EXISTSF(binary) bool nvlist_existsv(const nvlist_t *nvl, const char *namefmt, va_list nameap) { + char *name; + bool exists; + + nv_vasprintf(&name, namefmt, nameap); + if (name == NULL) + return (false); - return (nvlist_findv(nvl, NV_TYPE_NONE, namefmt, nameap) != NULL); + exists = nvlist_exists(nvl, name); + nv_free(name); + return (exists); } -#define NVLIST_EXISTSV(type, TYPE) \ +#define NVLIST_EXISTSV(type) \ bool \ nvlist_existsv_##type(const nvlist_t *nvl, const char *namefmt, \ va_list nameap) \ { \ + char *name; \ + bool exists; \ \ - return (nvlist_findv(nvl, NV_TYPE_##TYPE, namefmt, nameap) != \ - NULL); \ -} - -NVLIST_EXISTSV(null, NULL) -NVLIST_EXISTSV(bool, BOOL) -NVLIST_EXISTSV(number, NUMBER) -NVLIST_EXISTSV(string, STRING) -NVLIST_EXISTSV(nvlist, NVLIST) -NVLIST_EXISTSV(descriptor, DESCRIPTOR) -NVLIST_EXISTSV(binary, BINARY) + vasprintf(&name, namefmt, nameap); \ + if (name == NULL) \ + return (false); \ + exists = nvlist_exists_##type(nvl, name); \ + free(name); \ + return (exists); \ +} + +NVLIST_EXISTSV(null) +NVLIST_EXISTSV(bool) +NVLIST_EXISTSV(number) +NVLIST_EXISTSV(string) +NVLIST_EXISTSV(nvlist) +NVLIST_EXISTSV(descriptor) +NVLIST_EXISTSV(binary) #undef NVLIST_EXISTSV +#endif void nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp) @@ -1080,17 +1188,19 @@ nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp) NVPAIR_ASSERT(nvp); if (nvlist_error(nvl) != 0) { - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } if (nvlist_exists(nvl, nvpair_name(nvp))) { - nvl->nvl_error = errno = EEXIST; + nvl->nvl_error = EEXIST; + RESTORE_ERRNO(nvlist_error(nvl)); return; } newnvp = nvpair_clone(nvp); if (newnvp == NULL) { - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); + nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); + RESTORE_ERRNO(nvlist_error(nvl)); return; } @@ -1142,14 +1252,15 @@ nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, nvpair_t *nvp; if (nvlist_error(nvl) != 0) { - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_create_stringv(name, valuefmt, valueap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + if (nvp == NULL) { + nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); + RESTORE_ERRNO(nvl->nvl_error); + } else nvlist_move_nvpair(nvl, nvp); } @@ -1160,12 +1271,14 @@ nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value) nvlist_addf_nvlist(nvl, value, "%s", name); } +#ifndef _KERNEL void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value) { nvlist_addf_descriptor(nvl, value, "%s", name); } +#endif void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, @@ -1226,6 +1339,7 @@ nvlist_addf_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, va_end(nameap); } +#ifndef _KERNEL void nvlist_addf_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) { @@ -1235,6 +1349,7 @@ nvlist_addf_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) nvlist_addv_descriptor(nvl, value, namefmt, nameap); va_end(nameap); } +#endif void nvlist_addf_binary(nvlist_t *nvl, const void *value, size_t size, @@ -1253,14 +1368,15 @@ nvlist_addv_null(nvlist_t *nvl, const char *namefmt, va_list nameap) nvpair_t *nvp; if (nvlist_error(nvl) != 0) { - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_createv_null(namefmt, nameap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + if (nvp == NULL) { + nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); + RESTORE_ERRNO(nvl->nvl_error); + } else nvlist_move_nvpair(nvl, nvp); } @@ -1270,14 +1386,15 @@ nvlist_addv_bool(nvlist_t *nvl, bool value, const char *namefmt, va_list nameap) nvpair_t *nvp; if (nvlist_error(nvl) != 0) { - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_createv_bool(value, namefmt, nameap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + if (nvp == NULL) { + nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); + RESTORE_ERRNO(nvl->nvl_error); + } else nvlist_move_nvpair(nvl, nvp); } @@ -1288,14 +1405,15 @@ nvlist_addv_number(nvlist_t *nvl, uint64_t value, const char *namefmt, nvpair_t *nvp; if (nvlist_error(nvl) != 0) { - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_createv_number(value, namefmt, nameap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + if (nvp == NULL) { + nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); + RESTORE_ERRNO(nvl->nvl_error); + } else nvlist_move_nvpair(nvl, nvp); } @@ -1306,14 +1424,15 @@ nvlist_addv_string(nvlist_t *nvl, const char *value, const char *namefmt, nvpair_t *nvp; if (nvlist_error(nvl) != 0) { - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_createv_string(value, namefmt, nameap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + if (nvp == NULL) { + nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); + RESTORE_ERRNO(nvl->nvl_error); + } else nvlist_move_nvpair(nvl, nvp); } @@ -1324,17 +1443,19 @@ nvlist_addv_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, nvpair_t *nvp; if (nvlist_error(nvl) != 0) { - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_createv_nvlist(value, namefmt, nameap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + 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_addv_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) @@ -1352,6 +1473,7 @@ nvlist_addv_descriptor(nvlist_t *nvl, int value, const char *namefmt, else nvlist_move_nvpair(nvl, nvp); } +#endif void nvlist_addv_binary(nvlist_t *nvl, const void *value, size_t size, @@ -1360,14 +1482,15 @@ nvlist_addv_binary(nvlist_t *nvl, const void *value, size_t size, nvpair_t *nvp; if (nvlist_error(nvl) != 0) { - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_createv_binary(value, size, namefmt, nameap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + if (nvp == NULL) { + nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); + RESTORE_ERRNO(nvl->nvl_error); + } else nvlist_move_nvpair(nvl, nvp); } @@ -1380,12 +1503,13 @@ nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp) if (nvlist_error(nvl) != 0) { nvpair_free(nvp); - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } if (nvlist_exists(nvl, nvpair_name(nvp))) { nvpair_free(nvp); - nvl->nvl_error = errno = EEXIST; + nvl->nvl_error = EEXIST; + RESTORE_ERRNO(nvl->nvl_error); return; } @@ -1402,7 +1526,9 @@ nvlist_move_##type(nvlist_t *nvl, const char *name, vtype value) \ NVLIST_MOVE(char *, string) NVLIST_MOVE(nvlist_t *, nvlist) +#ifndef _KERNEL NVLIST_MOVE(int, descriptor) +#endif #undef NVLIST_MOVE @@ -1427,7 +1553,9 @@ nvlist_movef_##type(nvlist_t *nvl, vtype value, const char *namefmt, \ NVLIST_MOVEF(char *, string) NVLIST_MOVEF(nvlist_t *, nvlist) +#ifndef _KERNEL NVLIST_MOVEF(int, descriptor) +#endif #undef NVLIST_MOVEF @@ -1449,15 +1577,16 @@ nvlist_movev_string(nvlist_t *nvl, char *value, const char *namefmt, nvpair_t *nvp; if (nvlist_error(nvl) != 0) { - free(value); - errno = nvlist_error(nvl); + nv_free(value); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_movev_string(value, namefmt, nameap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + if (nvp == NULL) { + nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); + RESTORE_ERRNO(nvl->nvl_error); + } else nvlist_move_nvpair(nvl, nvp); } @@ -1470,17 +1599,19 @@ nvlist_movev_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, if (nvlist_error(nvl) != 0) { if (value != NULL && nvlist_get_nvpair_parent(value) != NULL) nvlist_destroy(value); - errno = nvlist_error(nvl); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_movev_nvlist(value, namefmt, nameap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + 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_movev_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) @@ -1499,6 +1630,7 @@ nvlist_movev_descriptor(nvlist_t *nvl, int value, const char *namefmt, else nvlist_move_nvpair(nvl, nvp); } +#endif void nvlist_movev_binary(nvlist_t *nvl, void *value, size_t size, @@ -1507,40 +1639,58 @@ nvlist_movev_binary(nvlist_t *nvl, void *value, size_t size, nvpair_t *nvp; if (nvlist_error(nvl) != 0) { - free(value); - errno = nvlist_error(nvl); + nv_free(value); + RESTORE_ERRNO(nvlist_error(nvl)); return; } nvp = nvpair_movev_binary(value, size, namefmt, nameap); - if (nvp == NULL) - nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM); - else + if (nvp == NULL) { + nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); + RESTORE_ERRNO(nvl->nvl_error); + } else nvlist_move_nvpair(nvl, nvp); } -#define NVLIST_GET(ftype, type) \ +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; \ \ - return (nvlist_getf_##type(nvl, "%s", name)); \ + 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(const nvpair_t *, nvpair) -NVLIST_GET(bool, bool) -NVLIST_GET(uint64_t, number) -NVLIST_GET(const char *, string) -NVLIST_GET(const nvlist_t *, nvlist) -NVLIST_GET(int, descriptor) +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; - return (nvlist_getf_binary(nvl, sizep, "%s", name)); + 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_GETF(ftype, type) \ @@ -1557,7 +1707,7 @@ nvlist_getf_##type(const nvlist_t *nvl, const char *namefmt, ...) \ return (value); \ } -NVLIST_GETF(const nvpair_t *, nvpair) +#ifndef _KERNEL NVLIST_GETF(bool, bool) NVLIST_GETF(uint64_t, number) NVLIST_GETF(const char *, string) @@ -1579,27 +1729,21 @@ nvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) return (value); } -const nvpair_t * -nvlist_getv_nvpair(const nvlist_t *nvl, const char *namefmt, va_list nameap) -{ - - return (nvlist_findv(nvl, NV_TYPE_NONE, namefmt, nameap)); -} - #define NVLIST_GETV(ftype, type, TYPE) \ ftype \ nvlist_getv_##type(const nvlist_t *nvl, const char *namefmt, \ va_list nameap) \ { \ - va_list cnameap; \ - const nvpair_t *nvp; \ + char *name; \ + ftype value; \ \ - va_copy(cnameap, nameap); \ - nvp = nvlist_findv(nvl, NV_TYPE_##TYPE, namefmt, cnameap); \ - va_end(cnameap); \ - if (nvp == NULL) \ - nvlist_report_missing(NV_TYPE_##TYPE, namefmt, nameap); \ - return (nvpair_get_##type(nvp)); \ + vasprintf(&name, namefmt, nameap); \ + if (name == NULL) \ + nvlist_report_missing(NV_TYPE_##TYPE, ""); \ + value = nvlist_get_##type(nvl, name); \ + free(name); \ + \ + return (value); \ } NVLIST_GETV(bool, bool, BOOL) @@ -1614,40 +1758,59 @@ const void * nvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) { - va_list cnameap; - const nvpair_t *nvp; + char *name; + const void *binary; - va_copy(cnameap, nameap); - nvp = nvlist_findv(nvl, NV_TYPE_BINARY, namefmt, cnameap); - va_end(cnameap); - if (nvp == NULL) - nvlist_report_missing(NV_TYPE_BINARY, namefmt, nameap); + nv_vasprintf(&name, namefmt, nameap); + if (name == NULL) + nvlist_report_missing(NV_TYPE_BINARY, ""); - return (nvpair_get_binary(nvp, sizep)); + binary = nvlist_get_binary(nvl, name, sizep); + nv_free(name); + return (binary); } +#endif -#define NVLIST_TAKE(ftype, type) \ +#define NVLIST_TAKE(ftype, type, TYPE) \ ftype \ nvlist_take_##type(nvlist_t *nvl, const char *name) \ { \ + nvpair_t *nvp; \ + ftype value; \ \ - return (nvlist_takef_##type(nvl, "%s", name)); \ + 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(nvpair_t *, nvpair) -NVLIST_TAKE(bool, bool) -NVLIST_TAKE(uint64_t, number) -NVLIST_TAKE(char *, string) -NVLIST_TAKE(nvlist_t *, nvlist) -NVLIST_TAKE(int, descriptor) +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); - return (nvlist_takef_binary(nvl, sizep, "%s", name)); + value = (void *)(intptr_t)nvpair_get_binary(nvp, sizep); + nvlist_remove_nvpair(nvl, nvp); + nvpair_free_structure(nvp); + return (value); } #define NVLIST_TAKEF(ftype, type) \ @@ -1664,7 +1827,7 @@ nvlist_takef_##type(nvlist_t *nvl, const char *namefmt, ...) \ return (value); \ } -NVLIST_TAKEF(nvpair_t *, nvpair) +#ifndef _KERNEL NVLIST_TAKEF(bool, bool) NVLIST_TAKEF(uint64_t, number) NVLIST_TAKEF(char *, string) @@ -1686,33 +1849,18 @@ nvlist_takef_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) return (value); } -nvpair_t * -nvlist_takev_nvpair(nvlist_t *nvl, const char *namefmt, va_list nameap) -{ - nvpair_t *nvp; - - nvp = nvlist_findv(nvl, NV_TYPE_NONE, namefmt, nameap); - if (nvp != NULL) - nvlist_remove_nvpair(nvl, nvp); - return (nvp); -} - #define NVLIST_TAKEV(ftype, type, TYPE) \ ftype \ nvlist_takev_##type(nvlist_t *nvl, const char *namefmt, va_list nameap) \ { \ - va_list cnameap; \ - nvpair_t *nvp; \ + char *name; \ ftype value; \ \ - va_copy(cnameap, nameap); \ - nvp = nvlist_findv(nvl, NV_TYPE_##TYPE, namefmt, cnameap); \ - va_end(cnameap); \ - if (nvp == NULL) \ - nvlist_report_missing(NV_TYPE_##TYPE, namefmt, nameap); \ - value = (ftype)(intptr_t)nvpair_get_##type(nvp); \ - nvlist_remove_nvpair(nvl, nvp); \ - nvpair_free_structure(nvp); \ + vasprintf(&name, namefmt, nameap); \ + if (name == NULL) \ + nvlist_report_missing(NV_TYPE_##TYPE, ""); \ + value = nvlist_take_##type(nvl, name); \ + free(name); \ return (value); \ } @@ -1728,21 +1876,18 @@ void * nvlist_takev_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) { - va_list cnameap; - nvpair_t *nvp; - void *value; + char *name; + void *binary; - va_copy(cnameap, nameap); - nvp = nvlist_findv(nvl, NV_TYPE_BINARY, namefmt, cnameap); - va_end(cnameap); - if (nvp == NULL) - nvlist_report_missing(NV_TYPE_BINARY, namefmt, nameap); + nv_vasprintf(&name, namefmt, nameap); + if (name == NULL) + nvlist_report_missing(NV_TYPE_BINARY, ""); - value = (void *)(intptr_t)nvpair_get_binary(nvp, sizep); - nvlist_remove_nvpair(nvl, nvp); - nvpair_free_structure(nvp); - return (value); + binary = nvlist_take_binary(nvl, name, sizep); + nv_free(name); + return (binary); } +#endif void nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp) @@ -1759,27 +1904,30 @@ void nvlist_free(nvlist_t *nvl, const char *name) { - nvlist_freef(nvl, "%s", name); + nvlist_free_type(nvl, name, NV_TYPE_NONE); } -#define NVLIST_FREE(type) \ +#define NVLIST_FREE(type, TYPE) \ void \ nvlist_free_##type(nvlist_t *nvl, const char *name) \ { \ \ - nvlist_freef_##type(nvl, "%s", name); \ + nvlist_free_type(nvl, name, NV_TYPE_##TYPE); \ } -NVLIST_FREE(null) -NVLIST_FREE(bool) -NVLIST_FREE(number) -NVLIST_FREE(string) -NVLIST_FREE(nvlist) -NVLIST_FREE(descriptor) -NVLIST_FREE(binary) +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 +#ifndef _KERNEL void nvlist_freef(nvlist_t *nvl, const char *namefmt, ...) { @@ -1822,8 +1970,13 @@ nvlist_freev(nvlist_t *nvl, const char *namefmt, va_list nameap) void \ nvlist_freev_##type(nvlist_t *nvl, const char *namefmt, va_list nameap) \ { \ + char *name; \ \ - nvlist_freev_type(nvl, NV_TYPE_##TYPE, namefmt, nameap); \ + vasprintf(&name, namefmt, nameap); \ + if (name == NULL) \ + nvlist_report_missing(NV_TYPE_##TYPE, ""); \ + nvlist_free_##type(nvl, name); \ + free(name); \ } NVLIST_FREEV(null, NULL) @@ -1834,6 +1987,7 @@ NVLIST_FREEV(nvlist, NVLIST) NVLIST_FREEV(descriptor, DESCRIPTOR) NVLIST_FREEV(binary, BINARY) #undef NVLIST_FREEV +#endif void nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp) diff --git a/external/libnv/nvpair.c b/external/libnv/subr_nvpair.c similarity index 87% rename from external/libnv/nvpair.c rename to external/libnv/subr_nvpair.c index 3688152401..f887e54733 100644 --- a/external/libnv/nvpair.c +++ b/external/libnv/subr_nvpair.c @@ -28,12 +28,22 @@ */ #include -__FBSDID("$FreeBSD: head/lib/libnv/nvpair.c 271847 2014-09-18 22:34:52Z pjd $"); +__FBSDID("$FreeBSD: head/sys/kern/subr_nvpair.c 279439 2015-03-01 00:34:27Z rstone $"); #include #include #include +#ifdef _KERNEL + +#include +#include +#include +#include + +#include + +#else #include #include #include @@ -43,22 +53,30 @@ __FBSDID("$FreeBSD: head/lib/libnv/nvpair.c 271847 2014-09-18 22:34:52Z pjd $"); #include #include +#include "common_impl.h" +#endif + #ifdef HAVE_PJDLOG #include #endif -#include "common_impl.h" -#include "nv.h" -#include "nv_impl.h" -#include "nvlist_impl.h" -#include "nvpair_impl.h" +#include +#include +#include +#include #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 #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 { @@ -184,10 +202,12 @@ nvpair_clone(const nvpair_t *nvp) 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); @@ -327,6 +347,7 @@ nvpair_pack_nvlist_up(unsigned char *ptr, size_t *leftp) return (ptr); } +#ifndef _KERNEL unsigned char * nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr, int64_t *fdidxp, size_t *leftp) @@ -356,6 +377,7 @@ nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr, int64_t *fdidxp, return (ptr); } +#endif unsigned char * nvpair_pack_binary(const nvpair_t *nvp, unsigned char *ptr, size_t *leftp) @@ -389,7 +411,7 @@ nvpair_init_datasize(nvpair_t *nvp) } const unsigned char * -nvpair_unpack_header(int flags, nvpair_t *nvp, const unsigned char *ptr, +nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr, size_t *leftp) { struct nvpair_header nvphdr; @@ -411,12 +433,12 @@ nvpair_unpack_header(int flags, nvpair_t *nvp, const unsigned char *ptr, } #if BYTE_ORDER == BIG_ENDIAN - if ((flags & NV_FLAG_BIG_ENDIAN) == 0) { + if (!isbe) { nvphdr.nvph_namesize = le16toh(nvphdr.nvph_namesize); nvphdr.nvph_datasize = le64toh(nvphdr.nvph_datasize); } #else - if ((flags & NV_FLAG_BIG_ENDIAN) != 0) { + if (isbe) { nvphdr.nvph_namesize = be16toh(nvphdr.nvph_namesize); nvphdr.nvph_datasize = be64toh(nvphdr.nvph_datasize); } @@ -446,19 +468,19 @@ nvpair_unpack_header(int flags, nvpair_t *nvp, const unsigned char *ptr, return (ptr); failed: - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } const unsigned char * -nvpair_unpack_null(int flags __unused, nvpair_t *nvp, const unsigned char *ptr, +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) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } @@ -466,7 +488,7 @@ nvpair_unpack_null(int flags __unused, nvpair_t *nvp, const unsigned char *ptr, } const unsigned char * -nvpair_unpack_bool(int flags __unused, nvpair_t *nvp, const unsigned char *ptr, +nvpair_unpack_bool(bool isbe __unused, nvpair_t *nvp, const unsigned char *ptr, size_t *leftp) { uint8_t value; @@ -474,11 +496,11 @@ nvpair_unpack_bool(int flags __unused, nvpair_t *nvp, const unsigned char *ptr, PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BOOL); if (nvp->nvp_datasize != sizeof(value)) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } if (*leftp < sizeof(value)) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } @@ -487,7 +509,7 @@ nvpair_unpack_bool(int flags __unused, nvpair_t *nvp, const unsigned char *ptr, *leftp -= sizeof(value); if (value != 0 && value != 1) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } @@ -497,22 +519,22 @@ nvpair_unpack_bool(int flags __unused, nvpair_t *nvp, const unsigned char *ptr, } const unsigned char * -nvpair_unpack_number(int flags, nvpair_t *nvp, const unsigned char *ptr, +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)) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } if (*leftp < sizeof(uint64_t)) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } - if ((flags & NV_FLAG_BIG_ENDIAN) != 0) + if (isbe) nvp->nvp_data = be64dec(ptr); else nvp->nvp_data = le64dec(ptr); @@ -523,24 +545,24 @@ nvpair_unpack_number(int flags, nvpair_t *nvp, const unsigned char *ptr, } const unsigned char * -nvpair_unpack_string(int flags __unused, nvpair_t *nvp, +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) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } if (strnlen((const char *)ptr, nvp->nvp_datasize) != nvp->nvp_datasize - 1) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } - nvp->nvp_data = (uint64_t)(uintptr_t)strdup((const char *)ptr); + nvp->nvp_data = (uint64_t)(uintptr_t)nv_strdup((const char *)ptr); if (nvp->nvp_data == 0) return (NULL); @@ -551,15 +573,15 @@ nvpair_unpack_string(int flags __unused, nvpair_t *nvp, } const unsigned char * -nvpair_unpack_nvlist(int *flagsp, nvpair_t *nvp, const unsigned char *ptr, - size_t *leftp, size_t nfds, nvlist_t **child) +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) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } @@ -567,7 +589,7 @@ nvpair_unpack_nvlist(int *flagsp, nvpair_t *nvp, const unsigned char *ptr, if (value == NULL) return (NULL); - ptr = nvlist_unpack_header(value, ptr, nfds, flagsp, leftp); + ptr = nvlist_unpack_header(value, ptr, nfds, NULL, leftp); if (ptr == NULL) return (NULL); @@ -577,8 +599,9 @@ nvpair_unpack_nvlist(int *flagsp, nvpair_t *nvp, const unsigned char *ptr, return (ptr); } +#ifndef _KERNEL const unsigned char * -nvpair_unpack_descriptor(int flags, nvpair_t *nvp, const unsigned char *ptr, +nvpair_unpack_descriptor(bool isbe, nvpair_t *nvp, const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds) { int64_t idx; @@ -594,7 +617,7 @@ nvpair_unpack_descriptor(int flags, nvpair_t *nvp, const unsigned char *ptr, return (NULL); } - if ((flags & NV_FLAG_BIG_ENDIAN) != 0) + if (isbe) idx = be64dec(ptr); else idx = le64dec(ptr); @@ -616,9 +639,10 @@ nvpair_unpack_descriptor(int flags, nvpair_t *nvp, const unsigned char *ptr, return (ptr); } +#endif const unsigned char * -nvpair_unpack_binary(int flags __unused, nvpair_t *nvp, +nvpair_unpack_binary(bool isbe __unused, nvpair_t *nvp, const unsigned char *ptr, size_t *leftp) { void *value; @@ -626,11 +650,11 @@ nvpair_unpack_binary(int flags __unused, nvpair_t *nvp, PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BINARY); if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } - value = malloc(nvp->nvp_datasize); + value = nv_malloc(nvp->nvp_datasize); if (value == NULL) return (NULL); @@ -644,20 +668,20 @@ nvpair_unpack_binary(int flags __unused, nvpair_t *nvp, } const unsigned char * -nvpair_unpack(int flags, const unsigned char *ptr, size_t *leftp, +nvpair_unpack(bool isbe, const unsigned char *ptr, size_t *leftp, nvpair_t **nvpp) { nvpair_t *nvp, *tmp; - nvp = calloc(1, sizeof(*nvp) + NV_NAME_MAX); + nvp = nv_calloc(1, sizeof(*nvp) + NV_NAME_MAX); if (nvp == NULL) return (NULL); nvp->nvp_name = (char *)(nvp + 1); - ptr = nvpair_unpack_header(flags, nvp, ptr, leftp); + ptr = nvpair_unpack_header(isbe, nvp, ptr, leftp); if (ptr == NULL) goto failed; - tmp = realloc(nvp, sizeof(*nvp) + strlen(nvp->nvp_name) + 1); + tmp = nv_realloc(nvp, sizeof(*nvp) + strlen(nvp->nvp_name) + 1); if (tmp == NULL) goto failed; nvp = tmp; @@ -669,7 +693,7 @@ nvpair_unpack(int flags, const unsigned char *ptr, size_t *leftp, *nvpp = nvp; return (ptr); failed: - free(nvp); + nv_free(nvp); return (NULL); } @@ -701,18 +725,18 @@ nvpair_allocv(int type, uint64_t data, size_t datasize, const char *namefmt, PJDLOG_ASSERT(type >= NV_TYPE_FIRST && type <= NV_TYPE_LAST); - namelen = vasprintf(&name, namefmt, nameap); + namelen = nv_vasprintf(&name, namefmt, nameap); if (namelen < 0) return (NULL); PJDLOG_ASSERT(namelen > 0); if (namelen >= NV_NAME_MAX) { - free(name); - errno = ENAMETOOLONG; + nv_free(name); + RESTORE_ERRNO(ENAMETOOLONG); return (NULL); } - nvp = calloc(1, sizeof(*nvp) + namelen + 1); + nvp = nv_calloc(1, sizeof(*nvp) + namelen + 1); if (nvp != NULL) { nvp->nvp_name = (char *)(nvp + 1); memcpy(nvp->nvp_name, name, namelen + 1); @@ -721,7 +745,7 @@ nvpair_allocv(int type, uint64_t data, size_t datasize, const char *namefmt, nvp->nvp_datasize = datasize; nvp->nvp_magic = NVPAIR_MAGIC; } - free(name); + nv_free(name); return (nvp); }; @@ -774,12 +798,12 @@ nvpair_create_stringv(const char *name, const char *valuefmt, va_list valueap) char *str; int len; - len = vasprintf(&str, valuefmt, valueap); + len = nv_vasprintf(&str, valuefmt, valueap); if (len < 0) return (NULL); nvp = nvpair_create_string(name, str); if (nvp == NULL) - free(str); + nv_free(str); return (nvp); } @@ -790,12 +814,14 @@ nvpair_create_nvlist(const char *name, const nvlist_t *value) return (nvpair_createf_nvlist(value, "%s", name)); } +#ifndef _KERNEL nvpair_t * nvpair_create_descriptor(const char *name, int value) { return (nvpair_createf_descriptor(value, "%s", name)); } +#endif nvpair_t * nvpair_create_binary(const char *name, const void *value, size_t size) @@ -869,6 +895,7 @@ nvpair_createf_nvlist(const nvlist_t *value, const char *namefmt, ...) return (nvp); } +#ifndef _KERNEL nvpair_t * nvpair_createf_descriptor(int value, const char *namefmt, ...) { @@ -881,6 +908,7 @@ nvpair_createf_descriptor(int value, const char *namefmt, ...) return (nvp); } +#endif nvpair_t * nvpair_createf_binary(const void *value, size_t size, const char *namefmt, ...) @@ -926,11 +954,11 @@ nvpair_createv_string(const char *value, const char *namefmt, va_list nameap) char *data; if (value == NULL) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } - data = strdup(value); + data = nv_strdup(value); if (data == NULL) return (NULL); size = strlen(value) + 1; @@ -938,7 +966,7 @@ nvpair_createv_string(const char *value, const char *namefmt, va_list nameap) nvp = nvpair_allocv(NV_TYPE_STRING, (uint64_t)(uintptr_t)data, size, namefmt, nameap); if (nvp == NULL) - free(data); + nv_free(data); return (nvp); } @@ -951,7 +979,7 @@ nvpair_createv_nvlist(const nvlist_t *value, const char *namefmt, nvpair_t *nvp; if (value == NULL) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } @@ -969,6 +997,7 @@ nvpair_createv_nvlist(const nvlist_t *value, const char *namefmt, return (nvp); } +#ifndef _KERNEL nvpair_t * nvpair_createv_descriptor(int value, const char *namefmt, va_list nameap) { @@ -990,6 +1019,7 @@ nvpair_createv_descriptor(int value, const char *namefmt, va_list nameap) return (nvp); } +#endif nvpair_t * nvpair_createv_binary(const void *value, size_t size, const char *namefmt, @@ -999,11 +1029,11 @@ nvpair_createv_binary(const void *value, size_t size, const char *namefmt, void *data; if (value == NULL || size == 0) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } - data = malloc(size); + data = nv_malloc(size); if (data == NULL) return (NULL); memcpy(data, value, size); @@ -1011,7 +1041,7 @@ nvpair_createv_binary(const void *value, size_t size, const char *namefmt, nvp = nvpair_allocv(NV_TYPE_BINARY, (uint64_t)(uintptr_t)data, size, namefmt, nameap); if (nvp == NULL) - free(data); + nv_free(data); return (nvp); } @@ -1030,12 +1060,14 @@ nvpair_move_nvlist(const char *name, nvlist_t *value) return (nvpair_movef_nvlist(value, "%s", name)); } +#ifndef _KERNEL nvpair_t * nvpair_move_descriptor(const char *name, int value) { return (nvpair_movef_descriptor(value, "%s", name)); } +#endif nvpair_t * nvpair_move_binary(const char *name, void *value, size_t size) @@ -1070,6 +1102,7 @@ nvpair_movef_nvlist(nvlist_t *value, const char *namefmt, ...) return (nvp); } +#ifndef _KERNEL nvpair_t * nvpair_movef_descriptor(int value, const char *namefmt, ...) { @@ -1082,6 +1115,7 @@ nvpair_movef_descriptor(int value, const char *namefmt, ...) return (nvp); } +#endif nvpair_t * nvpair_movef_binary(void *value, size_t size, const char *namefmt, ...) @@ -1100,16 +1134,20 @@ nvpair_t * nvpair_movev_string(char *value, const char *namefmt, va_list nameap) { nvpair_t *nvp; + int serrno; if (value == NULL) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } nvp = nvpair_allocv(NV_TYPE_STRING, (uint64_t)(uintptr_t)value, strlen(value) + 1, namefmt, nameap); - if (nvp == NULL) - free(value); + if (nvp == NULL) { + SAVE_ERRNO(serrno); + nv_free(value); + RESTORE_ERRNO(serrno); + } return (nvp); } @@ -1120,7 +1158,13 @@ nvpair_movev_nvlist(nvlist_t *value, const char *namefmt, va_list nameap) nvpair_t *nvp; if (value == NULL || nvlist_get_nvpair_parent(value) != NULL) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); + return (NULL); + } + + if (nvlist_error(value) != 0) { + RESTORE_ERRNO(nvlist_error(value)); + nvlist_destroy(value); return (NULL); } @@ -1134,31 +1178,51 @@ nvpair_movev_nvlist(nvlist_t *value, const char *namefmt, va_list nameap) return (nvp); } +#ifndef _KERNEL nvpair_t * nvpair_movev_descriptor(int value, const char *namefmt, va_list nameap) { + nvpair_t *nvp; + int serrno; if (value < 0 || !fd_is_valid(value)) { errno = EBADF; return (NULL); } - return (nvpair_allocv(NV_TYPE_DESCRIPTOR, (uint64_t)value, - sizeof(int64_t), namefmt, nameap)); + nvp = nvpair_allocv(NV_TYPE_DESCRIPTOR, (uint64_t)value, + sizeof(int64_t), namefmt, nameap); + if (nvp == NULL) { + serrno = errno; + close(value); + errno = serrno; + } + + return (nvp); } +#endif nvpair_t * nvpair_movev_binary(void *value, size_t size, const char *namefmt, va_list nameap) { + nvpair_t *nvp; + int serrno; if (value == NULL || size == 0) { - errno = EINVAL; + RESTORE_ERRNO(EINVAL); return (NULL); } - return (nvpair_allocv(NV_TYPE_BINARY, (uint64_t)(uintptr_t)value, size, - namefmt, nameap)); + nvp = nvpair_allocv(NV_TYPE_BINARY, (uint64_t)(uintptr_t)value, size, + namefmt, nameap); + if (nvp == NULL) { + SAVE_ERRNO(serrno); + nv_free(value); + RESTORE_ERRNO(serrno); + } + + return (nvp); } bool @@ -1199,6 +1263,7 @@ nvpair_get_nvlist(const nvpair_t *nvp) return ((const nvlist_t *)(intptr_t)nvp->nvp_data); } +#ifndef _KERNEL int nvpair_get_descriptor(const nvpair_t *nvp) { @@ -1208,6 +1273,7 @@ nvpair_get_descriptor(const nvpair_t *nvp) return ((int)nvp->nvp_data); } +#endif const void * nvpair_get_binary(const nvpair_t *nvp, size_t *sizep) @@ -1230,20 +1296,22 @@ nvpair_free(nvpair_t *nvp) 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: - free((char *)(intptr_t)nvp->nvp_data); + nv_free((char *)(intptr_t)nvp->nvp_data); break; case NV_TYPE_BINARY: - free((void *)(intptr_t)nvp->nvp_data); + nv_free((void *)(intptr_t)nvp->nvp_data); break; } - free(nvp); + nv_free(nvp); } void @@ -1254,7 +1322,7 @@ nvpair_free_structure(nvpair_t *nvp) PJDLOG_ASSERT(nvp->nvp_list == NULL); nvp->nvp_magic = 0; - free(nvp); + nv_free(nvp); } const char * diff --git a/external/libnv/dnv.h b/external/libnv/sys/dnv.h similarity index 97% rename from external/libnv/dnv.h rename to external/libnv/sys/dnv.h index c4ba65b1f4..fcf0512fcd 100644 --- a/external/libnv/dnv.h +++ b/external/libnv/sys/dnv.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: head/lib/libnv/dnv.h 258065 2013-11-12 19:39:14Z pjd $ + * $FreeBSD: head/sys/sys/dnv.h 279439 2015-03-01 00:34:27Z rstone $ */ #ifndef _DNV_H_ @@ -34,9 +34,11 @@ #include +#ifndef _KERNEL #include #include #include +#endif #ifndef _NVLIST_T_DECLARED #define _NVLIST_T_DECLARED @@ -45,6 +47,8 @@ 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 @@ -60,6 +64,7 @@ const nvlist_t *dnvlist_get_nvlist(const nvlist_t *nvl, const char *name, const 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); @@ -73,6 +78,7 @@ const char *dnvlist_getv_string(const nvlist_t *nvl, const char *defval, const c 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 @@ -89,6 +95,7 @@ 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); @@ -102,5 +109,8 @@ char *dnvlist_takev_string(nvlist_t *nvl, char *defval, const char *namefmt, va_ 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/external/libnv/nv.h b/external/libnv/sys/nv.h similarity index 93% rename from external/libnv/nv.h rename to external/libnv/sys/nv.h index 4caffae5e8..fd4e3725db 100644 --- a/external/libnv/nv.h +++ b/external/libnv/sys/nv.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: head/lib/libnv/nv.h 271579 2014-09-14 09:30:09Z pjd $ + * $FreeBSD: head/sys/sys/nv.h 279439 2015-03-01 00:34:27Z rstone $ */ #ifndef _NV_H_ @@ -34,10 +34,12 @@ #include +#ifndef _KERNEL #include #include #include #include +#endif #ifndef _NVLIST_T_DECLARED #define _NVLIST_T_DECLARED @@ -63,15 +65,24 @@ typedef struct nvlist nvlist_t; */ #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); +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); @@ -83,7 +94,7 @@ 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); +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 @@ -98,7 +109,9 @@ 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); /* @@ -112,9 +125,13 @@ 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); /* @@ -124,7 +141,9 @@ void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_ 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); /* @@ -137,7 +156,9 @@ 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); /* @@ -150,7 +171,9 @@ 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); /* @@ -166,14 +189,21 @@ 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); /* * Below are the same functions, but which operate on format strings and * variable argument lists. + * + * Functions that are not inserting a new pair into the nvlist cannot handle + * a failure to allocate the memory to hold the new name. Therefore these + * functions are not provided in the kernel. */ +#ifndef _KERNEL bool nvlist_existsf(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3); bool nvlist_existsf_type(const nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4); @@ -195,33 +225,47 @@ bool nvlist_existsv_string(const nvlist_t *nvl, const char *namefmt, va_list nam bool nvlist_existsv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0); bool nvlist_existsv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0); bool nvlist_existsv_binary(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0); +#endif void nvlist_addf_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3); void nvlist_addf_bool(nvlist_t *nvl, bool value, const char *namefmt, ...) __printflike(3, 4); void nvlist_addf_number(nvlist_t *nvl, uint64_t value, const char *namefmt, ...) __printflike(3, 4); void nvlist_addf_string(nvlist_t *nvl, const char *value, const char *namefmt, ...) __printflike(3, 4); void nvlist_addf_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, ...) __printflike(3, 4); +#ifndef _KERNEL void nvlist_addf_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4); +#endif void nvlist_addf_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, ...) __printflike(4, 5); +#if !defined(_KERNEL) || defined(_VA_LIST_DECLARED) void nvlist_addv_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0); void nvlist_addv_bool(nvlist_t *nvl, bool value, const char *namefmt, va_list nameap) __printflike(3, 0); void nvlist_addv_number(nvlist_t *nvl, uint64_t value, const char *namefmt, va_list nameap) __printflike(3, 0); void nvlist_addv_string(nvlist_t *nvl, const char *value, const char *namefmt, va_list nameap) __printflike(3, 0); void nvlist_addv_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0); +#ifndef _KERNEL void nvlist_addv_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0); +#endif void nvlist_addv_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0); +#endif void nvlist_movef_string(nvlist_t *nvl, char *value, const char *namefmt, ...) __printflike(3, 4); void nvlist_movef_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, ...) __printflike(3, 4); +#ifndef _KERNEL void nvlist_movef_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4); +#endif void nvlist_movef_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, ...) __printflike(4, 5); +#if !defined(_KERNEL) || defined(_VA_LIST_DECLARED) void nvlist_movev_string(nvlist_t *nvl, char *value, const char *namefmt, va_list nameap) __printflike(3, 0); void nvlist_movev_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0); +#ifndef _KERNEL void nvlist_movev_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0); +#endif void nvlist_movev_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0); +#endif +#ifndef _KERNEL bool nvlist_getf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3); uint64_t nvlist_getf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3); const char *nvlist_getf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3); @@ -271,5 +315,8 @@ void nvlist_freev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __p void nvlist_freev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0); void nvlist_freev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0); void nvlist_freev_binary(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0); +#endif /* _KERNEL */ + +__END_DECLS #endif /* !_NV_H_ */ diff --git a/external/libnv/nv_impl.h b/external/libnv/sys/nv_impl.h similarity index 85% rename from external/libnv/nv_impl.h rename to external/libnv/sys/nv_impl.h index ed5312dab7..944ba1473a 100644 --- a/external/libnv/nv_impl.h +++ b/external/libnv/sys/nv_impl.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: head/lib/libnv/nv_impl.h 271579 2014-09-14 09:30:09Z pjd $ + * $FreeBSD: head/sys/sys/nv_impl.h 279439 2015-03-01 00:34:27Z rstone $ */ #ifndef _NV_IMPL_H_ @@ -46,6 +46,37 @@ typedef struct nvpair nvpair_t; #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); @@ -97,14 +128,6 @@ const void *nvpair_get_binary(const nvpair_t *nvp, size_t *sizep); void nvpair_free(nvpair_t *nvp); -const nvpair_t *nvlist_getf_nvpair(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3); - -const nvpair_t *nvlist_getv_nvpair(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0); - -nvpair_t *nvlist_takef_nvpair(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3); - -nvpair_t *nvlist_takev_nvpair(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0); - nvpair_t *nvpair_createf_null(const char *namefmt, ...) __printflike(1, 2); nvpair_t *nvpair_createf_bool(bool value, const char *namefmt, ...) __printflike(2, 3); nvpair_t *nvpair_createf_number(uint64_t value, const char *namefmt, ...) __printflike(2, 3); diff --git a/external/libnv/nvlist_impl.h b/external/libnv/sys/nvlist_impl.h similarity index 91% rename from external/libnv/nvlist_impl.h rename to external/libnv/sys/nvlist_impl.h index 7e7151b74a..1576afd5d2 100644 --- a/external/libnv/nvlist_impl.h +++ b/external/libnv/sys/nvlist_impl.h @@ -26,13 +26,15 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: head/lib/libnv/nvlist_impl.h 271579 2014-09-14 09:30:09Z pjd $ + * $FreeBSD: head/sys/sys/nvlist_impl.h 279439 2015-03-01 00:34:27Z rstone $ */ #ifndef _NVLIST_IMPL_H_ #define _NVLIST_IMPL_H_ +#ifndef _KERNEL #include +#endif #include "nv.h" @@ -42,6 +44,6 @@ nvlist_t *nvlist_xunpack(const void *buf, size_t size, const int *fds, 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, int *flagsp, size_t *leftp); + const unsigned char *ptr, size_t nfds, bool *isbep, size_t *leftp); #endif /* !_NVLIST_IMPL_H_ */ diff --git a/external/libnv/nvpair_impl.h b/external/libnv/sys/nvpair_impl.h similarity index 83% rename from external/libnv/nvpair_impl.h rename to external/libnv/sys/nvpair_impl.h index a266621725..fbcd28ed3d 100644 --- a/external/libnv/nvpair_impl.h +++ b/external/libnv/sys/nvpair_impl.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: head/lib/libnv/nvpair_impl.h 271579 2014-09-14 09:30:09Z pjd $ + * $FreeBSD: head/sys/sys/nvpair_impl.h 279439 2015-03-01 00:34:27Z rstone $ */ #ifndef _NVPAIR_IMPL_H_ @@ -34,7 +34,9 @@ #include +#ifndef _KERNEL #include +#endif #include "nv.h" @@ -48,7 +50,7 @@ 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(int flags, const unsigned char *ptr, +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); @@ -72,21 +74,21 @@ unsigned char *nvpair_pack_binary(const nvpair_t *nvp, unsigned char *ptr, unsigned char *nvpair_pack_nvlist_up(unsigned char *ptr, size_t *leftp); /* Unpack data functions. */ -const unsigned char *nvpair_unpack_header(int flags, nvpair_t *nvp, +const unsigned char *nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr, size_t *leftp); -const unsigned char *nvpair_unpack_null(int flags, nvpair_t *nvp, +const unsigned char *nvpair_unpack_null(bool isbe, nvpair_t *nvp, const unsigned char *ptr, size_t *leftp); -const unsigned char *nvpair_unpack_bool(int flags, nvpair_t *nvp, +const unsigned char *nvpair_unpack_bool(bool isbe, nvpair_t *nvp, const unsigned char *ptr, size_t *leftp); -const unsigned char *nvpair_unpack_number(int flags, nvpair_t *nvp, +const unsigned char *nvpair_unpack_number(bool isbe, nvpair_t *nvp, const unsigned char *ptr, size_t *leftp); -const unsigned char *nvpair_unpack_string(int flags, nvpair_t *nvp, +const unsigned char *nvpair_unpack_string(bool isbe, nvpair_t *nvp, const unsigned char *ptr, size_t *leftp); -const unsigned char *nvpair_unpack_nvlist(int *flagsp, nvpair_t *nvp, +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(int flags, nvpair_t *nvp, +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(int flags, nvpair_t *nvp, +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/external/libnv/tests/dnv_tests.cc b/external/libnv/tests/dnv_tests.cc new file mode 100644 index 0000000000..8f46f9c1cc --- /dev/null +++ b/external/libnv/tests/dnv_tests.cc @@ -0,0 +1,577 @@ +/*- + * 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 +__FBSDID("$FreeBSD: head/lib/libnv/tests/dnv_tests.cc 279760 2015-03-08 00:30:52Z dim $"); + +#include +#include +#include + +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_getf_bool(nvl, false, "%c%s", 'n', "ame"), 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_getf_bool(nvl, true, "%d", 123), true); + + nvlist_add_bool(nvl, key, true); + + ATF_REQUIRE_EQ(dnvlist_get_bool(nvl, "otherkey", true), true); + ATF_REQUIRE_EQ(dnvlist_getf_bool(nvl, false, "%d%c", 12, 'c'), 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_getf_number(nvl, 65, "key"), 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_getf_number(nvl, 12, "%s", key), 12); + + nvlist_add_number(nvl, key, 24841); + + ATF_REQUIRE_EQ(dnvlist_get_number(nvl, "hthth", 184), 184); + ATF_REQUIRE_EQ(dnvlist_getf_number(nvl, 5641, "%d", 1234), 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_getf_string(nvl, "rs", "%s", key); + 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_getf_string(nvl, "d", "%s", key); + 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_getf_string(nvl, "5", "%s", "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)); + + actual_value = dnvlist_getf_nvlist(nvl, NULL, "%s", key); + 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); + ATF_REQUIRE_EQ(dnvlist_getf_nvlist(nvl, dummy, "%s", key), dummy); + + nvlist_move_nvlist(nvl, key, nvlist_create(0)); + ATF_REQUIRE_EQ(dnvlist_get_nvlist(nvl, "456", dummy), dummy); + ATF_REQUIRE_EQ(dnvlist_getf_nvlist(nvl, dummy, "%s", "gh"), 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); + + actual_value = dnvlist_getf_binary(nvl, &actual_size, "g", 1, "%s", k); + 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_getf_binary(nvl, &actual_size, default_value, + default_size, "%s", key); + 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_getf_binary(nvl, &actual_size, default_value, + default_size, "s"); + 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(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/external/libnv/tests/nv_tests.cc b/external/libnv/tests/nv_tests.cc new file mode 100644 index 0000000000..fcdc8683ca --- /dev/null +++ b/external/libnv/tests/nv_tests.cc @@ -0,0 +1,1254 @@ +/*- + * 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 +__FBSDID("$FreeBSD: head/lib/libnv/tests/nv_tests.cc 279760 2015-03-08 00:30:52Z dim $"); + +#include +#include + +#include +#include +#include +#include +#include + +/* + * 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(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_existsf(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists_null(nvl, key)); + ATF_REQUIRE(nvlist_existsf_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(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_existsf(nvl, "%s%s", "na", "me")); + ATF_REQUIRE(nvlist_exists_bool(nvl, key)); + ATF_REQUIRE(nvlist_existsf_bool(nvl, "%s%c", "nam", 'e')); + ATF_REQUIRE_EQ(nvlist_get_bool(nvl, key), true); + ATF_REQUIRE_EQ(nvlist_getf_bool(nvl, "%c%s", 'n', "ame"), 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(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_existsf(nvl, "%s%d", "foo", 123)); + ATF_REQUIRE(nvlist_exists_number(nvl, key)); + ATF_REQUIRE(nvlist_existsf_number(nvl, "%s", key)); + ATF_REQUIRE_EQ(nvlist_get_number(nvl, key), value); + ATF_REQUIRE_EQ(nvlist_getf_number(nvl, "%s", 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(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_existsf(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists_string(nvl, key)); + ATF_REQUIRE(nvlist_existsf_string(nvl, "%s", key)); + ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, key), value), 0); + ATF_REQUIRE_EQ(strcmp(nvlist_getf_string(nvl, "%s", 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(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_existsf(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists_nvlist(nvl, key)); + ATF_REQUIRE(nvlist_existsf_nvlist(nvl, "%s", key)); + + 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); + + value = nvlist_getf_nvlist(nvl, "%s", key); + ATF_REQUIRE(nvlist_exists_null(value, subkey)); + 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(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_existsf(nvl, "%s", key)); + ATF_REQUIRE(nvlist_exists_binary(nvl, key)); + ATF_REQUIRE(nvlist_existsf_binary(nvl, "%s", key)); + + 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); + + ret_value = nvlist_getf_binary(nvl, &ret_size, "%s", key); + ATF_REQUIRE_EQ(value_size, ret_size); + ATF_REQUIRE_EQ(memcmp(value, ret_value, ret_size), 0); + 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(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(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(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(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 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::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/external/libnv/tests/nvlist_send_recv_test.c b/external/libnv/tests/nvlist_send_recv_test.c index ec23eade1e..b6a9f75c78 100644 --- a/external/libnv/tests/nvlist_send_recv_test.c +++ b/external/libnv/tests/nvlist_send_recv_test.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: head/lib/libnv/tests/nvlist_send_recv_test.c 269603 2014-08-05 18:41:27Z ngie $ + * $FreeBSD: head/lib/libnv/tests/nvlist_send_recv_test.c 279432 2015-03-01 00:22:09Z rstone $ */ #include @@ -58,8 +58,10 @@ 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); @@ -75,6 +77,7 @@ child(int sock) 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); @@ -86,7 +89,7 @@ static void parent(int sock) { nvlist_t *nvl; - const nvlist_t *cnvl; + const nvlist_t *cnvl, *empty; const char *name, *cname; void *cookie, *ccookie; int type, ctype; @@ -187,6 +190,13 @@ parent(int sock) 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); @@ -283,6 +293,13 @@ parent(int sock) 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); @@ -296,7 +313,7 @@ main(void) int status, socks[2]; pid_t pid; - printf("1..126\n"); + printf("1..134\n"); fflush(stdout); if (socketpair(PF_UNIX, SOCK_STREAM, 0, socks) < 0)