handle error imsg directly in got_privsep_recv_imsg()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/lib/privsep.c b/lib/privsep.c
index aad3015..28b8501 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -106,6 +106,25 @@ got_privsep_wait_for_child(pid_t pid)
return NULL;
}
+static const struct got_error *
+recv_imsg_error(struct imsg *imsg, size_t datalen)
+{
+ struct got_imsg_error *ierr;
+
+ if (datalen != sizeof(*ierr))
+ return got_error(GOT_ERR_PRIVSEP_LEN);
+
+ ierr = imsg->data;
+ if (ierr->code == GOT_ERR_ERRNO) {
+ static struct got_error serr;
+ serr.code = GOT_ERR_ERRNO;
+ serr.msg = strerror(ierr->errno_code);
+ return &serr;
+ }
+
+ return got_error(ierr->code);
+}
+
const struct got_error *
got_privsep_recv_imsg(struct imsg *imsg, struct imsgbuf *ibuf,
size_t min_datalen)
@@ -127,26 +146,12 @@ got_privsep_recv_imsg(struct imsg *imsg, struct imsgbuf *ibuf,
if (imsg->hdr.len < IMSG_HEADER_SIZE + min_datalen)
return got_error(GOT_ERR_PRIVSEP_LEN);
- return NULL;
-}
-
-static const struct got_error *
-recv_imsg_error(struct imsg *imsg, size_t datalen)
-{
- struct got_imsg_error *ierr;
-
- if (datalen != sizeof(*ierr))
- return got_error(GOT_ERR_PRIVSEP_LEN);
-
- ierr = imsg->data;
- if (ierr->code == GOT_ERR_ERRNO) {
- static struct got_error serr;
- serr.code = GOT_ERR_ERRNO;
- serr.msg = strerror(ierr->errno_code);
- return &serr;
+ if (imsg->hdr.type == GOT_IMSG_ERROR) {
+ size_t datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
+ return recv_imsg_error(imsg, datalen);
}
- return got_error(ierr->code);
+ return NULL;
}
/* Attempt to send an error in an imsg. Complain on stderr as a last resort. */
@@ -357,9 +362,6 @@ got_privsep_recv_obj(struct got_object **obj, struct imsgbuf *ibuf)
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
switch (imsg.hdr.type) {
- case GOT_IMSG_ERROR:
- err = recv_imsg_error(&imsg, datalen);
- break;
case GOT_IMSG_OBJECT:
err = got_privsep_get_imsg_obj(obj, &imsg, ibuf);
break;
@@ -481,9 +483,6 @@ got_privsep_recv_commit(struct got_commit_object **commit, struct imsgbuf *ibuf)
len = 0;
switch (imsg.hdr.type) {
- case GOT_IMSG_ERROR:
- err = recv_imsg_error(&imsg, datalen);
- break;
case GOT_IMSG_COMMIT:
if (datalen < sizeof(*icommit)) {
err = got_error(GOT_ERR_PRIVSEP_LEN);
@@ -807,9 +806,6 @@ got_privsep_recv_blob(size_t *size, struct imsgbuf *ibuf)
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
switch (imsg.hdr.type) {
- case GOT_IMSG_ERROR:
- err = recv_imsg_error(&imsg, datalen);
- break;
case GOT_IMSG_BLOB:
if (datalen != sizeof(*iblob)) {
err = got_error(GOT_ERR_PRIVSEP_LEN);