2 876c234b 2018-09-10 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 876c234b 2018-09-10 stsp * Permission to use, copy, modify, and distribute this software for any
5 876c234b 2018-09-10 stsp * purpose with or without fee is hereby granted, provided that the above
6 876c234b 2018-09-10 stsp * copyright notice and this permission notice appear in all copies.
8 876c234b 2018-09-10 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 876c234b 2018-09-10 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 876c234b 2018-09-10 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 876c234b 2018-09-10 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 876c234b 2018-09-10 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 876c234b 2018-09-10 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 876c234b 2018-09-10 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 876c234b 2018-09-10 stsp #include <sys/types.h>
18 876c234b 2018-09-10 stsp #include <sys/queue.h>
19 876c234b 2018-09-10 stsp #include <sys/uio.h>
20 876c234b 2018-09-10 stsp #include <sys/time.h>
21 876c234b 2018-09-10 stsp #include <sys/limits.h>
22 876c234b 2018-09-10 stsp #include <sys/syslimits.h>
23 876c234b 2018-09-10 stsp #include <sys/mman.h>
25 876c234b 2018-09-10 stsp #include <limits.h>
26 99437157 2018-11-11 stsp #include <signal.h>
27 876c234b 2018-09-10 stsp #include <stdint.h>
28 876c234b 2018-09-10 stsp #include <imsg.h>
29 876c234b 2018-09-10 stsp #include <stdio.h>
30 876c234b 2018-09-10 stsp #include <stdlib.h>
31 876c234b 2018-09-10 stsp #include <string.h>
32 876c234b 2018-09-10 stsp #include <sha1.h>
33 876c234b 2018-09-10 stsp #include <zlib.h>
35 876c234b 2018-09-10 stsp #include "got_error.h"
36 876c234b 2018-09-10 stsp #include "got_object.h"
38 876c234b 2018-09-10 stsp #include "got_lib_delta.h"
39 876c234b 2018-09-10 stsp #include "got_lib_inflate.h"
40 876c234b 2018-09-10 stsp #include "got_lib_object.h"
41 c59b3346 2018-09-11 stsp #include "got_lib_object_cache.h"
42 876c234b 2018-09-10 stsp #include "got_lib_object_parse.h"
43 876c234b 2018-09-10 stsp #include "got_lib_privsep.h"
44 876c234b 2018-09-10 stsp #include "got_lib_pack.h"
46 99437157 2018-11-11 stsp static volatile sig_atomic_t sigint_received;
49 99437157 2018-11-11 stsp catch_sigint(int signo)
51 99437157 2018-11-11 stsp sigint_received = 1;
54 876c234b 2018-09-10 stsp static const struct got_error *
55 876c234b 2018-09-10 stsp object_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
56 c59b3346 2018-09-11 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
58 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
59 876c234b 2018-09-10 stsp struct got_imsg_packed_object iobj;
60 876c234b 2018-09-10 stsp struct got_object *obj;
61 106807b4 2018-09-15 stsp struct got_object_id id;
62 876c234b 2018-09-10 stsp size_t datalen;
64 876c234b 2018-09-10 stsp datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
65 876c234b 2018-09-10 stsp if (datalen != sizeof(iobj))
66 876c234b 2018-09-10 stsp return got_error(GOT_ERR_PRIVSEP_LEN);
67 876c234b 2018-09-10 stsp memcpy(&iobj, imsg->data, sizeof(iobj));
68 106807b4 2018-09-15 stsp memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH);
70 106807b4 2018-09-15 stsp err = got_packfile_open_object(&obj, pack, packidx, iobj.idx, &id);
73 c59b3346 2018-09-11 stsp obj->refcnt++;
75 c59b3346 2018-09-11 stsp err = got_object_cache_add(objcache, &obj->id, obj);
78 c59b3346 2018-09-11 stsp obj->refcnt++;
80 876c234b 2018-09-10 stsp err = got_privsep_send_obj(ibuf, obj);
82 876c234b 2018-09-10 stsp got_object_close(obj);
86 876c234b 2018-09-10 stsp static const struct got_error *
87 c59b3346 2018-09-11 stsp get_object(struct got_object **obj, struct imsg *imsg, struct imsgbuf *ibuf,
88 c59b3346 2018-09-11 stsp struct got_pack *pack, struct got_packidx *packidx,
89 c59b3346 2018-09-11 stsp struct got_object_cache *objcache, int type)
91 c59b3346 2018-09-11 stsp const struct got_error *err = NULL;
92 c59b3346 2018-09-11 stsp struct got_object *iobj;
94 c59b3346 2018-09-11 stsp err = got_privsep_get_imsg_obj(&iobj, imsg, ibuf);
98 c59b3346 2018-09-11 stsp if (iobj->type != type) {
99 c59b3346 2018-09-11 stsp err = got_error(GOT_ERR_OBJ_TYPE);
103 c59b3346 2018-09-11 stsp if ((iobj->flags & GOT_OBJ_FLAG_PACKED) == 0)
104 c59b3346 2018-09-11 stsp return got_error(GOT_ERR_OBJ_NOT_PACKED);
106 c59b3346 2018-09-11 stsp *obj = got_object_cache_get(objcache, &iobj->id);
107 c59b3346 2018-09-11 stsp if (*obj == NULL) {
108 c59b3346 2018-09-11 stsp err = got_packfile_open_object(obj, pack, packidx,
109 c59b3346 2018-09-11 stsp iobj->pack_idx, &iobj->id);
113 c59b3346 2018-09-11 stsp (*obj)->refcnt++;
115 c59b3346 2018-09-11 stsp got_object_close(iobj);
116 c59b3346 2018-09-11 stsp return err;
119 c59b3346 2018-09-11 stsp static const struct got_error *
120 876c234b 2018-09-10 stsp commit_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
121 c59b3346 2018-09-11 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
123 cfd633c2 2018-09-10 stsp const struct got_error *err = NULL;
124 cfd633c2 2018-09-10 stsp struct got_object *obj = NULL;
125 cfd633c2 2018-09-10 stsp struct got_commit_object *commit = NULL;
126 cfd633c2 2018-09-10 stsp uint8_t *buf;
127 cfd633c2 2018-09-10 stsp size_t len;
129 c59b3346 2018-09-11 stsp err = get_object(&obj, imsg, ibuf, pack, packidx, objcache,
130 c59b3346 2018-09-11 stsp GOT_OBJ_TYPE_COMMIT);
132 cfd633c2 2018-09-10 stsp return err;
134 cfd633c2 2018-09-10 stsp err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack);
136 cfd633c2 2018-09-10 stsp return err;
138 cfd633c2 2018-09-10 stsp obj->size = len;
139 cfd633c2 2018-09-10 stsp err = got_object_parse_commit(&commit, buf, len);
142 cfd633c2 2018-09-10 stsp err = got_privsep_send_commit(ibuf, commit);
144 cfd633c2 2018-09-10 stsp got_object_close(obj);
145 cfd633c2 2018-09-10 stsp got_object_commit_close(commit);
147 7762fe12 2018-11-05 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
148 7762fe12 2018-11-05 stsp err = NULL;
150 7762fe12 2018-11-05 stsp got_privsep_send_error(ibuf, err);
153 7762fe12 2018-11-05 stsp return err;
156 7762fe12 2018-11-05 stsp static const struct got_error *
157 876c234b 2018-09-10 stsp tree_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
158 c59b3346 2018-09-11 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
160 e7885405 2018-09-10 stsp const struct got_error *err = NULL;
161 e7885405 2018-09-10 stsp struct got_object *obj = NULL;
162 e7885405 2018-09-10 stsp struct got_tree_object *tree = NULL;
163 e7885405 2018-09-10 stsp uint8_t *buf;
164 e7885405 2018-09-10 stsp size_t len;
166 c59b3346 2018-09-11 stsp err = get_object(&obj, imsg, ibuf, pack, packidx, objcache,
167 c59b3346 2018-09-11 stsp GOT_OBJ_TYPE_TREE);
169 e7885405 2018-09-10 stsp return err;
171 e7885405 2018-09-10 stsp err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack);
173 e7885405 2018-09-10 stsp return err;
175 e7885405 2018-09-10 stsp obj->size = len;
176 e7885405 2018-09-10 stsp err = got_object_parse_tree(&tree, buf, len);
179 e7885405 2018-09-10 stsp err = got_privsep_send_tree(ibuf, tree);
181 e7885405 2018-09-10 stsp got_object_close(obj);
182 e7885405 2018-09-10 stsp got_object_tree_close(tree);
184 e7885405 2018-09-10 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
185 e7885405 2018-09-10 stsp err = NULL;
187 e7885405 2018-09-10 stsp got_privsep_send_error(ibuf, err);
190 e7885405 2018-09-10 stsp return err;
193 876c234b 2018-09-10 stsp static const struct got_error *
194 3840f4c9 2018-09-12 stsp receive_file(FILE **f, struct imsgbuf *ibuf, int imsg_code)
196 3840f4c9 2018-09-12 stsp const struct got_error *err;
197 3840f4c9 2018-09-12 stsp struct imsg imsg;
198 55da3778 2018-09-10 stsp size_t datalen;
200 3840f4c9 2018-09-12 stsp err = got_privsep_recv_imsg(&imsg, ibuf, 0);
202 55da3778 2018-09-10 stsp return err;
204 3840f4c9 2018-09-12 stsp if (imsg.hdr.type != imsg_code) {
205 55da3778 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_MSG);
209 3840f4c9 2018-09-12 stsp datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
210 55da3778 2018-09-10 stsp if (datalen != 0) {
211 55da3778 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
214 3840f4c9 2018-09-12 stsp if (imsg.fd == -1) {
215 55da3778 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_NO_FD);
219 3840f4c9 2018-09-12 stsp *f = fdopen(imsg.fd, "w+");
220 3840f4c9 2018-09-12 stsp if (*f == NULL) {
221 3840f4c9 2018-09-12 stsp close(imsg.fd);
222 55da3778 2018-09-10 stsp err = got_error_from_errno();
226 3840f4c9 2018-09-12 stsp imsg_free(&imsg);
227 3840f4c9 2018-09-12 stsp return err;
230 3840f4c9 2018-09-12 stsp static const struct got_error *
231 3840f4c9 2018-09-12 stsp blob_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
232 3840f4c9 2018-09-12 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
234 3840f4c9 2018-09-12 stsp const struct got_error *err = NULL;
235 3840f4c9 2018-09-12 stsp struct got_object *obj = NULL;
236 3840f4c9 2018-09-12 stsp FILE *outfile = NULL, *basefile = NULL, *accumfile = NULL;
238 3840f4c9 2018-09-12 stsp err = get_object(&obj, imsg, ibuf, pack, packidx, objcache,
239 3840f4c9 2018-09-12 stsp GOT_OBJ_TYPE_BLOB);
241 3840f4c9 2018-09-12 stsp return err;
243 3840f4c9 2018-09-12 stsp err = receive_file(&outfile, ibuf, GOT_IMSG_BLOB_OUTFD);
245 3840f4c9 2018-09-12 stsp return err;
246 3840f4c9 2018-09-12 stsp err = receive_file(&basefile, ibuf, GOT_IMSG_TMPFD);
248 3840f4c9 2018-09-12 stsp return err;
249 3840f4c9 2018-09-12 stsp err = receive_file(&accumfile, ibuf, GOT_IMSG_TMPFD);
251 3840f4c9 2018-09-12 stsp return err;
253 3840f4c9 2018-09-12 stsp err = got_packfile_extract_object(pack, obj, outfile, basefile,
254 3840f4c9 2018-09-12 stsp accumfile);
258 55da3778 2018-09-10 stsp err = got_privsep_send_blob(ibuf, obj->size);
260 3840f4c9 2018-09-12 stsp if (outfile)
261 3840f4c9 2018-09-12 stsp fclose(outfile);
262 3840f4c9 2018-09-12 stsp if (basefile)
263 3840f4c9 2018-09-12 stsp fclose(basefile);
264 3840f4c9 2018-09-12 stsp if (accumfile)
265 3840f4c9 2018-09-12 stsp fclose(accumfile);
267 c59b3346 2018-09-11 stsp got_object_close(obj);
268 3840f4c9 2018-09-12 stsp if (err && err->code != GOT_ERR_PRIVSEP_PIPE)
269 3840f4c9 2018-09-12 stsp got_privsep_send_error(ibuf, err);
271 55da3778 2018-09-10 stsp return err;
274 876c234b 2018-09-10 stsp static const struct got_error *
275 f4a881ce 2018-11-17 stsp tag_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
276 f4a881ce 2018-11-17 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
278 f4a881ce 2018-11-17 stsp const struct got_error *err = NULL;
279 f4a881ce 2018-11-17 stsp struct got_object *obj = NULL;
280 f4a881ce 2018-11-17 stsp struct got_tag_object *tag = NULL;
281 f4a881ce 2018-11-17 stsp uint8_t *buf;
282 f4a881ce 2018-11-17 stsp size_t len;
284 f4a881ce 2018-11-17 stsp err = get_object(&obj, imsg, ibuf, pack, packidx, objcache,
285 f4a881ce 2018-11-17 stsp GOT_OBJ_TYPE_TAG);
287 f4a881ce 2018-11-17 stsp return err;
289 f4a881ce 2018-11-17 stsp err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack);
291 f4a881ce 2018-11-17 stsp return err;
293 f4a881ce 2018-11-17 stsp obj->size = len;
294 f4a881ce 2018-11-17 stsp err = got_object_parse_tag(&tag, buf, len);
297 f4a881ce 2018-11-17 stsp err = got_privsep_send_tag(ibuf, tag);
299 f4a881ce 2018-11-17 stsp got_object_close(obj);
300 f4a881ce 2018-11-17 stsp got_object_tag_close(tag);
302 f4a881ce 2018-11-17 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
303 f4a881ce 2018-11-17 stsp err = NULL;
305 f4a881ce 2018-11-17 stsp got_privsep_send_error(ibuf, err);
308 f4a881ce 2018-11-17 stsp return err;
311 f4a881ce 2018-11-17 stsp static const struct got_error *
312 876c234b 2018-09-10 stsp receive_packidx(struct got_packidx **packidx, struct imsgbuf *ibuf)
314 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
315 876c234b 2018-09-10 stsp struct imsg imsg;
316 876c234b 2018-09-10 stsp struct got_imsg_packidx ipackidx;
317 876c234b 2018-09-10 stsp size_t datalen;
318 876c234b 2018-09-10 stsp struct got_packidx *p;
320 876c234b 2018-09-10 stsp *packidx = NULL;
322 876c234b 2018-09-10 stsp err = got_privsep_recv_imsg(&imsg, ibuf, 0);
324 876c234b 2018-09-10 stsp return err;
326 876c234b 2018-09-10 stsp p = calloc(1, sizeof(*p));
327 876c234b 2018-09-10 stsp if (p == NULL) {
328 876c234b 2018-09-10 stsp err = got_error_from_errno();
332 876c234b 2018-09-10 stsp if (imsg.hdr.type != GOT_IMSG_PACKIDX) {
333 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_MSG);
337 876c234b 2018-09-10 stsp if (imsg.fd == -1) {
338 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_NO_FD);
342 876c234b 2018-09-10 stsp datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
343 876c234b 2018-09-10 stsp if (datalen != sizeof(ipackidx)) {
344 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
347 876c234b 2018-09-10 stsp memcpy(&ipackidx, imsg.data, sizeof(ipackidx));
349 876c234b 2018-09-10 stsp p->len = ipackidx.len;
350 876c234b 2018-09-10 stsp p->fd = dup(imsg.fd);
351 876c234b 2018-09-10 stsp if (p->fd == -1) {
352 56bef47a 2018-09-15 stsp err = got_error_from_errno();
355 56bef47a 2018-09-15 stsp if (lseek(p->fd, 0, SEEK_SET) == -1) {
356 876c234b 2018-09-10 stsp err = got_error_from_errno();
360 876c234b 2018-09-10 stsp #ifndef GOT_PACK_NO_MMAP
361 876c234b 2018-09-10 stsp p->map = mmap(NULL, p->len, PROT_READ, MAP_PRIVATE, p->fd, 0);
362 876c234b 2018-09-10 stsp if (p->map == MAP_FAILED)
363 876c234b 2018-09-10 stsp p->map = NULL; /* fall back to read(2) */
365 876c234b 2018-09-10 stsp err = got_packidx_init_hdr(p, 1);
368 876c234b 2018-09-10 stsp if (imsg.fd != -1)
369 876c234b 2018-09-10 stsp close(imsg.fd);
370 876c234b 2018-09-10 stsp got_packidx_close(p);
372 876c234b 2018-09-10 stsp *packidx = p;
373 876c234b 2018-09-10 stsp imsg_free(&imsg);
374 876c234b 2018-09-10 stsp return err;
377 876c234b 2018-09-10 stsp static const struct got_error *
378 876c234b 2018-09-10 stsp receive_pack(struct got_pack **packp, struct imsgbuf *ibuf)
380 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
381 876c234b 2018-09-10 stsp struct imsg imsg;
382 876c234b 2018-09-10 stsp struct got_imsg_pack ipack;
383 876c234b 2018-09-10 stsp size_t datalen;
384 876c234b 2018-09-10 stsp struct got_pack *pack;
386 876c234b 2018-09-10 stsp *packp = NULL;
388 876c234b 2018-09-10 stsp err = got_privsep_recv_imsg(&imsg, ibuf, 0);
390 876c234b 2018-09-10 stsp return err;
392 876c234b 2018-09-10 stsp pack = calloc(1, sizeof(*pack));
393 876c234b 2018-09-10 stsp if (pack == NULL) {
394 876c234b 2018-09-10 stsp err = got_error_from_errno();
398 876c234b 2018-09-10 stsp if (imsg.hdr.type != GOT_IMSG_PACK) {
399 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_MSG);
403 876c234b 2018-09-10 stsp if (imsg.fd == -1) {
404 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_NO_FD);
408 876c234b 2018-09-10 stsp datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
409 876c234b 2018-09-10 stsp if (datalen != sizeof(ipack)) {
410 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
413 876c234b 2018-09-10 stsp memcpy(&ipack, imsg.data, sizeof(ipack));
415 876c234b 2018-09-10 stsp pack->filesize = ipack.filesize;
416 876c234b 2018-09-10 stsp pack->fd = dup(imsg.fd);
417 876c234b 2018-09-10 stsp if (pack->fd == -1) {
418 876c234b 2018-09-10 stsp err = got_error_from_errno();
421 56bef47a 2018-09-15 stsp if (lseek(pack->fd, 0, SEEK_SET) == -1) {
422 56bef47a 2018-09-15 stsp err = got_error_from_errno();
425 876c234b 2018-09-10 stsp pack->path_packfile = strdup(ipack.path_packfile);
426 876c234b 2018-09-10 stsp if (pack->path_packfile == NULL) {
427 876c234b 2018-09-10 stsp err = got_error_from_errno();
431 876c234b 2018-09-10 stsp #ifndef GOT_PACK_NO_MMAP
432 876c234b 2018-09-10 stsp pack->map = mmap(NULL, pack->filesize, PROT_READ, MAP_PRIVATE,
433 876c234b 2018-09-10 stsp pack->fd, 0);
434 876c234b 2018-09-10 stsp if (pack->map == MAP_FAILED)
435 876c234b 2018-09-10 stsp pack->map = NULL; /* fall back to read(2) */
439 876c234b 2018-09-10 stsp if (imsg.fd != -1)
440 876c234b 2018-09-10 stsp close(imsg.fd);
441 876c234b 2018-09-10 stsp free(pack);
443 876c234b 2018-09-10 stsp *packp = pack;
444 876c234b 2018-09-10 stsp imsg_free(&imsg);
445 876c234b 2018-09-10 stsp return err;
449 876c234b 2018-09-10 stsp main(int argc, char *argv[])
451 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
452 876c234b 2018-09-10 stsp struct imsgbuf ibuf;
453 876c234b 2018-09-10 stsp struct imsg imsg;
454 c59b3346 2018-09-11 stsp struct got_packidx *packidx = NULL;
455 c59b3346 2018-09-11 stsp struct got_pack *pack = NULL;
456 c59b3346 2018-09-11 stsp struct got_object_cache objcache;
458 876c234b 2018-09-10 stsp //static int attached;
459 876c234b 2018-09-10 stsp //while (!attached) sleep(1);
461 99437157 2018-11-11 stsp signal(SIGINT, catch_sigint);
463 876c234b 2018-09-10 stsp imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
465 c59b3346 2018-09-11 stsp err = got_object_cache_init(&objcache, GOT_OBJECT_CACHE_TYPE_OBJ);
467 c59b3346 2018-09-11 stsp err = got_error_from_errno();
468 c59b3346 2018-09-11 stsp got_privsep_send_error(&ibuf, err);
472 2ff12563 2018-09-15 stsp #ifndef PROFILE
473 876c234b 2018-09-10 stsp /* revoke access to most system calls */
474 876c234b 2018-09-10 stsp if (pledge("stdio recvfd", NULL) == -1) {
475 876c234b 2018-09-10 stsp err = got_error_from_errno();
476 876c234b 2018-09-10 stsp got_privsep_send_error(&ibuf, err);
481 876c234b 2018-09-10 stsp err = receive_packidx(&packidx, &ibuf);
483 876c234b 2018-09-10 stsp got_privsep_send_error(&ibuf, err);
487 876c234b 2018-09-10 stsp err = receive_pack(&pack, &ibuf);
489 876c234b 2018-09-10 stsp got_privsep_send_error(&ibuf, err);
493 876c234b 2018-09-10 stsp while (1) {
494 876c234b 2018-09-10 stsp imsg.fd = -1;
496 99437157 2018-11-11 stsp if (sigint_received) {
497 99437157 2018-11-11 stsp err = got_error(GOT_ERR_CANCELLED);
501 876c234b 2018-09-10 stsp err = got_privsep_recv_imsg(&imsg, &ibuf, 0);
503 876c234b 2018-09-10 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
504 876c234b 2018-09-10 stsp err = NULL;
508 876c234b 2018-09-10 stsp if (imsg.hdr.type == GOT_IMSG_STOP)
511 876c234b 2018-09-10 stsp switch (imsg.hdr.type) {
512 876c234b 2018-09-10 stsp case GOT_IMSG_PACKED_OBJECT_REQUEST:
513 c59b3346 2018-09-11 stsp err = object_request(&imsg, &ibuf, pack, packidx,
514 c59b3346 2018-09-11 stsp &objcache);
516 876c234b 2018-09-10 stsp case GOT_IMSG_COMMIT_REQUEST:
517 c59b3346 2018-09-11 stsp err = commit_request(&imsg, &ibuf, pack, packidx,
518 7762fe12 2018-11-05 stsp &objcache);
520 876c234b 2018-09-10 stsp case GOT_IMSG_TREE_REQUEST:
521 c59b3346 2018-09-11 stsp err = tree_request(&imsg, &ibuf, pack, packidx,
522 c59b3346 2018-09-11 stsp &objcache);
524 876c234b 2018-09-10 stsp case GOT_IMSG_BLOB_REQUEST:
525 c59b3346 2018-09-11 stsp err = blob_request(&imsg, &ibuf, pack, packidx,
526 c59b3346 2018-09-11 stsp &objcache);
528 f4a881ce 2018-11-17 stsp case GOT_IMSG_TAG_REQUEST:
529 f4a881ce 2018-11-17 stsp err = tag_request(&imsg, &ibuf, pack, packidx,
530 f4a881ce 2018-11-17 stsp &objcache);
533 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_MSG);
537 876c234b 2018-09-10 stsp if (imsg.fd != -1)
538 876c234b 2018-09-10 stsp close(imsg.fd);
539 876c234b 2018-09-10 stsp imsg_free(&imsg);
544 c59b3346 2018-09-11 stsp if (packidx)
545 c59b3346 2018-09-11 stsp got_packidx_close(packidx);
547 c59b3346 2018-09-11 stsp got_pack_close(pack);
548 48d5fe42 2018-09-15 stsp got_object_cache_close(&objcache);
549 876c234b 2018-09-10 stsp imsg_clear(&ibuf);
551 80d5f134 2018-11-11 stsp if (!sigint_received && err->code != GOT_ERR_PRIVSEP_PIPE) {
552 80d5f134 2018-11-11 stsp fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
553 99437157 2018-11-11 stsp got_privsep_send_error(&ibuf, err);
556 876c234b 2018-09-10 stsp close(GOT_IMSG_FD_CHILD);
557 876c234b 2018-09-10 stsp return err ? 1 : 0;