"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cursor/os-compatibility.c" between
wayland-1.17.0.tar.xz and wayland-1.18.0.tar.xz

About: Wayland is a computer display server protocol for a compositor to talk to its clients and a library for Linux implementing that protocol.

os-compatibility.c  (wayland-1.17.0.tar.xz):os-compatibility.c  (wayland-1.18.0.tar.xz)
skipping to change at line 28 skipping to change at line 28
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
#define _GNU_SOURCE #define _GNU_SOURCE
#include "config.h"
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "config.h" #ifdef HAVE_MEMFD_CREATE
#include <sys/mman.h>
#endif
#include "os-compatibility.h" #include "os-compatibility.h"
#ifndef HAVE_MKOSTEMP #ifndef HAVE_MKOSTEMP
static int static int
set_cloexec_or_close(int fd) set_cloexec_or_close(int fd)
{ {
long flags; long flags;
if (fd == -1) if (fd == -1)
return -1; return -1;
skipping to change at line 102 skipping to change at line 107
* *
* The file is suitable for buffer sharing between processes by * The file is suitable for buffer sharing between processes by
* transmitting the file descriptor over Unix sockets using the * transmitting the file descriptor over Unix sockets using the
* SCM_RIGHTS methods. * SCM_RIGHTS methods.
* *
* If the C library implements posix_fallocate(), it is used to * If the C library implements posix_fallocate(), it is used to
* guarantee that disk space is available for the file at the * guarantee that disk space is available for the file at the
* given size. If disk space is insufficent, errno is set to ENOSPC. * given size. If disk space is insufficent, errno is set to ENOSPC.
* If posix_fallocate() is not supported, program may receive * If posix_fallocate() is not supported, program may receive
* SIGBUS on accessing mmap()'ed file contents instead. * SIGBUS on accessing mmap()'ed file contents instead.
*
* If the C library implements memfd_create(), it is used to create the
* file purely in memory, without any backing file name on the file
* system, and then sealing off the possibility of shrinking it. This
* can then be checked before accessing mmap()'ed file contents, to
* make sure SIGBUS can't happen. It also avoids requiring
* XDG_RUNTIME_DIR.
*/ */
int int
os_create_anonymous_file(off_t size) os_create_anonymous_file(off_t size)
{ {
static const char template[] = "/wayland-cursor-shared-XXXXXX"; static const char template[] = "/wayland-cursor-shared-XXXXXX";
const char *path; const char *path;
char *name; char *name;
int fd; int fd;
int ret; int ret;
path = getenv("XDG_RUNTIME_DIR"); #ifdef HAVE_MEMFD_CREATE
if (!path) { fd = memfd_create("wayland-cursor", MFD_CLOEXEC | MFD_ALLOW_SEALING);
errno = ENOENT; if (fd >= 0) {
return -1; /* We can add this seal before calling posix_fallocate(), as
} * the file is currently zero-sized anyway.
*
name = malloc(strlen(path) + sizeof(template)); * There is also no need to check for the return value, we
if (!name) * couldn't do anything with it anyway.
return -1; */
fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL);
strcpy(name, path); } else
strcat(name, template); #endif
{
path = getenv("XDG_RUNTIME_DIR");
if (!path) {
errno = ENOENT;
return -1;
}
name = malloc(strlen(path) + sizeof(template));
if (!name)
return -1;
strcpy(name, path);
strcat(name, template);
fd = create_tmpfile_cloexec(name); fd = create_tmpfile_cloexec(name);
free(name); free(name);
if (fd < 0) if (fd < 0)
return -1; return -1;
}
#ifdef HAVE_POSIX_FALLOCATE #ifdef HAVE_POSIX_FALLOCATE
/*
* Filesystems that do support fallocate will return EOPNOTSUPP.
* In this case we need to fall back to ftruncate
*/
ret = posix_fallocate(fd, 0, size); ret = posix_fallocate(fd, 0, size);
if (ret != 0) { if (ret == 0) {
return fd;
} else if (ret != EOPNOTSUPP) {
close(fd); close(fd);
errno = ret; errno = ret;
return -1; return -1;
} }
#else #endif
ret = ftruncate(fd, size); ret = ftruncate(fd, size);
if (ret < 0) { if (ret < 0) {
close(fd); close(fd);
return -1; return -1;
} }
#endif
return fd; return fd;
} }
 End of changes. 11 change blocks. 
20 lines changed or deleted 51 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)