mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-20 05:33:47 -04:00
server: set CLOEXEC | NONBLOCK directly in socket() call
This commit is contained in:
parent
e1b6aa87fb
commit
a326427caf
1 changed files with 2 additions and 17 deletions
19
server.c
19
server.c
|
|
@ -225,22 +225,12 @@ try_connect(const char *sock_path)
|
||||||
{
|
{
|
||||||
enum connect_status ret = CONNECT_ERR;
|
enum connect_status ret = CONNECT_ERR;
|
||||||
|
|
||||||
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
LOG_ERRNO("failed to create UNIX socket");
|
LOG_ERRNO("failed to create UNIX socket");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use non-blocking, so that we don't get stuck in connect()
|
|
||||||
* waiting for a timeout */
|
|
||||||
int flags;
|
|
||||||
if ((flags = fcntl(fd, F_GETFL)) < 0 ||
|
|
||||||
fcntl(fd, F_SETFL, flags | O_NONBLOCK))
|
|
||||||
{
|
|
||||||
LOG_ERRNO("failed to set O_NONBLOCK");
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
||||||
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
|
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
|
||||||
|
|
||||||
|
|
@ -264,7 +254,7 @@ err:
|
||||||
struct server *
|
struct server *
|
||||||
server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl)
|
server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl)
|
||||||
{
|
{
|
||||||
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
LOG_ERRNO("failed to create UNIX socket");
|
LOG_ERRNO("failed to create UNIX socket");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -290,11 +280,6 @@ server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl)
|
||||||
|
|
||||||
unlink(sock_path);
|
unlink(sock_path);
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC) < 0) {
|
|
||||||
LOG_ERRNO("failed to set FD_CLOEXEC on socket");
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
||||||
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
|
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue