commit 3e36ea51f650498b743754daa74d4aa039129956 from: Omar Polo date: Sun Apr 24 15:27:43 2022 UTC unbreak history file I can't use the ""generate temp file + rename" trick used for the session file, because I only add items that are not "dirty". the history-on-disk things needs some improvements, mostly to limitate the size of the file, but for the time being unbreak it! commit - 154fe22a526e064cce847afa71d8c833a008bd7d commit + 3e36ea51f650498b743754daa74d4aa039129956 blob - 29dd22293830349fed6858a83f1c516bd2b6862b blob + 23d9e0bb5edc8cc2d93bdb7ebb000798766902bb --- session.c +++ session.c @@ -194,7 +194,7 @@ savetab(FILE *fp, struct tab *tab, int killed) void save_session(void) { - FILE *tmp; + FILE *tmp, *hist; struct tab *tab; size_t i; int fd, err= 0; @@ -229,15 +229,8 @@ save_session(void) if (rename(sfn, session_file)) return; - strlcpy(sfn, history_file_tmp, sizeof(sfn)); - if ((fd = mkstemp(sfn)) == -1 || - (tmp = fdopen(fd, "w")) == NULL) { - if (fd != -1) { - unlink(sfn); - close(fd); - } + if ((hist = fopen(history_file, "a")) == NULL) return; - } if (history.dirty) { for (i = 0; i < history.len && history.dirty > 0; ++i) { @@ -246,22 +239,15 @@ save_session(void) history.dirty--; history.items[i].dirty = 0; - fprintf(tmp, "%lld %s\n", + fprintf(hist, "%lld %s\n", (long long)history.items[i].ts, history.items[i].uri); } history.dirty = 0; } - err = ferror(tmp); - fclose(tmp); - - if (err) { - unlink(sfn); - return; - } - - rename(sfn, history_file); + err = ferror(hist); + fclose(hist); } void