svn commit: r292631 - in user/ngie/stable-10-libnv: contrib/mdocml etc/mtree lib lib/libnv lib/libnv/tests share/mk
Garrett Cooper
ngie at FreeBSD.org
Tue Dec 22 23:02:14 UTC 2015
Author: ngie
Date: Tue Dec 22 23:02:12 2015
New Revision: 292631
URL: https://svnweb.freebsd.org/changeset/base/292631
Log:
MFC r258065,r258594,r259430,r260222,r261407,r261408,r263479,r264021,r266351,r269603:
r258065 (by pjd):
Bring in libnv library for managing name/value pairs. The following types
are currently supported:
- NV_TYPE_NULL - only name, no data;
- NV_TYPE_BOOL - boolean (true or false);
- NV_TYPE_NUMBER - 64bit unsigned integer;
- NV_TYPE_STRING - C string;
- NV_TYPE_NVLIST - nested nvlist;
- NV_TYPE_DESCRIPTOR - file descriptor;
- NV_TYPE_BINARY - binary data.
For detailed documentation and examples see nv(3) manual page.
Sponsored by: The FreeBSD Foundation
r258594 (by pjd):
Fix double free().
Reported by: Coverity
Coverity CID: 1130048
r259430 (by pjd):
MFp4 @1189139:
Get rid of the msg_peek() function, which has a problem. If there was less
data in the socket buffer than requested by the caller, the function would busy
loop, as select(2) will always return immediately.
We can just receive nvlhdr now, because some time ago we splitted receive of
data from the receive of descriptors.
r260222 (by pjd):
MFp4 @1189711:
Fix resource leaks on nvlist_destroy().
Reported by: Mariusz Zaborski <oshogbo at FreeBSD.org>
r261407 (by pjd):
Fix sending empty nvlist.
Submitted by: Mariusz Zaborski <oshogbo at FreeBSD.org>
r261408 (by pjd):
Assert input arguments to buf_send() and buf_recv().
Submitted by: Mariusz Zaborski <oshogbo at FreeBSD.org>
r263479 (by bdrewery):
nv(3) was not in 10.0.
It might be MFC'd to stable/10 for 10.1, but for now update the manual to
avoid confusion on its availability.
Discussed with: pjd
r264021 (by jilles):
libnv: Don't lose big-endian flag when receiving a message.
A bug caused the "big endian" flag to be lost when receiving a message. As a
result, the bits are interpreted as little endian and an extremely large
allocation is attempted.
This change fixes ping(8)'s communication to casperd(8) on big-endian
architectures.
Reported by: Anton Shterenlikht
Tested by: danfe
r266351 (by rstone):
Correct a typo.
r269603:
Integrate lib/libnv into the build/kyua
Rename all of the TAP test applications from <test> to <test>_test
to match the convention described in the TestSuite wiki page
Phabric: D538
Approved by: jmmv (mentor)
Sponsored by: EMC / Isilon Storage Division
Added:
user/ngie/stable-10-libnv/lib/libnv/
- copied from r258065, head/lib/libnv/
user/ngie/stable-10-libnv/lib/libnv/tests/
- copied from r269603, head/lib/libnv/tests/
Modified:
user/ngie/stable-10-libnv/contrib/mdocml/lib.in
user/ngie/stable-10-libnv/etc/mtree/BSD.tests.dist
user/ngie/stable-10-libnv/lib/Makefile
user/ngie/stable-10-libnv/lib/libnv/Makefile
user/ngie/stable-10-libnv/lib/libnv/msgio.c
user/ngie/stable-10-libnv/lib/libnv/msgio.h
user/ngie/stable-10-libnv/lib/libnv/nv.3
user/ngie/stable-10-libnv/lib/libnv/nvlist.c
user/ngie/stable-10-libnv/lib/libnv/nvpair.c
user/ngie/stable-10-libnv/share/mk/bsd.libnames.mk
Directory Properties:
user/ngie/stable-10-libnv/ (props changed)
Modified: user/ngie/stable-10-libnv/contrib/mdocml/lib.in
==============================================================================
--- user/ngie/stable-10-libnv/contrib/mdocml/lib.in Tue Dec 22 22:52:37 2015 (r292630)
+++ user/ngie/stable-10-libnv/contrib/mdocml/lib.in Tue Dec 22 23:02:12 2015 (r292631)
@@ -67,6 +67,7 @@ LINE("libmemstat", "Kernel Memory Alloca
LINE("libmenu", "Curses Menu Library (libmenu, \\-lmenu)")
LINE("libnetgraph", "Netgraph User Library (libnetgraph, \\-lnetgraph)")
LINE("libnetpgp", "Netpgp signing, verification, encryption and decryption (libnetpgp, \\-lnetpgp)")
+LINE("libnv", "Name/value pairs library (libnv, \\-lnv)")
LINE("libossaudio", "OSS Audio Emulation Library (libossaudio, \\-lossaudio)")
LINE("libpam", "Pluggable Authentication Module Library (libpam, \\-lpam)")
LINE("libpcap", "Packet Capture Library (libpcap, \\-lpcap)")
Modified: user/ngie/stable-10-libnv/etc/mtree/BSD.tests.dist
==============================================================================
--- user/ngie/stable-10-libnv/etc/mtree/BSD.tests.dist Tue Dec 22 22:52:37 2015 (r292630)
+++ user/ngie/stable-10-libnv/etc/mtree/BSD.tests.dist Tue Dec 22 23:02:12 2015 (r292631)
@@ -140,6 +140,8 @@
..
libmp
..
+ libnv
+ ..
librt
..
libthr
@@ -204,7 +206,6 @@
execve
..
pipe
- ..
..
kqueue
..
Modified: user/ngie/stable-10-libnv/lib/Makefile
==============================================================================
--- user/ngie/stable-10-libnv/lib/Makefile Tue Dec 22 22:52:37 2015 (r292630)
+++ user/ngie/stable-10-libnv/lib/Makefile Tue Dec 22 23:02:12 2015 (r292631)
@@ -70,6 +70,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
libnetbsd \
${_libnetgraph} \
${_libngatm} \
+ libnv \
libopie \
libpam \
libpcap \
Modified: user/ngie/stable-10-libnv/lib/libnv/Makefile
==============================================================================
--- head/lib/libnv/Makefile Tue Nov 12 19:39:14 2013 (r258065)
+++ user/ngie/stable-10-libnv/lib/libnv/Makefile Tue Dec 22 23:02:12 2015 (r292631)
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <src.opts.mk>
+
LIB= nv
SHLIBDIR?= /lib
SHLIB_MAJOR= 0
@@ -158,4 +160,8 @@ MLINKS+=nv.3 nvlist_existsv.3 \
WARNS?= 6
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.lib.mk>
Modified: user/ngie/stable-10-libnv/lib/libnv/msgio.c
==============================================================================
--- head/lib/libnv/msgio.c Tue Nov 12 19:39:14 2013 (r258065)
+++ user/ngie/stable-10-libnv/lib/libnv/msgio.c Tue Dec 22 23:02:12 2015 (r292631)
@@ -113,30 +113,6 @@ fd_wait(int fd, bool doread)
NULL, NULL);
}
-int
-msg_peek(int sock, void *buf, size_t size)
-{
- ssize_t done;
-
- PJDLOG_ASSERT(sock >= 0);
- PJDLOG_ASSERT(size > 0);
-
- do {
- fd_wait(sock, true);
- done = recv(sock, buf, size, MSG_PEEK | MSG_WAITALL);
- if (done == -1) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
- return (-1);
- } else if (done == 0) {
- errno = ENOTCONN;
- return (-1);
- }
- } while (done != (ssize_t)size);
-
- return (0);
-}
-
static int
msg_recv(int sock, struct msghdr *msg)
{
@@ -362,6 +338,10 @@ buf_send(int sock, void *buf, size_t siz
ssize_t done;
unsigned char *ptr;
+ PJDLOG_ASSERT(sock >= 0);
+ PJDLOG_ASSERT(size > 0);
+ PJDLOG_ASSERT(buf != NULL);
+
ptr = buf;
do {
fd_wait(sock, false);
@@ -387,8 +367,11 @@ buf_recv(int sock, void *buf, size_t siz
ssize_t done;
unsigned char *ptr;
+ PJDLOG_ASSERT(sock >= 0);
+ PJDLOG_ASSERT(buf != NULL);
+
ptr = buf;
- do {
+ while (size > 0) {
fd_wait(sock, true);
done = recv(sock, ptr, size, 0);
if (done == -1) {
@@ -401,7 +384,7 @@ buf_recv(int sock, void *buf, size_t siz
}
size -= done;
ptr += done;
- } while (size > 0);
+ }
return (0);
}
Modified: user/ngie/stable-10-libnv/lib/libnv/msgio.h
==============================================================================
--- head/lib/libnv/msgio.h Tue Nov 12 19:39:14 2013 (r258065)
+++ user/ngie/stable-10-libnv/lib/libnv/msgio.h Tue Dec 22 23:02:12 2015 (r292631)
@@ -38,8 +38,6 @@ struct cmsgcred;
struct iovec;
struct msghdr;
-int msg_peek(int sock, void *buf, size_t size);
-
int cred_send(int sock);
int cred_recv(int sock, struct cmsgcred *cred);
Modified: user/ngie/stable-10-libnv/lib/libnv/nv.3
==============================================================================
--- head/lib/libnv/nv.3 Tue Nov 12 19:39:14 2013 (r258065)
+++ user/ngie/stable-10-libnv/lib/libnv/nv.3 Tue Dec 22 23:02:12 2015 (r292631)
@@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 8, 2013
+.Dd March 21, 2014
.Dt NV 3
.Os
.Sh NAME
@@ -194,7 +194,7 @@ The API supports the following data type
.Bl -ohang -offset indent
.It Sy null ( NV_TYPE_NULL )
There is no data associated with the name.
-.It Sy bool ( NV_TYPE_BOLL )
+.It Sy bool ( NV_TYPE_BOOL )
The value can be either
.Dv true
or
@@ -594,7 +594,7 @@ while ((name = nvlist_next(nvl, &type, &
The
.Nm libnv
library appeared in
-.Fx 10.0 .
+.Fx 11.0 .
.Sh AUTHORS
.An -nosplit
The
Modified: user/ngie/stable-10-libnv/lib/libnv/nvlist.c
==============================================================================
--- head/lib/libnv/nvlist.c Tue Nov 12 19:39:14 2013 (r258065)
+++ user/ngie/stable-10-libnv/lib/libnv/nvlist.c Tue Dec 22 23:02:12 2015 (r292631)
@@ -125,8 +125,10 @@ nvlist_destroy(nvlist_t *nvl)
NVLIST_ASSERT(nvl);
- while ((nvp = nvlist_first_nvpair(nvl)) != NULL)
+ while ((nvp = nvlist_first_nvpair(nvl)) != NULL) {
nvlist_remove_nvpair(nvl, nvp);
+ nvpair_free(nvp);
+ }
nvl->nvl_magic = 0;
free(nvl);
@@ -580,7 +582,7 @@ nvlist_check_header(struct nvlist_header
errno = EINVAL;
return (false);
}
- if ((nvlhdrp->nvlh_flags &= ~NV_FLAG_ALL_MASK) != 0) {
+ if ((nvlhdrp->nvlh_flags & ~NV_FLAG_ALL_MASK) != 0) {
errno = EINVAL;
return (false);
}
@@ -724,11 +726,11 @@ nvlist_recv(int sock)
{
struct nvlist_header nvlhdr;
nvlist_t *nvl, *ret;
+ unsigned char *buf;
size_t nfds, size;
- void *buf;
int serrno, *fds;
- if (msg_peek(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
+ if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
return (NULL);
if (!nvlist_check_header(&nvlhdr))
@@ -741,10 +743,12 @@ nvlist_recv(int sock)
if (buf == NULL)
return (NULL);
+ memcpy(buf, &nvlhdr, sizeof(nvlhdr));
+
ret = NULL;
fds = NULL;
- if (buf_recv(sock, buf, size) == -1)
+ if (buf_recv(sock, buf + sizeof(nvlhdr), size - sizeof(nvlhdr)) == -1)
goto out;
if (nfds > 0) {
Modified: user/ngie/stable-10-libnv/lib/libnv/nvpair.c
==============================================================================
--- head/lib/libnv/nvpair.c Tue Nov 12 19:39:14 2013 (r258065)
+++ user/ngie/stable-10-libnv/lib/libnv/nvpair.c Tue Dec 22 23:02:12 2015 (r292631)
@@ -683,10 +683,8 @@ nvpair_unpack(int flags, const unsigned
if (ptr == NULL)
goto failed;
tmp = realloc(nvp, sizeof(*nvp) + strlen(nvp->nvp_name) + 1);
- if (tmp == NULL) {
- free(nvp);
+ if (tmp == NULL)
goto failed;
- }
nvp = tmp;
/* Update nvp_name after realloc(). */
nvp->nvp_name = (char *)(nvp + 1);
Modified: user/ngie/stable-10-libnv/share/mk/bsd.libnames.mk
==============================================================================
--- user/ngie/stable-10-libnv/share/mk/bsd.libnames.mk Tue Dec 22 22:52:37 2015 (r292630)
+++ user/ngie/stable-10-libnv/share/mk/bsd.libnames.mk Tue Dec 22 23:02:12 2015 (r292631)
@@ -100,6 +100,7 @@ LIBNCURSES?= ${DESTDIR}${LIBDIR}/libncur
LIBNCURSESW?= ${DESTDIR}${LIBDIR}/libncursesw.a
LIBNETGRAPH?= ${DESTDIR}${LIBDIR}/libnetgraph.a
LIBNGATM?= ${DESTDIR}${LIBDIR}/libngatm.a
+LIBNV?= ${DESTDIR}${LIBDIR}/libnv.a
LIBNVPAIR?= ${DESTDIR}${LIBDIR}/libnvpair.a
LIBOPIE?= ${DESTDIR}${LIBDIR}/libopie.a
More information about the svn-src-user
mailing list