summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/package.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2010-09-06 02:38:25 +0200
committerAdam Borowski <kilobyte@angband.pl>2010-09-06 02:38:25 +0200
commitb57f86755026f0eea077c763259e4a16c2ae0925 (patch)
tree1b852325d092658ae1fdf55d1a02ae791057840a /crawl-ref/source/package.cc
parenta16ef2ae22a9124bbe19495e301b86525946a7b3 (diff)
downloadcrawl-ref-b57f86755026f0eea077c763259e4a16c2ae0925.tar.gz
crawl-ref-b57f86755026f0eea077c763259e4a16c2ae0925.zip
Use file locking on the save file to prevent corruption from running Crawl twice.
This fixes Mantis 2061. I did not reuse the existing lk_open() because it's non-portable, waits for the lock to become available and works using FILE* not a descriptor (bad for random access).
Diffstat (limited to 'crawl-ref/source/package.cc')
-rw-r--r--crawl-ref/source/package.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/crawl-ref/source/package.cc b/crawl-ref/source/package.cc
index 23c5b6d368..2d505da240 100644
--- a/crawl-ref/source/package.cc
+++ b/crawl-ref/source/package.cc
@@ -38,6 +38,7 @@ Caveats/issues:
#include "package.h"
#include "endianness.h"
#include "errors.h"
+#include "syscalls.h"
#undef FSCK_VERBOSE
#undef COSTLY_ASSERTS
@@ -109,6 +110,9 @@ package::package(const char* file, bool writeable, bool empty)
if (fd == -1)
sysfail("can't open save file (%s)", file);
+ if (!lock_file(fd))
+ fail("Another game is already in progress using this save!");
+
file_header head;
ssize_t res = ::read(fd, &head, sizeof(file_header));
if (res < 0)