use a dedicated imsg for sending the pack index output file descriptor
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 92 93 94
diff --git a/lib/fetch.c b/lib/fetch.c
index 2fdd0e7..0a0cc26 100644
--- a/lib/fetch.c
+++ b/lib/fetch.c
@@ -502,7 +502,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
if (err != NULL)
goto done;
npackfd = -1;
- err = got_privsep_send_tmpfd(&idxibuf, nidxfd);
+ err = got_privsep_send_index_pack_outfd(&idxibuf, nidxfd);
if (err != NULL)
goto done;
nidxfd = -1;
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index b949a92..0e76d54 100644
--- a/lib/got_lib_privsep.h
+++ b/lib/got_lib_privsep.h
@@ -116,6 +116,7 @@ enum got_imsg_type {
GOT_IMSG_FETCH_DOWNLOAD_PROGRESS,
GOT_IMSG_FETCH_DONE,
GOT_IMSG_IDXPACK_REQUEST,
+ GOT_IMSG_IDXPACK_OUTFD,
GOT_IMSG_IDXPACK_PROGRESS,
GOT_IMSG_IDXPACK_DONE,
@@ -377,6 +378,8 @@ const struct got_error *got_privsep_send_obj(struct imsgbuf *,
struct got_object *);
const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
uint8_t *, int);
+const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
+ int);
const struct got_error *got_privsep_send_index_pack_progress(struct imsgbuf *,
int, int, int, int);
const struct got_error *got_privsep_send_index_pack_done(struct imsgbuf *);
diff --git a/lib/privsep.c b/lib/privsep.c
index b42b1cd..938c697 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -368,13 +368,12 @@ got_privsep_send_blob_outfd(struct imsgbuf *ibuf, int outfd)
return flush_imsg(ibuf);
}
-const struct got_error *
-got_privsep_send_tmpfd(struct imsgbuf *ibuf, int fd)
+static const struct got_error *
+send_fd(struct imsgbuf *ibuf, int imsg_code, int fd)
{
const struct got_error *err = NULL;
- if (imsg_compose(ibuf, GOT_IMSG_TMPFD, 0, 0, fd, NULL, 0)
- == -1) {
+ if (imsg_compose(ibuf, imsg_code, 0, 0, fd, NULL, 0) == -1) {
err = got_error_from_errno("imsg_compose TMPFD");
close(fd);
return err;
@@ -384,6 +383,12 @@ got_privsep_send_tmpfd(struct imsgbuf *ibuf, int fd)
}
const struct got_error *
+got_privsep_send_tmpfd(struct imsgbuf *ibuf, int fd)
+{
+ return send_fd(ibuf, GOT_IMSG_TMPFD, fd);
+}
+
+const struct got_error *
got_privsep_send_obj(struct imsgbuf *ibuf, struct got_object *obj)
{
struct got_imsg_object iobj;
@@ -783,6 +788,12 @@ got_privsep_send_index_pack_req(struct imsgbuf *ibuf, uint8_t *pack_hash,
}
const struct got_error *
+got_privsep_send_index_pack_outfd(struct imsgbuf *ibuf, int fd)
+{
+ return send_fd(ibuf, GOT_IMSG_IDXPACK_OUTFD, fd);
+}
+
+const struct got_error *
got_privsep_send_index_pack_progress(struct imsgbuf *ibuf, int nobj_total,
int nobj_indexed, int nobj_loose, int nobj_resolved)
{
diff --git a/libexec/got-index-pack/got-index-pack.c b/libexec/got-index-pack/got-index-pack.c
index 3a91c76..f64e530 100644
--- a/libexec/got-index-pack/got-index-pack.c
+++ b/libexec/got-index-pack/got-index-pack.c
@@ -845,7 +845,7 @@ main(int argc, char **argv)
goto done;
if (imsg.hdr.type == GOT_IMSG_STOP)
goto done;
- if (imsg.hdr.type != GOT_IMSG_TMPFD) {
+ if (imsg.hdr.type != GOT_IMSG_IDXPACK_OUTFD) {
err = got_error(GOT_ERR_PRIVSEP_MSG);
goto done;
}