aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-02-20 11:08:34 -0500
committerGitHub <noreply@github.com>2019-02-20 11:08:34 -0500
commit18600f457be7a538e39914c37b72fee1a933ebe1 (patch)
tree0ed5fd18d49a97a33a0500604639e138be521aeb
parent50011e7170d1d6a58a6b1e4997da6ce105180481 (diff)
parentcfe7e28416323c1384b95a4eeb377c738444f063 (diff)
Merge pull request #1564 from emersion/remove-sock-cloexec
xwayland: remove remaining SOCK_CLOEXEC
-rw-r--r--xwayland/sockets.c36
-rw-r--r--xwayland/sockets.h1
-rw-r--r--xwayland/xwayland.c18
3 files changed, 28 insertions, 27 deletions
diff --git a/xwayland/sockets.c b/xwayland/sockets.c
index 112a8bb0..f90e3ca4 100644
--- a/xwayland/sockets.c
+++ b/xwayland/sockets.c
@@ -1,8 +1,4 @@
#define _POSIX_C_SOURCE 200809L
-#ifdef __FreeBSD__
-// for SOCK_CLOEXEC
-#define __BSD_VISIBLE 1
-#endif
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
@@ -25,31 +21,53 @@ static const char *socket_fmt = "/tmp/.X11-unix/X%d";
static const char *socket_fmt2 = "/tmp/.X11-unix/X%d_";
#endif
+bool set_cloexec(int fd, bool cloexec) {
+ int flags = fcntl(fd, F_GETFD);
+ if (flags == -1) {
+ wlr_log_errno(WLR_ERROR, "fcntl failed");
+ return false;
+ }
+ if (cloexec) {
+ flags = flags | FD_CLOEXEC;
+ } else {
+ flags = flags & ~FD_CLOEXEC;
+ }
+ if (fcntl(fd, F_SETFD, flags) == -1) {
+ wlr_log_errno(WLR_ERROR, "fcntl failed");
+ return false;
+ }
+ return true;
+}
+
static int open_socket(struct sockaddr_un *addr, size_t path_size) {
int fd, rc;
socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1;
- fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
- wlr_log_errno(WLR_DEBUG, "Failed to create socket %c%s",
+ wlr_log_errno(WLR_ERROR, "Failed to create socket %c%s",
addr->sun_path[0] ? addr->sun_path[0] : '@',
addr->sun_path + 1);
return -1;
}
+ if (!set_cloexec(fd, true)) {
+ close(fd);
+ return -1;
+ }
if (addr->sun_path[0]) {
unlink(addr->sun_path);
}
if (bind(fd, (struct sockaddr*)addr, size) < 0) {
rc = errno;
- wlr_log_errno(WLR_DEBUG, "Failed to bind socket %c%s",
+ wlr_log_errno(WLR_ERROR, "Failed to bind socket %c%s",
addr->sun_path[0] ? addr->sun_path[0] : '@',
addr->sun_path + 1);
goto cleanup;
}
if (listen(fd, 1) < 0) {
rc = errno;
- wlr_log_errno(WLR_DEBUG, "Failed to listen to socket %c%s",
+ wlr_log_errno(WLR_ERROR, "Failed to listen to socket %c%s",
addr->sun_path[0] ? addr->sun_path[0] : '@',
addr->sun_path + 1);
goto cleanup;
@@ -67,7 +85,7 @@ cleanup:
}
static bool open_sockets(int socks[2], int display) {
- struct sockaddr_un addr = { .sun_family = AF_LOCAL };
+ struct sockaddr_un addr = { .sun_family = AF_UNIX };
size_t path_size;
mkdir(socket_dir, 0777);
diff --git a/xwayland/sockets.h b/xwayland/sockets.h
index 73eb36e0..cf42b970 100644
--- a/xwayland/sockets.h
+++ b/xwayland/sockets.h
@@ -1,6 +1,7 @@
#ifndef XWAYLAND_SOCKETS_H
#define XWAYLAND_SOCKETS_H
+bool set_cloexec(int fd, bool cloexec);
void unlink_display_sockets(int display);
int open_display_sockets(int socks[2]);
diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c
index be2e34d9..c01acb33 100644
--- a/xwayland/xwayland.c
+++ b/xwayland/xwayland.c
@@ -32,24 +32,6 @@ static void safe_close(int fd) {
}
}
-static bool set_cloexec(int fd, bool cloexec) {
- int flags = fcntl(fd, F_GETFD);
- if (flags == -1) {
- wlr_log_errno(WLR_ERROR, "fcntl failed");
- return false;
- }
- if (cloexec) {
- flags = flags | FD_CLOEXEC;
- } else {
- flags = flags & ~FD_CLOEXEC;
- }
- if (fcntl(fd, F_SETFD, flags) == -1) {
- wlr_log_errno(WLR_ERROR, "fcntl failed");
- return false;
- }
- return true;
-}
-
static int fill_arg(char ***argv, const char *fmt, ...) {
int len;
char **cur_arg = *argv;