2 5aa81393 2020-01-06 stsp * Copyright (c) 2018, 2019, 2020 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/syslimits.h>
22 876c234b 2018-09-10 stsp #include <sys/mman.h>
24 876c234b 2018-09-10 stsp #include <limits.h>
25 99437157 2018-11-11 stsp #include <signal.h>
26 876c234b 2018-09-10 stsp #include <stdint.h>
27 876c234b 2018-09-10 stsp #include <imsg.h>
28 876c234b 2018-09-10 stsp #include <stdio.h>
29 876c234b 2018-09-10 stsp #include <stdlib.h>
30 876c234b 2018-09-10 stsp #include <string.h>
31 876c234b 2018-09-10 stsp #include <sha1.h>
32 876c234b 2018-09-10 stsp #include <zlib.h>
34 876c234b 2018-09-10 stsp #include "got_error.h"
35 876c234b 2018-09-10 stsp #include "got_object.h"
36 3022d272 2019-11-14 stsp #include "got_path.h"
38 876c234b 2018-09-10 stsp #include "got_lib_delta.h"
39 ab2f42e7 2019-11-10 stsp #include "got_lib_delta_cache.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 704b89c4 2019-05-23 stsp open_object(struct got_object **obj, struct got_pack *pack,
56 704b89c4 2019-05-23 stsp struct got_packidx *packidx, int idx, struct got_object_id *id,
57 704b89c4 2019-05-23 stsp struct got_object_cache *objcache)
59 704b89c4 2019-05-23 stsp const struct got_error *err;
61 704b89c4 2019-05-23 stsp err = got_packfile_open_object(obj, pack, packidx, idx, id);
64 704b89c4 2019-05-23 stsp (*obj)->refcnt++;
66 704b89c4 2019-05-23 stsp err = got_object_cache_add(objcache, id, *obj);
68 79c99a64 2019-05-23 stsp if (err->code == GOT_ERR_OBJ_EXISTS ||
69 79c99a64 2019-05-23 stsp err->code == GOT_ERR_OBJ_TOO_LARGE)
73 704b89c4 2019-05-23 stsp (*obj)->refcnt++;
74 704b89c4 2019-05-23 stsp return NULL;
77 704b89c4 2019-05-23 stsp static const struct got_error *
78 876c234b 2018-09-10 stsp object_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
79 c59b3346 2018-09-11 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
81 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
82 876c234b 2018-09-10 stsp struct got_imsg_packed_object iobj;
83 876c234b 2018-09-10 stsp struct got_object *obj;
84 106807b4 2018-09-15 stsp struct got_object_id id;
85 876c234b 2018-09-10 stsp size_t datalen;
87 876c234b 2018-09-10 stsp datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
88 876c234b 2018-09-10 stsp if (datalen != sizeof(iobj))
89 876c234b 2018-09-10 stsp return got_error(GOT_ERR_PRIVSEP_LEN);
90 876c234b 2018-09-10 stsp memcpy(&iobj, imsg->data, sizeof(iobj));
91 106807b4 2018-09-15 stsp memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH);
93 704b89c4 2019-05-23 stsp obj = got_object_cache_get(objcache, &id);
95 704b89c4 2019-05-23 stsp obj->refcnt++;
97 704b89c4 2019-05-23 stsp err = open_object(&obj, pack, packidx, iobj.idx, &id,
103 876c234b 2018-09-10 stsp err = got_privsep_send_obj(ibuf, obj);
105 876c234b 2018-09-10 stsp got_object_close(obj);
106 876c234b 2018-09-10 stsp return err;
109 ca6e02ac 2020-01-07 stsp const struct got_error *
110 ca6e02ac 2020-01-07 stsp open_commit(struct got_commit_object **commit, struct got_pack *pack,
111 ca6e02ac 2020-01-07 stsp struct got_packidx *packidx, int obj_idx, struct got_object_id *id,
112 ca6e02ac 2020-01-07 stsp struct got_object_cache *objcache)
114 cfd633c2 2018-09-10 stsp const struct got_error *err = NULL;
115 cb5e38fd 2019-05-23 stsp struct got_object *obj = NULL;
116 cb5e38fd 2019-05-23 stsp uint8_t *buf = NULL;
117 cfd633c2 2018-09-10 stsp size_t len;
119 ca6e02ac 2020-01-07 stsp *commit = NULL;
121 ca6e02ac 2020-01-07 stsp obj = got_object_cache_get(objcache, id);
123 704b89c4 2019-05-23 stsp obj->refcnt++;
125 ca6e02ac 2020-01-07 stsp err = open_object(&obj, pack, packidx, obj_idx, id,
128 704b89c4 2019-05-23 stsp return err;
131 cfd633c2 2018-09-10 stsp err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack);
135 cfd633c2 2018-09-10 stsp obj->size = len;
137 ca6e02ac 2020-01-07 stsp err = got_object_parse_commit(commit, buf, len);
139 ca6e02ac 2020-01-07 stsp got_object_close(obj);
141 ca6e02ac 2020-01-07 stsp return err;
144 ca6e02ac 2020-01-07 stsp static const struct got_error *
145 ca6e02ac 2020-01-07 stsp commit_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
146 ca6e02ac 2020-01-07 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
148 ca6e02ac 2020-01-07 stsp const struct got_error *err = NULL;
149 ca6e02ac 2020-01-07 stsp struct got_imsg_packed_object iobj;
150 ca6e02ac 2020-01-07 stsp struct got_commit_object *commit = NULL;
151 ca6e02ac 2020-01-07 stsp struct got_object_id id;
152 ca6e02ac 2020-01-07 stsp size_t datalen;
154 ca6e02ac 2020-01-07 stsp datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
155 ca6e02ac 2020-01-07 stsp if (datalen != sizeof(iobj))
156 ca6e02ac 2020-01-07 stsp return got_error(GOT_ERR_PRIVSEP_LEN);
157 ca6e02ac 2020-01-07 stsp memcpy(&iobj, imsg->data, sizeof(iobj));
158 ca6e02ac 2020-01-07 stsp memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH);
160 ca6e02ac 2020-01-07 stsp err = open_commit(&commit, pack, packidx, iobj.idx, &id, objcache);
164 cfd633c2 2018-09-10 stsp err = got_privsep_send_commit(ibuf, commit);
166 cb5e38fd 2019-05-23 stsp if (commit)
167 cb5e38fd 2019-05-23 stsp got_object_commit_close(commit);
169 7762fe12 2018-11-05 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
170 7762fe12 2018-11-05 stsp err = NULL;
172 7762fe12 2018-11-05 stsp got_privsep_send_error(ibuf, err);
175 7762fe12 2018-11-05 stsp return err;
178 ca6e02ac 2020-01-07 stsp const struct got_error *
179 ca6e02ac 2020-01-07 stsp open_tree(uint8_t **buf, struct got_pathlist_head *entries, int *nentries,
180 ca6e02ac 2020-01-07 stsp struct got_pack *pack, struct got_packidx *packidx, int obj_idx,
181 ca6e02ac 2020-01-07 stsp struct got_object_id *id, struct got_object_cache *objcache)
183 ca6e02ac 2020-01-07 stsp const struct got_error *err = NULL;
184 ca6e02ac 2020-01-07 stsp struct got_object *obj = NULL;
185 ca6e02ac 2020-01-07 stsp size_t len;
187 ca6e02ac 2020-01-07 stsp *buf = NULL;
188 ca6e02ac 2020-01-07 stsp *nentries = 0;
190 ca6e02ac 2020-01-07 stsp obj = got_object_cache_get(objcache, id);
192 ca6e02ac 2020-01-07 stsp obj->refcnt++;
194 ca6e02ac 2020-01-07 stsp err = open_object(&obj, pack, packidx, obj_idx, id,
197 ca6e02ac 2020-01-07 stsp return err;
200 ca6e02ac 2020-01-07 stsp err = got_packfile_extract_object_to_mem(buf, &len, obj, pack);
204 ca6e02ac 2020-01-07 stsp obj->size = len;
206 ca6e02ac 2020-01-07 stsp err = got_object_parse_tree(entries, nentries, *buf, len);
208 ca6e02ac 2020-01-07 stsp got_object_close(obj);
210 ca6e02ac 2020-01-07 stsp free(*buf);
211 ca6e02ac 2020-01-07 stsp *buf = NULL;
213 ca6e02ac 2020-01-07 stsp return err;
216 7762fe12 2018-11-05 stsp static const struct got_error *
217 876c234b 2018-09-10 stsp tree_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
218 c59b3346 2018-09-11 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
220 e7885405 2018-09-10 stsp const struct got_error *err = NULL;
221 13c729f7 2018-12-24 stsp struct got_imsg_packed_object iobj;
222 3022d272 2019-11-14 stsp struct got_pathlist_head entries;
223 3022d272 2019-11-14 stsp int nentries = 0;
224 cb5e38fd 2019-05-23 stsp uint8_t *buf = NULL;
225 13c729f7 2018-12-24 stsp struct got_object_id id;
226 13c729f7 2018-12-24 stsp size_t datalen;
228 3022d272 2019-11-14 stsp TAILQ_INIT(&entries);
230 13c729f7 2018-12-24 stsp datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
231 13c729f7 2018-12-24 stsp if (datalen != sizeof(iobj))
232 13c729f7 2018-12-24 stsp return got_error(GOT_ERR_PRIVSEP_LEN);
233 13c729f7 2018-12-24 stsp memcpy(&iobj, imsg->data, sizeof(iobj));
234 13c729f7 2018-12-24 stsp memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH);
236 ca6e02ac 2020-01-07 stsp err = open_tree(&buf, &entries, &nentries, pack, packidx, iobj.idx,
237 ca6e02ac 2020-01-07 stsp &id, objcache);
239 ca6e02ac 2020-01-07 stsp return err;
241 3022d272 2019-11-14 stsp err = got_privsep_send_tree(ibuf, &entries, nentries);
242 b87b4170 2020-01-06 stsp got_object_parsed_tree_entries_free(&entries);
245 e7885405 2018-09-10 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
246 e7885405 2018-09-10 stsp err = NULL;
248 e7885405 2018-09-10 stsp got_privsep_send_error(ibuf, err);
251 e7885405 2018-09-10 stsp return err;
254 876c234b 2018-09-10 stsp static const struct got_error *
255 3840f4c9 2018-09-12 stsp receive_file(FILE **f, struct imsgbuf *ibuf, int imsg_code)
257 3840f4c9 2018-09-12 stsp const struct got_error *err;
258 3840f4c9 2018-09-12 stsp struct imsg imsg;
259 55da3778 2018-09-10 stsp size_t datalen;
261 3840f4c9 2018-09-12 stsp err = got_privsep_recv_imsg(&imsg, ibuf, 0);
263 55da3778 2018-09-10 stsp return err;
265 3840f4c9 2018-09-12 stsp if (imsg.hdr.type != imsg_code) {
266 55da3778 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_MSG);
270 3840f4c9 2018-09-12 stsp datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
271 55da3778 2018-09-10 stsp if (datalen != 0) {
272 55da3778 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
275 3840f4c9 2018-09-12 stsp if (imsg.fd == -1) {
276 55da3778 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_NO_FD);
280 3840f4c9 2018-09-12 stsp *f = fdopen(imsg.fd, "w+");
281 3840f4c9 2018-09-12 stsp if (*f == NULL) {
282 638f9024 2019-05-13 stsp err = got_error_from_errno("fdopen");
283 3a6ce05a 2019-02-11 stsp close(imsg.fd);
287 3840f4c9 2018-09-12 stsp imsg_free(&imsg);
288 3840f4c9 2018-09-12 stsp return err;
291 3840f4c9 2018-09-12 stsp static const struct got_error *
292 3840f4c9 2018-09-12 stsp blob_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
293 3840f4c9 2018-09-12 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
295 3840f4c9 2018-09-12 stsp const struct got_error *err = NULL;
296 ebc55e2d 2018-12-24 stsp struct got_imsg_packed_object iobj;
297 3840f4c9 2018-09-12 stsp struct got_object *obj = NULL;
298 3840f4c9 2018-09-12 stsp FILE *outfile = NULL, *basefile = NULL, *accumfile = NULL;
299 ebc55e2d 2018-12-24 stsp struct got_object_id id;
300 ebc55e2d 2018-12-24 stsp size_t datalen;
301 ac544f8c 2019-01-13 stsp uint64_t blob_size;
302 ac544f8c 2019-01-13 stsp uint8_t *buf = NULL;
304 ebc55e2d 2018-12-24 stsp datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
305 ebc55e2d 2018-12-24 stsp if (datalen != sizeof(iobj))
306 ebc55e2d 2018-12-24 stsp return got_error(GOT_ERR_PRIVSEP_LEN);
307 ebc55e2d 2018-12-24 stsp memcpy(&iobj, imsg->data, sizeof(iobj));
308 ebc55e2d 2018-12-24 stsp memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH);
310 704b89c4 2019-05-23 stsp obj = got_object_cache_get(objcache, &id);
312 704b89c4 2019-05-23 stsp obj->refcnt++;
314 704b89c4 2019-05-23 stsp err = open_object(&obj, pack, packidx, iobj.idx, &id,
317 704b89c4 2019-05-23 stsp return err;
320 3840f4c9 2018-09-12 stsp err = receive_file(&outfile, ibuf, GOT_IMSG_BLOB_OUTFD);
323 3840f4c9 2018-09-12 stsp err = receive_file(&basefile, ibuf, GOT_IMSG_TMPFD);
326 3840f4c9 2018-09-12 stsp err = receive_file(&accumfile, ibuf, GOT_IMSG_TMPFD);
330 ac544f8c 2019-01-13 stsp if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
331 42c69117 2019-11-10 stsp err = got_pack_get_max_delta_object_size(&blob_size, obj, pack);
335 ac544f8c 2019-01-13 stsp blob_size = obj->size;
337 ac544f8c 2019-01-13 stsp if (blob_size <= GOT_PRIVSEP_INLINE_BLOB_DATA_MAX)
338 ac544f8c 2019-01-13 stsp err = got_packfile_extract_object_to_mem(&buf, &obj->size,
339 ac544f8c 2019-01-13 stsp obj, pack);
341 ac544f8c 2019-01-13 stsp err = got_packfile_extract_object(pack, obj, outfile, basefile,
342 ac544f8c 2019-01-13 stsp accumfile);
346 ac544f8c 2019-01-13 stsp err = got_privsep_send_blob(ibuf, obj->size, obj->hdrlen, buf);
349 fb43ecf1 2019-02-11 stsp if (outfile && fclose(outfile) != 0 && err == NULL)
350 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
351 638f9024 2019-05-13 stsp if (basefile && fclose(basefile) != 0 && err == NULL)
352 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
353 fb43ecf1 2019-02-11 stsp if (accumfile && fclose(accumfile) != 0 && err == NULL)
354 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
355 cb5e38fd 2019-05-23 stsp got_object_close(obj);
356 3840f4c9 2018-09-12 stsp if (err && err->code != GOT_ERR_PRIVSEP_PIPE)
357 3840f4c9 2018-09-12 stsp got_privsep_send_error(ibuf, err);
359 55da3778 2018-09-10 stsp return err;
362 876c234b 2018-09-10 stsp static const struct got_error *
363 f4a881ce 2018-11-17 stsp tag_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
364 f4a881ce 2018-11-17 stsp struct got_packidx *packidx, struct got_object_cache *objcache)
366 f4a881ce 2018-11-17 stsp const struct got_error *err = NULL;
367 268f7291 2018-12-24 stsp struct got_imsg_packed_object iobj;
368 f4a881ce 2018-11-17 stsp struct got_object *obj = NULL;
369 f4a881ce 2018-11-17 stsp struct got_tag_object *tag = NULL;
370 cb5e38fd 2019-05-23 stsp uint8_t *buf = NULL;
371 f4a881ce 2018-11-17 stsp size_t len;
372 268f7291 2018-12-24 stsp struct got_object_id id;
373 268f7291 2018-12-24 stsp size_t datalen;
375 268f7291 2018-12-24 stsp datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
376 268f7291 2018-12-24 stsp if (datalen != sizeof(iobj))
377 268f7291 2018-12-24 stsp return got_error(GOT_ERR_PRIVSEP_LEN);
378 268f7291 2018-12-24 stsp memcpy(&iobj, imsg->data, sizeof(iobj));
379 268f7291 2018-12-24 stsp memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH);
381 704b89c4 2019-05-23 stsp obj = got_object_cache_get(objcache, &id);
383 704b89c4 2019-05-23 stsp obj->refcnt++;
385 704b89c4 2019-05-23 stsp err = open_object(&obj, pack, packidx, iobj.idx, &id,
388 704b89c4 2019-05-23 stsp return err;
391 f4a881ce 2018-11-17 stsp err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack);
395 f4a881ce 2018-11-17 stsp obj->size = len;
396 f4a881ce 2018-11-17 stsp err = got_object_parse_tag(&tag, buf, len);
400 f4a881ce 2018-11-17 stsp err = got_privsep_send_tag(ibuf, tag);
403 cb5e38fd 2019-05-23 stsp got_object_close(obj);
405 cb5e38fd 2019-05-23 stsp got_object_tag_close(tag);
407 ca6e02ac 2020-01-07 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
408 ca6e02ac 2020-01-07 stsp err = NULL;
410 ca6e02ac 2020-01-07 stsp got_privsep_send_error(ibuf, err);
413 ca6e02ac 2020-01-07 stsp return err;
416 ca6e02ac 2020-01-07 stsp static struct got_parsed_tree_entry *
417 ca6e02ac 2020-01-07 stsp find_entry_by_name(struct got_pathlist_head *entries, int nentries,
418 ca6e02ac 2020-01-07 stsp const char *name, size_t len)
420 ca6e02ac 2020-01-07 stsp struct got_pathlist_entry *pe;
422 ca6e02ac 2020-01-07 stsp /* Note that tree entries are sorted in strncmp() order. */
423 ca6e02ac 2020-01-07 stsp TAILQ_FOREACH(pe, entries, entry) {
424 ca6e02ac 2020-01-07 stsp int cmp = strncmp(pe->path, name, len);
425 ca6e02ac 2020-01-07 stsp if (cmp < 0)
427 ca6e02ac 2020-01-07 stsp if (cmp > 0)
429 ca6e02ac 2020-01-07 stsp if (pe->path[len] == '\0')
430 ca6e02ac 2020-01-07 stsp return (struct got_parsed_tree_entry *)pe->data;
432 ca6e02ac 2020-01-07 stsp return NULL;
435 ca6e02ac 2020-01-07 stsp const struct got_error *
436 ca6e02ac 2020-01-07 stsp tree_path_changed(int *changed, uint8_t **buf1, uint8_t **buf2,
437 ca6e02ac 2020-01-07 stsp struct got_pathlist_head *entries1, int *nentries1,
438 ca6e02ac 2020-01-07 stsp struct got_pathlist_head *entries2, int *nentries2,
439 ca6e02ac 2020-01-07 stsp const char *path, struct got_pack *pack, struct got_packidx *packidx,
440 ca6e02ac 2020-01-07 stsp struct imsgbuf *ibuf, struct got_object_cache *objcache)
442 ca6e02ac 2020-01-07 stsp const struct got_error *err = NULL;
443 ca6e02ac 2020-01-07 stsp struct got_parsed_tree_entry *pte1 = NULL, *pte2 = NULL;
444 ca6e02ac 2020-01-07 stsp const char *seg, *s;
445 ca6e02ac 2020-01-07 stsp size_t seglen;
447 ca6e02ac 2020-01-07 stsp *changed = 0;
449 ca6e02ac 2020-01-07 stsp /* We are expecting an absolute in-repository path. */
450 ca6e02ac 2020-01-07 stsp if (path[0] != '/')
451 ca6e02ac 2020-01-07 stsp return got_error(GOT_ERR_NOT_ABSPATH);
453 ca6e02ac 2020-01-07 stsp /* We not do support comparing the root path. */
454 ca6e02ac 2020-01-07 stsp if (path[1] == '\0')
455 ca6e02ac 2020-01-07 stsp return got_error(GOT_ERR_BAD_PATH);
458 ca6e02ac 2020-01-07 stsp s++; /* skip leading '/' */
460 ca6e02ac 2020-01-07 stsp seglen = 0;
461 ca6e02ac 2020-01-07 stsp while (*s) {
462 ca6e02ac 2020-01-07 stsp if (*s != '/') {
469 ca6e02ac 2020-01-07 stsp pte1 = find_entry_by_name(entries1, *nentries1, seg, seglen);
470 ca6e02ac 2020-01-07 stsp if (pte1 == NULL) {
471 ca6e02ac 2020-01-07 stsp err = got_error(GOT_ERR_NO_OBJ);
475 ca6e02ac 2020-01-07 stsp pte2 = find_entry_by_name(entries2, *nentries2, seg, seglen);
476 ca6e02ac 2020-01-07 stsp if (pte2 == NULL) {
477 ca6e02ac 2020-01-07 stsp *changed = 1;
481 ca6e02ac 2020-01-07 stsp if (pte1->mode != pte2->mode) {
482 ca6e02ac 2020-01-07 stsp *changed = 1;
486 ca6e02ac 2020-01-07 stsp if (memcmp(pte1->id, pte2->id, SHA1_DIGEST_LENGTH) == 0) {
487 ca6e02ac 2020-01-07 stsp *changed = 0;
491 ca6e02ac 2020-01-07 stsp if (*s == '\0') { /* final path element */
492 ca6e02ac 2020-01-07 stsp *changed = 1;
496 ca6e02ac 2020-01-07 stsp seg = s + 1;
498 ca6e02ac 2020-01-07 stsp seglen = 0;
500 ca6e02ac 2020-01-07 stsp struct got_object_id id1, id2;
503 ca6e02ac 2020-01-07 stsp idx = got_packidx_get_object_idx_sha1(packidx,
505 ca6e02ac 2020-01-07 stsp if (idx == -1) {
506 ca6e02ac 2020-01-07 stsp err = got_error(GOT_ERR_NO_OBJ);
509 ca6e02ac 2020-01-07 stsp memcpy(id1.sha1, pte1->id, SHA1_DIGEST_LENGTH);
510 ca6e02ac 2020-01-07 stsp got_object_parsed_tree_entries_free(entries1);
511 ca6e02ac 2020-01-07 stsp *nentries1 = 0;
512 ca6e02ac 2020-01-07 stsp free(*buf1);
513 ca6e02ac 2020-01-07 stsp *buf1 = NULL;
514 ca6e02ac 2020-01-07 stsp err = open_tree(buf1, entries1, nentries1, pack,
515 ca6e02ac 2020-01-07 stsp packidx, idx, &id1, objcache);
516 ca6e02ac 2020-01-07 stsp pte1 = NULL;
520 ca6e02ac 2020-01-07 stsp idx = got_packidx_get_object_idx_sha1(packidx,
522 ca6e02ac 2020-01-07 stsp if (idx == -1) {
523 ca6e02ac 2020-01-07 stsp err = got_error(GOT_ERR_NO_OBJ);
526 ca6e02ac 2020-01-07 stsp memcpy(id2.sha1, pte2->id, SHA1_DIGEST_LENGTH);
527 ca6e02ac 2020-01-07 stsp got_object_parsed_tree_entries_free(entries2);
528 ca6e02ac 2020-01-07 stsp *nentries2 = 0;
529 ca6e02ac 2020-01-07 stsp free(*buf2);
530 ca6e02ac 2020-01-07 stsp *buf2 = NULL;
531 ca6e02ac 2020-01-07 stsp err = open_tree(buf2, entries2, nentries2, pack,
532 ca6e02ac 2020-01-07 stsp packidx, idx, &id2, objcache);
533 ca6e02ac 2020-01-07 stsp pte2 = NULL;
539 ca6e02ac 2020-01-07 stsp return err;
542 ca6e02ac 2020-01-07 stsp static const struct got_error *
543 ca6e02ac 2020-01-07 stsp commit_traversal_request(struct imsg *imsg, struct imsgbuf *ibuf,
544 ca6e02ac 2020-01-07 stsp struct got_pack *pack, struct got_packidx *packidx,
545 ca6e02ac 2020-01-07 stsp struct got_object_cache *objcache)
547 ca6e02ac 2020-01-07 stsp const struct got_error *err = NULL;
548 ca6e02ac 2020-01-07 stsp struct got_imsg_packed_object iobj;
549 ca6e02ac 2020-01-07 stsp struct got_object_qid *pid;
550 ca6e02ac 2020-01-07 stsp struct got_commit_object *commit = NULL, *pcommit = NULL;
551 ca6e02ac 2020-01-07 stsp struct got_pathlist_head entries, pentries;
552 ca6e02ac 2020-01-07 stsp int nentries = 0, pnentries = 0;
553 ca6e02ac 2020-01-07 stsp struct got_object_id id;
554 ca6e02ac 2020-01-07 stsp size_t datalen, path_len;
555 ca6e02ac 2020-01-07 stsp char *path = NULL;
556 ca6e02ac 2020-01-07 stsp const int min_alloc = 64;
557 ca6e02ac 2020-01-07 stsp int changed = 0, ncommits = 0, nallocated = 0;
558 ca6e02ac 2020-01-07 stsp struct got_object_id *commit_ids = NULL;
560 ca6e02ac 2020-01-07 stsp TAILQ_INIT(&entries);
561 ca6e02ac 2020-01-07 stsp TAILQ_INIT(&pentries);
563 ca6e02ac 2020-01-07 stsp datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
564 ca6e02ac 2020-01-07 stsp if (datalen < sizeof(iobj))
565 ca6e02ac 2020-01-07 stsp return got_error(GOT_ERR_PRIVSEP_LEN);
566 ca6e02ac 2020-01-07 stsp memcpy(&iobj, imsg->data, sizeof(iobj));
567 ca6e02ac 2020-01-07 stsp memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH);
569 ca6e02ac 2020-01-07 stsp path_len = datalen - sizeof(iobj) - 1;
570 ca6e02ac 2020-01-07 stsp if (path_len < 0)
571 ca6e02ac 2020-01-07 stsp return got_error(GOT_ERR_PRIVSEP_LEN);
572 ca6e02ac 2020-01-07 stsp if (path_len > 0) {
573 ca6e02ac 2020-01-07 stsp path = imsg->data + sizeof(iobj);
574 ca6e02ac 2020-01-07 stsp if (path[path_len] != '\0')
575 ca6e02ac 2020-01-07 stsp return got_error(GOT_ERR_PRIVSEP_LEN);
578 ca6e02ac 2020-01-07 stsp nallocated = min_alloc;
579 ca6e02ac 2020-01-07 stsp commit_ids = reallocarray(NULL, nallocated, sizeof(*commit_ids));
580 ca6e02ac 2020-01-07 stsp if (commit_ids == NULL)
581 ca6e02ac 2020-01-07 stsp return got_error_from_errno("reallocarray");
584 ca6e02ac 2020-01-07 stsp const size_t max_datalen = MAX_IMSGSIZE - IMSG_HEADER_SIZE;
587 ca6e02ac 2020-01-07 stsp if (sigint_received) {
588 ca6e02ac 2020-01-07 stsp err = got_error(GOT_ERR_CANCELLED);
592 ca6e02ac 2020-01-07 stsp if (commit == NULL) {
593 ca6e02ac 2020-01-07 stsp idx = got_packidx_get_object_idx(packidx, &id);
594 ca6e02ac 2020-01-07 stsp if (idx == -1)
596 ca6e02ac 2020-01-07 stsp err = open_commit(&commit, pack, packidx,
597 ca6e02ac 2020-01-07 stsp idx, &id, objcache);
599 ca6e02ac 2020-01-07 stsp if (err->code != GOT_ERR_NO_OBJ)
601 ca6e02ac 2020-01-07 stsp err = NULL;
606 ca6e02ac 2020-01-07 stsp if (sizeof(struct got_imsg_traversed_commits) +
607 ca6e02ac 2020-01-07 stsp ncommits * SHA1_DIGEST_LENGTH >= max_datalen) {
608 ca6e02ac 2020-01-07 stsp err = got_privsep_send_traversed_commits(commit_ids,
609 ca6e02ac 2020-01-07 stsp ncommits, ibuf);
612 ca6e02ac 2020-01-07 stsp ncommits = 0;
614 ca6e02ac 2020-01-07 stsp ncommits++;
615 ca6e02ac 2020-01-07 stsp if (ncommits > nallocated) {
616 ca6e02ac 2020-01-07 stsp struct got_object_id *new;
617 ca6e02ac 2020-01-07 stsp nallocated += min_alloc;
618 ca6e02ac 2020-01-07 stsp new = reallocarray(commit_ids, nallocated,
619 ca6e02ac 2020-01-07 stsp sizeof(*commit_ids));
620 ca6e02ac 2020-01-07 stsp if (new == NULL) {
621 ca6e02ac 2020-01-07 stsp err = got_error_from_errno("reallocarray");
624 ca6e02ac 2020-01-07 stsp commit_ids = new;
626 ca6e02ac 2020-01-07 stsp memcpy(commit_ids[ncommits - 1].sha1, id.sha1,
627 ca6e02ac 2020-01-07 stsp SHA1_DIGEST_LENGTH);
629 ca6e02ac 2020-01-07 stsp pid = SIMPLEQ_FIRST(&commit->parent_ids);
630 ca6e02ac 2020-01-07 stsp if (pid == NULL)
633 ca6e02ac 2020-01-07 stsp idx = got_packidx_get_object_idx(packidx, pid->id);
634 ca6e02ac 2020-01-07 stsp if (idx == -1)
637 ca6e02ac 2020-01-07 stsp err = open_commit(&pcommit, pack, packidx, idx, pid->id,
640 ca6e02ac 2020-01-07 stsp if (err->code != GOT_ERR_NO_OBJ)
642 ca6e02ac 2020-01-07 stsp err = NULL;
646 ca6e02ac 2020-01-07 stsp if (path[0] == '/' && path[1] == '\0') {
647 ca6e02ac 2020-01-07 stsp if (got_object_id_cmp(pcommit->tree_id,
648 ca6e02ac 2020-01-07 stsp commit->tree_id) != 0) {
649 ca6e02ac 2020-01-07 stsp changed = 1;
654 ca6e02ac 2020-01-07 stsp uint8_t *buf = NULL, *pbuf = NULL;
656 ca6e02ac 2020-01-07 stsp idx = got_packidx_get_object_idx(packidx,
657 ca6e02ac 2020-01-07 stsp commit->tree_id);
658 ca6e02ac 2020-01-07 stsp if (idx == -1)
660 ca6e02ac 2020-01-07 stsp pidx = got_packidx_get_object_idx(packidx,
661 ca6e02ac 2020-01-07 stsp pcommit->tree_id);
662 ca6e02ac 2020-01-07 stsp if (pidx == -1)
665 ca6e02ac 2020-01-07 stsp err = open_tree(&buf, &entries, &nentries, pack,
666 ca6e02ac 2020-01-07 stsp packidx, idx, commit->tree_id, objcache);
669 ca6e02ac 2020-01-07 stsp err = open_tree(&pbuf, &pentries, &pnentries, pack,
670 ca6e02ac 2020-01-07 stsp packidx, pidx, pcommit->tree_id, objcache);
676 ca6e02ac 2020-01-07 stsp err = tree_path_changed(&changed, &buf, &pbuf,
677 ca6e02ac 2020-01-07 stsp &entries, &nentries, &pentries, &pnentries, path,
678 ca6e02ac 2020-01-07 stsp pack, packidx, ibuf, objcache);
680 ca6e02ac 2020-01-07 stsp got_object_parsed_tree_entries_free(&entries);
681 ca6e02ac 2020-01-07 stsp nentries = 0;
683 ca6e02ac 2020-01-07 stsp got_object_parsed_tree_entries_free(&pentries);
684 ca6e02ac 2020-01-07 stsp pnentries = 0;
685 ca6e02ac 2020-01-07 stsp free(pbuf);
687 ca6e02ac 2020-01-07 stsp if (err->code != GOT_ERR_NO_OBJ)
689 ca6e02ac 2020-01-07 stsp err = NULL;
694 ca6e02ac 2020-01-07 stsp if (!changed) {
695 ca6e02ac 2020-01-07 stsp memcpy(id.sha1, pid->id->sha1, SHA1_DIGEST_LENGTH);
696 ca6e02ac 2020-01-07 stsp got_object_commit_close(commit);
697 ca6e02ac 2020-01-07 stsp commit = pcommit;
698 ca6e02ac 2020-01-07 stsp pcommit = NULL;
700 ca6e02ac 2020-01-07 stsp } while (!changed);
702 ca6e02ac 2020-01-07 stsp if (ncommits > 0) {
703 ca6e02ac 2020-01-07 stsp err = got_privsep_send_traversed_commits(commit_ids,
704 ca6e02ac 2020-01-07 stsp ncommits, ibuf);
708 ca6e02ac 2020-01-07 stsp if (changed) {
709 ca6e02ac 2020-01-07 stsp err = got_privsep_send_commit(ibuf, commit);
714 ca6e02ac 2020-01-07 stsp err = got_privsep_send_commit_traversal_done(ibuf);
716 ca6e02ac 2020-01-07 stsp free(commit_ids);
717 ca6e02ac 2020-01-07 stsp if (commit)
718 ca6e02ac 2020-01-07 stsp got_object_commit_close(commit);
719 ca6e02ac 2020-01-07 stsp if (pcommit)
720 ca6e02ac 2020-01-07 stsp got_object_commit_close(pcommit);
721 ca6e02ac 2020-01-07 stsp if (nentries != 0)
722 ca6e02ac 2020-01-07 stsp got_object_parsed_tree_entries_free(&entries);
723 ca6e02ac 2020-01-07 stsp if (pnentries != 0)
724 ca6e02ac 2020-01-07 stsp got_object_parsed_tree_entries_free(&pentries);
726 f4a881ce 2018-11-17 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
727 f4a881ce 2018-11-17 stsp err = NULL;
729 f4a881ce 2018-11-17 stsp got_privsep_send_error(ibuf, err);
732 f4a881ce 2018-11-17 stsp return err;
735 f4a881ce 2018-11-17 stsp static const struct got_error *
736 876c234b 2018-09-10 stsp receive_packidx(struct got_packidx **packidx, struct imsgbuf *ibuf)
738 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
739 876c234b 2018-09-10 stsp struct imsg imsg;
740 876c234b 2018-09-10 stsp struct got_imsg_packidx ipackidx;
741 876c234b 2018-09-10 stsp size_t datalen;
742 876c234b 2018-09-10 stsp struct got_packidx *p;
744 876c234b 2018-09-10 stsp *packidx = NULL;
746 876c234b 2018-09-10 stsp err = got_privsep_recv_imsg(&imsg, ibuf, 0);
748 876c234b 2018-09-10 stsp return err;
750 876c234b 2018-09-10 stsp p = calloc(1, sizeof(*p));
751 876c234b 2018-09-10 stsp if (p == NULL) {
752 638f9024 2019-05-13 stsp err = got_error_from_errno("calloc");
756 876c234b 2018-09-10 stsp if (imsg.hdr.type != GOT_IMSG_PACKIDX) {
757 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_MSG);
761 876c234b 2018-09-10 stsp if (imsg.fd == -1) {
762 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_NO_FD);
766 876c234b 2018-09-10 stsp datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
767 876c234b 2018-09-10 stsp if (datalen != sizeof(ipackidx)) {
768 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
771 876c234b 2018-09-10 stsp memcpy(&ipackidx, imsg.data, sizeof(ipackidx));
773 876c234b 2018-09-10 stsp p->len = ipackidx.len;
774 876c234b 2018-09-10 stsp p->fd = dup(imsg.fd);
775 876c234b 2018-09-10 stsp if (p->fd == -1) {
776 638f9024 2019-05-13 stsp err = got_error_from_errno("dup");
779 56bef47a 2018-09-15 stsp if (lseek(p->fd, 0, SEEK_SET) == -1) {
780 638f9024 2019-05-13 stsp err = got_error_from_errno("lseek");
784 876c234b 2018-09-10 stsp #ifndef GOT_PACK_NO_MMAP
785 876c234b 2018-09-10 stsp p->map = mmap(NULL, p->len, PROT_READ, MAP_PRIVATE, p->fd, 0);
786 876c234b 2018-09-10 stsp if (p->map == MAP_FAILED)
787 876c234b 2018-09-10 stsp p->map = NULL; /* fall back to read(2) */
789 876c234b 2018-09-10 stsp err = got_packidx_init_hdr(p, 1);
792 876c234b 2018-09-10 stsp if (imsg.fd != -1)
793 876c234b 2018-09-10 stsp close(imsg.fd);
794 876c234b 2018-09-10 stsp got_packidx_close(p);
796 876c234b 2018-09-10 stsp *packidx = p;
797 876c234b 2018-09-10 stsp imsg_free(&imsg);
798 876c234b 2018-09-10 stsp return err;
801 876c234b 2018-09-10 stsp static const struct got_error *
802 876c234b 2018-09-10 stsp receive_pack(struct got_pack **packp, struct imsgbuf *ibuf)
804 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
805 876c234b 2018-09-10 stsp struct imsg imsg;
806 876c234b 2018-09-10 stsp struct got_imsg_pack ipack;
807 876c234b 2018-09-10 stsp size_t datalen;
808 876c234b 2018-09-10 stsp struct got_pack *pack;
810 876c234b 2018-09-10 stsp *packp = NULL;
812 876c234b 2018-09-10 stsp err = got_privsep_recv_imsg(&imsg, ibuf, 0);
814 876c234b 2018-09-10 stsp return err;
816 876c234b 2018-09-10 stsp pack = calloc(1, sizeof(*pack));
817 876c234b 2018-09-10 stsp if (pack == NULL) {
818 638f9024 2019-05-13 stsp err = got_error_from_errno("calloc");
822 876c234b 2018-09-10 stsp if (imsg.hdr.type != GOT_IMSG_PACK) {
823 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_MSG);
827 876c234b 2018-09-10 stsp if (imsg.fd == -1) {
828 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_NO_FD);
832 876c234b 2018-09-10 stsp datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
833 876c234b 2018-09-10 stsp if (datalen != sizeof(ipack)) {
834 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
837 876c234b 2018-09-10 stsp memcpy(&ipack, imsg.data, sizeof(ipack));
839 876c234b 2018-09-10 stsp pack->filesize = ipack.filesize;
840 876c234b 2018-09-10 stsp pack->fd = dup(imsg.fd);
841 876c234b 2018-09-10 stsp if (pack->fd == -1) {
842 638f9024 2019-05-13 stsp err = got_error_from_errno("dup");
845 56bef47a 2018-09-15 stsp if (lseek(pack->fd, 0, SEEK_SET) == -1) {
846 638f9024 2019-05-13 stsp err = got_error_from_errno("lseek");
849 876c234b 2018-09-10 stsp pack->path_packfile = strdup(ipack.path_packfile);
850 876c234b 2018-09-10 stsp if (pack->path_packfile == NULL) {
851 638f9024 2019-05-13 stsp err = got_error_from_errno("strdup");
855 ab2f42e7 2019-11-10 stsp pack->delta_cache = got_delta_cache_alloc(100,
856 ab2f42e7 2019-11-10 stsp GOT_DELTA_RESULT_SIZE_CACHED_MAX);
857 ab2f42e7 2019-11-10 stsp if (pack->delta_cache == NULL) {
858 ab2f42e7 2019-11-10 stsp err = got_error_from_errno("got_delta_cache_alloc");
862 876c234b 2018-09-10 stsp #ifndef GOT_PACK_NO_MMAP
863 876c234b 2018-09-10 stsp pack->map = mmap(NULL, pack->filesize, PROT_READ, MAP_PRIVATE,
864 876c234b 2018-09-10 stsp pack->fd, 0);
865 876c234b 2018-09-10 stsp if (pack->map == MAP_FAILED)
866 876c234b 2018-09-10 stsp pack->map = NULL; /* fall back to read(2) */
870 876c234b 2018-09-10 stsp if (imsg.fd != -1)
871 876c234b 2018-09-10 stsp close(imsg.fd);
872 876c234b 2018-09-10 stsp free(pack);
874 876c234b 2018-09-10 stsp *packp = pack;
875 876c234b 2018-09-10 stsp imsg_free(&imsg);
876 876c234b 2018-09-10 stsp return err;
880 876c234b 2018-09-10 stsp main(int argc, char *argv[])
882 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
883 876c234b 2018-09-10 stsp struct imsgbuf ibuf;
884 876c234b 2018-09-10 stsp struct imsg imsg;
885 c59b3346 2018-09-11 stsp struct got_packidx *packidx = NULL;
886 c59b3346 2018-09-11 stsp struct got_pack *pack = NULL;
887 c59b3346 2018-09-11 stsp struct got_object_cache objcache;
889 876c234b 2018-09-10 stsp //static int attached;
890 876c234b 2018-09-10 stsp //while (!attached) sleep(1);
892 99437157 2018-11-11 stsp signal(SIGINT, catch_sigint);
894 876c234b 2018-09-10 stsp imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
896 c59b3346 2018-09-11 stsp err = got_object_cache_init(&objcache, GOT_OBJECT_CACHE_TYPE_OBJ);
898 638f9024 2019-05-13 stsp err = got_error_from_errno("got_object_cache_init");
899 c59b3346 2018-09-11 stsp got_privsep_send_error(&ibuf, err);
903 2ff12563 2018-09-15 stsp #ifndef PROFILE
904 876c234b 2018-09-10 stsp /* revoke access to most system calls */
905 876c234b 2018-09-10 stsp if (pledge("stdio recvfd", NULL) == -1) {
906 638f9024 2019-05-13 stsp err = got_error_from_errno("pledge");
907 876c234b 2018-09-10 stsp got_privsep_send_error(&ibuf, err);
912 876c234b 2018-09-10 stsp err = receive_packidx(&packidx, &ibuf);
914 876c234b 2018-09-10 stsp got_privsep_send_error(&ibuf, err);
918 876c234b 2018-09-10 stsp err = receive_pack(&pack, &ibuf);
920 876c234b 2018-09-10 stsp got_privsep_send_error(&ibuf, err);
925 876c234b 2018-09-10 stsp imsg.fd = -1;
927 99437157 2018-11-11 stsp if (sigint_received) {
928 99437157 2018-11-11 stsp err = got_error(GOT_ERR_CANCELLED);
932 876c234b 2018-09-10 stsp err = got_privsep_recv_imsg(&imsg, &ibuf, 0);
934 876c234b 2018-09-10 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
935 876c234b 2018-09-10 stsp err = NULL;
939 876c234b 2018-09-10 stsp if (imsg.hdr.type == GOT_IMSG_STOP)
942 876c234b 2018-09-10 stsp switch (imsg.hdr.type) {
943 876c234b 2018-09-10 stsp case GOT_IMSG_PACKED_OBJECT_REQUEST:
944 c59b3346 2018-09-11 stsp err = object_request(&imsg, &ibuf, pack, packidx,
945 c59b3346 2018-09-11 stsp &objcache);
947 876c234b 2018-09-10 stsp case GOT_IMSG_COMMIT_REQUEST:
948 c59b3346 2018-09-11 stsp err = commit_request(&imsg, &ibuf, pack, packidx,
949 7762fe12 2018-11-05 stsp &objcache);
951 876c234b 2018-09-10 stsp case GOT_IMSG_TREE_REQUEST:
952 c59b3346 2018-09-11 stsp err = tree_request(&imsg, &ibuf, pack, packidx,
953 c59b3346 2018-09-11 stsp &objcache);
955 876c234b 2018-09-10 stsp case GOT_IMSG_BLOB_REQUEST:
956 c59b3346 2018-09-11 stsp err = blob_request(&imsg, &ibuf, pack, packidx,
957 c59b3346 2018-09-11 stsp &objcache);
959 f4a881ce 2018-11-17 stsp case GOT_IMSG_TAG_REQUEST:
960 f4a881ce 2018-11-17 stsp err = tag_request(&imsg, &ibuf, pack, packidx,
961 f4a881ce 2018-11-17 stsp &objcache);
963 ca6e02ac 2020-01-07 stsp case GOT_IMSG_COMMIT_TRAVERSAL_REQUEST:
964 ca6e02ac 2020-01-07 stsp err = commit_traversal_request(&imsg, &ibuf, pack,
965 ca6e02ac 2020-01-07 stsp packidx, &objcache);
968 876c234b 2018-09-10 stsp err = got_error(GOT_ERR_PRIVSEP_MSG);
972 3a6ce05a 2019-02-11 stsp if (imsg.fd != -1 && close(imsg.fd) != 0 && err == NULL)
973 638f9024 2019-05-13 stsp err = got_error_from_errno("close");
974 876c234b 2018-09-10 stsp imsg_free(&imsg);
979 c59b3346 2018-09-11 stsp if (packidx)
980 c59b3346 2018-09-11 stsp got_packidx_close(packidx);
982 c59b3346 2018-09-11 stsp got_pack_close(pack);
983 48d5fe42 2018-09-15 stsp got_object_cache_close(&objcache);
984 876c234b 2018-09-10 stsp imsg_clear(&ibuf);
986 80d5f134 2018-11-11 stsp if (!sigint_received && err->code != GOT_ERR_PRIVSEP_PIPE) {
987 80d5f134 2018-11-11 stsp fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
988 99437157 2018-11-11 stsp got_privsep_send_error(&ibuf, err);
991 3a6ce05a 2019-02-11 stsp if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL)
992 638f9024 2019-05-13 stsp err = got_error_from_errno("close");
993 876c234b 2018-09-10 stsp return err ? 1 : 0;