summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorreyk <reyk@openbsd.org>2016-10-10 17:15:30 +0000
committerreyk <reyk@openbsd.org>2016-10-10 17:15:30 +0000
commita0a7f51d01b591e61044e17ea2a7e5ed2b7c520c (patch)
treeb5921ea4bf5ba321d9bb3138f7a3066eb67e9366 /lib/libutil
parentFix msgbuf_write() usage idiom and modify the treatment for socket close (diff)
downloadwireguard-openbsd-a0a7f51d01b591e61044e17ea2a7e5ed2b7c520c.tar.xz
wireguard-openbsd-a0a7f51d01b591e61044e17ea2a7e5ed2b7c520c.zip
Fixup the example for msgbuf_write() and imsg_read() to check the
error cases for -1 and 0 explicitly (it initially only checked for -1, I updated it to also check for 0, and rzalamena@ figured out that 0 has to be checked in a differently). OK millert@ rzalamena@
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/imsg_init.316
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libutil/imsg_init.3 b/lib/libutil/imsg_init.3
index cf66e17279e..fa6ad22927d 100644
--- a/lib/libutil/imsg_init.3
+++ b/lib/libutil/imsg_init.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: imsg_init.3,v 1.15 2015/12/29 18:05:23 benno Exp $
+.\" $OpenBSD: imsg_init.3,v 1.16 2016/10/10 17:15:30 reyk Exp $
.\"
.\" Copyright (c) 2010 Nicholas Marriott <nicm@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 29 2015 $
+.Dd $Mdocdate: October 10 2016 $
.Dt IMSG_INIT 3
.Os
.Sh NAME
@@ -501,9 +501,12 @@ library is used to monitor the socket file descriptor.
When the socket is ready for writing, queued messages are transmitted with
.Fn msgbuf_write :
.Bd -literal -offset indent
- if (msgbuf_write(&ibuf-\*(Gtw) \*(Lt= 0 && errno != EAGAIN) {
+ if ((n = msgbuf_write(&ibuf-\*(Gtw)) == -1 && errno != EAGAIN) {
/* handle write failure */
}
+ if (n == 0) {
+ /* handle closed connection */
+ }
.Ed
.Pp
And when ready for reading, messages are first received using
@@ -518,8 +521,11 @@ dispatch_imsg(struct imsgbuf *ibuf)
ssize_t n, datalen;
int idata;
- if (((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) || n == 0) {
- /* handle socket error */
+ if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) {
+ /* handle read error */
+ }
+ if (n == 0) {
+ /* handle closed connection */
}
for (;;) {