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
parent 8344117e7b
commit ccfb61efa4
9 changed files with 11 additions and 11 deletions

View file

@ -153,7 +153,7 @@ static int raw_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;
@ -267,7 +267,7 @@ static int raw_stream_setup_socket(struct server *server, struct stream *stream)
char buf[128];
struct ifreq req;
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

@ -263,7 +263,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;
}
@ -286,7 +286,7 @@ int main(int argc, char *argv[])
int fds2[2];
struct pw_protocol_native_connection *in2, *out2;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds2) < 0)
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds2) < 0)
spa_assert_not_reached();
in2 = pw_protocol_native_connection_new(context, fds2[0]);

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;