commit - 7b4e4feb80bf2d3d829877aeabd4355677e8b8d2
commit + be97d6e6eed961ec5caf528306c94ffd55437328
blob - a654bc1709f8b481dd006a43944b44cc3c993c79
blob + f2c755588ed794e744644bee143216ebc661df94
--- fs.c
+++ fs.c
static void
handle_quit(struct imsg *imsg, size_t datalen)
{
+ unlink(crashed_file);
+
event_loopbreak();
}
+/*
+ * Check if the last time telescope crashed. The check is done by
+ * looking at `crashed_file': if it exists then last time we crashed.
+ * Then, while here, touch the file too. During IMSG_QUIT we'll
+ * remove it.
+ */
int
last_time_crashed(void)
{
- int fd;
-
- if ((fd = open(crashed_file, O_RDONLY)) == -1)
- return 0;
+ int fd, crashed = 1;
+ if (unlink(crashed_file) == -1 && errno == ENOENT)
+ crashed = 0;
+
+ if ((fd = open(crashed_file, O_CREAT|O_WRONLY, 0600)) == -1)
+ return crashed;
close(fd);
- unlink(crashed_file);
- return 1;
+
+ return crashed;
}
int
blob - cd954fb064de426894e1046005693ecee44b544b
blob + 0d78ae0872f40a846b77522681d4122160684ec7
--- telescope.c
+++ telescope.c
#include "compat.h"
#include <sys/socket.h>
+#include <sys/wait.h>
+#include <errno.h>
#include <getopt.h>
#include <signal.h>
#include <stdio.h>
main(int argc, char * const *argv)
{
struct imsgev net_ibuf, fs_ibuf;
+ pid_t pid;
int pipe2net[2], pipe2fs[2];
int ch, configtest = 0, fail = 0;
int has_url = 0;
int proc = -1;
int sessionfd;
+ int status;
char path[PATH_MAX];
const char *url = NEW_TAB_URL;
const char *argv0;
ui_send_net(IMSG_QUIT, 0, NULL, 0);
imsg_flush(&iev_fs->ibuf);
imsg_flush(&iev_net->ibuf);
+
+ /* wait for children to terminate */
+ do {
+ pid = wait(&status);
+ if (pid == -1) {
+ if (errno != EINTR && errno != ECHILD)
+ err(1, "wait");
+ } else if (WIFSIGNALED(status))
+ warnx("child terminated; signal %d", WTERMSIG(status));
+ } while (pid != -1 || (pid == -1 && errno == EINTR));
close(sessionfd);