Skip to content

Commit

Permalink
Rename symbol set_cloexec to sway_set_cloexec, remove duplicates.
Browse files Browse the repository at this point in the history
set_cloexec is defined by both sway and wlroots (and who-knows-else),
so rename the sway one for supporting static linkage. We also remove
the duplicate version of this in client/.

Fixes: swaywm#4677
  • Loading branch information
sheenobu authored and ddevault committed Nov 1, 2019
1 parent cf95de9 commit 7efb5d4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 23 deletions.
16 changes: 2 additions & 14 deletions client/pool-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,7 @@
#include <wayland-client.h>
#include "config.h"
#include "pool-buffer.h"

static bool set_cloexec(int fd) {
long flags = fcntl(fd, F_GETFD);
if (flags == -1) {
return false;
}

if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) {
return false;
}

return true;
}
#include "util.h"

static int create_pool_file(size_t size, char **name) {
static const char template[] = "sway-client-XXXXXX";
Expand All @@ -46,7 +34,7 @@ static int create_pool_file(size_t size, char **name) {
return -1;
}

if (!set_cloexec(fd)) {
if (!sway_set_cloexec(fd, true)) {
close(fd);
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion common/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel)
return NULL;
}

bool set_cloexec(int fd, bool cloexec) {
bool sway_set_cloexec(int fd, bool cloexec) {
int flags = fcntl(fd, F_GETFD);
if (flags == -1) {
sway_log_errno(SWAY_ERROR, "fcntl failed");
Expand Down
2 changes: 1 addition & 1 deletion include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ float parse_float(const char *value);

const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel);

bool set_cloexec(int fd, bool cloexec);
bool sway_set_cloexec(int fd, bool cloexec);

#endif
4 changes: 2 additions & 2 deletions sway/config/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void invoke_swaybar(struct bar_config *bar) {
sway_log_errno(SWAY_ERROR, "socketpair failed");
return;
}
if (!set_cloexec(sockets[0], true) || !set_cloexec(sockets[1], true)) {
if (!sway_set_cloexec(sockets[0], true) || !sway_set_cloexec(sockets[1], true)) {
return;
}

Expand Down Expand Up @@ -222,7 +222,7 @@ static void invoke_swaybar(struct bar_config *bar) {
sway_log_errno(SWAY_ERROR, "fork failed");
_exit(EXIT_FAILURE);
} else if (pid == 0) {
if (!set_cloexec(sockets[1], false)) {
if (!sway_set_cloexec(sockets[1], false)) {
_exit(EXIT_FAILURE);
}

Expand Down
4 changes: 2 additions & 2 deletions sway/config/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ static bool _spawn_swaybg(char **command) {
sway_log_errno(SWAY_ERROR, "socketpair failed");
return false;
}
if (!set_cloexec(sockets[0], true) || !set_cloexec(sockets[1], true)) {
if (!sway_set_cloexec(sockets[0], true) || !sway_set_cloexec(sockets[1], true)) {
return false;
}

Expand All @@ -529,7 +529,7 @@ static bool _spawn_swaybg(char **command) {
sway_log_errno(SWAY_ERROR, "fork failed");
_exit(EXIT_FAILURE);
} else if (pid == 0) {
if (!set_cloexec(sockets[1], false)) {
if (!sway_set_cloexec(sockets[1], false)) {
_exit(EXIT_FAILURE);
}

Expand Down
6 changes: 3 additions & 3 deletions sway/swaynag.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool swaynag_spawn(const char *swaynag_command,
sway_log(SWAY_ERROR, "Failed to create pipe for swaynag");
return false;
}
if (!set_cloexec(swaynag->fd[1], true)) {
if (!sway_set_cloexec(swaynag->fd[1], true)) {
goto failed;
}
}
Expand All @@ -46,7 +46,7 @@ bool swaynag_spawn(const char *swaynag_command,
sway_log_errno(SWAY_ERROR, "socketpair failed");
goto failed;
}
if (!set_cloexec(sockets[0], true) || !set_cloexec(sockets[1], true)) {
if (!sway_set_cloexec(sockets[0], true) || !sway_set_cloexec(sockets[1], true)) {
goto failed;
}

Expand All @@ -69,7 +69,7 @@ bool swaynag_spawn(const char *swaynag_command,
sway_log_errno(SWAY_ERROR, "fork failed");
_exit(EXIT_FAILURE);
} else if (pid == 0) {
if (!set_cloexec(sockets[1], false)) {
if (!sway_set_cloexec(sockets[1], false)) {
_exit(EXIT_FAILURE);
}

Expand Down

0 comments on commit 7efb5d4

Please sign in to comment.