aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2019-02-19 16:18:31 +0100
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-02-25 17:10:04 -0500
commit468d09b6641272d02ab80760fe0a55e8aab03c2e (patch)
tree8cc12e6202d5100f72f379ebce368a154b2b0e59
parentAdd 'visible' key to view json response (diff)
downloadsway-468d09b6641272d02ab80760fe0a55e8aab03c2e.tar.gz
sway-468d09b6641272d02ab80760fe0a55e8aab03c2e.tar.zst
sway-468d09b6641272d02ab80760fe0a55e8aab03c2e.zip
Don't use SOCK_CLOEXEC
Manually set the CLOEXEC flag instead, since SOCK_CLOEXEC isn't POSIX.
-rw-r--r--sway/config/output.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index 513d03e0..e7fbad83 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -175,12 +175,33 @@ static void handle_swaybg_client_destroy(struct wl_listener *listener,
175 output->swaybg_client = NULL; 175 output->swaybg_client = NULL;
176} 176}
177 177
178static bool set_cloexec(int fd, bool cloexec) {
179 int flags = fcntl(fd, F_GETFD);
180 if (flags == -1) {
181 sway_log_errno(SWAY_ERROR, "fcntl failed");
182 return false;
183 }
184 if (cloexec) {
185 flags = flags | FD_CLOEXEC;
186 } else {
187 flags = flags & ~FD_CLOEXEC;
188 }
189 if (fcntl(fd, F_SETFD, flags) == -1) {
190 sway_log_errno(SWAY_ERROR, "fcntl failed");
191 return false;
192 }
193 return true;
194}
195
178static bool spawn_swaybg(struct sway_output *output, char *const cmd[]) { 196static bool spawn_swaybg(struct sway_output *output, char *const cmd[]) {
179 int sockets[2]; 197 int sockets[2];
180 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sockets) != 0) { 198 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0) {
181 sway_log_errno(SWAY_ERROR, "socketpair failed"); 199 sway_log_errno(SWAY_ERROR, "socketpair failed");
182 return false; 200 return false;
183 } 201 }
202 if (!set_cloexec(sockets[0], true) || !set_cloexec(sockets[1], true)) {
203 return false;
204 }
184 205
185 output->swaybg_client = wl_client_create(server.wl_display, sockets[0]); 206 output->swaybg_client = wl_client_create(server.wl_display, sockets[0]);
186 if (output->swaybg_client == NULL) { 207 if (output->swaybg_client == NULL) {
@@ -202,14 +223,7 @@ static bool spawn_swaybg(struct sway_output *output, char *const cmd[]) {
202 sway_log_errno(SWAY_ERROR, "fork failed"); 223 sway_log_errno(SWAY_ERROR, "fork failed");
203 exit(EXIT_FAILURE); 224 exit(EXIT_FAILURE);
204 } else if (pid == 0) { 225 } else if (pid == 0) {
205 // Remove the CLOEXEC flag 226 if (!set_cloexec(sockets[1], false)) {
206 int flags = fcntl(sockets[1], F_GETFD);
207 if (flags == -1) {
208 sway_log_errno(SWAY_ERROR, "fcntl() failed");
209 exit(EXIT_FAILURE);
210 }
211 if (fcntl(sockets[1], F_SETFD, flags & ~FD_CLOEXEC) == -1) {
212 sway_log_errno(SWAY_ERROR, "fcntl() failed");
213 exit(EXIT_FAILURE); 227 exit(EXIT_FAILURE);
214 } 228 }
215 229
@@ -225,6 +239,10 @@ static bool spawn_swaybg(struct sway_output *output, char *const cmd[]) {
225 exit(EXIT_SUCCESS); 239 exit(EXIT_SUCCESS);
226 } 240 }
227 241
242 if (close(sockets[1]) != 0) {
243 sway_log_errno(SWAY_ERROR, "close failed");
244 return false;
245 }
228 if (waitpid(pid, NULL, 0) < 0) { 246 if (waitpid(pid, NULL, 0) < 0) {
229 sway_log_errno(SWAY_ERROR, "waitpid failed"); 247 sway_log_errno(SWAY_ERROR, "waitpid failed");
230 return false; 248 return false;