mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-04 13:29:51 -05:00
os: wrap socket(SOCK_CLOEXEC) calls
Some system C libraries do not offer SOCK_CLOEXEC flag. Add a new header for OS compatibility wrappers. Wrap socket() calls into wl_os_socket_cloexec() which makes sure the O_CLOEXEC flag gets set on the file descriptor. On systems having SOCK_CLOEXEC this uses the old socket() call, and falls back if it fails due to the flag (kernel not supporting it). wayland-os.h is private and not exported. Add close-on-exec tests for both normal and forced fallback paths. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This commit is contained in:
parent
da6b1a8e47
commit
7134a439c1
7 changed files with 211 additions and 3 deletions
|
|
@ -44,6 +44,7 @@
|
|||
#include "wayland-private.h"
|
||||
#include "wayland-server.h"
|
||||
#include "wayland-server-protocol.h"
|
||||
#include "wayland-os.h"
|
||||
|
||||
struct wl_socket {
|
||||
int fd;
|
||||
|
|
@ -970,7 +971,7 @@ wl_display_add_socket(struct wl_display *display, const char *name)
|
|||
if (s == NULL)
|
||||
return -1;
|
||||
|
||||
s->fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||
s->fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
|
||||
if (s->fd < 0) {
|
||||
free(s);
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue