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/uio.h>
20 #include <sys/time.h>
21 #include <sys/stat.h>
23 #include <stdint.h>
24 #include <errno.h>
25 #include <limits.h>
26 #include <signal.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <fcntl.h>
32 #include <unistd.h>
33 #include <zlib.h>
34 #include <err.h>
36 #include "got_error.h"
37 #include "got_object.h"
38 #include "got_path.h"
39 #include "got_version.h"
40 #include "got_fetch.h"
41 #include "got_reference.h"
43 #include "got_lib_sha1.h"
44 #include "got_lib_delta.h"
45 #include "got_lib_object.h"
46 #include "got_lib_object_parse.h"
47 #include "got_lib_privsep.h"
48 #include "got_lib_pack.h"
49 #include "got_lib_pkt.h"
50 #include "got_lib_gitproto.h"
51 #include "got_lib_ratelimit.h"
53 #ifndef nitems
54 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
55 #endif
57 struct got_object *indexed;
58 static int chattygot;
60 static const struct got_capability got_capabilities[] = {
61 { GOT_CAPA_AGENT, "got/" GOT_VERSION_STR },
62 { GOT_CAPA_OFS_DELTA, NULL },
63 #if 0
64 { GOT_CAPA_SIDE_BAND_64K, NULL },
65 #endif
66 { GOT_CAPA_REPORT_STATUS, NULL },
67 { GOT_CAPA_DELETE_REFS, NULL },
68 };
70 static const struct got_error *
71 send_upload_progress(struct imsgbuf *ibuf, off_t bytes,
72 struct got_ratelimit *rl)
73 {
74 const struct got_error *err = NULL;
75 int elapsed = 0;
77 if (rl) {
78 err = got_ratelimit_check(&elapsed, rl);
79 if (err || !elapsed)
80 return err;
81 }
83 if (imsg_compose(ibuf, GOT_IMSG_SEND_UPLOAD_PROGRESS, 0, 0, -1,
84 &bytes, sizeof(bytes)) == -1)
85 return got_error_from_errno(
86 "imsg_compose SEND_UPLOAD_PROGRESS");
88 return got_privsep_flush_imsg(ibuf);
89 }
91 static const struct got_error *
92 send_pack_request(struct imsgbuf *ibuf)
93 {
94 if (imsg_compose(ibuf, GOT_IMSG_SEND_PACK_REQUEST, 0, 0, -1,
95 NULL, 0) == -1)
96 return got_error_from_errno("imsg_compose SEND_PACK_REQUEST");
97 return got_privsep_flush_imsg(ibuf);
98 }
100 static const struct got_error *
101 send_done(struct imsgbuf *ibuf)
103 if (imsg_compose(ibuf, GOT_IMSG_SEND_DONE, 0, 0, -1, NULL, 0) == -1)
104 return got_error_from_errno("imsg_compose SEND_DONE");
105 return got_privsep_flush_imsg(ibuf);
108 static const struct got_error *
109 recv_packfd(int *packfd, struct imsgbuf *ibuf)
111 const struct got_error *err;
112 struct imsg imsg;
114 *packfd = -1;
116 err = got_privsep_recv_imsg(&imsg, ibuf, 0);
117 if (err)
118 return err;
120 if (imsg.hdr.type == GOT_IMSG_STOP) {
121 err = got_error(GOT_ERR_CANCELLED);
122 goto done;
125 if (imsg.hdr.type != GOT_IMSG_SEND_PACKFD) {
126 err = got_error(GOT_ERR_PRIVSEP_MSG);
127 goto done;
130 if (imsg.hdr.len - IMSG_HEADER_SIZE != 0) {
131 err = got_error(GOT_ERR_PRIVSEP_LEN);
132 goto done;
135 *packfd = imsg.fd;
136 done:
137 imsg_free(&imsg);
138 return err;
141 static const struct got_error *
142 send_pack_file(int sendfd, int packfd, struct imsgbuf *ibuf)
144 const struct got_error *err;
145 unsigned char buf[8192];
146 ssize_t r, w;
147 off_t wtotal = 0;
148 struct got_ratelimit rl;
150 if (lseek(packfd, 0L, SEEK_SET) == -1)
151 return got_error_from_errno("lseek");
153 got_ratelimit_init(&rl, 0, 500);
155 for (;;) {
156 r = read(packfd, buf, sizeof(buf));
157 if (r == -1)
158 return got_error_from_errno("read");
159 if (r == 0)
160 break;
161 w = write(sendfd, buf, r);
162 if (w == -1)
163 return got_error_from_errno("write");
164 if (w != r)
165 return got_error(GOT_ERR_IO);
166 wtotal += w;
167 err = send_upload_progress(ibuf, wtotal, &rl);
168 if (err)
169 return err;
172 return send_upload_progress(ibuf, wtotal, NULL);
175 static const struct got_error *
176 send_error(const char *buf, size_t len)
178 static char msg[1024];
179 size_t i;
181 for (i = 0; i < len && i < sizeof(msg) - 1; i++) {
182 if (!isprint(buf[i]))
183 return got_error_msg(GOT_ERR_BAD_PACKET,
184 "non-printable error message received from server");
185 msg[i] = buf[i];
187 msg[i] = '\0';
188 return got_error_msg(GOT_ERR_SEND_FAILED, msg);
191 static const struct got_error *
192 send_their_ref(struct imsgbuf *ibuf, struct got_object_id *refid,
193 const char *refname)
195 const struct got_error *err = NULL;
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 err = got_error_from_errno("imsg_add SEND_REMOTE_REF");
210 ibuf_free(wbuf);
211 return err;
213 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1) {
214 err = got_error_from_errno("imsg_add SEND_REMOTE_REF");
215 ibuf_free(wbuf);
216 return err;
218 if (imsg_add(wbuf, refname, reflen) == -1) {
219 err = got_error_from_errno("imsg_add SEND_REMOTE_REF");
220 ibuf_free(wbuf);
221 return err;
224 wbuf->fd = -1;
225 imsg_close(ibuf, wbuf);
226 return got_privsep_flush_imsg(ibuf);
229 static const struct got_error *
230 send_ref_status(struct imsgbuf *ibuf, const char *refname, int success,
231 struct got_pathlist_head *refs, struct got_pathlist_head *delete_refs)
233 const struct got_error *err = NULL;
234 struct ibuf *wbuf;
235 size_t len, reflen = strlen(refname);
236 struct got_pathlist_entry *pe;
237 int ref_valid = 0;
238 char *eol;
240 eol = strchr(refname, '\n');
241 if (eol == NULL) {
242 return got_error_msg(GOT_ERR_BAD_PACKET,
243 "unexpected message from server");
245 *eol = '\0';
247 TAILQ_FOREACH(pe, refs, entry) {
248 if (strcmp(refname, pe->path) == 0) {
249 ref_valid = 1;
250 break;
253 if (!ref_valid) {
254 TAILQ_FOREACH(pe, delete_refs, entry) {
255 if (strcmp(refname, pe->path) == 0) {
256 ref_valid = 1;
257 break;
261 if (!ref_valid) {
262 return got_error_msg(GOT_ERR_BAD_PACKET,
263 "unexpected message from server");
266 len = sizeof(struct got_imsg_send_ref_status) + reflen;
267 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
268 return got_error(GOT_ERR_NO_SPACE);
270 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REF_STATUS,
271 0, 0, len);
272 if (wbuf == NULL)
273 return got_error_from_errno("imsg_create SEND_REF_STATUS");
275 /* Keep in sync with struct got_imsg_send_ref_status definition! */
276 if (imsg_add(wbuf, &success, sizeof(success)) == -1) {
277 err = got_error_from_errno("imsg_add SEND_REF_STATUS");
278 ibuf_free(wbuf);
279 return err;
281 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1) {
282 err = got_error_from_errno("imsg_add SEND_REF_STATUS");
283 ibuf_free(wbuf);
284 return err;
286 if (imsg_add(wbuf, refname, reflen) == -1) {
287 err = got_error_from_errno("imsg_add SEND_REF_STATUS");
288 ibuf_free(wbuf);
289 return err;
292 wbuf->fd = -1;
293 imsg_close(ibuf, wbuf);
294 return got_privsep_flush_imsg(ibuf);
297 static const struct got_error *
298 describe_refchange(int *n, int *sent_my_capabilites,
299 const char *my_capabilities, char *buf, size_t bufsize,
300 const char *refname, const char *old_hashstr, const char *new_hashstr)
302 *n = snprintf(buf, bufsize, "%s %s %s",
303 old_hashstr, new_hashstr, refname);
304 if (*n >= bufsize)
305 return got_error(GOT_ERR_NO_SPACE);
307 /*
308 * We must announce our capabilities along with the first
309 * reference. Unfortunately, the protocol requires an embedded
310 * NUL as a separator between reference name and capabilities,
311 * which we have to deal with here.
312 * It also requires a linefeed for terminating packet data.
313 */
314 if (!*sent_my_capabilites && my_capabilities != NULL) {
315 int m;
316 if (*n >= bufsize - 1)
317 return got_error(GOT_ERR_NO_SPACE);
318 m = snprintf(buf + *n + 1, /* offset after '\0' */
319 bufsize - (*n + 1), "%s\n", my_capabilities);
320 if (*n + m >= bufsize)
321 return got_error(GOT_ERR_NO_SPACE);
322 *n += m;
323 *sent_my_capabilites = 1;
324 } else {
325 *n = strlcat(buf, "\n", bufsize);
326 if (*n >= bufsize)
327 return got_error(GOT_ERR_NO_SPACE);
330 return NULL;
333 static const struct got_error *
334 send_pack(int fd, struct got_pathlist_head *refs,
335 struct got_pathlist_head *delete_refs, struct imsgbuf *ibuf)
337 const struct got_error *err = NULL;
338 char buf[GOT_PKT_MAX];
339 const unsigned char zero_id[SHA1_DIGEST_LENGTH] = { 0 };
340 char old_hashstr[SHA1_DIGEST_STRING_LENGTH];
341 char new_hashstr[SHA1_DIGEST_STRING_LENGTH];
342 struct got_pathlist_head their_refs;
343 int is_firstpkt = 1;
344 int n, nsent = 0;
345 int packfd = -1;
346 char *id_str = NULL, *refname = NULL;
347 struct got_object_id *id = NULL;
348 char *server_capabilities = NULL, *my_capabilities = NULL;
349 struct got_pathlist_entry *pe;
350 int sent_my_capabilites = 0;
352 TAILQ_INIT(&their_refs);
354 if (TAILQ_EMPTY(refs) && TAILQ_EMPTY(delete_refs))
355 return got_error(GOT_ERR_SEND_EMPTY);
357 while (1) {
358 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
359 if (err)
360 goto done;
361 if (n == 0)
362 break;
363 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
364 err = send_error(&buf[4], n - 4);
365 goto done;
367 free(id_str);
368 free(refname);
369 err = got_gitproto_parse_refline(&id_str, &refname,
370 &server_capabilities, buf, n);
371 if (err)
372 goto done;
373 if (is_firstpkt) {
374 if (chattygot && server_capabilities[0] != '\0')
375 fprintf(stderr, "%s: server capabilities: %s\n",
376 getprogname(), server_capabilities);
377 err = got_gitproto_match_capabilities(&my_capabilities,
378 NULL, server_capabilities, got_capabilities,
379 nitems(got_capabilities));
380 if (err)
381 goto done;
382 if (chattygot)
383 fprintf(stderr, "%s: my capabilities:%s\n",
384 getprogname(), my_capabilities);
385 is_firstpkt = 0;
387 if (strstr(refname, "^{}")) {
388 if (chattygot) {
389 fprintf(stderr, "%s: ignoring %s\n",
390 getprogname(), refname);
392 continue;
395 id = malloc(sizeof(*id));
396 if (id == NULL) {
397 err = got_error_from_errno("malloc");
398 goto done;
400 if (!got_parse_sha1_digest(id->sha1, id_str)) {
401 err = got_error(GOT_ERR_BAD_OBJ_ID_STR);
402 goto done;
404 err = send_their_ref(ibuf, id, refname);
405 if (err)
406 goto done;
408 err = got_pathlist_append(&their_refs, refname, id);
409 if (chattygot)
410 fprintf(stderr, "%s: remote has %s %s\n",
411 getprogname(), refname, id_str);
412 free(id_str);
413 id_str = NULL;
414 refname = NULL; /* do not free; owned by their_refs */
415 id = NULL; /* do not free; owned by their_refs */
418 if (!TAILQ_EMPTY(delete_refs)) {
419 if (my_capabilities == NULL ||
420 strstr(my_capabilities, GOT_CAPA_DELETE_REFS) == NULL) {
421 err = got_error(GOT_ERR_CAPA_DELETE_REFS);
422 goto done;
426 TAILQ_FOREACH(pe, delete_refs, entry) {
427 const char *refname = pe->path;
428 struct got_pathlist_entry *their_pe;
429 struct got_object_id *their_id = NULL;
431 TAILQ_FOREACH(their_pe, &their_refs, entry) {
432 const char *their_refname = their_pe->path;
433 if (got_path_cmp(refname, their_refname,
434 strlen(refname), strlen(their_refname)) == 0) {
435 their_id = their_pe->data;
436 break;
439 if (their_id == NULL) {
440 err = got_error_fmt(GOT_ERR_NOT_REF,
441 "%s does not exist in remote repository",
442 refname);
443 goto done;
446 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
447 sizeof(old_hashstr));
448 got_sha1_digest_to_str(zero_id, new_hashstr,
449 sizeof(new_hashstr));
450 err = describe_refchange(&n, &sent_my_capabilites,
451 my_capabilities, buf, sizeof(buf), refname,
452 old_hashstr, new_hashstr);
453 if (err)
454 goto done;
455 err = got_pkt_writepkt(fd, buf, n, chattygot);
456 if (err)
457 goto done;
458 if (chattygot) {
459 fprintf(stderr, "%s: deleting %s %s\n",
460 getprogname(), refname, old_hashstr);
462 nsent++;
465 TAILQ_FOREACH(pe, refs, entry) {
466 const char *refname = pe->path;
467 struct got_object_id *id = pe->data;
468 struct got_object_id *their_id = NULL;
469 struct got_pathlist_entry *their_pe;
471 TAILQ_FOREACH(their_pe, &their_refs, entry) {
472 const char *their_refname = their_pe->path;
473 if (got_path_cmp(refname, their_refname,
474 strlen(refname), strlen(their_refname)) == 0) {
475 their_id = their_pe->data;
476 break;
479 if (their_id) {
480 if (got_object_id_cmp(id, their_id) == 0) {
481 if (chattygot) {
482 fprintf(stderr,
483 "%s: no change for %s\n",
484 getprogname(), refname);
486 continue;
488 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
489 sizeof(old_hashstr));
490 } else {
491 got_sha1_digest_to_str(zero_id, old_hashstr,
492 sizeof(old_hashstr));
494 got_sha1_digest_to_str(id->sha1, new_hashstr,
495 sizeof(new_hashstr));
496 err = describe_refchange(&n, &sent_my_capabilites,
497 my_capabilities, buf, sizeof(buf), refname,
498 old_hashstr, new_hashstr);
499 if (err)
500 goto done;
501 err = got_pkt_writepkt(fd, buf, n, chattygot);
502 if (err)
503 goto done;
504 if (chattygot) {
505 if (their_id) {
506 fprintf(stderr, "%s: updating %s %s -> %s\n",
507 getprogname(), refname, old_hashstr,
508 new_hashstr);
509 } else {
510 fprintf(stderr, "%s: creating %s %s\n",
511 getprogname(), refname, new_hashstr);
514 nsent++;
516 err = got_pkt_flushpkt(fd, chattygot);
517 if (err)
518 goto done;
520 err = send_pack_request(ibuf);
521 if (err)
522 goto done;
524 err = recv_packfd(&packfd, ibuf);
525 if (err)
526 goto done;
528 if (packfd != -1) {
529 err = send_pack_file(fd, packfd, ibuf);
530 if (err)
531 goto done;
534 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
535 if (err)
536 goto done;
537 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
538 err = send_error(&buf[4], n - 4);
539 goto done;
540 } else if (n < 10 || strncmp(buf, "unpack ok\n", 10) != 0) {
541 err = got_error_msg(GOT_ERR_BAD_PACKET,
542 "unexpected message from server");
543 goto done;
546 while (nsent > 0) {
547 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
548 if (err)
549 goto done;
550 if (n < 3) {
551 err = got_error_msg(GOT_ERR_BAD_PACKET,
552 "unexpected message from server");
553 goto done;
554 } else if (strncmp(buf, "ok ", 3) == 0) {
555 err = send_ref_status(ibuf, buf + 3, 1,
556 refs, delete_refs);
557 if (err)
558 goto done;
559 } else if (strncmp(buf, "ng ", 3) == 0) {
560 err = send_ref_status(ibuf, buf + 3, 0,
561 refs, delete_refs);
562 if (err)
563 goto done;
564 } else {
565 err = got_error_msg(GOT_ERR_BAD_PACKET,
566 "unexpected message from server");
567 goto done;
569 nsent--;
572 err = send_done(ibuf);
573 done:
574 TAILQ_FOREACH(pe, &their_refs, entry) {
575 free((void *)pe->path);
576 free(pe->data);
578 got_pathlist_free(&their_refs);
579 free(id_str);
580 free(id);
581 free(refname);
582 free(server_capabilities);
583 return err;
586 int
587 main(int argc, char **argv)
589 const struct got_error *err = NULL;
590 int sendfd;
591 struct imsgbuf ibuf;
592 struct imsg imsg;
593 struct got_pathlist_head refs;
594 struct got_pathlist_head delete_refs;
595 struct got_pathlist_entry *pe;
596 struct got_imsg_send_request send_req;
597 struct got_imsg_send_ref href;
598 size_t datalen, i;
599 #if 0
600 static int attached;
601 while (!attached)
602 sleep (1);
603 #endif
605 TAILQ_INIT(&refs);
606 TAILQ_INIT(&delete_refs);
608 imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
609 #ifndef PROFILE
610 /* revoke access to most system calls */
611 if (pledge("stdio recvfd", NULL) == -1) {
612 err = got_error_from_errno("pledge");
613 got_privsep_send_error(&ibuf, err);
614 return 1;
617 /* revoke fs access */
618 if (landlock_no_fs() == -1) {
619 err = got_error_from_errno("landlock_no_fs");
620 got_privsep_send_error(&ibuf, err);
621 return 1;
623 #endif
624 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
625 if (err->code == GOT_ERR_PRIVSEP_PIPE)
626 err = NULL;
627 goto done;
629 if (imsg.hdr.type == GOT_IMSG_STOP)
630 goto done;
631 if (imsg.hdr.type != GOT_IMSG_SEND_REQUEST) {
632 err = got_error(GOT_ERR_PRIVSEP_MSG);
633 goto done;
635 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
636 if (datalen < sizeof(send_req)) {
637 err = got_error(GOT_ERR_PRIVSEP_LEN);
638 goto done;
640 memcpy(&send_req, imsg.data, sizeof(send_req));
641 sendfd = imsg.fd;
642 imsg_free(&imsg);
644 if (send_req.verbosity > 0)
645 chattygot += send_req.verbosity;
647 for (i = 0; i < send_req.nrefs; i++) {
648 struct got_object_id *id;
649 char *refname;
651 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
652 if (err->code == GOT_ERR_PRIVSEP_PIPE)
653 err = NULL;
654 goto done;
656 if (imsg.hdr.type == GOT_IMSG_STOP)
657 goto done;
658 if (imsg.hdr.type != GOT_IMSG_SEND_REF) {
659 err = got_error(GOT_ERR_PRIVSEP_MSG);
660 goto done;
662 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
663 if (datalen < sizeof(href)) {
664 err = got_error(GOT_ERR_PRIVSEP_LEN);
665 goto done;
667 memcpy(&href, imsg.data, sizeof(href));
668 if (datalen - sizeof(href) < href.name_len) {
669 err = got_error(GOT_ERR_PRIVSEP_LEN);
670 goto done;
672 refname = malloc(href.name_len + 1);
673 if (refname == NULL) {
674 err = got_error_from_errno("malloc");
675 goto done;
677 memcpy(refname, imsg.data + sizeof(href), href.name_len);
678 refname[href.name_len] = '\0';
680 /*
681 * Prevent sending of references that won't make any
682 * sense outside the local repository's context.
683 */
684 if (strncmp(refname, "refs/got/", 9) == 0 ||
685 strncmp(refname, "refs/remotes/", 13) == 0) {
686 err = got_error_fmt(GOT_ERR_SEND_BAD_REF,
687 "%s", refname);
688 goto done;
691 id = malloc(sizeof(*id));
692 if (id == NULL) {
693 free(refname);
694 err = got_error_from_errno("malloc");
695 goto done;
697 memcpy(id->sha1, href.id, SHA1_DIGEST_LENGTH);
698 if (href.delete)
699 err = got_pathlist_append(&delete_refs, refname, id);
700 else
701 err = got_pathlist_append(&refs, refname, id);
702 if (err) {
703 free(refname);
704 free(id);
705 goto done;
708 imsg_free(&imsg);
711 err = send_pack(sendfd, &refs, &delete_refs, &ibuf);
712 done:
713 TAILQ_FOREACH(pe, &refs, entry) {
714 free((char *)pe->path);
715 free(pe->data);
717 got_pathlist_free(&refs);
718 TAILQ_FOREACH(pe, &delete_refs, entry) {
719 free((char *)pe->path);
720 free(pe->data);
722 got_pathlist_free(&delete_refs);
723 if (sendfd != -1 && close(sendfd) == -1 && err == NULL)
724 err = got_error_from_errno("close");
725 if (err != NULL && err->code != GOT_ERR_CANCELLED) {
726 fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
727 got_privsep_send_error(&ibuf, err);
730 exit(0);