2 1fce2e75 2021-08-14 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 1fce2e75 2021-08-14 op * Permission to use, copy, modify, and distribute this software for any
5 1fce2e75 2021-08-14 op * purpose with or without fee is hereby granted, provided that the above
6 1fce2e75 2021-08-14 op * copyright notice and this permission notice appear in all copies.
8 1fce2e75 2021-08-14 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 1fce2e75 2021-08-14 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 1fce2e75 2021-08-14 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 1fce2e75 2021-08-14 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 1fce2e75 2021-08-14 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 1fce2e75 2021-08-14 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 1fce2e75 2021-08-14 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 1fce2e75 2021-08-14 op #include "compat.h"
19 1fce2e75 2021-08-14 op #include <errno.h>
20 64f4f8e2 2022-04-24 op #include <fcntl.h>
21 f63b8f73 2022-04-24 op #include <limits.h>
22 1fce2e75 2021-08-14 op #include <stdio.h>
23 1fce2e75 2021-08-14 op #include <stdlib.h>
24 1fce2e75 2021-08-14 op #include <string.h>
25 9e97090d 2022-02-26 op #include <time.h>
26 1fce2e75 2021-08-14 op #include <unistd.h>
28 1fce2e75 2021-08-14 op #include "defaults.h"
29 b9fcc0e9 2021-10-08 op #include "fs.h"
30 1fce2e75 2021-08-14 op #include "minibuffer.h"
31 1fce2e75 2021-08-14 op #include "session.h"
32 1fce2e75 2021-08-14 op #include "ui.h"
34 9e97090d 2022-02-26 op struct history history;
36 1fce2e75 2021-08-14 op static struct event autosaveev;
39 1fce2e75 2021-08-14 op switch_to_tab(struct tab *tab)
41 1fce2e75 2021-08-14 op current_tab = tab;
42 1fce2e75 2021-08-14 op tab->flags &= ~TAB_URGENT;
44 fb8dcd1c 2022-01-18 op if (operating && tab->flags & TAB_LAZY)
45 ed21a9a1 2022-01-11 op load_url_in_tab(tab, tab->hist_cur->h, NULL, LU_MODE_NOHIST);
49 1fce2e75 2021-08-14 op tab_new_id(void)
51 1fce2e75 2021-08-14 op static uint32_t tab_counter;
53 1fce2e75 2021-08-14 op return tab_counter++;
57 1fce2e75 2021-08-14 op new_tab(const char *url, const char *base, struct tab *after)
59 1fce2e75 2021-08-14 op struct tab *tab;
61 87aeb47b 2021-08-18 op ui_schedule_redraw();
62 1fce2e75 2021-08-14 op autosave_hook();
64 1fce2e75 2021-08-14 op if ((tab = calloc(1, sizeof(*tab))) == NULL) {
65 1fce2e75 2021-08-14 op event_loopbreak();
69 1fce2e75 2021-08-14 op TAILQ_INIT(&tab->hist.head);
70 1fce2e75 2021-08-14 op TAILQ_INIT(&tab->buffer.head);
71 1fce2e75 2021-08-14 op TAILQ_INIT(&tab->buffer.page.head);
72 3b30597e 2022-02-11 op evtimer_set(&tab->loadingev, NULL, NULL);
74 1fce2e75 2021-08-14 op tab->id = tab_new_id();
76 1fce2e75 2021-08-14 op if (after != NULL)
77 1fce2e75 2021-08-14 op TAILQ_INSERT_AFTER(&tabshead, after, tab, tabs);
79 1fce2e75 2021-08-14 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
81 ea639250 2021-01-02 op if (!operating)
82 ea639250 2021-01-02 op tab->flags |= TAB_LAZY;
83 1fce2e75 2021-08-14 op load_url_in_tab(tab, url, base, 0);
84 ea639250 2021-01-02 op switch_to_tab(tab);
89 6c74799d 2022-01-05 op * Move a tab from the tablist to the killed tab list and erase its
90 05de8ac3 2022-01-06 op * contents. Append should always be 0 to prepend tabs so unkill_tab
91 05de8ac3 2022-01-06 op * can work correctly; appending is only useful during startup when
92 05de8ac3 2022-01-06 op * receiving the list of killed tabs to keep the correct order.
93 05de8ac3 2022-01-06 op * NB: doesn't update the current_tab.
96 05de8ac3 2022-01-06 op kill_tab(struct tab *tab, int append)
100 1fce2e75 2021-08-14 op stop_tab(tab);
101 6c74799d 2022-01-05 op erase_buffer(&tab->buffer);
102 6c74799d 2022-01-05 op TAILQ_REMOVE(&tabshead, tab, tabs);
103 87aeb47b 2021-08-18 op ui_schedule_redraw();
104 1fce2e75 2021-08-14 op autosave_hook();
106 1fce2e75 2021-08-14 op if (evtimer_pending(&tab->loadingev, NULL))
107 1fce2e75 2021-08-14 op evtimer_del(&tab->loadingev);
110 05de8ac3 2022-01-06 op TAILQ_INSERT_TAIL(&ktabshead, tab, tabs);
112 05de8ac3 2022-01-06 op TAILQ_INSERT_HEAD(&ktabshead, tab, tabs);
114 6c74799d 2022-01-05 op /* gc closed tabs */
116 6c74799d 2022-01-05 op TAILQ_FOREACH(tab, &ktabshead, tabs)
118 6c74799d 2022-01-05 op while (count > max_killed_tabs) {
120 6c74799d 2022-01-05 op free_tab(TAILQ_LAST(&ktabshead, tabshead));
125 265508d0 2022-01-05 op * Resurrects the lastest killed tab and returns it. The tab is already
126 6c74799d 2022-01-05 op * added to the tab list with the TAB_LAZY flag set. NB: this doesn't
127 6c74799d 2022-01-05 op * update current_tab.
130 6c74799d 2022-01-05 op unkill_tab(void)
132 6c74799d 2022-01-05 op struct tab *t;
134 6c74799d 2022-01-05 op if (TAILQ_EMPTY(&ktabshead))
137 b7286684 2022-01-13 op ui_schedule_redraw();
138 6c74799d 2022-01-05 op autosave_hook();
140 6c74799d 2022-01-05 op t = TAILQ_FIRST(&ktabshead);
141 6c74799d 2022-01-05 op TAILQ_REMOVE(&ktabshead, t, tabs);
142 6c74799d 2022-01-05 op TAILQ_INSERT_TAIL(&tabshead, t, tabs);
143 6c74799d 2022-01-05 op t->flags |= TAB_LAZY;
148 1b45e5df 2022-01-05 op * Free every resource linked to the tab, including the tab itself, and
149 1b45e5df 2022-01-05 op * removes it from the *killed* tablist.
152 6c74799d 2022-01-05 op free_tab(struct tab *tab)
154 6c74799d 2022-01-05 op TAILQ_REMOVE(&ktabshead, tab, tabs);
155 bf935370 2022-01-05 op hist_clear(&tab->hist);
160 1fce2e75 2021-08-14 op stop_tab(struct tab *tab)
162 1fce2e75 2021-08-14 op ui_send_net(IMSG_STOP, tab->id, NULL, 0);
165 6c74799d 2022-01-05 op static inline void
166 f63b8f73 2022-04-24 op savetab(FILE *fp, struct tab *tab, int killed)
168 f63b8f73 2022-04-24 op struct hist *h;
169 f63b8f73 2022-04-24 op size_t top_line, current_line;
172 f63b8f73 2022-04-24 op get_scroll_position(tab, &top_line, ¤t_line);
174 f63b8f73 2022-04-24 op fprintf(fp, "%s ", tab->hist_cur->h);
175 6c74799d 2022-01-05 op if (tab == current_tab)
176 f63b8f73 2022-04-24 op fprintf(fp, "current,");
178 f63b8f73 2022-04-24 op fprintf(fp, "killed,");
180 f63b8f73 2022-04-24 op fprintf(fp, "top=%zu,cur=%zu %s\n", top_line, current_line,
181 f63b8f73 2022-04-24 op tab->buffer.page.title);
184 6c74799d 2022-01-05 op TAILQ_FOREACH(h, &tab->hist.head, entries) {
185 6c74799d 2022-01-05 op if (h == tab->hist_cur) {
190 f63b8f73 2022-04-24 op fprintf(fp, "%s %s\n", future ? ">" : "<", h->h);
195 6c74799d 2022-01-05 op save_session(void)
197 3e36ea51 2022-04-24 op FILE *tmp, *hist;
198 de6a6a40 2022-04-24 op struct tab *tab;
200 de6a6a40 2022-04-24 op int fd, err= 0;
201 de6a6a40 2022-04-24 op char sfn[PATH_MAX];
203 6c74799d 2022-01-05 op if (safe_mode)
206 de6a6a40 2022-04-24 op strlcpy(sfn, session_file_tmp, sizeof(sfn));
207 de6a6a40 2022-04-24 op if ((fd = mkstemp(sfn)) == -1 ||
208 de6a6a40 2022-04-24 op (tmp = fdopen(fd, "w")) == NULL) {
209 de6a6a40 2022-04-24 op if (fd != -1) {
216 6c74799d 2022-01-05 op TAILQ_FOREACH(tab, &tabshead, tabs)
217 de6a6a40 2022-04-24 op savetab(tmp, tab, 0);
218 6c74799d 2022-01-05 op TAILQ_FOREACH(tab, &ktabshead, tabs)
219 de6a6a40 2022-04-24 op savetab(tmp, tab, 1);
221 de6a6a40 2022-04-24 op err = ferror(tmp);
229 de6a6a40 2022-04-24 op if (rename(sfn, session_file))
232 3e36ea51 2022-04-24 op if ((hist = fopen(history_file, "a")) == NULL)
235 9e97090d 2022-02-26 op if (history.dirty) {
236 9e97090d 2022-02-26 op for (i = 0; i < history.len && history.dirty > 0; ++i) {
237 9e97090d 2022-02-26 op if (!history.items[i].dirty)
239 9e97090d 2022-02-26 op history.dirty--;
240 9e97090d 2022-02-26 op history.items[i].dirty = 0;
242 3e36ea51 2022-04-24 op fprintf(hist, "%lld %s\n",
243 f63b8f73 2022-04-24 op (long long)history.items[i].ts,
244 f63b8f73 2022-04-24 op history.items[i].uri);
246 9e97090d 2022-02-26 op history.dirty = 0;
249 3e36ea51 2022-04-24 op err = ferror(hist);
250 3e36ea51 2022-04-24 op fclose(hist);
254 9e97090d 2022-02-26 op history_push(struct histitem *hi)
256 9e97090d 2022-02-26 op size_t i, oldest = 0;
259 9e97090d 2022-02-26 op for (i = 0; i < history.len; ++i) {
260 9e97090d 2022-02-26 op if (history.items[i].ts < history.items[oldest].ts)
263 9e97090d 2022-02-26 op /* remove duplicates */
264 9e97090d 2022-02-26 op if (!strcmp(history.items[i].uri, hi->uri))
268 9e97090d 2022-02-26 op if ((uri = strdup(hi->uri)) == NULL)
271 9e97090d 2022-02-26 op /* don't grow too much; replace the oldest */
272 9e97090d 2022-02-26 op if (history.len == HISTORY_CAP) {
273 9e97090d 2022-02-26 op history.items[oldest].ts = hi->ts;
274 9e97090d 2022-02-26 op free(history.items[oldest].uri);
275 9e97090d 2022-02-26 op history.items[oldest].uri = uri;
279 9e97090d 2022-02-26 op history.items[history.len].ts = hi->ts;
280 9e97090d 2022-02-26 op history.items[history.len].uri = uri;
281 9e97090d 2022-02-26 op history.len++;
285 9e97090d 2022-02-26 op history_cmp(const void *a, const void *b)
287 9e97090d 2022-02-26 op const struct history_item *i = a, *j = b;
288 9e97090d 2022-02-26 op return strcmp(i->uri, j->uri);
292 9e97090d 2022-02-26 op history_sort(void)
294 9e97090d 2022-02-26 op qsort(history.items, history.len, sizeof(history.items[0]),
295 9e97090d 2022-02-26 op history_cmp);
299 9e97090d 2022-02-26 op history_add(const char *uri)
301 9e97090d 2022-02-26 op size_t i, j, insert = 0, oldest = 0;
305 9e97090d 2022-02-26 op for (i = 0; i < history.len; ++i) {
306 9e97090d 2022-02-26 op if (history.items[i].ts < history.items[oldest].ts)
309 9e97090d 2022-02-26 op if (insert != 0 && insert < i)
312 9e97090d 2022-02-26 op c = strcmp(uri, history.items[i].uri);
313 9e97090d 2022-02-26 op if (c == 0) {
314 9e97090d 2022-02-26 op history.items[i].ts = time(NULL);
315 9e97090d 2022-02-26 op history.items[i].dirty = 1;
316 9e97090d 2022-02-26 op history.dirty++;
317 9e97090d 2022-02-26 op autosave_hook();
325 9e97090d 2022-02-26 op if ((u = strdup(uri)) == NULL)
328 9e97090d 2022-02-26 op /* if history is full, replace the oldest one */
329 9e97090d 2022-02-26 op if (history.len == HISTORY_CAP) {
330 9e97090d 2022-02-26 op free(history.items[oldest].uri);
331 9e97090d 2022-02-26 op history.items[oldest].uri = u;
332 9e97090d 2022-02-26 op history.items[oldest].ts = time(NULL);
333 9e97090d 2022-02-26 op history.items[oldest].dirty = 1;
334 9e97090d 2022-02-26 op history.dirty++;
335 9e97090d 2022-02-26 op history_sort();
336 9e97090d 2022-02-26 op autosave_hook();
340 9e97090d 2022-02-26 op /* otherwise just insert in the right spot */
342 9e97090d 2022-02-26 op for (j = history.len; j > insert; --j)
343 9e97090d 2022-02-26 op memcpy(&history.items[j], &history.items[j-1],
344 9e97090d 2022-02-26 op sizeof(history.items[j]));
346 9e97090d 2022-02-26 op history.items[insert].ts = time(NULL);
347 9e97090d 2022-02-26 op history.items[insert].uri = u;
348 9e97090d 2022-02-26 op history.items[insert].dirty = 1;
349 9e97090d 2022-02-26 op history.dirty++;
350 9e97090d 2022-02-26 op history.len++;
351 9e97090d 2022-02-26 op autosave_hook();
355 1fce2e75 2021-08-14 op autosave_init(void)
357 1fce2e75 2021-08-14 op evtimer_set(&autosaveev, autosave_timer, NULL);
361 1fce2e75 2021-08-14 op autosave_timer(int fd, short event, void *data)
363 1fce2e75 2021-08-14 op save_session();
367 1fce2e75 2021-08-14 op * Function to be called in "interesting" places where we may want to
368 1fce2e75 2021-08-14 op * schedule an autosave (like on new tab or before loading an url.)
371 1fce2e75 2021-08-14 op autosave_hook(void)
373 1fce2e75 2021-08-14 op struct timeval tv;
375 1fce2e75 2021-08-14 op if (autosave <= 0)
378 1fce2e75 2021-08-14 op if (!evtimer_pending(&autosaveev, NULL)) {
379 1fce2e75 2021-08-14 op tv.tv_sec = autosave;
380 1fce2e75 2021-08-14 op tv.tv_usec = 0;
382 1fce2e75 2021-08-14 op evtimer_add(&autosaveev, &tv);
386 64f4f8e2 2022-04-24 op static inline int
387 64f4f8e2 2022-04-24 op parse_khost_line(char *line, char *tmp[3])
391 64f4f8e2 2022-04-24 op for (ap = tmp; ap < &tmp[3] &&
392 64f4f8e2 2022-04-24 op (*ap = strsep(&line, " \t\n")) != NULL;) {
393 64f4f8e2 2022-04-24 op if (**ap != '\0')
397 64f4f8e2 2022-04-24 op return ap == &tmp[3] && *line == '\0';
401 64f4f8e2 2022-04-24 op load_certs(struct ohash *certs)
403 64f4f8e2 2022-04-24 op char *tmp[3], *line = NULL;
404 64f4f8e2 2022-04-24 op const char *errstr;
405 64f4f8e2 2022-04-24 op size_t lineno = 0, linesize = 0;
406 64f4f8e2 2022-04-24 op ssize_t linelen;
408 64f4f8e2 2022-04-24 op struct tofu_entry *e;
410 64f4f8e2 2022-04-24 op if ((f = fopen(known_hosts_file, "r")) == NULL)
413 64f4f8e2 2022-04-24 op if ((e = calloc(1, sizeof(*e))) == NULL) {
418 64f4f8e2 2022-04-24 op while ((linelen = getline(&line, &linesize, f)) != -1) {
421 64f4f8e2 2022-04-24 op if (parse_khost_line(line, tmp)) {
422 64f4f8e2 2022-04-24 op strlcpy(e->domain, tmp[0], sizeof(e->domain));
423 64f4f8e2 2022-04-24 op strlcpy(e->hash, tmp[1], sizeof(e->hash));
425 64f4f8e2 2022-04-24 op e->verified = strtonum(tmp[2], 0, 1, &errstr);
426 64f4f8e2 2022-04-24 op if (errstr != NULL)
427 64f4f8e2 2022-04-24 op errx(1, "%s:%zu verification for %s is %s: %s",
428 64f4f8e2 2022-04-24 op known_hosts_file, lineno,
429 64f4f8e2 2022-04-24 op e->domain, errstr, tmp[2]);
431 64f4f8e2 2022-04-24 op tofu_add(certs, e);
433 64f4f8e2 2022-04-24 op warnx("%s:%zu invalid entry",
434 64f4f8e2 2022-04-24 op known_hosts_file, lineno);
444 64f4f8e2 2022-04-24 op load_hist(void)
447 64f4f8e2 2022-04-24 op size_t linesize = 0;
448 64f4f8e2 2022-04-24 op ssize_t linelen;
449 64f4f8e2 2022-04-24 op char *nl, *spc, *line = NULL;
450 64f4f8e2 2022-04-24 op const char *errstr;
451 64f4f8e2 2022-04-24 op struct histitem hi;
453 64f4f8e2 2022-04-24 op if ((hist = fopen(history_file, "r")) == NULL)
456 64f4f8e2 2022-04-24 op while ((linelen = getline(&line, &linesize, hist)) != -1) {
457 64f4f8e2 2022-04-24 op if ((nl = strchr(line, '\n')) != NULL)
459 64f4f8e2 2022-04-24 op if ((spc = strchr(line, ' ')) == NULL)
464 64f4f8e2 2022-04-24 op memset(&hi, 0, sizeof(hi));
465 64f4f8e2 2022-04-24 op hi.ts = strtonum(line, INT64_MIN, INT64_MAX, &errstr);
466 64f4f8e2 2022-04-24 op if (errstr != NULL)
468 64f4f8e2 2022-04-24 op if (strlcpy(hi.uri, spc, sizeof(hi.uri)) >= sizeof(hi.uri))
471 64f4f8e2 2022-04-24 op history_push(&hi);
474 64f4f8e2 2022-04-24 op fclose(hist);
477 64f4f8e2 2022-04-24 op history_sort();
481 64f4f8e2 2022-04-24 op * Check if the last time telescope crashed. The check is done by
482 64f4f8e2 2022-04-24 op * looking at `crashed_file': if it exists then last time we crashed.
483 64f4f8e2 2022-04-24 op * Then, while here, touch the file too, it's removed during the
487 64f4f8e2 2022-04-24 op last_time_crashed(void)
489 64f4f8e2 2022-04-24 op int fd, crashed = 1;
491 64f4f8e2 2022-04-24 op if (safe_mode)
494 64f4f8e2 2022-04-24 op if (unlink(crashed_file) == -1 && errno == ENOENT)
497 64f4f8e2 2022-04-24 op if ((fd = open(crashed_file, O_CREAT|O_WRONLY, 0600)) == -1)
498 64f4f8e2 2022-04-24 op return crashed;
501 64f4f8e2 2022-04-24 op return crashed;
505 64f4f8e2 2022-04-24 op * Parse and restore a tab from the session file. The format is:
507 64f4f8e2 2022-04-24 op * URL [flags,...] [title]\n
509 64f4f8e2 2022-04-24 op static inline struct tab *
510 64f4f8e2 2022-04-24 op parse_tab_line(char *line, struct tab **ct)
512 64f4f8e2 2022-04-24 op struct tab *tab;
513 64f4f8e2 2022-04-24 op char *s, *t, *ap;
514 64f4f8e2 2022-04-24 op const char *uri, *title = "";
515 64f4f8e2 2022-04-24 op int current = 0, killed = 0;
516 64f4f8e2 2022-04-24 op size_t tline = 0, cline = 0;
519 64f4f8e2 2022-04-24 op if ((s = strchr(line, ' ')) == NULL)
523 64f4f8e2 2022-04-24 op if ((t = strchr(s, ' ')) != NULL) {
528 64f4f8e2 2022-04-24 op while ((ap = strsep(&s, ",")) != NULL) {
529 64f4f8e2 2022-04-24 op if (!strcmp(ap, "current"))
531 64f4f8e2 2022-04-24 op else if (!strcmp(ap, "killed"))
533 64f4f8e2 2022-04-24 op else if (!strncmp(ap, "top=", 4))
534 64f4f8e2 2022-04-24 op tline = strtonum(ap+4, 0, UINT32_MAX, NULL);
535 64f4f8e2 2022-04-24 op else if (!strncmp(ap, "cur=", 4))
536 64f4f8e2 2022-04-24 op cline = strtonum(ap + 4, 0, UINT32_MAX, NULL);
539 64f4f8e2 2022-04-24 op if (tline > cline) {
544 64f4f8e2 2022-04-24 op if ((tab = new_tab(uri, NULL, NULL)) == NULL)
545 64f4f8e2 2022-04-24 op err(1, "new_tab");
546 64f4f8e2 2022-04-24 op tab->hist_cur->line_off = tline;
547 64f4f8e2 2022-04-24 op tab->hist_cur->current_off = cline;
548 64f4f8e2 2022-04-24 op strlcpy(tab->buffer.page.title, title, sizeof(tab->buffer.page.title));
552 64f4f8e2 2022-04-24 op else if (killed)
553 64f4f8e2 2022-04-24 op kill_tab(tab, 1);
559 64f4f8e2 2022-04-24 op load_tabs(void)
561 64f4f8e2 2022-04-24 op struct tab *tab = NULL, *ct = NULL;
562 64f4f8e2 2022-04-24 op struct hist *h;
563 64f4f8e2 2022-04-24 op FILE *session;
564 64f4f8e2 2022-04-24 op size_t lineno = 0, linesize = 0;
565 64f4f8e2 2022-04-24 op ssize_t linelen;
566 64f4f8e2 2022-04-24 op char *uri, *line = NULL;
568 64f4f8e2 2022-04-24 op if ((session = fopen(session_file, "r")) == NULL) {
569 64f4f8e2 2022-04-24 op new_tab("about:new", NULL, NULL);
570 64f4f8e2 2022-04-24 op new_tab("about:help", NULL, NULL);
574 64f4f8e2 2022-04-24 op while ((linelen = getline(&line, &linesize, session)) != -1) {
577 64f4f8e2 2022-04-24 op if (linelen > 0 && line[linelen-1] == '\n')
578 64f4f8e2 2022-04-24 op line[linelen-1] = '\0';
580 64f4f8e2 2022-04-24 op if (*line == '<' || *line == '>') {
581 64f4f8e2 2022-04-24 op uri = line + 1;
582 64f4f8e2 2022-04-24 op if (*uri != ' ' || tab == NULL) {
583 64f4f8e2 2022-04-24 op fprintf(stderr, "%s:%zu invalid line\n",
584 64f4f8e2 2022-04-24 op session_file, lineno);
589 64f4f8e2 2022-04-24 op if ((h = calloc(1, sizeof(*h))) == NULL)
590 64f4f8e2 2022-04-24 op err(1, "calloc");
591 64f4f8e2 2022-04-24 op strlcpy(h->h, uri, sizeof(h->h));
593 64f4f8e2 2022-04-24 op if (*line == '>') /* future hist */
594 64f4f8e2 2022-04-24 op hist_push(&tab->hist, h);
596 64f4f8e2 2022-04-24 op hist_add_before(&tab->hist, tab->hist_cur, h);
598 64f4f8e2 2022-04-24 op tab = parse_tab_line(line, &ct);
601 64f4f8e2 2022-04-24 op fclose(session);
604 64f4f8e2 2022-04-24 op if (ct == NULL || TAILQ_EMPTY(&tabshead))
605 64f4f8e2 2022-04-24 op ct = new_tab("about:new", NULL, NULL);
607 64f4f8e2 2022-04-24 op switch_to_tab(ct);
609 64f4f8e2 2022-04-24 op if (last_time_crashed())
610 64f4f8e2 2022-04-24 op new_tab("about:crash", NULL, NULL);
614 64f4f8e2 2022-04-24 op load_session(struct ohash *certs)
616 64f4f8e2 2022-04-24 op load_certs(certs);
623 64f4f8e2 2022-04-24 op lock_session(void)
625 64f4f8e2 2022-04-24 op struct flock lock;
628 64f4f8e2 2022-04-24 op if ((fd = open(lockfile_path, O_WRONLY|O_CREAT, 0600)) == -1)
631 64f4f8e2 2022-04-24 op lock.l_start = 0;
632 64f4f8e2 2022-04-24 op lock.l_len = 0;
633 64f4f8e2 2022-04-24 op lock.l_type = F_WRLCK;
634 64f4f8e2 2022-04-24 op lock.l_whence = SEEK_SET;
636 64f4f8e2 2022-04-24 op if (fcntl(fd, F_SETLK, &lock) == -1) {