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 struct ibuf *wbuf;
196 size_t len, reflen = strlen(refname);
198 len = sizeof(struct got_imsg_send_remote_ref) + reflen;
199 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
200 return got_error(GOT_ERR_NO_SPACE);
202 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REMOTE_REF, 0, 0, len);
203 if (wbuf == NULL)
204 return got_error_from_errno("imsg_create SEND_REMOTE_REF");
206 /* Keep in sync with struct got_imsg_send_remote_ref definition! */
207 if (imsg_add(wbuf, refid->sha1, SHA1_DIGEST_LENGTH) == -1)
208 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
209 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
210 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
211 if (imsg_add(wbuf, refname, reflen) == -1)
212 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
214 wbuf->fd = -1;
215 imsg_close(ibuf, wbuf);
216 return got_privsep_flush_imsg(ibuf);
219 static const struct got_error *
220 send_ref_status(struct imsgbuf *ibuf, const char *refname, int success,
221 struct got_pathlist_head *refs, struct got_pathlist_head *delete_refs)
223 struct ibuf *wbuf;
224 size_t len, reflen = strlen(refname);
225 struct got_pathlist_entry *pe;
226 int ref_valid = 0;
227 char *eol;
229 eol = strchr(refname, '\n');
230 if (eol == NULL) {
231 return got_error_msg(GOT_ERR_BAD_PACKET,
232 "unexpected message from server");
234 *eol = '\0';
236 TAILQ_FOREACH(pe, refs, entry) {
237 if (strcmp(refname, pe->path) == 0) {
238 ref_valid = 1;
239 break;
242 if (!ref_valid) {
243 TAILQ_FOREACH(pe, delete_refs, entry) {
244 if (strcmp(refname, pe->path) == 0) {
245 ref_valid = 1;
246 break;
250 if (!ref_valid) {
251 return got_error_msg(GOT_ERR_BAD_PACKET,
252 "unexpected message from server");
255 len = sizeof(struct got_imsg_send_ref_status) + reflen;
256 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
257 return got_error(GOT_ERR_NO_SPACE);
259 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REF_STATUS,
260 0, 0, len);
261 if (wbuf == NULL)
262 return got_error_from_errno("imsg_create SEND_REF_STATUS");
264 /* Keep in sync with struct got_imsg_send_ref_status definition! */
265 if (imsg_add(wbuf, &success, sizeof(success)) == -1)
266 return got_error_from_errno("imsg_add SEND_REF_STATUS");
267 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
268 return got_error_from_errno("imsg_add SEND_REF_STATUS");
269 if (imsg_add(wbuf, refname, reflen) == -1)
270 return got_error_from_errno("imsg_add SEND_REF_STATUS");
272 wbuf->fd = -1;
273 imsg_close(ibuf, wbuf);
274 return got_privsep_flush_imsg(ibuf);
277 static const struct got_error *
278 describe_refchange(int *n, int *sent_my_capabilites,
279 const char *my_capabilities, char *buf, size_t bufsize,
280 const char *refname, const char *old_hashstr, const char *new_hashstr)
282 *n = snprintf(buf, bufsize, "%s %s %s",
283 old_hashstr, new_hashstr, refname);
284 if (*n >= bufsize)
285 return got_error(GOT_ERR_NO_SPACE);
287 /*
288 * We must announce our capabilities along with the first
289 * reference. Unfortunately, the protocol requires an embedded
290 * NUL as a separator between reference name and capabilities,
291 * which we have to deal with here.
292 * It also requires a linefeed for terminating packet data.
293 */
294 if (!*sent_my_capabilites && my_capabilities != NULL) {
295 int m;
296 if (*n >= bufsize - 1)
297 return got_error(GOT_ERR_NO_SPACE);
298 m = snprintf(buf + *n + 1, /* offset after '\0' */
299 bufsize - (*n + 1), "%s\n", my_capabilities);
300 if (*n + m >= bufsize)
301 return got_error(GOT_ERR_NO_SPACE);
302 *n += m;
303 *sent_my_capabilites = 1;
304 } else {
305 *n = strlcat(buf, "\n", bufsize);
306 if (*n >= bufsize)
307 return got_error(GOT_ERR_NO_SPACE);
310 return NULL;
313 static const struct got_error *
314 send_pack(int fd, struct got_pathlist_head *refs,
315 struct got_pathlist_head *delete_refs, struct imsgbuf *ibuf)
317 const struct got_error *err = NULL;
318 char buf[GOT_PKT_MAX];
319 const unsigned char zero_id[SHA1_DIGEST_LENGTH] = { 0 };
320 char old_hashstr[SHA1_DIGEST_STRING_LENGTH];
321 char new_hashstr[SHA1_DIGEST_STRING_LENGTH];
322 struct got_pathlist_head their_refs;
323 int is_firstpkt = 1;
324 int n, nsent = 0;
325 int packfd = -1;
326 char *id_str = NULL, *refname = NULL;
327 struct got_object_id *id = NULL;
328 char *server_capabilities = NULL, *my_capabilities = NULL;
329 struct got_pathlist_entry *pe;
330 int sent_my_capabilites = 0;
332 TAILQ_INIT(&their_refs);
334 if (TAILQ_EMPTY(refs) && TAILQ_EMPTY(delete_refs))
335 return got_error(GOT_ERR_SEND_EMPTY);
337 while (1) {
338 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
339 if (err)
340 goto done;
341 if (n == 0)
342 break;
343 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
344 err = send_error(&buf[4], n - 4);
345 goto done;
347 free(id_str);
348 free(refname);
349 err = got_gitproto_parse_refline(&id_str, &refname,
350 &server_capabilities, buf, n);
351 if (err)
352 goto done;
353 if (is_firstpkt) {
354 if (chattygot && server_capabilities[0] != '\0')
355 fprintf(stderr, "%s: server capabilities: %s\n",
356 getprogname(), server_capabilities);
357 err = got_gitproto_match_capabilities(&my_capabilities,
358 NULL, server_capabilities, got_capabilities,
359 nitems(got_capabilities));
360 if (err)
361 goto done;
362 if (chattygot)
363 fprintf(stderr, "%s: my capabilities:%s\n",
364 getprogname(), my_capabilities);
365 is_firstpkt = 0;
367 if (strstr(refname, "^{}")) {
368 if (chattygot) {
369 fprintf(stderr, "%s: ignoring %s\n",
370 getprogname(), refname);
372 continue;
375 id = malloc(sizeof(*id));
376 if (id == NULL) {
377 err = got_error_from_errno("malloc");
378 goto done;
380 if (!got_parse_sha1_digest(id->sha1, id_str)) {
381 err = got_error(GOT_ERR_BAD_OBJ_ID_STR);
382 goto done;
384 err = send_their_ref(ibuf, id, refname);
385 if (err)
386 goto done;
388 err = got_pathlist_append(&their_refs, refname, id);
389 if (chattygot)
390 fprintf(stderr, "%s: remote has %s %s\n",
391 getprogname(), refname, id_str);
392 free(id_str);
393 id_str = NULL;
394 refname = NULL; /* do not free; owned by their_refs */
395 id = NULL; /* do not free; owned by their_refs */
398 if (!TAILQ_EMPTY(delete_refs)) {
399 if (my_capabilities == NULL ||
400 strstr(my_capabilities, GOT_CAPA_DELETE_REFS) == NULL) {
401 err = got_error(GOT_ERR_CAPA_DELETE_REFS);
402 goto done;
406 TAILQ_FOREACH(pe, delete_refs, entry) {
407 const char *refname = pe->path;
408 struct got_pathlist_entry *their_pe;
409 struct got_object_id *their_id = NULL;
411 TAILQ_FOREACH(their_pe, &their_refs, entry) {
412 const char *their_refname = their_pe->path;
413 if (got_path_cmp(refname, their_refname,
414 strlen(refname), strlen(their_refname)) == 0) {
415 their_id = their_pe->data;
416 break;
419 if (their_id == NULL) {
420 err = got_error_fmt(GOT_ERR_NOT_REF,
421 "%s does not exist in remote repository",
422 refname);
423 goto done;
426 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
427 sizeof(old_hashstr));
428 got_sha1_digest_to_str(zero_id, new_hashstr,
429 sizeof(new_hashstr));
430 err = describe_refchange(&n, &sent_my_capabilites,
431 my_capabilities, buf, sizeof(buf), refname,
432 old_hashstr, new_hashstr);
433 if (err)
434 goto done;
435 err = got_pkt_writepkt(fd, buf, n, chattygot);
436 if (err)
437 goto done;
438 if (chattygot) {
439 fprintf(stderr, "%s: deleting %s %s\n",
440 getprogname(), refname, old_hashstr);
442 nsent++;
445 TAILQ_FOREACH(pe, refs, entry) {
446 const char *refname = pe->path;
447 struct got_object_id *id = pe->data;
448 struct got_object_id *their_id = NULL;
449 struct got_pathlist_entry *their_pe;
451 TAILQ_FOREACH(their_pe, &their_refs, entry) {
452 const char *their_refname = their_pe->path;
453 if (got_path_cmp(refname, their_refname,
454 strlen(refname), strlen(their_refname)) == 0) {
455 their_id = their_pe->data;
456 break;
459 if (their_id) {
460 if (got_object_id_cmp(id, their_id) == 0) {
461 if (chattygot) {
462 fprintf(stderr,
463 "%s: no change for %s\n",
464 getprogname(), refname);
466 continue;
468 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
469 sizeof(old_hashstr));
470 } else {
471 got_sha1_digest_to_str(zero_id, old_hashstr,
472 sizeof(old_hashstr));
474 got_sha1_digest_to_str(id->sha1, new_hashstr,
475 sizeof(new_hashstr));
476 err = describe_refchange(&n, &sent_my_capabilites,
477 my_capabilities, buf, sizeof(buf), refname,
478 old_hashstr, new_hashstr);
479 if (err)
480 goto done;
481 err = got_pkt_writepkt(fd, buf, n, chattygot);
482 if (err)
483 goto done;
484 if (chattygot) {
485 if (their_id) {
486 fprintf(stderr, "%s: updating %s %s -> %s\n",
487 getprogname(), refname, old_hashstr,
488 new_hashstr);
489 } else {
490 fprintf(stderr, "%s: creating %s %s\n",
491 getprogname(), refname, new_hashstr);
494 nsent++;
496 err = got_pkt_flushpkt(fd, chattygot);
497 if (err)
498 goto done;
500 err = send_pack_request(ibuf);
501 if (err)
502 goto done;
504 err = recv_packfd(&packfd, ibuf);
505 if (err)
506 goto done;
508 if (packfd != -1) {
509 err = send_pack_file(fd, packfd, ibuf);
510 if (err)
511 goto done;
514 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
515 if (err)
516 goto done;
517 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
518 err = send_error(&buf[4], n - 4);
519 goto done;
520 } else if (n < 10 || strncmp(buf, "unpack ok\n", 10) != 0) {
521 err = got_error_msg(GOT_ERR_BAD_PACKET,
522 "unexpected message from server");
523 goto done;
526 while (nsent > 0) {
527 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot);
528 if (err)
529 goto done;
530 if (n < 3) {
531 err = got_error_msg(GOT_ERR_BAD_PACKET,
532 "unexpected message from server");
533 goto done;
534 } else if (strncmp(buf, "ok ", 3) == 0) {
535 err = send_ref_status(ibuf, buf + 3, 1,
536 refs, delete_refs);
537 if (err)
538 goto done;
539 } else if (strncmp(buf, "ng ", 3) == 0) {
540 err = send_ref_status(ibuf, buf + 3, 0,
541 refs, delete_refs);
542 if (err)
543 goto done;
544 } else {
545 err = got_error_msg(GOT_ERR_BAD_PACKET,
546 "unexpected message from server");
547 goto done;
549 nsent--;
552 err = send_done(ibuf);
553 done:
554 TAILQ_FOREACH(pe, &their_refs, entry) {
555 free((void *)pe->path);
556 free(pe->data);
558 got_pathlist_free(&their_refs);
559 free(id_str);
560 free(id);
561 free(refname);
562 free(server_capabilities);
563 return err;
566 int
567 main(int argc, char **argv)
569 const struct got_error *err = NULL;
570 int sendfd;
571 struct imsgbuf ibuf;
572 struct imsg imsg;
573 struct got_pathlist_head refs;
574 struct got_pathlist_head delete_refs;
575 struct got_pathlist_entry *pe;
576 struct got_imsg_send_request send_req;
577 struct got_imsg_send_ref href;
578 size_t datalen, i;
579 #if 0
580 static int attached;
581 while (!attached)
582 sleep (1);
583 #endif
585 TAILQ_INIT(&refs);
586 TAILQ_INIT(&delete_refs);
588 imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
589 #ifndef PROFILE
590 /* revoke access to most system calls */
591 if (pledge("stdio recvfd", NULL) == -1) {
592 err = got_error_from_errno("pledge");
593 got_privsep_send_error(&ibuf, err);
594 return 1;
597 /* revoke fs access */
598 if (landlock_no_fs() == -1) {
599 err = got_error_from_errno("landlock_no_fs");
600 got_privsep_send_error(&ibuf, err);
601 return 1;
603 if (cap_enter() == -1) {
604 err = got_error_from_errno("cap_enter");
605 got_privsep_send_error(&ibuf, err);
606 return 1;
608 #endif
609 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
610 if (err->code == GOT_ERR_PRIVSEP_PIPE)
611 err = NULL;
612 goto done;
614 if (imsg.hdr.type == GOT_IMSG_STOP)
615 goto done;
616 if (imsg.hdr.type != GOT_IMSG_SEND_REQUEST) {
617 err = got_error(GOT_ERR_PRIVSEP_MSG);
618 goto done;
620 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
621 if (datalen < sizeof(send_req)) {
622 err = got_error(GOT_ERR_PRIVSEP_LEN);
623 goto done;
625 memcpy(&send_req, imsg.data, sizeof(send_req));
626 sendfd = imsg.fd;
627 imsg_free(&imsg);
629 if (send_req.verbosity > 0)
630 chattygot += send_req.verbosity;
632 for (i = 0; i < send_req.nrefs; i++) {
633 struct got_object_id *id;
634 char *refname;
636 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
637 if (err->code == GOT_ERR_PRIVSEP_PIPE)
638 err = NULL;
639 goto done;
641 if (imsg.hdr.type == GOT_IMSG_STOP)
642 goto done;
643 if (imsg.hdr.type != GOT_IMSG_SEND_REF) {
644 err = got_error(GOT_ERR_PRIVSEP_MSG);
645 goto done;
647 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
648 if (datalen < sizeof(href)) {
649 err = got_error(GOT_ERR_PRIVSEP_LEN);
650 goto done;
652 memcpy(&href, imsg.data, sizeof(href));
653 if (datalen - sizeof(href) < href.name_len) {
654 err = got_error(GOT_ERR_PRIVSEP_LEN);
655 goto done;
657 refname = malloc(href.name_len + 1);
658 if (refname == NULL) {
659 err = got_error_from_errno("malloc");
660 goto done;
662 memcpy(refname, imsg.data + sizeof(href), href.name_len);
663 refname[href.name_len] = '\0';
665 /*
666 * Prevent sending of references that won't make any
667 * sense outside the local repository's context.
668 */
669 if (strncmp(refname, "refs/got/", 9) == 0 ||
670 strncmp(refname, "refs/remotes/", 13) == 0) {
671 err = got_error_fmt(GOT_ERR_SEND_BAD_REF,
672 "%s", refname);
673 goto done;
676 id = malloc(sizeof(*id));
677 if (id == NULL) {
678 free(refname);
679 err = got_error_from_errno("malloc");
680 goto done;
682 memcpy(id->sha1, href.id, SHA1_DIGEST_LENGTH);
683 if (href.delete)
684 err = got_pathlist_append(&delete_refs, refname, id);
685 else
686 err = got_pathlist_append(&refs, refname, id);
687 if (err) {
688 free(refname);
689 free(id);
690 goto done;
693 imsg_free(&imsg);
696 err = send_pack(sendfd, &refs, &delete_refs, &ibuf);
697 done:
698 TAILQ_FOREACH(pe, &refs, entry) {
699 free((char *)pe->path);
700 free(pe->data);
702 got_pathlist_free(&refs);
703 TAILQ_FOREACH(pe, &delete_refs, entry) {
704 free((char *)pe->path);
705 free(pe->data);
707 got_pathlist_free(&delete_refs);
708 if (sendfd != -1 && close(sendfd) == -1 && err == NULL)
709 err = got_error_from_errno("close");
710 if (err != NULL && err->code != GOT_ERR_CANCELLED) {
711 fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
712 got_privsep_send_error(&ibuf, err);
715 exit(0);