Blob


1 #include <sys/socket.h>
3 #include <errno.h>
4 #include <limits.h>
5 #include <signal.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
11 #include "pages.h"
12 #include "parser.h"
13 #include "telescope.h"
14 #include "ui.h"
16 static struct imsgev *iev_fs, *iev_net;
18 struct tabshead tabshead = TAILQ_HEAD_INITIALIZER(tabshead);
19 struct proxylist proxies = TAILQ_HEAD_INITIALIZER(proxies);
21 enum telescope_process {
22 PROC_UI,
23 PROC_FS,
24 PROC_NET,
25 };
27 /* the first is also the fallback one */
28 static struct proto protos[] = {
29 { "gemini", load_gemini_url },
30 { "about", load_about_url },
31 { NULL, NULL },
32 };
34 static void die(void) __attribute__((__noreturn__));
35 static struct tab *tab_by_id(uint32_t);
36 static void handle_imsg_err(struct imsg*, size_t);
37 static void handle_imsg_check_cert(struct imsg*, size_t);
38 static void handle_check_cert_user_choice(int, struct tab *);
39 static void handle_maybe_save_new_cert(int, struct tab *);
40 static void handle_imsg_got_code(struct imsg*, size_t);
41 static void handle_imsg_got_meta(struct imsg*, size_t);
42 static void handle_maybe_save_page(int, struct tab *);
43 static void handle_save_page_path(const char *, struct tab *);
44 static void handle_imsg_file_opened(struct imsg*, size_t);
45 static void handle_imsg_buf(struct imsg*, size_t);
46 static void handle_imsg_eof(struct imsg*, size_t);
47 static void handle_imsg_bookmark_ok(struct imsg*, size_t);
48 static void handle_imsg_save_cert_ok(struct imsg*, size_t);
49 static void handle_imsg_update_cert_ok(struct imsg *, size_t);
50 static void handle_dispatch_imsg(int, short, void*);
51 static void load_page_from_str(struct tab*, const char*);
52 static void do_load_url(struct tab*, const char*);
53 static pid_t start_child(enum telescope_process, const char *, int);
54 static int ui_send_net(int, uint32_t, const void *, uint16_t);
55 static int ui_send_fs(int, uint32_t, const void *, uint16_t);
57 static imsg_handlerfn *handlers[] = {
58 [IMSG_ERR] = handle_imsg_err,
59 [IMSG_CHECK_CERT] = handle_imsg_check_cert,
60 [IMSG_GOT_CODE] = handle_imsg_got_code,
61 [IMSG_GOT_META] = handle_imsg_got_meta,
62 [IMSG_BUF] = handle_imsg_buf,
63 [IMSG_EOF] = handle_imsg_eof,
64 [IMSG_BOOKMARK_OK] = handle_imsg_bookmark_ok,
65 [IMSG_SAVE_CERT_OK] = handle_imsg_save_cert_ok,
66 [IMSG_UPDATE_CERT_OK] = handle_imsg_update_cert_ok,
67 [IMSG_FILE_OPENED] = handle_imsg_file_opened,
68 };
70 static struct ohash certs;
72 static void __attribute__((__noreturn__))
73 die(void)
74 {
75 abort(); /* TODO */
76 }
78 static struct tab *
79 tab_by_id(uint32_t id)
80 {
81 struct tab *t;
83 TAILQ_FOREACH(t, &tabshead, tabs) {
84 if (t->id == id)
85 return t;
86 }
88 die();
89 }
91 static void
92 handle_imsg_err(struct imsg *imsg, size_t datalen)
93 {
94 struct tab *tab;
95 char *page;
97 tab = tab_by_id(imsg->hdr.peerid);
99 page = imsg->data;
100 page[datalen-1] = '\0';
102 if (asprintf(&page, "# Error loading %s\n\n> %s\n",
103 tab->hist_cur->h, page) == -1)
104 die();
105 load_page_from_str(tab, page);
106 free(page);
109 static void
110 handle_imsg_check_cert(struct imsg *imsg, size_t datalen)
112 const char *hash, *host, *port;
113 int tofu_res;
114 struct tofu_entry *e;
115 struct tab *tab;
117 hash = imsg->data;
118 if (hash[datalen-1] != '\0')
119 abort();
121 tab = tab_by_id(imsg->hdr.peerid);
123 if (tab->proxy != NULL) {
124 host = tab->proxy->host;
125 port = tab->proxy->port;
126 } else {
127 host = tab->uri.host;
128 port = tab->uri.port;
131 if ((e = tofu_lookup(&certs, host, port)) == NULL) {
132 /* TODO: an update in libressl/libretls changed
133 * significantly. Find a better approach at storing
134 * the certs! */
135 if (datalen > sizeof(e->hash))
136 abort();
138 tofu_res = 1; /* trust on first use */
139 if ((e = calloc(1, sizeof(*e))) == NULL)
140 abort();
141 strlcpy(e->domain, host, sizeof(e->domain));
142 if (*port != '\0' && strcmp(port, "1965")) {
143 strlcat(e->domain, ":", sizeof(e->domain));
144 strlcat(e->domain, port, sizeof(e->domain));
146 strlcpy(e->hash, hash, sizeof(e->hash));
147 tofu_add(&certs, e);
148 ui_send_fs(IMSG_SAVE_CERT, tab->id, e, sizeof(*e));
149 } else
150 tofu_res = !strcmp(hash, e->hash);
152 if (tofu_res) {
153 if (e->verified == -1)
154 tab->trust = TS_TEMP_TRUSTED;
155 else if (e->verified == 1)
156 tab->trust = TS_VERIFIED;
157 else
158 tab->trust = TS_TRUSTED;
160 ui_send_net(IMSG_CERT_STATUS, imsg->hdr.peerid,
161 &tofu_res, sizeof(tofu_res));
162 } else {
163 tab->trust = TS_UNTRUSTED;
164 load_page_from_str(tab, "# Certificate mismatch\n");
165 if ((tab->cert = strdup(hash)) == NULL)
166 die();
167 ui_yornp("Certificate mismatch. Proceed?",
168 handle_check_cert_user_choice, tab);
172 static void
173 handle_check_cert_user_choice(int accept, struct tab *tab)
175 ui_send_net(IMSG_CERT_STATUS, tab->id, &accept,
176 sizeof(accept));
178 if (accept) {
179 /*
180 * trust the certificate for this session only. If
181 * the page results in a redirect while we're asking
182 * the user to save, we'll end up with an invalid
183 * tabid (one request == one tab id) and crash. It
184 * also makes sense to save it for the current session
185 * if the user accepted it.
186 */
187 tofu_temp_trust(&certs, tab->uri.host, tab->uri.port, tab->cert);
189 ui_yornp("Save the new certificate?",
190 handle_maybe_save_new_cert, tab);
191 } else {
192 free(tab->cert);
193 tab->cert = NULL;
197 static void
198 handle_maybe_save_new_cert(int accept, struct tab *tab)
200 struct tofu_entry *e;
201 const char *host, *port;
203 if (tab->proxy != NULL) {
204 host = tab->proxy->host;
205 port = tab->proxy->port;
206 } else {
207 host = tab->uri.host;
208 port = tab->uri.port;
211 if (!accept)
212 goto end;
214 if ((e = calloc(1, sizeof(*e))) == NULL)
215 die();
217 strlcpy(e->domain, host, sizeof(e->domain));
218 if (*port != '\0' && strcmp(port, "1965")) {
219 strlcat(e->domain, ":", sizeof(e->domain));
220 strlcat(e->domain, port, sizeof(e->domain));
222 strlcpy(e->hash, tab->cert, sizeof(e->hash));
223 ui_send_fs(IMSG_UPDATE_CERT, 0, e, sizeof(*e));
225 tofu_update(&certs, e);
227 tab->trust = TS_TRUSTED;
229 end:
230 free(tab->cert);
231 tab->cert = NULL;
234 static inline int
235 normalize_code(int n)
237 if (n < 20) {
238 if (n == 10 || n == 11)
239 return n;
240 return 10;
241 } else if (n < 30) {
242 return 20;
243 } else if (n < 40) {
244 if (n == 30 || n == 31)
245 return n;
246 return 30;
247 } else if (n < 50) {
248 if (n <= 44)
249 return n;
250 return 40;
251 } else if (n < 60) {
252 if (n <= 53 || n == 59)
253 return n;
254 return 50;
255 } else if (n < 70) {
256 if (n <= 62)
257 return n;
258 return 60;
259 } else
260 return MALFORMED_RESPONSE;
263 static void
264 handle_imsg_got_code(struct imsg *imsg, size_t datalen)
266 struct tab *tab;
268 tab = tab_by_id(imsg->hdr.peerid);
270 if (sizeof(tab->code) != datalen)
271 die();
273 memcpy(&tab->code, imsg->data, sizeof(tab->code));
274 tab->code = normalize_code(tab->code);
275 if (tab->code != 30 && tab->code != 31)
276 tab->redirect_count = 0;
279 static void
280 handle_imsg_got_meta(struct imsg *imsg, size_t datalen)
282 struct tab *tab;
284 tab = tab_by_id(imsg->hdr.peerid);
286 if (sizeof(tab->meta) <= datalen)
287 die();
289 memcpy(tab->meta, imsg->data, datalen);
291 if (tab->code < 10) { /* internal errors */
292 load_page_from_str(tab, err_pages[tab->code]);
293 } else if (tab->code < 20) { /* 1x */
294 load_page_from_str(tab, err_pages[tab->code]);
295 ui_require_input(tab, tab->code == 11);
296 } else if (tab->code == 20) {
297 if (setup_parser_for(tab)) {
298 ui_send_net(IMSG_PROCEED, tab->id, NULL, 0);
299 } else {
300 load_page_from_str(tab, err_pages[UNKNOWN_TYPE_OR_CSET]);
301 ui_yornp("Can't display page, wanna save?",
302 handle_maybe_save_page, tab);
304 } else if (tab->code < 40) { /* 3x */
305 tab->redirect_count++;
307 /* TODO: make customizable? */
308 if (tab->redirect_count > 5) {
309 load_page_from_str(tab,
310 err_pages[TOO_MUCH_REDIRECTS]);
311 } else
312 do_load_url(tab, tab->meta);
313 } else { /* 4x, 5x & 6x */
314 load_page_from_str(tab, err_pages[tab->code]);
318 static void
319 handle_maybe_save_page(int dosave, struct tab *tab)
321 if (dosave)
322 ui_read("Save to path", handle_save_page_path, tab);
323 else
324 stop_tab(tab);
327 static void
328 handle_save_page_path(const char *path, struct tab *tab)
330 if (path == NULL) {
331 stop_tab(tab);
332 return;
335 tab->path = strdup(path);
337 ui_send_fs(IMSG_FILE_OPEN, tab->id, path, strlen(path)+1);
340 static void
341 handle_imsg_file_opened(struct imsg *imsg, size_t datalen)
343 struct tab *tab;
344 char *page;
345 const char *e;
346 int l;
348 tab = tab_by_id(imsg->hdr.peerid);
350 if (imsg->fd == -1) {
351 stop_tab(tab);
353 e = imsg->data;
354 if (e[datalen-1] != '\0')
355 die();
356 l = asprintf(&page, "# Can't open file\n\n> %s: %s\n",
357 tab->path, e);
358 if (l == -1)
359 die();
360 load_page_from_str(tab, page);
361 free(page);
362 } else {
363 tab->fd = imsg->fd;
364 ui_send_net(IMSG_PROCEED, tab->id, NULL, 0);
368 static void
369 handle_imsg_buf(struct imsg *imsg, size_t datalen)
371 struct tab *tab;
372 int l;
373 char *page, buf[FMT_SCALED_STRSIZE] = {0};
375 tab = tab_by_id(imsg->hdr.peerid);
377 tab->bytes += datalen;
378 if (tab->fd == -1) {
379 if (!tab->buffer.page.parse(&tab->buffer.page,
380 imsg->data, datalen))
381 die();
382 } else {
383 write(tab->fd, imsg->data, datalen);
384 fmt_scaled(tab->bytes, buf);
385 l = asprintf(&page, "Saving to \"%s\"... (%s)\n",
386 tab->path,
387 buf);
388 if (l == -1)
389 die();
390 load_page_from_str(tab, page);
391 free(page);
394 ui_on_tab_refresh(tab);
397 static void
398 handle_imsg_eof(struct imsg *imsg, size_t datalen)
400 struct tab *tab;
401 int l;
402 char *page, buf[FMT_SCALED_STRSIZE] = {0};
404 tab = tab_by_id(imsg->hdr.peerid);
406 if (tab->fd == -1) {
407 if (!tab->buffer.page.free(&tab->buffer.page))
408 die();
409 } else {
410 fmt_scaled(tab->bytes, buf);
411 l = asprintf(&page, "Saved to \"%s\" (%s)\n",
412 tab->path,
413 buf);
414 if (l == -1)
415 die();
416 load_page_from_str(tab, page);
417 free(page);
419 close(tab->fd);
420 tab->fd = -1;
421 free(tab->path);
422 tab->path = NULL;
425 ui_on_tab_refresh(tab);
426 ui_on_tab_loaded(tab);
429 static void
430 handle_imsg_bookmark_ok(struct imsg *imsg, size_t datalen)
432 int res;
434 if (datalen != sizeof(res))
435 die();
437 memcpy(&res, imsg->data, sizeof(res));
438 if (res == 0)
439 message("Added to bookmarks!");
440 else
441 message("Failed to add to bookmarks: %s",
442 strerror(res));
445 static void
446 handle_imsg_save_cert_ok(struct imsg *imsg, size_t datalen)
448 int res;
450 if (datalen != sizeof(res))
451 die();
452 memcpy(&res, imsg->data, datalen);
453 if (res != 0)
454 message("Failed to save the cert for: %s",
455 strerror(res));
458 static void
459 handle_imsg_update_cert_ok(struct imsg *imsg, size_t datalen)
461 int res;
463 if (datalen != sizeof(res))
464 die();
465 memcpy(&res, imsg->data, datalen);
466 if (!res)
467 message("Failed to update the certificate");
470 static void
471 handle_dispatch_imsg(int fd, short ev, void *d)
473 struct imsgev *iev = d;
474 dispatch_imsg(iev, ev, handlers, sizeof(handlers));
477 static void
478 load_page_from_str(struct tab *tab, const char *page)
480 erase_buffer(&tab->buffer);
481 gemtext_initparser(&tab->buffer.page);
482 if (!tab->buffer.page.parse(&tab->buffer.page, page, strlen(page)))
483 die();
484 if (!tab->buffer.page.free(&tab->buffer.page))
485 die();
486 ui_on_tab_refresh(tab);
487 ui_on_tab_loaded(tab);
490 void
491 load_about_url(struct tab *tab, const char *url)
493 tab->trust = TS_VERIFIED;
495 gemtext_initparser(&tab->buffer.page);
497 ui_send_fs(IMSG_GET, tab->id,
498 tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
501 void
502 load_gemini_url(struct tab *tab, const char *url)
504 struct get_req req;
506 stop_tab(tab);
507 tab->id = tab_new_id();
509 memset(&req, 0, sizeof(req));
510 strlcpy(req.host, tab->uri.host, sizeof(req.host));
511 strlcpy(req.port, tab->uri.port, sizeof(req.host));
513 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
514 strlcat(req.req, "\r\n", sizeof(req.req));
516 req.proto = PROTO_GEMINI;
518 ui_send_net(IMSG_GET_RAW, tab->id,
519 &req, sizeof(req));
522 void
523 load_via_proxy(struct tab *tab, const char *url, struct proxy *p)
525 struct get_req req;
527 stop_tab(tab);
528 tab->id = tab_new_id();
529 tab->proxy = p;
531 memset(&req, 0, sizeof(req));
532 strlcpy(req.host, p->host, sizeof(req.host));
533 strlcpy(req.port, p->port, sizeof(req.host));
535 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
536 strlcat(req.req, "\r\n", sizeof(req.req));
538 req.proto = p->proto;
540 ui_send_net(IMSG_GET_RAW, tab->id,
541 &req, sizeof(req));
544 static void
545 do_load_url(struct tab *tab, const char *url)
547 struct phos_uri uri;
548 struct proto *p;
549 struct proxy *proxy;
550 char *t;
552 tab->proxy = NULL;
554 if (tab->fd != -1) {
555 close(tab->fd);
556 tab->fd = -1;
557 free(tab->path);
558 tab->path = NULL;
561 tab->trust = TS_UNKNOWN;
563 memcpy(&uri, &tab->uri, sizeof(tab->uri));
564 if (!phos_resolve_uri_from_str(&uri, url, &tab->uri)) {
565 if (asprintf(&t, "#error loading %s\n>%s\n",
566 url, "Can't parse the URI") == -1)
567 die();
568 strlcpy(tab->hist_cur->h, url, sizeof(tab->hist_cur->h));
569 load_page_from_str(tab, t);
570 free(t);
571 return;
574 phos_serialize_uri(&tab->uri, tab->hist_cur->h,
575 sizeof(tab->hist_cur->h));
577 for (p = protos; p->schema != NULL; ++p) {
578 if (!strcmp(tab->uri.scheme, p->schema)) {
579 p->loadfn(tab, url);
580 return;
584 TAILQ_FOREACH(proxy, &proxies, proxies) {
585 if (!strcmp(tab->uri.scheme, proxy->match_proto)) {
586 load_via_proxy(tab, url, proxy);
587 return;
591 protos[0].loadfn(tab, url);
594 void
595 load_url(struct tab *tab, const char *url)
597 if (tab->hist_cur != NULL)
598 hist_clear_forward(&tab->hist, TAILQ_NEXT(tab->hist_cur, entries));
600 if ((tab->hist_cur = calloc(1, sizeof(*tab->hist_cur))) == NULL) {
601 event_loopbreak();
602 return;
605 hist_push(&tab->hist, tab->hist_cur);
606 do_load_url(tab, url);
607 erase_buffer(&tab->buffer);
610 int
611 load_previous_page(struct tab *tab)
613 struct hist *h;
615 if ((h = TAILQ_PREV(tab->hist_cur, mhisthead, entries)) == NULL)
616 return 0;
617 tab->hist_cur = h;
618 do_load_url(tab, h->h);
619 return 1;
622 int
623 load_next_page(struct tab *tab)
625 struct hist *h;
627 if ((h = TAILQ_NEXT(tab->hist_cur, entries)) == NULL)
628 return 0;
629 tab->hist_cur = h;
630 do_load_url(tab, h->h);
631 return 1;
634 void
635 stop_tab(struct tab *tab)
637 ui_send_net(IMSG_STOP, tab->id, NULL, 0);
639 if (tab->fd != -1) {
640 close(tab->fd);
641 tab->fd = -1;
642 free(tab->path);
643 tab->path = NULL;
644 load_page_from_str(tab, "Stopped.\n");
648 void
649 add_to_bookmarks(const char *str)
651 ui_send_fs(IMSG_BOOKMARK_PAGE, 0,
652 str, strlen(str)+1);
655 void
656 save_session(void)
658 struct tab *tab;
660 ui_send_fs(IMSG_SESSION_START, 0, NULL, 0);
662 TAILQ_FOREACH(tab, &tabshead, tabs) {
663 ui_send_fs(IMSG_SESSION_TAB, 0,
664 tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
667 ui_send_fs(IMSG_SESSION_END, 0, NULL, 0);
670 static void
671 session_new_tab_cb(const char *url)
673 new_tab(url);
676 static pid_t
677 start_child(enum telescope_process p, const char *argv0, int fd)
679 const char *argv[4];
680 int argc = 0;
681 pid_t pid;
683 switch (pid = fork()) {
684 case -1:
685 die();
686 case 0:
687 break;
688 default:
689 close(fd);
690 return pid;
693 if (dup2(fd, 3) == -1)
694 err(1, "cannot setup imsg fd");
696 argv[argc++] = argv0;
697 switch (p) {
698 case PROC_UI:
699 errx(1, "Can't start ui process");
700 case PROC_FS:
701 argv[argc++] = "-Tf";
702 break;
703 case PROC_NET:
704 argv[argc++] = "-Tn";
705 break;
708 argv[argc++] = NULL;
709 execvp(argv0, (char *const *)argv);
710 err(1, "execvp(%s)", argv0);
713 static int
714 ui_send_net(int type, uint32_t peerid, const void *data,
715 uint16_t datalen)
717 return imsg_compose_event(iev_net, type, peerid, 0, -1, data,
718 datalen);
721 static int
722 ui_send_fs(int type, uint32_t peerid, const void *data, uint16_t datalen)
724 return imsg_compose_event(iev_fs, type, peerid, 0, -1, data,
725 datalen);
728 static void __attribute__((noreturn))
729 usage(int r)
731 fprintf(stderr, "USAGE: %s [-hn] [-c config] [url]\n", getprogname());
732 fprintf(stderr, "version: " PACKAGE " " VERSION "\n");
733 exit(r);
736 int
737 main(int argc, char * const *argv)
739 struct imsgev net_ibuf, fs_ibuf;
740 int pipe2net[2], pipe2fs[2];
741 int ch, configtest = 0, fail = 0;
742 int has_url = 0;
743 int proc = -1;
744 char path[PATH_MAX];
745 const char *url = NEW_TAB_URL;
746 const char *argv0;
748 argv0 = argv[0];
750 signal(SIGCHLD, SIG_IGN);
751 signal(SIGPIPE, SIG_IGN);
753 if (getenv("NO_COLOR") != NULL)
754 enable_colors = 0;
756 strlcpy(path, getenv("HOME"), sizeof(path));
757 strlcat(path, "/.telescope/config", sizeof(path));
759 while ((ch = getopt(argc, argv, "c:hnT:")) != -1) {
760 switch (ch) {
761 case 'c':
762 fail = 1;
763 strlcpy(path, optarg, sizeof(path));
764 break;
765 case 'n':
766 configtest = 1;
767 break;
768 case 'h':
769 usage(0);
770 case 'T':
771 switch (*optarg) {
772 case 'f':
773 proc = PROC_FS;
774 break;
775 case 'n':
776 proc = PROC_NET;
777 break;
778 default:
779 errx(1, "invalid process spec %c",
780 *optarg);
782 break;
783 default:
784 usage(1);
788 argc -= optind;
789 argv += optind;
791 if (proc != -1) {
792 if (argc > 0)
793 usage(1);
794 else if (proc == PROC_FS)
795 return fs_main();
796 else if (proc == PROC_NET)
797 return client_main();
798 else
799 usage(1);
802 if (argc != 0) {
803 has_url = 1;
804 url = argv[0];
807 /* setup keys before reading the config */
808 TAILQ_INIT(&global_map.m);
809 global_map.unhandled_input = global_key_unbound;
810 TAILQ_INIT(&minibuffer_map.m);
812 config_init();
813 parseconfig(path, fail);
814 if (configtest){
815 puts("config OK");
816 exit(0);
819 /* Start children. */
820 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe2fs) == -1)
821 err(1, "socketpair");
822 start_child(PROC_FS, argv0, pipe2fs[1]);
823 imsg_init(&fs_ibuf.ibuf, pipe2fs[0]);
824 iev_fs = &fs_ibuf;
825 iev_fs->handler = handle_dispatch_imsg;
827 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe2net) == -1)
828 err(1, "socketpair");
829 start_child(PROC_NET, argv0, pipe2net[1]);
830 imsg_init(&net_ibuf.ibuf, pipe2net[0]);
831 iev_net = &net_ibuf;
832 iev_net->handler = handle_dispatch_imsg;
834 setproctitle("ui");
836 /* initialize tofu & load certificates */
837 fs_init();
838 tofu_init(&certs, 5, offsetof(struct tofu_entry, domain));
839 load_certs(&certs);
841 event_init();
843 /* Setup event handlers for pipes to fs/net */
844 iev_fs->events = EV_READ;
845 event_set(&iev_fs->ev, iev_fs->ibuf.fd, iev_fs->events,
846 iev_fs->handler, iev_fs);
847 event_add(&iev_fs->ev, NULL);
849 iev_net->events = EV_READ;
850 event_set(&iev_net->ev, iev_net->ibuf.fd, iev_net->events,
851 iev_net->handler, iev_net);
852 event_add(&iev_net->ev, NULL);
854 if (ui_init()) {
855 load_last_session(session_new_tab_cb);
856 if (has_url || TAILQ_EMPTY(&tabshead))
857 new_tab(url);
859 sandbox_ui_process();
860 event_dispatch();
861 ui_end();
864 ui_send_fs(IMSG_QUIT, 0, NULL, 0);
865 ui_send_net(IMSG_QUIT, 0, NULL, 0);
866 imsg_flush(&iev_fs->ibuf);
868 return 0;