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
|
|
@ -36,6 +36,7 @@
|
|||
#include <sys/poll.h>
|
||||
|
||||
#include "wayland-util.h"
|
||||
#include "wayland-os.h"
|
||||
#include "wayland-client.h"
|
||||
#include "wayland-private.h"
|
||||
|
||||
|
|
@ -307,7 +308,7 @@ connect_to_socket(struct wl_display *display, const char *name)
|
|||
const char *runtime_dir;
|
||||
size_t name_size;
|
||||
|
||||
display->fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||
display->fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
|
||||
if (display->fd < 0)
|
||||
return -1;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue