(ef_open): Lock the file. This prevents two programs (servers in
particular) running on the same game state. fairland does not use ef_open() at this time, and thus ignores the lock.
This commit is contained in:
parent
18417fdef6
commit
de124108de
1 changed files with 9 additions and 0 deletions
|
@ -66,6 +66,7 @@ int
|
||||||
ef_open(int type, int how)
|
ef_open(int type, int how)
|
||||||
{
|
{
|
||||||
struct empfile *ep;
|
struct empfile *ep;
|
||||||
|
struct flock lock;
|
||||||
int oflags, fd, fsiz, size;
|
int oflags, fd, fsiz, size;
|
||||||
|
|
||||||
if (ef_check(type) < 0)
|
if (ef_check(type) < 0)
|
||||||
|
@ -90,6 +91,14 @@ ef_open(int type, int how)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lock.l_type = how & EFF_RDONLY ? F_RDLCK : F_WRLCK;
|
||||||
|
lock.l_whence = SEEK_SET;
|
||||||
|
lock.l_start = lock.l_len = 0;
|
||||||
|
if (fcntl(fd, F_SETLK, &lock) == -1) {
|
||||||
|
logerror("Can't lock %s (%s)", ep->file, strerror(errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* get file size */
|
/* get file size */
|
||||||
fsiz = fsize(fd);
|
fsiz = fsize(fd);
|
||||||
if (fsiz % ep->size) {
|
if (fsiz % ep->size) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue