Commit Graph

13 Commits

Author SHA1 Message Date
Olivier Fourdan
dd00220b1e cursor/os-compatibility: handle EINTR gracefully
If os_resize_anonymous_file() called from os_create_anonymous_file()
fails with EINTR (Interrupted system call), then the buffer allocation
fails.

To avoid that, retry posix_fallocate() on EINTR.

However, in the presence of an alarm, the interrupt may trigger
repeatedly and prevent a large posix_fallocate() to ever complete
successfully, so we need to first block SIGALRM to prevent this.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2022-06-09 19:18:47 +00:00
Antonin Décimo
9434e8d69f Check that XDG base directories paths are absolute
The [spec][1] reads:

> All paths set in these environment variables must be absolute. If an
> implementation encounters a relative path in any of these variables it should
> consider the path invalid and ignore it.

and

> If $XDG_DATA_HOME is either not set or empty, a default equal to
> $HOME/.local/share should be used.

Testing that the path is absolute also entails that is is non-empty.

[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Signed-off-by: Antonin Décimo <antonin.decimo@gmail.com>
2022-06-09 18:34:17 +00:00
Simon Ser
f710d01663 cursor/os-compatibility: fix trailing space
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-06-04 22:58:50 +02:00
Simon Ser
0297c2c47a cursor/os-compatibility: remove strcpy/strcat usage
These functions don't perform bounds checking, so they are easy to
misuse and complicate audits.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-06-04 22:58:47 +02:00
Maxime Roussin-Bélanger
0f0951d5c4 cursor: fix typo "insufficent" 2020-12-17 16:03:14 -05:00
Jan Beich
230885ebb4 cursor/os-compatibility: move resizing into a separate function
Signed-off-by: Jan Beich <jbeich@FreeBSD.org>
2020-02-23 20:42:54 +00:00
Jan Beich
1283d54dac cursor: posix_fallocate may fail with EINVAL if not supported
ZFS on FreeBSD >= 12.0 returns EINVAL, see
https://svnweb.freebsd.org/changeset/base/325320

Signed-off-by: Jan Beich <jbeich@FreeBSD.org>
2020-02-23 20:42:54 +00:00
Ihor Antonov
8e2199644e os: fallback for unsupported posix_fallocate
Some filesystems do not support fallocate and return EOPNOTSUPP.

On musl-based distros libwayland-cursor exits abruptly which causes the
application to crash. Unlike glibc, musl does not provide a fallback
mechanism for handling unsupported fallocate. Instead, musl developers
argue that application should handle the case of unsupported system
call.

This commit allows falback to ftruncate in case when EOPNOTSUPP
was recieved.

Signed-off-by: Ihor Antonov <ihor@antonovs.family>
2020-01-23 20:32:59 +00:00
Emmanuel Gil Peyrot
6908c8c85a cursor: Use memfd_create() when available
This (so-far) Linux-only API lets users create file descriptors purely
in memory, without any backing file on the filesystem and the race
condition which could ensue when unlink()ing it.

It also allows seals to be placed on the file, ensuring to every other
process that we won’t be allowed to shrink the contents, potentially
causing a SIGBUS when they try reading it.

This patch is best viewed with the -w option of git log -p.

Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Reviewed-by: Simon Ser <contact@emersion.fr>
2019-07-21 09:06:43 +00:00
Derek Foreman
5c48aac33b cursor: Remove "weston" from anonymous shm filenames
This mildly confused me during some debugging, so I guess it wouldn't
hurt to make the filename more indicative of where it was actually
created.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Yong Bakos <ybakos@humanoriented.com>
Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2016-11-21 09:58:25 +00:00
Bryce Harrington
3540ea2b9f cursor: Update boilerplate from MIT X11 license to MIT Expat license
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-12 15:51:38 -07:00
Pekka Paalanen
011b695403 os: use posix_fallocate in creating sharable buffers
If posix_fallocate is available, use it instead of ftruncate. Unlike
ftruncate, when posix_fallocate succeeds, it guarantees that you cannot
run out of disk space, when later writing to the mmap()'ed file.

With posix_fallocate, if os_create_anonymous_file() succeeds, the
program cannot get a SIGBUS later from accessing this file via mmap. If
there is insufficient disk space, the function fails and errno is set to
ENOSPC.

This is useful on systems, that limit the available buffer space by
having XDG_RUNTIME_DIR on a small tmpfs.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-12-02 16:18:59 -08:00
Pekka Paalanen
a88a4386cb cursor: use os_create_anonymous_file()
Copy the implementation of os_create_anonymous_file() here from weston,
so we can use it instead of hardcoding a path to /tmp.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-07-10 14:08:59 -04:00