Skip to contentSkip to conversation

uapi: always print valid errors

PATCH In review James Tucker 2 participants 2 messages Jan 8, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uapi: always print valid errors

ret_code is now initialized for the case of short reads. The 0 length reads/eof case is now treated appropriately.

---
 src/tools/ipc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/tools/ipc.c +4 -2
index c8ca431..cc512f3 100644
@@ -164,7 +164,7 @@ static int userspace_set_device(struct wgdevice *dev)
 	struct wgpeer *peer;
 	size_t len;
 	ssize_t ret;
-	int ret_code;
+	int ret_code = 0;
 	int fd = userspace_interface_fd(dev->interface);
 	if (fd < 0)
 		return fd;
@@ -177,8 +177,10 @@ static int userspace_set_device(struct wgdevice *dev)
 	if (ret < 0)
 		goto out;
 	ret = read(fd, &ret_code, sizeof(ret_code));
-	if (ret < 0)
+	if (ret <= 0) {
+		ret = -errno;
 		goto out;
+	}
 	ret = ret_code;
 out:
 	close(fd);
Signature · 1 line
2.11.0