Blob


1 /*
2 * Copyright (c) 2019 Ori Bernstein <ori@openbsd.org>
3 * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/uio.h>
21 #include <sys/time.h>
22 #include <sys/stat.h>
24 #include <stdint.h>
25 #include <errno.h>
26 #include <limits.h>
27 #include <signal.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <fcntl.h>
33 #include <unistd.h>
34 #include <zlib.h>
35 #include <err.h>
37 #include "got_error.h"
38 #include "got_object.h"
39 #include "got_path.h"
40 #include "got_version.h"
41 #include "got_fetch.h"
42 #include "got_reference.h"
44 #include "got_lib_sha1.h"
45 #include "got_lib_delta.h"
46 #include "got_lib_object.h"
47 #include "got_lib_object_parse.h"
48 #include "got_lib_privsep.h"
49 #include "got_lib_pack.h"
50 #include "got_lib_pkt.h"
51 #include "got_lib_gitproto.h"
52 #include "got_lib_ratelimit.h"
54 #ifndef nitems
55 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
56 #endif
58 struct got_object *indexed;
59 static int chattygot;
61 static const struct got_capability got_capabilities[] = {
62 { GOT_CAPA_AGENT, "got/" GOT_VERSION_STR },
63 { GOT_CAPA_OFS_DELTA, NULL },
64 #if 0
65 { GOT_CAPA_SIDE_BAND_64K, NULL },
66 #endif
67 { GOT_CAPA_REPORT_STATUS, NULL },
68 { GOT_CAPA_DELETE_REFS, NULL },
69 };
71 static const struct got_error *
72 send_upload_progress(struct imsgbuf *ibuf, off_t bytes,
73 struct got_ratelimit *rl)
74 {
75 const struct got_error *err = NULL;
76 int elapsed = 0;
78 if (rl) {
79 err = got_ratelimit_check(&elapsed, rl);
80 if (err || !elapsed)
81 return err;
82 }
84 if (imsg_compose(ibuf, GOT_IMSG_SEND_UPLOAD_PROGRESS, 0, 0, -1,
85 &bytes, sizeof(bytes)) == -1)
86 return got_error_from_errno(
87 "imsg_compose SEND_UPLOAD_PROGRESS");
89 return got_privsep_flush_imsg(ibuf);
90 }
92 static const struct got_error *
93 send_pack_request(struct imsgbuf *ibuf)
94 {
95 if (imsg_compose(ibuf, GOT_IMSG_SEND_PACK_REQUEST, 0, 0, -1,
96 NULL, 0) == -1)
97 return got_error_from_errno("imsg_compose SEND_PACK_REQUEST");
98 return got_privsep_flush_imsg(ibuf);
99 }
101 static const struct got_error *
102 send_done(struct imsgbuf *ibuf)
104 if (imsg_compose(ibuf, GOT_IMSG_SEND_DONE, 0, 0, -1, NULL, 0) == -1)
105 return got_error_from_errno("imsg_compose SEND_DONE");
106 return got_privsep_flush_imsg(ibuf);
109 static const struct got_error *
110 recv_packfd(int *packfd, struct imsgbuf *ibuf)
112 const struct got_error *err;
113 struct imsg imsg;
115 *packfd = -1;
117 err = got_privsep_recv_imsg(&imsg, ibuf, 0);
118 if (err)
119 return err;
121 if (imsg.hdr.type == GOT_IMSG_STOP) {
122 err = got_error(GOT_ERR_CANCELLED);
123 goto done;
126 if (imsg.hdr.type != GOT_IMSG_SEND_PACKFD) {
127 err = got_error(GOT_ERR_PRIVSEP_MSG);
128 goto done;
131 if (imsg.hdr.len - IMSG_HEADER_SIZE != 0) {
132 err = got_error(GOT_ERR_PRIVSEP_LEN);
133 goto done;
136 *packfd = imsg.fd;
137 done:
138 imsg_free(&imsg);
139 return err;
142 static const struct got_error *
143 send_pack_file(int sendfd, int packfd, struct imsgbuf *ibuf)
145 const struct got_error *err;
146 unsigned char buf[8192];
147 ssize_t r, w;
148 off_t wtotal = 0;
149 struct got_ratelimit rl;
151 if (lseek(packfd, 0L, SEEK_SET) == -1)
152 return got_error_from_errno("lseek");
154 got_ratelimit_init(&rl, 0, 500);
156 for (;;) {
157 r = read(packfd, buf, sizeof(buf));
158 if (r == -1)
159 return got_error_from_errno("read");
160 if (r == 0)
161 break;
162 w = write(sendfd, buf, r);
163 if (w == -1)
164 return got_error_from_errno("write");
165 if (w != r)
166 return got_error(GOT_ERR_IO);
167 wtotal += w;
168 err = send_upload_progress(ibuf, wtotal, &rl);
169 if (err)
170 return err;
173 return send_upload_progress(ibuf, wtotal, NULL);
176 static const struct got_error *
177 send_error(const char *buf, size_t len)
179 static char msg[1024];
180 size_t i;
182 for (i = 0; i < len && i < sizeof(msg) - 1; i++) {
183 if (!isprint(buf[i]))
184 return got_error_msg(GOT_ERR_BAD_PACKET,
185 "non-printable error message received from server");
186 msg[i] = buf[i];
188 msg[i] = '\0';
189 return got_error_msg(GOT_ERR_SEND_FAILED, msg);
192 static const struct got_error *
193 send_their_ref(struct imsgbuf *ibuf, struct got_object_id *refid,
194 const char *refname)
196 struct ibuf *wbuf;
197 size_t len, reflen = strlen(refname);
199 len = sizeof(struct got_imsg_send_remote_ref) + reflen;
200 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
201 return got_error(GOT_ERR_NO_SPACE);
203 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REMOTE_REF, 0, 0, len);
204 if (wbuf == NULL)
205 return got_error_from_errno("imsg_create SEND_REMOTE_REF");
207 /* Keep in sync with struct got_imsg_send_remote_ref definition! */
208 if (imsg_add(wbuf, refid->sha1, SHA1_DIGEST_LENGTH) == -1)
209 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
210 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
211 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
212 if (imsg_add(wbuf, refname, reflen) == -1)
213 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
215 wbuf->fd = -1;
216 imsg_close(ibuf, wbuf);
217 return got_privsep_flush_imsg(ibuf);
220 static const struct got_error *
221 send_ref_status(struct imsgbuf *ibuf, const char *refname, int success,
222 struct got_pathlist_head *refs, struct got_pathlist_head *delete_refs)
224 struct ibuf *wbuf;
225 size_t len, reflen = strlen(refname);
226 struct got_pathlist_entry *pe;
227 int ref_valid = 0;
228 char *eol;
230 eol = strchr(refname, '\n');
231 if (eol == NULL) {
232 return got_error_msg(GOT_ERR_BAD_PACKET,
233 "unexpected message from server");
235 *eol = '\0';
237 TAILQ_FOREACH(pe, refs, entry) {
238 if (strcmp(refname, pe->path) == 0) {
239 ref_valid = 1;
240 break;
243 if (!ref_valid) {
244 TAILQ_FOREACH(pe, delete_refs, entry) {
245 if (strcmp(refname, pe->path) == 0) {
246 ref_valid = 1;
247 break;
251 if (!ref_valid) {
252 return got_error_msg(GOT_ERR_BAD_PACKET,
253 "unexpected message from server");
256 len = sizeof(struct got_imsg_send_ref_status) + reflen;
257 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
258 return got_error(GOT_ERR_NO_SPACE);
260 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REF_STATUS,
261 0, 0, len);
262 if (wbuf == NULL)
263 return got_error_from_errno("imsg_create SEND_REF_STATUS");
265 /* Keep in sync with struct got_imsg_send_ref_status definition! */
266 if (imsg_add(wbuf, &success, sizeof(success)) == -1)
267 return got_error_from_errno("imsg_add SEND_REF_STATUS");
268 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
269 return got_error_from_errno("imsg_add SEND_REF_STATUS");
270 if (imsg_add(wbuf, refname, reflen) == -1)
271 return got_error_from_errno("imsg_add SEND_REF_STATUS");
273 wbuf->fd = -1;
274 imsg_close(ibuf, wbuf);
275 return got_privsep_flush_imsg(ibuf);
278 static const struct got_error *
279 describe_refchange(int *n, int *sent_my_capabilites,
280 const char *my_capabilities, char *buf, size_t bufsize,
281 const char *refname, const char *old_hashstr, const char *new_hashstr)
283 *n = snprintf(buf, bufsize, "%s %s %s",
284 old_hashstr, new_hashstr, refname);
285 if (*n < 0 || (size_t)*n >= bufsize)
286 return got_error(GOT_ERR_NO_SPACE);
288 /*
289 * We must announce our capabilities along with the first
290 * reference. Unfortunately, the protocol requires an embedded
291 * NUL as a separator between reference name and capabilities,
292 * which we have to deal with here.
293 * It also requires a linefeed for terminating packet data.
294 */
295 if (!*sent_my_capabilites && my_capabilities != NULL) {
296 int m;
297 if (*n >= bufsize - 1)
298 return got_error(GOT_ERR_NO_SPACE);
299 m = snprintf(buf + *n + 1, /* offset after '\0' */
300 bufsize - (*n + 1), "%s\n", my_capabilities);
301 if (m < 0 || *n + m >= bufsize)
302 return got_error(GOT_ERR_NO_SPACE);
303 *n += m;
304 *sent_my_capabilites = 1;
305 } else {
306 *n = strlcat(buf, "\n", bufsize);
307 if (*n >= bufsize)
308 return got_error(GOT_ERR_NO_SPACE);
311 return NULL;
314 static const struct got_error *
315 send_pack(int fd, struct got_pathlist_head *refs,
316 struct got_pathlist_head *delete_refs, struct imsgbuf *ibuf)
318 const struct got_error *err = NULL;
319 char buf[GOT_PKT_MAX];
320 const unsigned char zero_id[SHA1_DIGEST_LENGTH] = { 0 };
321 char old_hashstr[SHA1_DIGEST_STRING_LENGTH];
322 char new_hashstr[SHA1_DIGEST_STRING_LENGTH];
323 struct got_pathlist_head their_refs;
324 int is_firstpkt = 1;
325 int n, nsent = 0;
326 int packfd = -1;
327 char *id_str = NULL, *refname = NULL;
328 struct got_object_id *id = NULL;
329 char *server_capabilities = NULL, *my_capabilities = NULL;
330 struct got_pathlist_entry *pe;
331 int sent_my_capabilites = 0;
333 TAILQ_INIT(&their_refs);
335 if (TAILQ_EMPTY(refs) && TAILQ_EMPTY(delete_refs))
336 return got_error(GOT_ERR_SEND_EMPTY);
338 while (1) {
339 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
340 if (err)
341 goto done;
342 if (n == 0)
343 break;
344 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
345 err = send_error(&buf[4], n - 4);
346 goto done;
348 free(id_str);
349 free(refname);
350 err = got_gitproto_parse_refline(&id_str, &refname,
351 &server_capabilities, buf, n);
352 if (err)
353 goto done;
354 if (is_firstpkt) {
355 if (chattygot && server_capabilities[0] != '\0')
356 fprintf(stderr, "%s: server capabilities: %s\n",
357 getprogname(), server_capabilities);
358 err = got_gitproto_match_capabilities(&my_capabilities,
359 NULL, server_capabilities, got_capabilities,
360 nitems(got_capabilities));
361 if (err)
362 goto done;
363 if (chattygot)
364 fprintf(stderr, "%s: my capabilities:%s\n",
365 getprogname(), my_capabilities);
366 is_firstpkt = 0;
368 if (strstr(refname, "^{}")) {
369 if (chattygot) {
370 fprintf(stderr, "%s: ignoring %s\n",
371 getprogname(), refname);
373 continue;
376 id = malloc(sizeof(*id));
377 if (id == NULL) {
378 err = got_error_from_errno("malloc");
379 goto done;
381 if (!got_parse_sha1_digest(id->sha1, id_str)) {
382 err = got_error(GOT_ERR_BAD_OBJ_ID_STR);
383 goto done;
385 err = send_their_ref(ibuf, id, refname);
386 if (err)
387 goto done;
389 err = got_pathlist_append(&their_refs, refname, id);
390 if (err)
391 goto done;
393 if (chattygot)
394 fprintf(stderr, "%s: remote has %s %s\n",
395 getprogname(), refname, id_str);
396 free(id_str);
397 id_str = NULL;
398 refname = NULL; /* do not free; owned by their_refs */
399 id = NULL; /* do not free; owned by their_refs */
402 if (!TAILQ_EMPTY(delete_refs)) {
403 if (my_capabilities == NULL ||
404 strstr(my_capabilities, GOT_CAPA_DELETE_REFS) == NULL) {
405 err = got_error(GOT_ERR_CAPA_DELETE_REFS);
406 goto done;
410 TAILQ_FOREACH(pe, delete_refs, entry) {
411 const char *refname = pe->path;
412 struct got_pathlist_entry *their_pe;
413 struct got_object_id *their_id = NULL;
415 TAILQ_FOREACH(their_pe, &their_refs, entry) {
416 const char *their_refname = their_pe->path;
417 if (got_path_cmp(refname, their_refname,
418 strlen(refname), strlen(their_refname)) == 0) {
419 their_id = their_pe->data;
420 break;
423 if (their_id == NULL) {
424 err = got_error_fmt(GOT_ERR_NOT_REF,
425 "%s does not exist in remote repository",
426 refname);
427 goto done;
430 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
431 sizeof(old_hashstr));
432 got_sha1_digest_to_str(zero_id, new_hashstr,
433 sizeof(new_hashstr));
434 err = describe_refchange(&n, &sent_my_capabilites,
435 my_capabilities, buf, sizeof(buf), refname,
436 old_hashstr, new_hashstr);
437 if (err)
438 goto done;
439 err = got_pkt_writepkt(fd, buf, n, chattygot);
440 if (err)
441 goto done;
442 if (chattygot) {
443 fprintf(stderr, "%s: deleting %s %s\n",
444 getprogname(), refname, old_hashstr);
446 nsent++;
449 TAILQ_FOREACH(pe, refs, entry) {
450 const char *refname = pe->path;
451 struct got_object_id *id = pe->data;
452 struct got_object_id *their_id = NULL;
453 struct got_pathlist_entry *their_pe;
455 TAILQ_FOREACH(their_pe, &their_refs, entry) {
456 const char *their_refname = their_pe->path;
457 if (got_path_cmp(refname, their_refname,
458 strlen(refname), strlen(their_refname)) == 0) {
459 their_id = their_pe->data;
460 break;
463 if (their_id) {
464 if (got_object_id_cmp(id, their_id) == 0) {
465 if (chattygot) {
466 fprintf(stderr,
467 "%s: no change for %s\n",
468 getprogname(), refname);
470 continue;
472 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
473 sizeof(old_hashstr));
474 } else {
475 got_sha1_digest_to_str(zero_id, old_hashstr,
476 sizeof(old_hashstr));
478 got_sha1_digest_to_str(id->sha1, new_hashstr,
479 sizeof(new_hashstr));
480 err = describe_refchange(&n, &sent_my_capabilites,
481 my_capabilities, buf, sizeof(buf), refname,
482 old_hashstr, new_hashstr);
483 if (err)
484 goto done;
485 err = got_pkt_writepkt(fd, buf, n, chattygot);
486 if (err)
487 goto done;
488 if (chattygot) {
489 if (their_id) {
490 fprintf(stderr, "%s: updating %s %s -> %s\n",
491 getprogname(), refname, old_hashstr,
492 new_hashstr);
493 } else {
494 fprintf(stderr, "%s: creating %s %s\n",
495 getprogname(), refname, new_hashstr);
498 nsent++;
500 err = got_pkt_flushpkt(fd, chattygot);
501 if (err)
502 goto done;
504 err = send_pack_request(ibuf);
505 if (err)
506 goto done;
508 err = recv_packfd(&packfd, ibuf);
509 if (err)
510 goto done;
512 if (packfd != -1) {
513 err = send_pack_file(fd, packfd, ibuf);
514 if (err)
515 goto done;
518 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
519 if (err)
520 goto done;
521 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
522 err = send_error(&buf[4], n - 4);
523 goto done;
524 } else if (n < 10 || strncmp(buf, "unpack ok\n", 10) != 0) {
525 err = got_error_msg(GOT_ERR_BAD_PACKET,
526 "unexpected message from server");
527 goto done;
530 while (nsent > 0) {
531 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
532 if (err)
533 goto done;
534 if (n < 3) {
535 err = got_error_msg(GOT_ERR_BAD_PACKET,
536 "unexpected message from server");
537 goto done;
538 } else if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
539 err = send_error(&buf[4], n - 4);
540 goto done;
541 } else if (strncmp(buf, "ok ", 3) == 0) {
542 err = send_ref_status(ibuf, buf + 3, 1,
543 refs, delete_refs);
544 if (err)
545 goto done;
546 } else if (strncmp(buf, "ng ", 3) == 0) {
547 err = send_ref_status(ibuf, buf + 3, 0,
548 refs, delete_refs);
549 if (err)
550 goto done;
551 } else {
552 err = got_error_msg(GOT_ERR_BAD_PACKET,
553 "unexpected message from server");
554 goto done;
556 nsent--;
559 err = send_done(ibuf);
560 done:
561 TAILQ_FOREACH(pe, &their_refs, entry) {
562 free((void *)pe->path);
563 free(pe->data);
565 got_pathlist_free(&their_refs);
566 free(id_str);
567 free(id);
568 free(refname);
569 free(server_capabilities);
570 return err;
573 int
574 main(int argc, char **argv)
576 const struct got_error *err = NULL;
577 int sendfd;
578 struct imsgbuf ibuf;
579 struct imsg imsg;
580 struct got_pathlist_head refs;
581 struct got_pathlist_head delete_refs;
582 struct got_pathlist_entry *pe;
583 struct got_imsg_send_request send_req;
584 struct got_imsg_send_ref href;
585 size_t datalen, i;
586 #if 0
587 static int attached;
588 while (!attached)
589 sleep (1);
590 #endif
592 TAILQ_INIT(&refs);
593 TAILQ_INIT(&delete_refs);
595 imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
596 #ifndef PROFILE
597 /* revoke access to most system calls */
598 if (pledge("stdio recvfd", NULL) == -1) {
599 err = got_error_from_errno("pledge");
600 got_privsep_send_error(&ibuf, err);
601 return 1;
604 /* revoke fs access */
605 if (landlock_no_fs() == -1) {
606 err = got_error_from_errno("landlock_no_fs");
607 got_privsep_send_error(&ibuf, err);
608 return 1;
610 if (cap_enter() == -1) {
611 err = got_error_from_errno("cap_enter");
612 got_privsep_send_error(&ibuf, err);
613 return 1;
615 #endif
616 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
617 if (err->code == GOT_ERR_PRIVSEP_PIPE)
618 err = NULL;
619 goto done;
621 if (imsg.hdr.type == GOT_IMSG_STOP)
622 goto done;
623 if (imsg.hdr.type != GOT_IMSG_SEND_REQUEST) {
624 err = got_error(GOT_ERR_PRIVSEP_MSG);
625 goto done;
627 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
628 if (datalen < sizeof(send_req)) {
629 err = got_error(GOT_ERR_PRIVSEP_LEN);
630 goto done;
632 memcpy(&send_req, imsg.data, sizeof(send_req));
633 sendfd = imsg.fd;
634 imsg_free(&imsg);
636 if (send_req.verbosity > 0)
637 chattygot += send_req.verbosity;
639 for (i = 0; i < send_req.nrefs; i++) {
640 struct got_object_id *id;
641 char *refname;
643 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
644 if (err->code == GOT_ERR_PRIVSEP_PIPE)
645 err = NULL;
646 goto done;
648 if (imsg.hdr.type == GOT_IMSG_STOP)
649 goto done;
650 if (imsg.hdr.type != GOT_IMSG_SEND_REF) {
651 err = got_error(GOT_ERR_PRIVSEP_MSG);
652 goto done;
654 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
655 if (datalen < sizeof(href)) {
656 err = got_error(GOT_ERR_PRIVSEP_LEN);
657 goto done;
659 memcpy(&href, imsg.data, sizeof(href));
660 if (datalen - sizeof(href) < href.name_len) {
661 err = got_error(GOT_ERR_PRIVSEP_LEN);
662 goto done;
664 refname = malloc(href.name_len + 1);
665 if (refname == NULL) {
666 err = got_error_from_errno("malloc");
667 goto done;
669 memcpy(refname, imsg.data + sizeof(href), href.name_len);
670 refname[href.name_len] = '\0';
672 /*
673 * Prevent sending of references that won't make any
674 * sense outside the local repository's context.
675 */
676 if (strncmp(refname, "refs/got/", 9) == 0 ||
677 strncmp(refname, "refs/remotes/", 13) == 0) {
678 err = got_error_fmt(GOT_ERR_SEND_BAD_REF,
679 "%s", refname);
680 goto done;
683 id = malloc(sizeof(*id));
684 if (id == NULL) {
685 free(refname);
686 err = got_error_from_errno("malloc");
687 goto done;
689 memcpy(id->sha1, href.id, SHA1_DIGEST_LENGTH);
690 if (href.delete)
691 err = got_pathlist_append(&delete_refs, refname, id);
692 else
693 err = got_pathlist_append(&refs, refname, id);
694 if (err) {
695 free(refname);
696 free(id);
697 goto done;
700 imsg_free(&imsg);
703 err = send_pack(sendfd, &refs, &delete_refs, &ibuf);
704 done:
705 TAILQ_FOREACH(pe, &refs, entry) {
706 free((char *)pe->path);
707 free(pe->data);
709 got_pathlist_free(&refs);
710 TAILQ_FOREACH(pe, &delete_refs, entry) {
711 free((char *)pe->path);
712 free(pe->data);
714 got_pathlist_free(&delete_refs);
715 if (sendfd != -1 && close(sendfd) == -1 && err == NULL)
716 err = got_error_from_errno("close");
717 if (err != NULL && err->code != GOT_ERR_CANCELLED) {
718 fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
719 got_privsep_send_error(&ibuf, err);
722 exit(0);