002
2021-08-14
op
* Copyright (c) 2021 Omar Polo <op@omarpolo.com>
004
2021-08-14
op
* Permission to use, copy, modify, and distribute this software for any
005
2021-08-14
op
* purpose with or without fee is hereby granted, provided that the above
006
2021-08-14
op
* copyright notice and this permission notice appear in all copies.
008
2021-08-14
op
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
009
2021-08-14
op
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
010
2021-08-14
op
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
011
2021-08-14
op
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
012
2021-08-14
op
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
013
2021-08-14
op
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
014
2021-08-14
op
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
017
2021-08-14
op
#include "compat.h"
019
2021-08-14
op
#include <errno.h>
020
2022-04-24
op
#include <fcntl.h>
021
2022-04-24
op
#include <limits.h>
022
2021-08-14
op
#include <stdio.h>
023
2021-08-14
op
#include <stdlib.h>
024
2021-08-14
op
#include <string.h>
025
2022-02-26
op
#include <time.h>
026
2021-08-14
op
#include <unistd.h>
028
2021-08-14
op
#include "defaults.h"
029
2021-10-08
op
#include "fs.h"
030
2021-08-14
op
#include "minibuffer.h"
031
2021-08-14
op
#include "session.h"
032
2021-08-14
op
#include "ui.h"
034
2022-02-26
op
struct history history;
036
2021-08-14
op
static struct event autosaveev;
039
2021-08-14
op
switch_to_tab(struct tab *tab)
041
2021-08-14
op
current_tab = tab;
042
2021-08-14
op
tab->flags &= ~TAB_URGENT;
044
2022-01-18
op
if (operating && tab->flags & TAB_LAZY)
045
2022-01-11
op
load_url_in_tab(tab, tab->hist_cur->h, NULL, LU_MODE_NOHIST);
048
2021-08-14
op
unsigned int
049
2021-08-14
op
tab_new_id(void)
051
2021-08-14
op
static uint32_t tab_counter;
053
2021-08-14
op
return tab_counter++;
056
2021-08-14
op
struct tab *
057
2021-08-14
op
new_tab(const char *url, const char *base, struct tab *after)
059
2021-08-14
op
struct tab *tab;
061
2021-08-18
op
ui_schedule_redraw();
062
2021-08-14
op
autosave_hook();
064
2021-08-14
op
if ((tab = calloc(1, sizeof(*tab))) == NULL) {
065
2021-08-14
op
event_loopbreak();
066
2021-08-14
op
return NULL;
069
2021-08-14
op
TAILQ_INIT(&tab->hist.head);
070
2021-08-14
op
TAILQ_INIT(&tab->buffer.head);
071
2021-08-14
op
TAILQ_INIT(&tab->buffer.page.head);
072
2022-02-11
op
evtimer_set(&tab->loadingev, NULL, NULL);
074
2021-08-14
op
tab->id = tab_new_id();
076
2021-08-14
op
if (after != NULL)
077
2021-08-14
op
TAILQ_INSERT_AFTER(&tabshead, after, tab, tabs);
079
2021-08-14
op
TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
081
2021-01-02
op
if (!operating)
082
2021-01-02
op
tab->flags |= TAB_LAZY;
083
2021-08-14
op
load_url_in_tab(tab, url, base, 0);
084
2021-01-02
op
switch_to_tab(tab);
085
2021-08-14
op
return tab;
089
2022-01-05
op
* Move a tab from the tablist to the killed tab list and erase its
090
2022-01-06
op
* contents. Append should always be 0 to prepend tabs so unkill_tab
091
2022-01-06
op
* can work correctly; appending is only useful during startup when
092
2022-01-06
op
* receiving the list of killed tabs to keep the correct order.
093
2022-01-06
op
* NB: doesn't update the current_tab.
096
2022-01-06
op
kill_tab(struct tab *tab, int append)
098
2022-01-05
op
int count;
100
2021-08-14
op
stop_tab(tab);
101
2022-01-05
op
erase_buffer(&tab->buffer);
102
2022-01-05
op
TAILQ_REMOVE(&tabshead, tab, tabs);
103
2021-08-18
op
ui_schedule_redraw();
104
2021-08-14
op
autosave_hook();
106
2021-08-14
op
if (evtimer_pending(&tab->loadingev, NULL))
107
2021-08-14
op
evtimer_del(&tab->loadingev);
109
2022-01-06
op
if (append)
110
2022-01-06
op
TAILQ_INSERT_TAIL(&ktabshead, tab, tabs);
112
2022-01-06
op
TAILQ_INSERT_HEAD(&ktabshead, tab, tabs);
114
2022-01-05
op
/* gc closed tabs */
115
2022-01-05
op
count = 0;
116
2022-01-05
op
TAILQ_FOREACH(tab, &ktabshead, tabs)
118
2022-01-05
op
while (count > max_killed_tabs) {
120
2022-01-05
op
free_tab(TAILQ_LAST(&ktabshead, tabshead));
125
2022-01-05
op
* Resurrects the lastest killed tab and returns it. The tab is already
126
2022-01-05
op
* added to the tab list with the TAB_LAZY flag set. NB: this doesn't
127
2022-01-05
op
* update current_tab.
129
2022-01-05
op
struct tab *
130
2022-01-05
op
unkill_tab(void)
132
2022-01-05
op
struct tab *t;
134
2022-01-05
op
if (TAILQ_EMPTY(&ktabshead))
135
2022-01-05
op
return NULL;
137
2022-01-13
op
ui_schedule_redraw();
138
2022-01-05
op
autosave_hook();
140
2022-01-05
op
t = TAILQ_FIRST(&ktabshead);
141
2022-01-05
op
TAILQ_REMOVE(&ktabshead, t, tabs);
142
2022-01-05
op
TAILQ_INSERT_TAIL(&tabshead, t, tabs);
143
2022-01-05
op
t->flags |= TAB_LAZY;
144
2022-01-05
op
return t;
148
2022-01-05
op
* Free every resource linked to the tab, including the tab itself, and
149
2022-01-05
op
* removes it from the *killed* tablist.
152
2022-01-05
op
free_tab(struct tab *tab)
154
2022-01-05
op
TAILQ_REMOVE(&ktabshead, tab, tabs);
155
2022-01-05
op
hist_clear(&tab->hist);
156
2021-08-14
op
free(tab);
160
2021-08-14
op
stop_tab(struct tab *tab)
162
2021-08-14
op
ui_send_net(IMSG_STOP, tab->id, NULL, 0);
165
2022-01-05
op
static inline void
166
2022-04-24
op
savetab(FILE *fp, struct tab *tab, int killed)
168
2022-04-24
op
struct hist *h;
169
2022-04-24
op
size_t top_line, current_line;
170
2022-04-24
op
int future;
172
2022-04-24
op
get_scroll_position(tab, &top_line, ¤t_line);
174
2022-04-24
op
fprintf(fp, "%s ", tab->hist_cur->h);
175
2022-01-05
op
if (tab == current_tab)
176
2022-04-24
op
fprintf(fp, "current,");
177
2022-01-05
op
if (killed)
178
2022-04-24
op
fprintf(fp, "killed,");
180
2022-04-24
op
fprintf(fp, "top=%zu,cur=%zu %s\n", top_line, current_line,
181
2022-04-24
op
tab->buffer.page.title);
183
2022-01-05
op
future = 0;
184
2022-01-05
op
TAILQ_FOREACH(h, &tab->hist.head, entries) {
185
2022-01-05
op
if (h == tab->hist_cur) {
186
2022-01-05
op
future = 1;
187
2022-01-05
op
continue;
190
2022-04-24
op
fprintf(fp, "%s %s\n", future ? ">" : "<", h->h);
194
2022-05-11
op
static void
195
2022-05-11
op
save_tabs(void)
197
2022-05-11
op
FILE *fp;
198
2022-04-24
op
struct tab *tab;
199
2022-05-11
op
int fd, err;
200
2022-04-24
op
char sfn[PATH_MAX];
202
2022-04-24
op
strlcpy(sfn, session_file_tmp, sizeof(sfn));
203
2022-04-24
op
if ((fd = mkstemp(sfn)) == -1 ||
204
2022-05-11
op
(fp = fdopen(fd, "w")) == NULL) {
205
2022-04-24
op
if (fd != -1) {
206
2022-04-24
op
unlink(sfn);
207
2022-04-24
op
close(fd);
212
2022-01-05
op
TAILQ_FOREACH(tab, &tabshead, tabs)
213
2022-05-11
op
savetab(fp, tab, 0);
214
2022-01-05
op
TAILQ_FOREACH(tab, &ktabshead, tabs)
215
2022-05-11
op
savetab(fp, tab, 1);
217
2022-05-11
op
err = fflush(fp) == EOF;
218
2022-05-11
op
fclose(fp);
220
2022-05-11
op
if (err || rename(sfn, session_file) == -1)
221
2022-04-24
op
unlink(sfn);
224
2022-05-11
op
static void
225
2022-05-11
op
save_all_history(void)
227
2022-05-11
op
FILE *fp;
228
2022-05-11
op
size_t i;
229
2022-05-11
op
int fd, err;
230
2022-05-11
op
char sfn[PATH_MAX];
232
2022-05-11
op
strlcpy(sfn, history_file_tmp, sizeof(sfn));
233
2022-05-11
op
if ((fd = mkstemp(sfn)) == -1 ||
234
2022-05-11
op
(fp = fdopen(fd, "w")) == NULL) {
235
2022-05-11
op
if (fd != -1) {
236
2022-05-11
op
unlink(sfn);
237
2022-05-11
op
close(fd);
242
2022-05-11
op
for (i = 0; i < history.len; ++i) {
243
2022-05-11
op
history.items[i].dirty = 0;
244
2022-05-11
op
fprintf(fp, "%lld %s\n", (long long)history.items[i].ts,
245
2022-05-11
op
history.items[i].uri);
248
2022-05-11
op
err = fflush(fp) == EOF;
249
2022-05-11
op
fclose(fp);
251
2022-05-11
op
if (err || rename(sfn, history_file) == -1) {
252
2022-05-11
op
unlink(sfn);
256
2022-05-11
op
history.dirty = 0;
257
2022-05-11
op
history.extra = 0;
260
2022-05-11
op
static void
261
2022-05-11
op
save_dirty_history(void)
263
2022-05-11
op
FILE *fp;
264
2022-05-11
op
size_t i;
266
2022-05-11
op
if ((fp = fopen(history_file, "a")) == NULL)
269
2022-05-11
op
for (i = 0; i < history.len && history.dirty > 0; ++i) {
270
2022-05-11
op
if (!history.items[i].dirty)
271
2022-05-11
op
continue;
272
2022-05-11
op
history.dirty--;
273
2022-05-11
op
history.items[i].dirty = 0;
274
2022-05-11
op
fprintf(fp, "%lld %s\n", (long long)history.items[i].ts,
275
2022-05-11
op
history.items[i].uri);
277
2022-05-11
op
history.dirty = 0;
279
2022-05-11
op
fclose(fp);
283
2022-05-11
op
save_session(void)
285
2022-05-11
op
if (safe_mode)
288
2022-05-11
op
save_tabs();
290
2022-05-11
op
if (history.extra > HISTORY_CAP/2)
291
2022-05-11
op
save_all_history();
292
2022-05-11
op
else if (history.dirty)
293
2022-05-11
op
save_dirty_history();
297
2022-02-26
op
history_push(struct histitem *hi)
299
2022-02-26
op
size_t i, oldest = 0;
300
2022-02-26
op
char *uri;
302
2022-02-26
op
for (i = 0; i < history.len; ++i) {
303
2022-02-26
op
if (history.items[i].ts < history.items[oldest].ts)
304
2022-02-26
op
oldest = i;
306
2022-02-26
op
/* remove duplicates */
307
2022-02-26
op
if (!strcmp(history.items[i].uri, hi->uri))
311
2022-02-26
op
if ((uri = strdup(hi->uri)) == NULL)
314
2022-02-26
op
/* don't grow too much; replace the oldest */
315
2022-02-26
op
if (history.len == HISTORY_CAP) {
316
2022-02-26
op
history.items[oldest].ts = hi->ts;
317
2022-02-26
op
free(history.items[oldest].uri);
318
2022-02-26
op
history.items[oldest].uri = uri;
320
2022-05-11
op
/* Growed past the max value, signal to regen the file. */
321
2022-05-11
op
history.extra++;
325
2022-02-26
op
history.items[history.len].ts = hi->ts;
326
2022-02-26
op
history.items[history.len].uri = uri;
327
2022-02-26
op
history.len++;
330
2022-02-26
op
static int
331
2022-02-26
op
history_cmp(const void *a, const void *b)
333
2022-02-26
op
const struct history_item *i = a, *j = b;
334
2022-02-26
op
return strcmp(i->uri, j->uri);
338
2022-02-26
op
history_sort(void)
340
2022-02-26
op
qsort(history.items, history.len, sizeof(history.items[0]),
341
2022-02-26
op
history_cmp);
345
2022-02-26
op
history_add(const char *uri)
347
2022-02-26
op
size_t i, j, insert = 0, oldest = 0;
351
2022-02-26
op
for (i = 0; i < history.len; ++i) {
352
2022-02-26
op
if (history.items[i].ts < history.items[oldest].ts)
353
2022-02-26
op
oldest = i;
355
2022-02-26
op
if (insert != 0 && insert < i)
356
2022-02-26
op
continue;
358
2022-02-26
op
c = strcmp(uri, history.items[i].uri);
359
2022-02-26
op
if (c == 0) {
360
2022-02-26
op
history.items[i].ts = time(NULL);
361
2022-02-26
op
history.items[i].dirty = 1;
362
2022-02-26
op
history.dirty++;
363
2022-02-26
op
autosave_hook();
367
2022-02-26
op
if (c > 0)
368
2022-02-26
op
insert = i;
371
2022-02-26
op
if ((u = strdup(uri)) == NULL)
374
2022-02-26
op
/* if history is full, replace the oldest one */
375
2022-02-26
op
if (history.len == HISTORY_CAP) {
376
2022-02-26
op
free(history.items[oldest].uri);
377
2022-02-26
op
history.items[oldest].uri = u;
378
2022-02-26
op
history.items[oldest].ts = time(NULL);
379
2022-02-26
op
history.items[oldest].dirty = 1;
380
2022-02-26
op
history.dirty++;
381
2022-02-26
op
history_sort();
382
2022-02-26
op
autosave_hook();
386
2022-02-26
op
/* otherwise just insert in the right spot */
388
2022-02-26
op
for (j = history.len; j > insert; --j)
389
2022-02-26
op
memcpy(&history.items[j], &history.items[j-1],
390
2022-02-26
op
sizeof(history.items[j]));
392
2022-02-26
op
history.items[insert].ts = time(NULL);
393
2022-02-26
op
history.items[insert].uri = u;
394
2022-02-26
op
history.items[insert].dirty = 1;
395
2022-02-26
op
history.dirty++;
396
2022-02-26
op
history.len++;
397
2022-02-26
op
autosave_hook();
401
2021-08-14
op
autosave_init(void)
403
2021-08-14
op
evtimer_set(&autosaveev, autosave_timer, NULL);
407
2021-08-14
op
autosave_timer(int fd, short event, void *data)
409
2021-08-14
op
save_session();
413
2021-08-14
op
* Function to be called in "interesting" places where we may want to
414
2021-08-14
op
* schedule an autosave (like on new tab or before loading an url.)
417
2021-08-14
op
autosave_hook(void)
419
2021-08-14
op
struct timeval tv;
421
2021-08-14
op
if (autosave <= 0)
424
2021-08-14
op
if (!evtimer_pending(&autosaveev, NULL)) {
425
2021-08-14
op
tv.tv_sec = autosave;
426
2021-08-14
op
tv.tv_usec = 0;
428
2021-08-14
op
evtimer_add(&autosaveev, &tv);
432
2022-04-24
op
static inline int
433
2022-04-24
op
parse_khost_line(char *line, char *tmp[3])
435
2022-04-24
op
char **ap;
437
2022-04-24
op
for (ap = tmp; ap < &tmp[3] &&
438
2022-04-24
op
(*ap = strsep(&line, " \t\n")) != NULL;) {
439
2022-04-24
op
if (**ap != '\0')
443
2022-04-24
op
return ap == &tmp[3] && *line == '\0';
446
2022-04-24
op
static void
447
2022-04-24
op
load_certs(struct ohash *certs)
449
2022-04-24
op
char *tmp[3], *line = NULL;
450
2022-04-24
op
const char *errstr;
451
2022-04-24
op
size_t lineno = 0, linesize = 0;
452
2022-04-24
op
ssize_t linelen;
454
2022-04-24
op
struct tofu_entry *e;
456
2022-04-24
op
if ((f = fopen(known_hosts_file, "r")) == NULL)
459
2022-04-24
op
if ((e = calloc(1, sizeof(*e))) == NULL) {
460
2022-04-24
op
fclose(f);
464
2022-04-24
op
while ((linelen = getline(&line, &linesize, f)) != -1) {
465
2022-04-24
op
lineno++;
467
2022-04-24
op
if (parse_khost_line(line, tmp)) {
468
2022-04-24
op
strlcpy(e->domain, tmp[0], sizeof(e->domain));
469
2022-04-24
op
strlcpy(e->hash, tmp[1], sizeof(e->hash));
471
2022-04-24
op
e->verified = strtonum(tmp[2], 0, 1, &errstr);
472
2022-04-24
op
if (errstr != NULL)
473
2022-04-24
op
errx(1, "%s:%zu verification for %s is %s: %s",
474
2022-04-24
op
known_hosts_file, lineno,
475
2022-04-24
op
e->domain, errstr, tmp[2]);
477
2022-04-24
op
tofu_add(certs, e);
479
2022-04-24
op
warnx("%s:%zu invalid entry",
480
2022-04-24
op
known_hosts_file, lineno);
483
2022-04-24
op
free(line);
484
2022-04-24
op
fclose(f);
489
2022-04-24
op
static void
490
2022-04-24
op
load_hist(void)
492
2022-04-24
op
FILE *hist;
493
2022-04-24
op
size_t linesize = 0;
494
2022-04-24
op
ssize_t linelen;
495
2022-04-24
op
char *nl, *spc, *line = NULL;
496
2022-04-24
op
const char *errstr;
497
2022-04-24
op
struct histitem hi;
499
2022-04-24
op
if ((hist = fopen(history_file, "r")) == NULL)
502
2022-04-24
op
while ((linelen = getline(&line, &linesize, hist)) != -1) {
503
2022-04-24
op
if ((nl = strchr(line, '\n')) != NULL)
504
2022-04-24
op
*nl = '\0';
505
2022-04-24
op
if ((spc = strchr(line, ' ')) == NULL)
506
2022-04-24
op
continue;
507
2022-04-24
op
*spc = '\0';
510
2022-04-24
op
memset(&hi, 0, sizeof(hi));
511
2022-04-24
op
hi.ts = strtonum(line, INT64_MIN, INT64_MAX, &errstr);
512
2022-04-24
op
if (errstr != NULL)
513
2022-04-24
op
continue;
514
2022-04-24
op
if (strlcpy(hi.uri, spc, sizeof(hi.uri)) >= sizeof(hi.uri))
515
2022-04-24
op
continue;
517
2022-04-24
op
history_push(&hi);
520
2022-04-24
op
fclose(hist);
521
2022-04-24
op
free(line);
523
2022-04-24
op
history_sort();
527
2022-04-24
op
* Check if the last time telescope crashed. The check is done by
528
2022-04-24
op
* looking at `crashed_file': if it exists then last time we crashed.
529
2022-04-24
op
* Then, while here, touch the file too, it's removed during the
530
2022-04-24
op
* teardown.
532
2022-04-24
op
static int
533
2022-04-24
op
last_time_crashed(void)
535
2022-04-24
op
int fd, crashed = 1;
537
2022-04-24
op
if (safe_mode)
538
2022-04-24
op
return 0;
540
2022-04-24
op
if (unlink(crashed_file) == -1 && errno == ENOENT)
541
2022-04-24
op
crashed = 0;
543
2022-04-24
op
if ((fd = open(crashed_file, O_CREAT|O_WRONLY, 0600)) == -1)
544
2022-04-24
op
return crashed;
545
2022-04-24
op
close(fd);
547
2022-04-24
op
return crashed;
551
2022-04-24
op
* Parse and restore a tab from the session file. The format is:
553
2022-04-24
op
* URL [flags,...] [title]\n
555
2022-04-24
op
static inline struct tab *
556
2022-04-24
op
parse_tab_line(char *line, struct tab **ct)
558
2022-04-24
op
struct tab *tab;
559
2022-04-24
op
char *s, *t, *ap;
560
2022-04-24
op
const char *uri, *title = "";
561
2022-04-24
op
int current = 0, killed = 0;
562
2022-04-24
op
size_t tline = 0, cline = 0;
564
2022-04-24
op
uri = line;
565
2022-04-24
op
if ((s = strchr(line, ' ')) == NULL)
566
2022-04-24
op
return NULL;
567
2022-04-24
op
*s++ = '\0';
569
2022-04-24
op
if ((t = strchr(s, ' ')) != NULL) {
570
2022-04-24
op
*t++ = '\0';
571
2022-04-24
op
title = t;
574
2022-04-24
op
while ((ap = strsep(&s, ",")) != NULL) {
575
2022-04-24
op
if (!strcmp(ap, "current"))
576
2022-04-24
op
current = 1;
577
2022-04-24
op
else if (!strcmp(ap, "killed"))
578
2022-04-24
op
killed = 1;
579
2022-04-24
op
else if (!strncmp(ap, "top=", 4))
580
2022-04-24
op
tline = strtonum(ap+4, 0, UINT32_MAX, NULL);
581
2022-04-24
op
else if (!strncmp(ap, "cur=", 4))
582
2022-04-24
op
cline = strtonum(ap + 4, 0, UINT32_MAX, NULL);
585
2022-04-24
op
if (tline > cline) {
586
2022-04-24
op
tline = 0;
587
2022-04-24
op
cline = 0;
590
2022-04-24
op
if ((tab = new_tab(uri, NULL, NULL)) == NULL)
591
2022-04-24
op
err(1, "new_tab");
592
2022-04-24
op
tab->hist_cur->line_off = tline;
593
2022-04-24
op
tab->hist_cur->current_off = cline;
594
2022-04-24
op
strlcpy(tab->buffer.page.title, title, sizeof(tab->buffer.page.title));
596
2022-04-24
op
if (current)
597
2022-04-24
op
*ct = tab;
598
2022-04-24
op
else if (killed)
599
2022-04-24
op
kill_tab(tab, 1);
601
2022-04-24
op
return tab;
604
2022-04-24
op
static void
605
2022-04-24
op
load_tabs(void)
607
2022-04-24
op
struct tab *tab = NULL, *ct = NULL;
608
2022-04-24
op
struct hist *h;
609
2022-04-24
op
FILE *session;
610
2022-04-24
op
size_t lineno = 0, linesize = 0;
611
2022-04-24
op
ssize_t linelen;
612
2022-04-24
op
char *uri, *line = NULL;
614
2022-04-24
op
if ((session = fopen(session_file, "r")) == NULL) {
615
2022-04-24
op
new_tab("about:new", NULL, NULL);
616
2022-04-24
op
new_tab("about:help", NULL, NULL);
620
2022-04-24
op
while ((linelen = getline(&line, &linesize, session)) != -1) {
621
2022-04-24
op
lineno++;
623
2022-04-24
op
if (linelen > 0 && line[linelen-1] == '\n')
624
2022-04-24
op
line[linelen-1] = '\0';
626
2022-04-24
op
if (*line == '<' || *line == '>') {
627
2022-04-24
op
uri = line + 1;
628
2022-04-24
op
if (*uri != ' ' || tab == NULL) {
629
2022-04-24
op
fprintf(stderr, "%s:%zu invalid line\n",
630
2022-04-24
op
session_file, lineno);
631
2022-04-24
op
continue;
635
2022-04-24
op
if ((h = calloc(1, sizeof(*h))) == NULL)
636
2022-04-24
op
err(1, "calloc");
637
2022-04-24
op
strlcpy(h->h, uri, sizeof(h->h));
639
2022-04-24
op
if (*line == '>') /* future hist */
640
2022-04-24
op
hist_push(&tab->hist, h);
642
2022-04-24
op
hist_add_before(&tab->hist, tab->hist_cur, h);
644
2022-04-24
op
tab = parse_tab_line(line, &ct);
647
2022-04-24
op
fclose(session);
648
2022-04-24
op
free(line);
650
2022-04-24
op
if (ct == NULL || TAILQ_EMPTY(&tabshead))
651
2022-04-24
op
ct = new_tab("about:new", NULL, NULL);
653
2022-04-24
op
switch_to_tab(ct);
655
2022-04-24
op
if (last_time_crashed())
656
2022-04-24
op
new_tab("about:crash", NULL, NULL);
660
2022-04-24
op
load_session(struct ohash *certs)
662
2022-04-24
op
load_certs(certs);
663
2022-04-24
op
load_hist();
664
2022-04-24
op
load_tabs();
665
2022-04-24
op
return 0;
669
2022-04-24
op
lock_session(void)
671
2022-04-24
op
struct flock lock;
674
2022-04-24
op
if ((fd = open(lockfile_path, O_WRONLY|O_CREAT, 0600)) == -1)
675
2022-04-24
op
return -1;
677
2022-04-24
op
lock.l_start = 0;
678
2022-04-24
op
lock.l_len = 0;
679
2022-04-24
op
lock.l_type = F_WRLCK;
680
2022-04-24
op
lock.l_whence = SEEK_SET;
682
2022-04-24
op
if (fcntl(fd, F_SETLK, &lock) == -1) {
683
2022-04-24
op
close(fd);
684
2022-04-24
op
return -1;
687
2022-04-24
op
return fd;