GUAC-236: Acquire write lock on output file for in-progress screen recordings.

This commit is contained in:
Michael Jumper 2016-03-15 17:06:52 -07:00
parent c50561ef10
commit 0361dd2392

View File

@ -25,13 +25,14 @@
#include <guacamole/client.h> #include <guacamole/client.h>
#include <guacamole/socket.h> #include <guacamole/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <unistd.h>
#include <sys/types.h>
/** /**
* Attempts to open a new recording within the given path and having the given * Attempts to open a new recording within the given path and having the given
@ -105,6 +106,21 @@ static int guac_common_recording_open(const char* path,
} /* end if open succeeded */ } /* end if open succeeded */
/* Lock entire output file for writing by the current process */
struct flock file_lock = {
.l_type = F_WRLCK,
.l_whence = SEEK_SET,
.l_start = 0,
.l_len = 0,
.l_pid = getpid()
};
/* Abort if file cannot be locked for reading */
if (fcntl(fd, F_SETLK, &file_lock) == -1) {
close(fd);
return -1;
}
return fd; return fd;
} }