Commit 73ab1060354e23885c41d858ec39bcf11e2f5023

Stefan Sperling 2020-03-18T16:13:45

use a dedicated imsg for sending the pack index output file descriptor

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;
 	}