summaryrefslogtreecommitdiff
path: root/usr.bin/file
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 13:24:08 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2024-11-21 13:24:08 +0000
commite8cafc5cef482ce83d9245446ebc981a9c6efbe7 (patch)
tree785a541d8aaf9dfc2e276efa5db2c5c6fc288735 /usr.bin/file
parent84671b23213e8c6ba92d0184927901d648dbf307 (diff)
Implement the recv_imsg/read_message function in the correct way.
One needs to first check imsg_get() if there is a imsg already in the queue. Then if that returns 0 call imsgbuf_read(). Do this in a loop until imsg_get() returns an imsg. OK tb@ and nicm@ for file
Diffstat (limited to 'usr.bin/file')
-rw-r--r--usr.bin/file/file.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/usr.bin/file/file.c b/usr.bin/file/file.c
index 3dbf1296e07..7f03486b7ab 100644
--- a/usr.bin/file/file.c
+++ b/usr.bin/file/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.72 2024/11/21 13:20:27 claudio Exp $ */
+/* $OpenBSD: file.c,v 1.73 2024/11/21 13:24:07 claudio Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
@@ -294,25 +294,25 @@ send_message(struct imsgbuf *ibuf, void *msg, size_t msglen, int fd)
static int
read_message(struct imsgbuf *ibuf, struct imsg *imsg, pid_t from)
{
- int n;
-
- while ((n = imsgbuf_read(ibuf)) == -1 && errno == EAGAIN)
- /* nothing */ ;
- if (n == -1)
- err(1, "imsgbuf_read");
- if (n == 0)
- return (0);
-
- if ((n = imsg_get(ibuf, imsg)) == -1)
- err(1, "imsg_get");
- if (n == 0)
- return (0);
-
- if ((pid_t)imsg->hdr.pid != from)
- errx(1, "PIDs don't match");
-
- return (n);
+ while (1) {
+ switch (imsg_get(ibuf, imsg)) {
+ case -1:
+ err(1, "imsg_get");
+ case 0:
+ break;
+ default:
+ if ((pid_t)imsg->hdr.pid != from)
+ errx(1, "PIDs don't match");
+ return (1);
+ }
+ switch (imsgbuf_read(ibuf)) {
+ case -1:
+ err(1, "imsgbuf_read");
+ case 0:
+ return (0);
+ }
+ }
}
static void