Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Jan 2016 07:18:22 +0000 (UTC)
From:      Garrett Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r293079 - in user/ngie/stable-10-libnv/sys: kern sys
Message-ID:  <201601030718.u037IM7B092045@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Sun Jan  3 07:18:22 2016
New Revision: 293079
URL: https://svnweb.freebsd.org/changeset/base/293079

Log:
  MFC r282248,r282258,r282282:
  
  r282248 (by oshogbo):
  
  Style fixes.
  
  r282258 (by oshogbo):
  
  Save errno from close override.
  
  r282282 (by oshogbo):
  
  Rename macros to use prefix ERRNO. Add macro ERRNO_SET. Now
  ERRNO_{RESTORE/SAVE} must by used together, additional variable is not
  needed. Always use ERRNO_{SAVE/RESTORE/SET} macros.

Modified:
  user/ngie/stable-10-libnv/sys/kern/subr_nvlist.c
  user/ngie/stable-10-libnv/sys/kern/subr_nvpair.c
  user/ngie/stable-10-libnv/sys/sys/nv_impl.h
Directory Properties:
  user/ngie/stable-10-libnv/   (props changed)

Modified: user/ngie/stable-10-libnv/sys/kern/subr_nvlist.c
==============================================================================
--- user/ngie/stable-10-libnv/sys/kern/subr_nvlist.c	Sun Jan  3 06:51:57 2016	(r293078)
+++ user/ngie/stable-10-libnv/sys/kern/subr_nvlist.c	Sun Jan  3 07:18:22 2016	(r293079)
@@ -142,12 +142,11 @@ void
 nvlist_destroy(nvlist_t *nvl)
 {
 	nvpair_t *nvp;
-	int serrno;
 
 	if (nvl == NULL)
 		return;
 
-	SAVE_ERRNO(serrno);
+	ERRNO_SAVE();
 
 	NVLIST_ASSERT(nvl);
 
@@ -158,7 +157,7 @@ nvlist_destroy(nvlist_t *nvl)
 	nvl->nvl_magic = 0;
 	nv_free(nvl);
 
-	RESTORE_ERRNO(serrno);
+	ERRNO_RESTORE();
 }
 
 void
@@ -275,7 +274,7 @@ nvlist_find(const nvlist_t *nvl, int typ
 	}
 
 	if (nvp == NULL)
-		RESTORE_ERRNO(ENOENT);
+		ERRNO_SET(ENOENT);
 
 	return (nvp);
 }
@@ -318,7 +317,7 @@ nvlist_clone(const nvlist_t *nvl)
 	NVLIST_ASSERT(nvl);
 
 	if (nvl->nvl_error != 0) {
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 		return (NULL);
 	}
 
@@ -608,7 +607,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_
 	NVLIST_ASSERT(nvl);
 
 	if (nvl->nvl_error != 0) {
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 		return (NULL);
 	}
 
@@ -698,12 +697,12 @@ nvlist_pack(const nvlist_t *nvl, size_t 
 	NVLIST_ASSERT(nvl);
 
 	if (nvl->nvl_error != 0) {
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 		return (NULL);
 	}
 
 	if (nvlist_ndescriptors(nvl) > 0) {
-		RESTORE_ERRNO(EOPNOTSUPP);
+		ERRNO_SET(EOPNOTSUPP);
 		return (NULL);
 	}
 
@@ -715,11 +714,11 @@ nvlist_check_header(struct nvlist_header
 {
 
 	if (nvlhdrp->nvlh_magic != NVLIST_HEADER_MAGIC) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (false);
 	}
 	if ((nvlhdrp->nvlh_flags & ~NV_FLAG_ALL_MASK) != 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (false);
 	}
 #if BYTE_ORDER == BIG_ENDIAN
@@ -771,7 +770,7 @@ nvlist_unpack_header(nvlist_t *nvl, cons
 
 	return (ptr);
 failed:
-	RESTORE_ERRNO(EINVAL);
+	ERRNO_SET(EINVAL);
 	return (NULL);
 }
 
@@ -865,10 +864,10 @@ nvlist_send(int sock, const nvlist_t *nv
 	int *fds;
 	void *data;
 	int64_t fdidx;
-	int serrno, ret;
+	int ret;
 
 	if (nvlist_error(nvl) != 0) {
-		errno = nvlist_error(nvl);
+		ERRNO_SET(nvlist_error(nvl));
 		return (-1);
 	}
 
@@ -894,10 +893,10 @@ nvlist_send(int sock, const nvlist_t *nv
 
 	ret = 0;
 out:
-	serrno = errno;
+	ERRNO_SAVE();
 	free(fds);
 	free(data);
-	errno = serrno;
+	ERRNO_RESTORE();
 	return (ret);
 }
 
@@ -908,7 +907,7 @@ nvlist_recv(int sock)
 	nvlist_t *nvl, *ret;
 	unsigned char *buf;
 	size_t nfds, size, i;
-	int serrno, *fds;
+	int *fds;
 
 	if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
 		return (NULL);
@@ -941,17 +940,19 @@ nvlist_recv(int sock)
 
 	nvl = nvlist_xunpack(buf, size, fds, nfds);
 	if (nvl == NULL) {
+		ERRNO_SAVE();
 		for (i = 0; i < nfds; i++)
 			close(fds[i]);
+		ERRNO_RESTORE();
 		goto out;
 	}
 
 	ret = nvl;
 out:
-	serrno = errno;
+	ERRNO_SAVE();
 	free(buf);
 	free(fds);
-	errno = serrno;
+	ERRNO_RESTORE();
 
 	return (ret);
 }
@@ -1064,19 +1065,19 @@ nvlist_add_nvpair(nvlist_t *nvl, const n
 	NVPAIR_ASSERT(nvp);
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 	if (nvlist_exists(nvl, nvpair_name(nvp))) {
 		nvl->nvl_error = EEXIST;
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	newnvp = nvpair_clone(nvp);
 	if (newnvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
@@ -1100,16 +1101,17 @@ nvlist_add_stringv(nvlist_t *nvl, const 
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_stringv(name, valuefmt, valueap);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 void
@@ -1118,16 +1120,17 @@ nvlist_add_null(nvlist_t *nvl, const cha
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_null(name);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 void
@@ -1136,16 +1139,17 @@ nvlist_add_bool(nvlist_t *nvl, const cha
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_bool(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 void
@@ -1154,16 +1158,17 @@ nvlist_add_number(nvlist_t *nvl, const c
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_number(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 void
@@ -1172,16 +1177,17 @@ nvlist_add_string(nvlist_t *nvl, const c
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_string(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 void
@@ -1190,16 +1196,17 @@ nvlist_add_nvlist(nvlist_t *nvl, const c
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_nvlist(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 #ifndef _KERNEL
@@ -1228,16 +1235,17 @@ nvlist_add_binary(nvlist_t *nvl, const c
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_binary(name, value, size);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 void
@@ -1249,13 +1257,13 @@ nvlist_move_nvpair(nvlist_t *nvl, nvpair
 
 	if (nvlist_error(nvl) != 0) {
 		nvpair_free(nvp);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 	if (nvlist_exists(nvl, nvpair_name(nvp))) {
 		nvpair_free(nvp);
 		nvl->nvl_error = EEXIST;
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 		return;
 	}
 
@@ -1269,16 +1277,17 @@ nvlist_move_string(nvlist_t *nvl, const 
 
 	if (nvlist_error(nvl) != 0) {
 		nv_free(value);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_move_string(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 void
@@ -1289,16 +1298,17 @@ nvlist_move_nvlist(nvlist_t *nvl, const 
 	if (nvlist_error(nvl) != 0) {
 		if (value != NULL && nvlist_get_nvpair_parent(value) != NULL)
 			nvlist_destroy(value);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_move_nvlist(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 #ifndef _KERNEL
@@ -1309,15 +1319,17 @@ nvlist_move_descriptor(nvlist_t *nvl, co
 
 	if (nvlist_error(nvl) != 0) {
 		close(value);
-		errno = nvlist_error(nvl);
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_move_descriptor(name, value);
-	if (nvp == NULL)
-		nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
-	else
+	if (nvp == NULL) {
+		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 #endif
 
@@ -1328,16 +1340,17 @@ nvlist_move_binary(nvlist_t *nvl, const 
 
 	if (nvlist_error(nvl) != 0) {
 		nv_free(value);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_move_binary(name, value, size);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
-	} else
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 
 const nvpair_t *

Modified: user/ngie/stable-10-libnv/sys/kern/subr_nvpair.c
==============================================================================
--- user/ngie/stable-10-libnv/sys/kern/subr_nvpair.c	Sun Jan  3 06:51:57 2016	(r293078)
+++ user/ngie/stable-10-libnv/sys/kern/subr_nvpair.c	Sun Jan  3 07:18:22 2016	(r293079)
@@ -468,7 +468,7 @@ nvpair_unpack_header(bool isbe, nvpair_t
 
 	return (ptr);
 failed:
-	RESTORE_ERRNO(EINVAL);
+	ERRNO_SET(EINVAL);
 	return (NULL);
 }
 
@@ -480,7 +480,7 @@ nvpair_unpack_null(bool isbe __unused, n
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NULL);
 
 	if (nvp->nvp_datasize != 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -496,11 +496,11 @@ nvpair_unpack_bool(bool isbe __unused, n
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BOOL);
 
 	if (nvp->nvp_datasize != sizeof(value)) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 	if (*leftp < sizeof(value)) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -509,7 +509,7 @@ nvpair_unpack_bool(bool isbe __unused, n
 	*leftp -= sizeof(value);
 
 	if (value != 0 && value != 1) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -526,11 +526,11 @@ nvpair_unpack_number(bool isbe, nvpair_t
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NUMBER);
 
 	if (nvp->nvp_datasize != sizeof(uint64_t)) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 	if (*leftp < sizeof(uint64_t)) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -552,13 +552,13 @@ nvpair_unpack_string(bool isbe __unused,
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_STRING);
 
 	if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	if (strnlen((const char *)ptr, nvp->nvp_datasize) !=
 	    nvp->nvp_datasize - 1) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -581,7 +581,7 @@ nvpair_unpack_nvlist(bool isbe __unused,
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NVLIST);
 
 	if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -609,11 +609,11 @@ nvpair_unpack_descriptor(bool isbe, nvpa
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR);
 
 	if (nvp->nvp_datasize != sizeof(idx)) {
-		errno = EINVAL;
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 	if (*leftp < sizeof(idx)) {
-		errno = EINVAL;
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -623,12 +623,12 @@ nvpair_unpack_descriptor(bool isbe, nvpa
 		idx = le64dec(ptr);
 
 	if (idx < 0) {
-		errno = EINVAL;
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	if ((size_t)idx >= nfds) {
-		errno = EINVAL;
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -650,7 +650,7 @@ nvpair_unpack_binary(bool isbe __unused,
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BINARY);
 
 	if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -725,7 +725,7 @@ nvpair_allocv(const char *name, int type
 
 	namelen = strlen(name);
 	if (namelen >= NV_NAME_MAX) {
-		RESTORE_ERRNO(ENAMETOOLONG);
+		ERRNO_SET(ENAMETOOLONG);
 		return (NULL);
 	}
 
@@ -802,7 +802,7 @@ nvpair_create_string(const char *name, c
 	char *data;
 
 	if (value == NULL) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -826,7 +826,7 @@ nvpair_create_nvlist(const char *name, c
 	nvpair_t *nvp;
 
 	if (value == NULL) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -850,7 +850,7 @@ nvpair_create_descriptor(const char *nam
 	nvpair_t *nvp;
 
 	if (value < 0 || !fd_is_valid(value)) {
-		errno = EBADF;
+		ERRNO_SET(EBADF);
 		return (NULL);
 	}
 
@@ -860,8 +860,11 @@ nvpair_create_descriptor(const char *nam
 
 	nvp = nvpair_allocv(name, NV_TYPE_DESCRIPTOR, (uint64_t)value,
 	    sizeof(int64_t));
-	if (nvp == NULL)
+	if (nvp == NULL) {
+		ERRNO_SAVE();
 		close(value);
+		ERRNO_RESTORE();
+	}
 
 	return (nvp);
 }
@@ -874,7 +877,7 @@ nvpair_create_binary(const char *name, c
 	void *data;
 
 	if (value == NULL || size == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -895,19 +898,18 @@ nvpair_t *
 nvpair_move_string(const char *name, char *value)
 {
 	nvpair_t *nvp;
-	int serrno;
 
 	if (value == NULL) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	nvp = nvpair_allocv(name, NV_TYPE_STRING, (uint64_t)(uintptr_t)value,
 	    strlen(value) + 1);
 	if (nvp == NULL) {
-		SAVE_ERRNO(serrno);
+		ERRNO_SAVE();
 		nv_free(value);
-		RESTORE_ERRNO(serrno);
+		ERRNO_RESTORE();
 	}
 
 	return (nvp);
@@ -919,12 +921,12 @@ nvpair_move_nvlist(const char *name, nvl
 	nvpair_t *nvp;
 
 	if (value == NULL || nvlist_get_nvpair_parent(value) != NULL) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	if (nvlist_error(value) != 0) {
-		RESTORE_ERRNO(nvlist_error(value));
+		ERRNO_SET(nvlist_error(value));
 		nvlist_destroy(value);
 		return (NULL);
 	}
@@ -944,19 +946,18 @@ nvpair_t *
 nvpair_move_descriptor(const char *name, int value)
 {
 	nvpair_t *nvp;
-	int serrno;
 
 	if (value < 0 || !fd_is_valid(value)) {
-		errno = EBADF;
+		ERRNO_SET(EBADF);
 		return (NULL);
 	}
 
 	nvp = nvpair_allocv(name, NV_TYPE_DESCRIPTOR, (uint64_t)value,
 	    sizeof(int64_t));
 	if (nvp == NULL) {
-		serrno = errno;
+		ERRNO_SAVE();
 		close(value);
-		errno = serrno;
+		ERRNO_RESTORE();
 	}
 
 	return (nvp);
@@ -967,19 +968,18 @@ nvpair_t *
 nvpair_move_binary(const char *name, void *value, size_t size)
 {
 	nvpair_t *nvp;
-	int serrno;
 
 	if (value == NULL || size == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	nvp = nvpair_allocv(name, NV_TYPE_BINARY, (uint64_t)(uintptr_t)value,
 	    size);
 	if (nvp == NULL) {
-		SAVE_ERRNO(serrno);
+		ERRNO_SAVE();
 		nv_free(value);
-		RESTORE_ERRNO(serrno);
+		ERRNO_RESTORE();
 	}
 
 	return (nvp);

Modified: user/ngie/stable-10-libnv/sys/sys/nv_impl.h
==============================================================================
--- user/ngie/stable-10-libnv/sys/sys/nv_impl.h	Sun Jan  3 06:51:57 2016	(r293078)
+++ user/ngie/stable-10-libnv/sys/sys/nv_impl.h	Sun Jan  3 07:18:22 2016	(r293079)
@@ -41,8 +41,8 @@ typedef struct nvpair nvpair_t;
 
 #define	NV_TYPE_NVLIST_UP		255
 
-#define	NV_TYPE_FIRST		NV_TYPE_NULL
-#define	NV_TYPE_LAST		NV_TYPE_BINARY
+#define	NV_TYPE_FIRST			NV_TYPE_NULL
+#define	NV_TYPE_LAST			NV_TYPE_BINARY
 
 #define	NV_FLAG_BIG_ENDIAN		0x80
 
@@ -56,8 +56,9 @@ typedef struct nvpair nvpair_t;
 #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_SET(var)			do { } while (0)
+#define	ERRNO_SAVE()			do { do { } while(0)
+#define	ERRNO_RESTORE()			} while (0)
 
 #define	ERRNO_OR_DEFAULT(default)	(default)
 
@@ -70,8 +71,14 @@ typedef struct nvpair nvpair_t;
 #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_SET(var)			do { errno = (var); } while (0)
+#define	ERRNO_SAVE()			do {				\
+						int _serrno;		\
+									\
+						_serrno = errno
+
+#define	ERRNO_RESTORE()				errno = _serrno;	\
+					} while (0)
 
 #define	ERRNO_OR_DEFAULT(default)	(errno == 0 ? (default) : errno)
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601030718.u037IM7B092045>