2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <sys/socket.h>
29 #include "minibuffer.h"
31 #include "telescope.h"
34 static struct option longopts[] = {
35 {"colors", no_argument, NULL, 'c'},
36 {"help", no_argument, NULL, 'h'},
37 {"version", no_argument, NULL, 'v'},
41 static const char *opts = "Cc:hnT:v";
43 static struct imsgev *iev_fs, *iev_net;
45 struct tabshead tabshead = TAILQ_HEAD_INITIALIZER(tabshead);
46 struct proxylist proxies = TAILQ_HEAD_INITIALIZER(proxies);
48 enum telescope_process {
54 /* the first is also the fallback one */
55 static struct proto protos[] = {
56 { "gemini", load_gemini_url },
57 { "about", load_about_url },
62 #define CANNOT_FETCH 0
63 #define TOO_MUCH_REDIRECTS 1
64 #define MALFORMED_RESPONSE 2
65 #define UNKNOWN_TYPE_OR_CSET 3
66 #define UNKNOWN_PROTOCOL 4
68 /* XXX: keep in sync with telescope.c:/^normalize_code/ */
69 const char *err_pages[70] = {
70 [CANNOT_FETCH] = "# Couldn't load the page\n",
71 [TOO_MUCH_REDIRECTS] = "# Too much redirects\n",
72 [MALFORMED_RESPONSE] = "# Got a malformed response\n",
73 [UNKNOWN_TYPE_OR_CSET] = "# Unsupported type or charset\n",
74 [UNKNOWN_PROTOCOL] = "# Unknown protocol\n",
76 [10] = "# Input required\n",
77 [11] = "# Input required\n",
78 [40] = "# Temporary failure\n",
79 [41] = "# Server unavailable\n",
80 [42] = "# CGI error\n",
81 [43] = "# Proxy error\n",
82 [44] = "# Slow down\n",
83 [50] = "# Permanent failure\n",
84 [51] = "# Not found\n",
86 [53] = "# Proxy request refused\n",
87 [59] = "# Bad request\n",
88 [60] = "# Client certificate required\n",
89 [61] = "# Certificate not authorised\n",
90 [62] = "# Certificate not valid\n"
93 static void die(void) __attribute__((__noreturn__));
94 static struct tab *tab_by_id(uint32_t);
95 static void handle_imsg_err(struct imsg*, size_t);
96 static void handle_imsg_check_cert(struct imsg*, size_t);
97 static void handle_check_cert_user_choice(int, struct tab *);
98 static void handle_maybe_save_new_cert(int, struct tab *);
99 static void handle_imsg_got_code(struct imsg*, size_t);
100 static void handle_imsg_got_meta(struct imsg*, size_t);
101 static void handle_maybe_save_page(int, struct tab *);
102 static void handle_save_page_path(const char *, struct tab *);
103 static void handle_imsg_file_opened(struct imsg*, size_t);
104 static void handle_imsg_buf(struct imsg*, size_t);
105 static void handle_imsg_eof(struct imsg*, size_t);
106 static void handle_imsg_bookmark_ok(struct imsg*, size_t);
107 static void handle_imsg_save_cert_ok(struct imsg*, size_t);
108 static void handle_imsg_update_cert_ok(struct imsg *, size_t);
109 static void handle_dispatch_imsg(int, short, void*);
110 static void load_page_from_str(struct tab*, const char*);
111 static int do_load_url(struct tab*, const char *, const char *);
112 static void parse_session_line(char *, const char **, uint32_t *);
113 static void load_last_session(void);
114 static pid_t start_child(enum telescope_process, const char *, int);
115 static int ui_send_net(int, uint32_t, const void *, uint16_t);
116 static int ui_send_fs(int, uint32_t, const void *, uint16_t);
118 static imsg_handlerfn *handlers[] = {
119 [IMSG_ERR] = handle_imsg_err,
120 [IMSG_CHECK_CERT] = handle_imsg_check_cert,
121 [IMSG_GOT_CODE] = handle_imsg_got_code,
122 [IMSG_GOT_META] = handle_imsg_got_meta,
123 [IMSG_BUF] = handle_imsg_buf,
124 [IMSG_EOF] = handle_imsg_eof,
125 [IMSG_BOOKMARK_OK] = handle_imsg_bookmark_ok,
126 [IMSG_SAVE_CERT_OK] = handle_imsg_save_cert_ok,
127 [IMSG_UPDATE_CERT_OK] = handle_imsg_update_cert_ok,
128 [IMSG_FILE_OPENED] = handle_imsg_file_opened,
131 static struct ohash certs;
133 static void __attribute__((__noreturn__))
140 tab_by_id(uint32_t id)
144 TAILQ_FOREACH(t, &tabshead, tabs) {
153 handle_imsg_err(struct imsg *imsg, size_t datalen)
158 if ((tab = tab_by_id(imsg->hdr.peerid)) == NULL)
162 page[datalen-1] = '\0';
164 if (asprintf(&page, "# Error loading %s\n\n> %s\n",
165 tab->hist_cur->h, page) == -1)
167 load_page_from_str(tab, page);
172 handle_imsg_check_cert(struct imsg *imsg, size_t datalen)
174 const char *hash, *host, *port;
176 struct tofu_entry *e;
180 if (hash[datalen-1] != '\0')
183 if ((tab = tab_by_id(imsg->hdr.peerid)) == NULL)
186 if (tab->proxy != NULL) {
187 host = tab->proxy->host;
188 port = tab->proxy->port;
190 host = tab->uri.host;
191 port = tab->uri.port;
194 if ((e = tofu_lookup(&certs, host, port)) == NULL) {
195 /* TODO: an update in libressl/libretls changed
196 * significantly. Find a better approach at storing
198 if (datalen > sizeof(e->hash))
201 tofu_res = 1; /* trust on first use */
202 if ((e = calloc(1, sizeof(*e))) == NULL)
204 strlcpy(e->domain, host, sizeof(e->domain));
205 if (*port != '\0' && strcmp(port, "1965")) {
206 strlcat(e->domain, ":", sizeof(e->domain));
207 strlcat(e->domain, port, sizeof(e->domain));
209 strlcpy(e->hash, hash, sizeof(e->hash));
211 ui_send_fs(IMSG_SAVE_CERT, tab->id, e, sizeof(*e));
213 tofu_res = !strcmp(hash, e->hash);
216 if (e->verified == -1)
217 tab->trust = TS_TEMP_TRUSTED;
218 else if (e->verified == 1)
219 tab->trust = TS_VERIFIED;
221 tab->trust = TS_TRUSTED;
223 ui_send_net(IMSG_CERT_STATUS, imsg->hdr.peerid,
224 &tofu_res, sizeof(tofu_res));
226 tab->trust = TS_UNTRUSTED;
227 load_page_from_str(tab, "# Certificate mismatch\n");
228 if ((tab->cert = strdup(hash)) == NULL)
230 ui_yornp("Certificate mismatch. Proceed?",
231 handle_check_cert_user_choice, tab);
236 handle_check_cert_user_choice(int accept, struct tab *tab)
238 ui_send_net(IMSG_CERT_STATUS, tab->id, &accept,
243 * trust the certificate for this session only. If
244 * the page results in a redirect while we're asking
245 * the user to save, we'll end up with an invalid
246 * tabid (one request == one tab id) and crash. It
247 * also makes sense to save it for the current session
248 * if the user accepted it.
250 tofu_temp_trust(&certs, tab->uri.host, tab->uri.port, tab->cert);
252 ui_yornp("Save the new certificate?",
253 handle_maybe_save_new_cert, tab);
261 handle_maybe_save_new_cert(int accept, struct tab *tab)
263 struct tofu_entry *e;
264 const char *host, *port;
266 if (tab->proxy != NULL) {
267 host = tab->proxy->host;
268 port = tab->proxy->port;
270 host = tab->uri.host;
271 port = tab->uri.port;
277 if ((e = calloc(1, sizeof(*e))) == NULL)
280 strlcpy(e->domain, host, sizeof(e->domain));
281 if (*port != '\0' && strcmp(port, "1965")) {
282 strlcat(e->domain, ":", sizeof(e->domain));
283 strlcat(e->domain, port, sizeof(e->domain));
285 strlcpy(e->hash, tab->cert, sizeof(e->hash));
286 ui_send_fs(IMSG_UPDATE_CERT, 0, e, sizeof(*e));
288 tofu_update(&certs, e);
290 tab->trust = TS_TRUSTED;
298 normalize_code(int n)
301 if (n == 10 || n == 11)
307 if (n == 30 || n == 31)
315 if (n <= 53 || n == 59)
323 return MALFORMED_RESPONSE;
327 handle_imsg_got_code(struct imsg *imsg, size_t datalen)
331 if ((tab = tab_by_id(imsg->hdr.peerid)) == NULL)
334 if (sizeof(tab->code) != datalen)
337 memcpy(&tab->code, imsg->data, sizeof(tab->code));
338 tab->code = normalize_code(tab->code);
339 if (tab->code != 30 && tab->code != 31)
340 tab->redirect_count = 0;
344 handle_imsg_got_meta(struct imsg *imsg, size_t datalen)
348 if ((tab = tab_by_id(imsg->hdr.peerid)) == NULL)
351 if (sizeof(tab->meta) <= datalen)
354 memcpy(tab->meta, imsg->data, datalen);
356 if (tab->code < 10) { /* internal errors */
357 load_page_from_str(tab, err_pages[tab->code]);
358 } else if (tab->code < 20) { /* 1x */
359 load_page_from_str(tab, err_pages[tab->code]);
360 ui_require_input(tab, tab->code == 11);
361 } else if (tab->code == 20) {
362 if (setup_parser_for(tab)) {
363 ui_send_net(IMSG_PROCEED, tab->id, NULL, 0);
365 load_page_from_str(tab, err_pages[UNKNOWN_TYPE_OR_CSET]);
366 ui_yornp("Can't display page, wanna save?",
367 handle_maybe_save_page, tab);
369 } else if (tab->code < 40) { /* 3x */
370 tab->redirect_count++;
372 /* TODO: make customizable? */
373 if (tab->redirect_count > 5) {
374 load_page_from_str(tab,
375 err_pages[TOO_MUCH_REDIRECTS]);
377 do_load_url(tab, tab->meta, NULL);
378 } else { /* 4x, 5x & 6x */
379 load_page_from_str(tab, err_pages[tab->code]);
384 handle_maybe_save_page(int dosave, struct tab *tab)
387 ui_read("Save to path", handle_save_page_path, tab);
393 handle_save_page_path(const char *path, struct tab *tab)
400 tab->path = strdup(path);
402 ui_send_fs(IMSG_FILE_OPEN, tab->id, path, strlen(path)+1);
406 handle_imsg_file_opened(struct imsg *imsg, size_t datalen)
413 if ((tab = tab_by_id(imsg->hdr.peerid)) == NULL) {
419 if (imsg->fd == -1) {
423 if (e[datalen-1] != '\0')
425 l = asprintf(&page, "# Can't open file\n\n> %s: %s\n",
429 load_page_from_str(tab, page);
433 ui_send_net(IMSG_PROCEED, tab->id, NULL, 0);
438 handle_imsg_buf(struct imsg *imsg, size_t datalen)
442 char *page, buf[FMT_SCALED_STRSIZE] = {0};
444 if ((tab = tab_by_id(imsg->hdr.peerid)) == NULL)
447 tab->bytes += datalen;
449 if (!tab->buffer.page.parse(&tab->buffer.page,
450 imsg->data, datalen))
453 write(tab->fd, imsg->data, datalen);
454 fmt_scaled(tab->bytes, buf);
455 l = asprintf(&page, "Saving to \"%s\"... (%s)\n",
460 load_page_from_str(tab, page);
464 ui_on_tab_refresh(tab);
468 handle_imsg_eof(struct imsg *imsg, size_t datalen)
472 char *page, buf[FMT_SCALED_STRSIZE] = {0};
474 if ((tab = tab_by_id(imsg->hdr.peerid)) == NULL)
478 if (!tab->buffer.page.free(&tab->buffer.page))
481 fmt_scaled(tab->bytes, buf);
482 l = asprintf(&page, "Saved to \"%s\" (%s)\n",
487 load_page_from_str(tab, page);
496 ui_on_tab_refresh(tab);
497 ui_on_tab_loaded(tab);
501 handle_imsg_bookmark_ok(struct imsg *imsg, size_t datalen)
505 if (datalen != sizeof(res))
508 memcpy(&res, imsg->data, sizeof(res));
510 message("Added to bookmarks!");
512 message("Failed to add to bookmarks: %s",
517 handle_imsg_save_cert_ok(struct imsg *imsg, size_t datalen)
521 if (datalen != sizeof(res))
523 memcpy(&res, imsg->data, datalen);
525 message("Failed to save the cert for: %s",
530 handle_imsg_update_cert_ok(struct imsg *imsg, size_t datalen)
534 if (datalen != sizeof(res))
536 memcpy(&res, imsg->data, datalen);
538 message("Failed to update the certificate");
542 handle_dispatch_imsg(int fd, short ev, void *d)
544 struct imsgev *iev = d;
546 if (dispatch_imsg(iev, ev, handlers, sizeof(handlers)) == -1)
547 err(1, "connection closed");
551 load_page_from_str(struct tab *tab, const char *page)
553 erase_buffer(&tab->buffer);
554 gemtext_initparser(&tab->buffer.page);
555 if (!tab->buffer.page.parse(&tab->buffer.page, page, strlen(page)))
557 if (!tab->buffer.page.free(&tab->buffer.page))
559 ui_on_tab_refresh(tab);
560 ui_on_tab_loaded(tab);
564 load_about_url(struct tab *tab, const char *url)
566 tab->trust = TS_VERIFIED;
568 gemtext_initparser(&tab->buffer.page);
570 ui_send_fs(IMSG_GET, tab->id,
571 tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
575 load_gemini_url(struct tab *tab, const char *url)
580 tab->id = tab_new_id();
582 memset(&req, 0, sizeof(req));
583 strlcpy(req.host, tab->uri.host, sizeof(req.host));
584 strlcpy(req.port, tab->uri.port, sizeof(req.host));
586 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
587 strlcat(req.req, "\r\n", sizeof(req.req));
589 req.proto = PROTO_GEMINI;
591 ui_send_net(IMSG_GET_RAW, tab->id,
596 load_via_proxy(struct tab *tab, const char *url, struct proxy *p)
601 tab->id = tab_new_id();
604 memset(&req, 0, sizeof(req));
605 strlcpy(req.host, p->host, sizeof(req.host));
606 strlcpy(req.port, p->port, sizeof(req.host));
608 strlcpy(req.req, tab->hist_cur->h, sizeof(req.req));
609 strlcat(req.req, "\r\n", sizeof(req.req));
611 req.proto = p->proto;
613 ui_send_net(IMSG_GET_RAW, tab->id,
618 * Effectively load the given url in the given tab. Return 1 when
619 * loading the page asynchronously, and thus when an erase_buffer can
620 * be done right after this function return, or 0 when loading the
621 * page synchronously. In this last case, erase_buffer *MUST* be
622 * called by the handling function (such as load_page_from_str).
625 do_load_url(struct tab *tab, const char *url, const char *base)
641 tab->trust = TS_UNKNOWN;
644 memcpy(&uri, &tab->uri, sizeof(tab->uri));
646 phos_parse_absolute_uri(base, &uri);
648 if (!phos_resolve_uri_from_str(&uri, url, &tab->uri)) {
649 if (asprintf(&t, "#error loading %s\n>%s\n",
650 url, "Can't parse the URI") == -1)
652 strlcpy(tab->hist_cur->h, url, sizeof(tab->hist_cur->h));
653 load_page_from_str(tab, t);
658 phos_serialize_uri(&tab->uri, tab->hist_cur->h,
659 sizeof(tab->hist_cur->h));
661 for (p = protos; p->schema != NULL; ++p) {
662 if (!strcmp(tab->uri.scheme, p->schema)) {
668 TAILQ_FOREACH(proxy, &proxies, proxies) {
669 if (!strcmp(tab->uri.scheme, proxy->match_proto)) {
670 load_via_proxy(tab, url, proxy);
675 load_page_from_str(tab, err_pages[UNKNOWN_PROTOCOL]);
680 * Load url in tab. If tab is marked as lazy, only prepare the url
681 * but don't load it. If tab is lazy and a url was already prepared,
685 load_url(struct tab *tab, const char *url, const char *base)
689 lazy = tab->flags & TAB_LAZY;
691 if (lazy && tab->hist_cur != NULL) {
693 tab->flags &= ~TAB_LAZY;
696 if (!lazy || tab->hist_cur == NULL) {
697 if (tab->hist_cur != NULL)
698 hist_clear_forward(&tab->hist,
699 TAILQ_NEXT(tab->hist_cur, entries));
701 if ((tab->hist_cur = calloc(1, sizeof(*tab->hist_cur))) == NULL) {
706 strlcpy(tab->buffer.page.title, url,
707 sizeof(tab->buffer.page.title));
708 hist_push(&tab->hist, tab->hist_cur);
711 strlcpy(tab->hist_cur->h, url,
712 sizeof(tab->hist_cur->h));
715 if (!lazy && do_load_url(tab, url, base))
716 erase_buffer(&tab->buffer);
720 load_previous_page(struct tab *tab)
724 if ((h = TAILQ_PREV(tab->hist_cur, mhisthead, entries)) == NULL)
727 do_load_url(tab, h->h, NULL);
732 load_next_page(struct tab *tab)
736 if ((h = TAILQ_NEXT(tab->hist_cur, entries)) == NULL)
739 do_load_url(tab, h->h, NULL);
744 * Free every resource linked to the tab, including the tab itself.
745 * Removes the tab from the tablist, but doesn't update the
746 * current_tab though.
749 free_tab(struct tab *tab)
753 if (evtimer_pending(&tab->loadingev, NULL))
754 evtimer_del(&tab->loadingev);
756 TAILQ_REMOVE(&tabshead, tab, tabs);
761 stop_tab(struct tab *tab)
763 ui_send_net(IMSG_STOP, tab->id, NULL, 0);
770 load_page_from_str(tab, "Stopped.\n");
775 add_to_bookmarks(const char *str)
777 ui_send_fs(IMSG_BOOKMARK_PAGE, 0,
788 ui_send_fs(IMSG_SESSION_START, 0, NULL, 0);
790 TAILQ_FOREACH(tab, &tabshead, tabs) {
792 if (tab == current_tab)
793 flags |= TAB_CURRENT;
795 t = tab->hist_cur->h;
796 ui_send_fs(IMSG_SESSION_TAB, flags, t, strlen(t)+1);
798 t = tab->buffer.page.title;
799 ui_send_fs(IMSG_SESSION_TAB_TITLE, 0, t, strlen(t)+1);
802 ui_send_fs(IMSG_SESSION_END, 0, NULL, 0);
806 * Parse a line of the session file. The format is:
808 * URL [flags,...] [title]\n
811 parse_session_line(char *line, const char **title, uint32_t *flags)
817 if ((s = strchr(line, ' ')) == NULL)
822 if ((t = strchr(s, ' ')) != NULL) {
827 while ((ap = strsep(&s, ",")) != NULL) {
830 else if (!strcmp(ap, "current"))
831 *flags |= TAB_CURRENT;
833 message("unknown tab flag: %s", ap);
838 load_last_session(void)
841 char *nl, *line = NULL;
846 struct tab *tab, *curr = NULL;
848 if ((session = fopen(session_file, "r")) == NULL) {
850 new_tab("about:new", NULL);
851 switch_to_tab(new_tab("about:help", NULL));
855 while ((linelen = getline(&line, &linesize, session)) != -1) {
856 if ((nl = strchr(line, '\n')) != NULL)
858 parse_session_line(line, &title, &flags);
859 if ((tab = new_tab(line, NULL)) == NULL)
861 strlcpy(tab->buffer.page.title, title,
862 sizeof(tab->buffer.page.title));
863 if (flags & TAB_CURRENT)
868 message("error reading %s: %s",
869 session_file, strerror(errno));
876 if (last_time_crashed())
877 switch_to_tab(new_tab("about:crash", NULL));
883 start_child(enum telescope_process p, const char *argv0, int fd)
889 switch (pid = fork()) {
899 if (dup2(fd, 3) == -1)
900 err(1, "cannot setup imsg fd");
902 argv[argc++] = argv0;
905 errx(1, "Can't start ui process");
907 argv[argc++] = "-Tf";
910 argv[argc++] = "-Tn";
915 execvp(argv0, (char *const *)argv);
916 err(1, "execvp(%s)", argv0);
920 ui_send_net(int type, uint32_t peerid, const void *data,
923 return imsg_compose_event(iev_net, type, peerid, 0, -1, data,
928 ui_send_fs(int type, uint32_t peerid, const void *data, uint16_t datalen)
930 return imsg_compose_event(iev_fs, type, peerid, 0, -1, data,
934 static void __attribute__((noreturn))
937 fprintf(stderr, "USAGE: %s [-hnv] [-c config] [url]\n",
939 fprintf(stderr, "version: " PACKAGE " " VERSION "\n");
944 main(int argc, char * const *argv)
946 struct imsgev net_ibuf, fs_ibuf;
947 int pipe2net[2], pipe2fs[2];
948 int ch, configtest = 0, fail = 0;
953 const char *url = NEW_TAB_URL;
958 signal(SIGCHLD, SIG_IGN);
959 signal(SIGPIPE, SIG_IGN);
961 if (getenv("NO_COLOR") != NULL)
964 strlcpy(path, getenv("HOME"), sizeof(path));
965 strlcat(path, "/.telescope/config", sizeof(path));
967 while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) {
970 exit(ui_print_colors());
973 strlcpy(path, optarg, sizeof(path));
989 errx(1, "invalid process spec %c",
994 printf("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
1008 else if (proc == PROC_FS)
1010 else if (proc == PROC_NET)
1011 return client_main();
1021 /* setup keys before reading the config */
1022 TAILQ_INIT(&global_map.m);
1023 global_map.unhandled_input = global_key_unbound;
1024 TAILQ_INIT(&minibuffer_map.m);
1027 parseconfig(path, fail);
1034 if ((sessionfd = lock_session()) == -1)
1035 errx(1, "can't lock session, is another instance of "
1036 "telescope already running?");
1038 /* Start children. */
1039 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe2fs) == -1)
1040 err(1, "socketpair");
1041 start_child(PROC_FS, argv0, pipe2fs[1]);
1042 imsg_init(&fs_ibuf.ibuf, pipe2fs[0]);
1044 iev_fs->handler = handle_dispatch_imsg;
1046 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe2net) == -1)
1047 err(1, "socketpair");
1048 start_child(PROC_NET, argv0, pipe2net[1]);
1049 imsg_init(&net_ibuf.ibuf, pipe2net[0]);
1050 iev_net = &net_ibuf;
1051 iev_net->handler = handle_dispatch_imsg;
1055 /* initialize tofu & load certificates */
1056 tofu_init(&certs, 5, offsetof(struct tofu_entry, domain));
1061 /* Setup event handlers for pipes to fs/net */
1062 iev_fs->events = EV_READ;
1063 event_set(&iev_fs->ev, iev_fs->ibuf.fd, iev_fs->events,
1064 iev_fs->handler, iev_fs);
1065 event_add(&iev_fs->ev, NULL);
1067 iev_net->events = EV_READ;
1068 event_set(&iev_net->ev, iev_net->ibuf.fd, iev_net->events,
1069 iev_net->handler, iev_net);
1070 event_add(&iev_net->ev, NULL);
1073 load_last_session();
1074 if (has_url || TAILQ_EMPTY(&tabshead))
1077 sandbox_ui_process();
1082 ui_send_fs(IMSG_QUIT, 0, NULL, 0);
1083 ui_send_net(IMSG_QUIT, 0, NULL, 0);
1084 imsg_flush(&iev_fs->ibuf);
1085 imsg_flush(&iev_net->ibuf);