2 * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <sys/queue.h>
18 #include <sys/types.h>
33 #include "got_error.h"
34 #include "got_cancel.h"
35 #include "got_object.h"
36 #include "got_repository.h"
37 #include "got_reference.h"
38 #include "got_repository_admin.h"
40 #include "got_lib_delta.h"
41 #include "got_lib_object.h"
42 #include "got_lib_object_idset.h"
43 #include "got_lib_sha1.h"
44 #include "got_lib_pack.h"
45 #include "got_lib_ratelimit.h"
46 #include "got_lib_pack_create.h"
47 #include "got_lib_poll.h"
51 #include "repo_read.h"
54 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
57 static struct repo_read {
60 struct got_repository *repo;
65 struct repo_read_client {
66 STAILQ_ENTRY(repo_read_client) entry;
72 struct gotd_object_id_array want_ids;
73 struct gotd_object_id_array have_ids;
75 STAILQ_HEAD(repo_read_clients, repo_read_client);
77 static struct repo_read_clients repo_read_clients[GOTD_CLIENT_TABLE_SIZE];
78 static SIPHASH_KEY clients_hash_key;
81 client_hash(uint32_t client_id)
83 return SipHash24(&clients_hash_key, &client_id, sizeof(client_id));
87 add_client(struct repo_read_client *client, uint32_t client_id, int fd)
91 client->id = client_id;
93 client->delta_cache_fd = -1;
94 client->pack_pipe = -1;
95 slot = client_hash(client->id) % nitems(repo_read_clients);
96 STAILQ_INSERT_HEAD(&repo_read_clients[slot], client, entry);
99 static struct repo_read_client *
100 find_client(uint32_t client_id)
103 struct repo_read_client *c;
105 slot = client_hash(client_id) % nitems(repo_read_clients);
106 STAILQ_FOREACH(c, &repo_read_clients[slot], entry) {
107 if (c->id == client_id)
114 static volatile sig_atomic_t sigint_received;
115 static volatile sig_atomic_t sigterm_received;
118 catch_sigint(int signo)
124 catch_sigterm(int signo)
126 sigterm_received = 1;
129 static const struct got_error *
130 check_cancelled(void *arg)
132 if (sigint_received || sigterm_received)
133 return got_error(GOT_ERR_CANCELLED);
138 static const struct got_error *
139 send_symref(struct got_reference *symref, struct imsgbuf *ibuf)
141 const struct got_error *err = NULL;
142 struct gotd_imsg_symref isymref;
143 const char *refname = got_ref_get_name(symref);
144 const char *target = got_ref_get_symref_target(symref);
147 struct got_object_id *target_id;
149 err = got_ref_resolve(&target_id, repo_read.repo, symref);
153 memset(&isymref, 0, sizeof(isymref));
154 isymref.name_len = strlen(refname);
155 isymref.target_len = strlen(target);
156 memcpy(isymref.target_id, target_id->sha1, sizeof(isymref.target_id));
158 len = sizeof(isymref) + isymref.name_len + isymref.target_len;
159 if (len > MAX_IMSGSIZE - IMSG_HEADER_SIZE) {
160 err = got_error(GOT_ERR_NO_SPACE);
164 wbuf = imsg_create(ibuf, GOTD_IMSG_SYMREF, 0, 0, len);
166 err = got_error_from_errno("imsg_create SYMREF");
170 if (imsg_add(wbuf, &isymref, sizeof(isymref)) == -1) {
171 err = got_error_from_errno("imsg_add SYMREF");
174 if (imsg_add(wbuf, refname, isymref.name_len) == -1) {
175 err = got_error_from_errno("imsg_add SYMREF");
178 if (imsg_add(wbuf, target, isymref.target_len) == -1) {
179 err = got_error_from_errno("imsg_add SYMREF");
184 imsg_close(ibuf, wbuf);
190 static const struct got_error *
191 send_peeled_tag_ref(struct got_reference *ref, struct got_object *obj,
192 struct imsgbuf *ibuf)
194 const struct got_error *err = NULL;
195 struct got_tag_object *tag;
197 char *peeled_refname = NULL;
198 struct got_object_id *id;
201 err = got_object_tag_open(&tag, repo_read.repo, obj);
205 if (asprintf(&peeled_refname, "%s^{}", got_ref_get_name(ref)) == -1) {
206 err = got_error_from_errno("asprintf");
210 id = got_object_tag_get_object_id(tag);
211 namelen = strlen(peeled_refname);
213 len = sizeof(struct gotd_imsg_ref) + namelen;
214 if (len > MAX_IMSGSIZE - IMSG_HEADER_SIZE) {
215 err = got_error(GOT_ERR_NO_SPACE);
219 wbuf = imsg_create(ibuf, GOTD_IMSG_REF, PROC_REPO_READ,
222 err = got_error_from_errno("imsg_create MREF");
226 /* Keep in sync with struct gotd_imsg_ref definition. */
227 if (imsg_add(wbuf, id->sha1, SHA1_DIGEST_LENGTH) == -1) {
228 err = got_error_from_errno("imsg_add REF");
231 if (imsg_add(wbuf, &namelen, sizeof(namelen)) == -1) {
232 err = got_error_from_errno("imsg_add REF");
235 if (imsg_add(wbuf, peeled_refname, namelen) == -1) {
236 err = got_error_from_errno("imsg_add REF");
241 imsg_close(ibuf, wbuf);
243 got_object_tag_close(tag);
247 static const struct got_error *
248 send_ref(struct got_reference *ref, struct imsgbuf *ibuf)
250 const struct got_error *err;
251 const char *refname = got_ref_get_name(ref);
253 struct got_object_id *id = NULL;
254 struct got_object *obj = NULL;
258 namelen = strlen(refname);
260 len = sizeof(struct gotd_imsg_ref) + namelen;
261 if (len > MAX_IMSGSIZE - IMSG_HEADER_SIZE)
262 return got_error(GOT_ERR_NO_SPACE);
264 err = got_ref_resolve(&id, repo_read.repo, ref);
268 wbuf = imsg_create(ibuf, GOTD_IMSG_REF, PROC_REPO_READ,
271 err = got_error_from_errno("imsg_create REF");
275 /* Keep in sync with struct gotd_imsg_ref definition. */
276 if (imsg_add(wbuf, id->sha1, SHA1_DIGEST_LENGTH) == -1)
277 return got_error_from_errno("imsg_add REF");
278 if (imsg_add(wbuf, &namelen, sizeof(namelen)) == -1)
279 return got_error_from_errno("imsg_add REF");
280 if (imsg_add(wbuf, refname, namelen) == -1)
281 return got_error_from_errno("imsg_add REF");
284 imsg_close(ibuf, wbuf);
286 err = got_object_open(&obj, repo_read.repo, id);
289 if (obj->type == GOT_OBJ_TYPE_TAG)
290 err = send_peeled_tag_ref(ref, obj, ibuf);
293 got_object_close(obj);
298 static const struct got_error *
299 list_refs(struct repo_read_client **client, struct imsg *imsg)
301 const struct got_error *err;
302 struct got_reflist_head refs;
303 struct got_reflist_entry *re;
304 struct gotd_imsg_list_refs_internal ireq;
306 struct gotd_imsg_reflist irefs;
308 int client_fd = imsg->fd;
313 return got_error(GOT_ERR_PRIVSEP_NO_FD);
315 datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
316 if (datalen != sizeof(ireq))
317 return got_error(GOT_ERR_PRIVSEP_LEN);
318 memcpy(&ireq, imsg->data, sizeof(ireq));
320 *client = find_client(ireq.client_id);
322 return got_error_msg(GOT_ERR_CLIENT_ID, "duplicate client ID");
324 *client = calloc(1, sizeof(**client));
326 return got_error_from_errno("calloc");
327 add_client(*client, ireq.client_id, client_fd);
329 imsg_init(&ibuf, client_fd);
331 err = got_ref_list(&refs, repo_read.repo, "",
332 got_ref_cmp_by_name, NULL);
336 memset(&irefs, 0, sizeof(irefs));
337 TAILQ_FOREACH(re, &refs, entry) {
338 struct got_object_id *id;
341 if (got_ref_is_symbolic(re->ref)) {
342 const char *refname = got_ref_get_name(re->ref);
343 if (strcmp(refname, GOT_REF_HEAD) == 0)
350 /* Account for a peeled tag refs. */
351 err = got_ref_resolve(&id, repo_read.repo, re->ref);
354 err = got_object_get_type(&obj_type, repo_read.repo, id);
358 if (obj_type == GOT_OBJ_TYPE_TAG)
362 if (imsg_compose(&ibuf, GOTD_IMSG_REFLIST, PROC_REPO_READ,
363 repo_read.pid, -1, &irefs, sizeof(irefs)) == -1) {
364 err = got_error_from_errno("imsg_compose REFLIST");
369 * Send the HEAD symref first. In Git-protocol versions < 2
370 * the HEAD symref must be announced on the initial line of
371 * the server's ref advertisement.
372 * For now, we do not advertise symrefs other than HEAD.
374 TAILQ_FOREACH(re, &refs, entry) {
375 if (!got_ref_is_symbolic(re->ref) ||
376 strcmp(got_ref_get_name(re->ref), GOT_REF_HEAD) != 0)
378 err = send_symref(re->ref, &ibuf);
383 TAILQ_FOREACH(re, &refs, entry) {
384 if (got_ref_is_symbolic(re->ref))
386 err = send_ref(re->ref, &ibuf);
391 err = gotd_imsg_flush(&ibuf);
393 got_ref_list_free(&refs);
398 static const struct got_error *
399 record_object_id(struct gotd_object_id_array *array, struct got_object_id *id)
401 const size_t alloc_chunksz = 256;
403 if (array->ids == NULL) {
404 array->ids = reallocarray(NULL, alloc_chunksz,
405 sizeof(*array->ids));
406 if (array->ids == NULL)
407 return got_error_from_errno("reallocarray");
408 array->nalloc = alloc_chunksz;
410 } else if (array->nalloc <= array->nids) {
411 struct got_object_id **new;
412 new = recallocarray(array->ids, array->nalloc,
413 array->nalloc + alloc_chunksz, sizeof(*new));
415 return got_error_from_errno("recallocarray");
417 array->nalloc += alloc_chunksz;
420 array->ids[array->nids] = got_object_id_dup(id);
421 if (array->ids[array->nids] == NULL)
422 return got_error_from_errno("got_object_id_dup");
428 free_object_ids(struct gotd_object_id_array *array)
432 for (i = 0; i < array->nids; i++)
441 static const struct got_error *
442 recv_want(struct repo_read_client **client, struct imsg *imsg)
444 const struct got_error *err;
445 struct gotd_imsg_want iwant;
447 char hex[SHA1_DIGEST_STRING_LENGTH];
448 struct got_object_id id;
452 datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
453 if (datalen != sizeof(iwant))
454 return got_error(GOT_ERR_PRIVSEP_LEN);
455 memcpy(&iwant, imsg->data, sizeof(iwant));
457 memset(&id, 0, sizeof(id));
458 memcpy(id.sha1, iwant.object_id, SHA1_DIGEST_LENGTH);
460 if (log_getverbose() > 0 &&
461 got_sha1_digest_to_str(id.sha1, hex, sizeof(hex)))
462 log_debug("client wants %s", hex);
464 *client = find_client(iwant.client_id);
466 return got_error(GOT_ERR_CLIENT_ID);
468 imsg_init(&ibuf, (*client)->fd);
470 err = got_object_get_type(&obj_type, repo_read.repo, &id);
474 if (obj_type != GOT_OBJ_TYPE_COMMIT &&
475 obj_type != GOT_OBJ_TYPE_TAG)
476 return got_error(GOT_ERR_OBJ_TYPE);
478 err = record_object_id(&(*client)->want_ids, &id);
482 gotd_imsg_send_ack(&id, &ibuf, PROC_REPO_READ, repo_read.pid);
487 static const struct got_error *
488 recv_have(struct repo_read_client **client, struct imsg *imsg)
490 const struct got_error *err;
491 struct gotd_imsg_have ihave;
493 char hex[SHA1_DIGEST_STRING_LENGTH];
494 struct got_object_id id;
498 datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
499 if (datalen != sizeof(ihave))
500 return got_error(GOT_ERR_PRIVSEP_LEN);
501 memcpy(&ihave, imsg->data, sizeof(ihave));
503 memset(&id, 0, sizeof(id));
504 memcpy(id.sha1, ihave.object_id, SHA1_DIGEST_LENGTH);
506 if (log_getverbose() > 0 &&
507 got_sha1_digest_to_str(id.sha1, hex, sizeof(hex)))
508 log_debug("client has %s", hex);
510 *client = find_client(ihave.client_id);
512 return got_error(GOT_ERR_CLIENT_ID);
514 imsg_init(&ibuf, (*client)->fd);
516 err = got_object_get_type(&obj_type, repo_read.repo, &id);
518 if (err->code == GOT_ERR_NO_OBJ) {
519 gotd_imsg_send_nak(&id, &ibuf,
520 PROC_REPO_READ, repo_read.pid);
526 if (obj_type != GOT_OBJ_TYPE_COMMIT &&
527 obj_type != GOT_OBJ_TYPE_TAG) {
528 gotd_imsg_send_nak(&id, &ibuf, PROC_REPO_READ, repo_read.pid);
529 err = got_error(GOT_ERR_OBJ_TYPE);
533 err = record_object_id(&(*client)->have_ids, &id);
537 gotd_imsg_send_ack(&id, &ibuf, PROC_REPO_READ, repo_read.pid);
543 struct repo_read_pack_progress_arg {
545 struct imsgbuf *ibuf;
549 static const struct got_error *
550 pack_progress(void *arg, int ncolored, int nfound, int ntrees,
551 off_t packfile_size, int ncommits, int nobj_total, int nobj_deltify,
554 struct repo_read_pack_progress_arg *a = arg;
555 struct gotd_imsg_packfile_progress iprog;
558 if (!a->report_progress)
560 if (packfile_size > 0 && a->sent_ready)
563 memset(&iprog, 0, sizeof(iprog));
564 iprog.ncolored = ncolored;
565 iprog.nfound = nfound;
566 iprog.ntrees = ntrees;
567 iprog.packfile_size = packfile_size;
568 iprog.ncommits = ncommits;
569 iprog.nobj_total = nobj_total;
570 iprog.nobj_deltify = nobj_deltify;
571 iprog.nobj_written = nobj_written;
573 /* Using synchronous writes since we are blocking the event loop. */
574 if (packfile_size == 0) {
575 ret = imsg_compose(a->ibuf, GOTD_IMSG_PACKFILE_PROGRESS,
576 PROC_REPO_READ, repo_read.pid, -1, &iprog, sizeof(iprog));
578 return got_error_from_errno("imsg compose "
579 "PACKFILE_PROGRESS");
583 ret = imsg_compose(a->ibuf, GOTD_IMSG_PACKFILE_READY,
584 PROC_REPO_READ, repo_read.pid, -1, &iprog, sizeof(iprog));
586 return got_error_from_errno("imsg compose "
591 return gotd_imsg_flush(a->ibuf);
594 static const struct got_error *
595 receive_delta_cache_fd(struct repo_read_client **client, struct imsg *imsg,
596 struct gotd_imsgev *iev)
598 struct gotd_imsg_send_packfile ireq;
601 log_debug("receving delta cache file");
604 return got_error(GOT_ERR_PRIVSEP_NO_FD);
606 datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
607 if (datalen != sizeof(ireq))
608 return got_error(GOT_ERR_PRIVSEP_LEN);
609 memcpy(&ireq, imsg->data, sizeof(ireq));
611 *client = find_client(ireq.client_id);
613 return got_error(GOT_ERR_CLIENT_ID);
615 if ((*client)->delta_cache_fd != -1)
616 return got_error(GOT_ERR_PRIVSEP_MSG);
618 (*client)->delta_cache_fd = imsg->fd;
619 (*client)->report_progress = ireq.report_progress;
623 static const struct got_error *
624 receive_pack_pipe(struct repo_read_client **client, struct imsg *imsg,
625 struct gotd_imsgev *iev)
627 struct gotd_imsg_packfile_pipe ireq;
630 log_debug("receving pack pipe descriptor");
633 return got_error(GOT_ERR_PRIVSEP_NO_FD);
635 datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
636 if (datalen != sizeof(ireq))
637 return got_error(GOT_ERR_PRIVSEP_LEN);
638 memcpy(&ireq, imsg->data, sizeof(ireq));
640 *client = find_client(ireq.client_id);
642 return got_error(GOT_ERR_CLIENT_ID);
643 if ((*client)->pack_pipe != -1)
644 return got_error(GOT_ERR_PRIVSEP_MSG);
646 (*client)->pack_pipe = imsg->fd;
650 static const struct got_error *
651 send_packfile(struct repo_read_client *client, struct imsg *imsg,
652 struct gotd_imsgev *iev)
654 const struct got_error *err = NULL;
655 struct gotd_imsg_packfile_done idone;
656 uint8_t packsha1[SHA1_DIGEST_LENGTH];
657 char hex[SHA1_DIGEST_STRING_LENGTH];
658 FILE *delta_cache = NULL;
660 struct repo_read_pack_progress_arg pa;
661 struct got_ratelimit rl;
663 log_debug("packfile request received");
665 got_ratelimit_init(&rl, 2, 0);
667 if (client->delta_cache_fd == -1 || client->pack_pipe == -1)
668 return got_error(GOT_ERR_PRIVSEP_NO_FD);
670 imsg_init(&ibuf, client->fd);
672 delta_cache = fdopen(client->delta_cache_fd, "w+");
673 if (delta_cache == NULL) {
674 err = got_error_from_errno("fdopen");
677 client->delta_cache_fd = -1;
679 memset(&pa, 0, sizeof(pa));
681 pa.report_progress = client->report_progress;
683 err = got_pack_create(packsha1, client->pack_pipe, delta_cache,
684 client->have_ids.ids, client->have_ids.nids,
685 client->want_ids.ids, client->want_ids.nids,
686 repo_read.repo, 0, 1, pack_progress, &pa, &rl,
687 check_cancelled, NULL);
691 if (log_getverbose() > 0 &&
692 got_sha1_digest_to_str(packsha1, hex, sizeof(hex)))
693 log_debug("sent pack-%s.pack", hex);
695 memset(&idone, 0, sizeof(idone));
696 idone.client_id = client->id;
697 if (gotd_imsg_compose_event(iev, GOTD_IMSG_PACKFILE_DONE,
698 PROC_REPO_READ, -1, &idone, sizeof(idone)) == -1)
699 err = got_error_from_errno("imsg compose PACKFILE_DONE");
701 if (delta_cache != NULL && fclose(delta_cache) == EOF && err == NULL)
702 err = got_error_from_errno("fclose");
707 static const struct got_error *
708 recv_disconnect(struct imsg *imsg)
710 const struct got_error *err = NULL;
711 struct gotd_imsg_disconnect idisconnect;
713 int client_fd, delta_cache_fd, pack_pipe;
714 struct repo_read_client *client = NULL;
717 datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
718 if (datalen != sizeof(idisconnect))
719 return got_error(GOT_ERR_PRIVSEP_LEN);
720 memcpy(&idisconnect, imsg->data, sizeof(idisconnect));
722 log_debug("client disconnecting");
724 client = find_client(idisconnect.client_id);
726 return got_error(GOT_ERR_CLIENT_ID);
728 slot = client_hash(client->id) % nitems(repo_read_clients);
729 STAILQ_REMOVE(&repo_read_clients[slot], client, repo_read_client,
731 free_object_ids(&client->have_ids);
732 free_object_ids(&client->want_ids);
733 client_fd = client->fd;
734 delta_cache_fd = client->delta_cache_fd;
735 pack_pipe = client->pack_pipe;
737 if (close(client_fd) == -1)
738 err = got_error_from_errno("close");
739 if (delta_cache_fd != -1 && close(delta_cache_fd) == -1 && err == NULL)
740 return got_error_from_errno("close");
741 if (pack_pipe != -1 && close(pack_pipe) == -1 && err == NULL)
742 return got_error_from_errno("close");
747 repo_read_dispatch(int fd, short event, void *arg)
749 const struct got_error *err = NULL;
750 struct gotd_imsgev *iev = arg;
751 struct imsgbuf *ibuf = &iev->ibuf;
755 struct repo_read_client *client = NULL;
757 if (event & EV_READ) {
758 if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
759 fatal("imsg_read error");
760 if (n == 0) /* Connection closed. */
764 if (event & EV_WRITE) {
765 n = msgbuf_write(&ibuf->w);
766 if (n == -1 && errno != EAGAIN)
767 fatal("msgbuf_write");
768 if (n == 0) /* Connection closed. */
772 while (err == NULL && check_cancelled(NULL) == NULL) {
774 if ((n = imsg_get(ibuf, &imsg)) == -1)
775 fatal("%s: imsg_get", __func__);
776 if (n == 0) /* No more messages. */
779 switch (imsg.hdr.type) {
780 case GOTD_IMSG_LIST_REFS_INTERNAL:
781 err = list_refs(&client, &imsg);
783 log_warnx("%s: ls-refs: %s", repo_read.title,
787 err = recv_want(&client, &imsg);
789 log_warnx("%s: want-line: %s", repo_read.title,
793 err = recv_have(&client, &imsg);
795 log_warnx("%s: have-line: %s", repo_read.title,
798 case GOTD_IMSG_SEND_PACKFILE:
799 err = receive_delta_cache_fd(&client, &imsg, iev);
801 log_warnx("%s: receiving delta cache: %s",
802 repo_read.title, err->msg);
804 case GOTD_IMSG_PACKFILE_PIPE:
805 err = receive_pack_pipe(&client, &imsg, iev);
807 log_warnx("%s: receiving pack pipe: %s",
808 repo_read.title, err->msg);
811 if (client->pack_pipe == -1)
813 err = send_packfile(client, &imsg, iev);
815 log_warnx("%s: sending packfile: %s",
816 repo_read.title, err->msg);
818 case GOTD_IMSG_DISCONNECT:
819 err = recv_disconnect(&imsg);
821 log_warnx("%s: disconnect: %s",
822 repo_read.title, err->msg);
825 log_debug("%s: unexpected imsg %d", repo_read.title,
833 if (!shut && check_cancelled(NULL) == NULL) {
835 gotd_imsg_send_error_event(iev, PROC_REPO_READ,
836 client ? client->id : 0, err) == -1) {
837 log_warnx("could not send error to parent: %s",
840 gotd_imsg_event_add(iev);
842 /* This pipe is dead. Remove its event handler */
844 event_loopexit(NULL);
849 repo_read_main(const char *title, int *pack_fds, int *temp_fds)
851 const struct got_error *err = NULL;
852 struct gotd_imsgev iev;
854 repo_read.title = title;
855 repo_read.pid = getpid();
856 repo_read.pack_fds = pack_fds;
857 repo_read.temp_fds = temp_fds;
859 arc4random_buf(&clients_hash_key, sizeof(clients_hash_key));
862 * Open a repository in the root directory.
863 * We are already in chroot at this point.
865 err = got_repo_open(&repo_read.repo, "/", NULL, pack_fds);
868 if (!got_repo_is_bare(repo_read.repo)) {
869 err = got_error_msg(GOT_ERR_NOT_GIT_REPO,
870 "bare git repository required");
874 got_repo_temp_fds_set(repo_read.repo, temp_fds);
876 signal(SIGINT, catch_sigint);
877 signal(SIGTERM, catch_sigterm);
878 signal(SIGPIPE, SIG_IGN);
879 signal(SIGHUP, SIG_IGN);
881 imsg_init(&iev.ibuf, GOTD_SOCK_FILENO);
882 iev.handler = repo_read_dispatch;
883 iev.events = EV_READ;
884 iev.handler_arg = NULL;
885 event_set(&iev.ev, iev.ibuf.fd, EV_READ, repo_read_dispatch, &iev);
886 if (event_add(&iev.ev, NULL) == -1) {
887 err = got_error_from_errno("event_add");
894 log_warnx("%s: %s", title, err->msg);
895 repo_read_shutdown();
899 repo_read_shutdown(void)
901 log_debug("%s: shutting down", repo_read.title);
903 got_repo_close(repo_read.repo);
904 got_repo_pack_fds_close(repo_read.pack_fds);
905 got_repo_temp_fds_close(repo_read.temp_fds);