treewide: make more file descriptors cloexec

Avoid file descriptor leakage into child processes by marking them `O_CLOEXEC`.
This commit is contained in:
Barnabás Pőcze 2025-10-28 20:03:13 +01:00 committed by Wim Taymans
parent 6ef23a1a9a
commit e5b741732d
9 changed files with 9 additions and 9 deletions

View file

@ -143,7 +143,7 @@ int avb_server_make_socket(struct server *server, uint16_t type, const uint8_t m
struct packet_mreq mreq;
struct sockaddr_ll sll;
fd = socket(AF_PACKET, SOCK_RAW|SOCK_NONBLOCK, htons(ETH_P_ALL));
fd = socket(AF_PACKET, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, htons(ETH_P_ALL));
if (fd < 0) {
pw_log_error("socket() failed: %m");
return -errno;

View file

@ -181,7 +181,7 @@ int main(int argc, char *argv[])
spa_assert_se(loop != NULL);
context = pw_context_new(pw_main_loop_get_loop(loop), NULL, 0);
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds) < 0) {
spa_assert_not_reached();
return -1;
}

View file

@ -880,7 +880,7 @@ static int send_sap(struct impl *impl, struct session *sess, bool bye)
if ((str = pw_properties_get(sess->props, "source.ip")) == NULL) {
if (impl->ifname) {
int fd = socket(impl->sap_addr.ss_family, SOCK_DGRAM, 0);
int fd = socket(impl->sap_addr.ss_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (fd >= 0) {
struct ifreq req;
spa_zero(req);

View file

@ -125,7 +125,7 @@ static void test_create(void)
unlink(temp);
listen_fd = socket(AF_UNIX, SOCK_STREAM, 0);
listen_fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
spa_assert_se(listen_fd >= 0);
sockaddr.sun_family = AF_UNIX;