diff options
author | Mattias Andrée <maandree@member.fsf.org> | 2015-12-28 17:12:34 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@member.fsf.org> | 2015-12-28 17:12:34 +0100 |
commit | fc88512b5e985fc26ba4fb92b6b0bb19723524a3 (patch) | |
tree | 64412c7be3d381117b21c4caba294ceabbbc39a0 /src/satd-diminished.c | |
parent | that is why I used MSG_PEEK initially (diff) | |
download | sat-fc88512b5e985fc26ba4fb92b6b0bb19723524a3.tar.gz sat-fc88512b5e985fc26ba4fb92b6b0bb19723524a3.tar.bz2 sat-fc88512b5e985fc26ba4fb92b6b0bb19723524a3.tar.xz |
support recovering from a crash
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to '')
-rw-r--r-- | src/satd-diminished.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/satd-diminished.c b/src/satd-diminished.c index 7ab6478..7d18a27 100644 --- a/src/satd-diminished.c +++ b/src/satd-diminished.c @@ -37,6 +37,11 @@ */ #define STATE_FILENO 4 +/** + * The file descriptor for connection to the current client. + */ +#define CONN_FILENO 5 + /** * Command: queue a job. @@ -77,6 +82,13 @@ main(int argc, char *argv[]) pid_t pid; char type; const char *image; + struct stat _attr; + + /* Pick-up where we left off. */ + if (!fstat(CONN_FILENO, _attr)) { + fd = CONN_FILENO; + goto fork_again; + } accept_again: fd = accept(SOCK_FILENO, NULL, NULL); @@ -91,6 +103,11 @@ accept_again: goto fail; } } + if (fd != CONN_FILENO) { + if (dup2(fd, CONN_FILENO) == -1) + goto fail; + close(fd), fd = CONN_FILENO; + } fork_again: if (recv(fd, &type, (size_t)1, MSG_PEEK /* Just peek in case we fail! */) <= 0) { perror(argv[0]); |