mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-05-06 06:46:29 -04:00
treewide: make more file descriptors cloexec
Avoid file descriptor leakage into child processes by marking them `O_CLOEXEC`.
This commit is contained in:
parent
8344117e7b
commit
ccfb61efa4
9 changed files with 11 additions and 11 deletions
|
|
@ -548,7 +548,7 @@ static int setup_socket(struct state *state)
|
||||||
struct ifreq req;
|
struct ifreq req;
|
||||||
struct props *p = &state->props;
|
struct props *p = &state->props;
|
||||||
|
|
||||||
fd = socket(AF_PACKET, SOCK_DGRAM|SOCK_NONBLOCK, htons(ETH_P_TSN));
|
fd = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, htons(ETH_P_TSN));
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
spa_log_error(state->log, "socket() failed: %m");
|
spa_log_error(state->log, "socket() failed: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
|
||||||
|
|
@ -2617,7 +2617,7 @@ static int sco_create_socket(struct impl *backend, struct spa_bt_adapter *adapte
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
bdaddr_t src;
|
bdaddr_t src;
|
||||||
|
|
||||||
spa_autoclose int sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET | SOCK_NONBLOCK, BTPROTO_SCO);
|
spa_autoclose int sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, BTPROTO_SCO);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
spa_log_error(backend->log, "socket(SEQPACKET, SCO) %s", strerror(errno));
|
spa_log_error(backend->log, "socket(SEQPACKET, SCO) %s", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
|
|
@ -758,7 +758,7 @@ static bool parse_clock_id(struct impl *this, const char *s)
|
||||||
|
|
||||||
static bool parse_clock_device(struct impl *this, const char *s)
|
static bool parse_clock_device(struct impl *this, const char *s)
|
||||||
{
|
{
|
||||||
int fd = open(s, O_RDONLY);
|
int fd = open(s, O_RDONLY | O_CLOEXEC);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
spa_log_info(this->log, "failed to open clock device '%s': %m", s);
|
spa_log_info(this->log, "failed to open clock device '%s': %m", s);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ static VkShaderModule createShaderModule(struct vulkan_compute_state *s, const c
|
||||||
int fd;
|
int fd;
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
|
|
||||||
if ((fd = open(shaderFile, 0, O_RDONLY)) == -1) {
|
if ((fd = open(shaderFile, 0, O_RDONLY | O_CLOEXEC)) == -1) {
|
||||||
spa_log_error(s->log, "can't open %s: %m", shaderFile);
|
spa_log_error(s->log, "can't open %s: %m", shaderFile);
|
||||||
return VK_NULL_HANDLE;
|
return VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ static int raw_make_socket(struct server *server, uint16_t type, const uint8_t m
|
||||||
struct packet_mreq mreq;
|
struct packet_mreq mreq;
|
||||||
struct sockaddr_ll sll;
|
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) {
|
if (fd < 0) {
|
||||||
pw_log_error("socket() failed: %m");
|
pw_log_error("socket() failed: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
@ -267,7 +267,7 @@ static int raw_stream_setup_socket(struct server *server, struct stream *stream)
|
||||||
char buf[128];
|
char buf[128];
|
||||||
struct ifreq req;
|
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) {
|
if (fd < 0) {
|
||||||
pw_log_error("socket() failed: %m");
|
pw_log_error("socket() failed: %m");
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ int main(int argc, char *argv[])
|
||||||
spa_assert_se(loop != NULL);
|
spa_assert_se(loop != NULL);
|
||||||
context = pw_context_new(pw_main_loop_get_loop(loop), NULL, 0);
|
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();
|
spa_assert_not_reached();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -286,7 +286,7 @@ int main(int argc, char *argv[])
|
||||||
int fds2[2];
|
int fds2[2];
|
||||||
struct pw_protocol_native_connection *in2, *out2;
|
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();
|
spa_assert_not_reached();
|
||||||
|
|
||||||
in2 = pw_protocol_native_connection_new(context, fds2[0]);
|
in2 = pw_protocol_native_connection_new(context, fds2[0]);
|
||||||
|
|
|
||||||
|
|
@ -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 ((str = pw_properties_get(sess->props, "source.ip")) == NULL) {
|
||||||
if (impl->ifname) {
|
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) {
|
if (fd >= 0) {
|
||||||
struct ifreq req;
|
struct ifreq req;
|
||||||
spa_zero(req);
|
spa_zero(req);
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ static void test_create(void)
|
||||||
|
|
||||||
unlink(temp);
|
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);
|
spa_assert_se(listen_fd >= 0);
|
||||||
|
|
||||||
sockaddr.sun_family = AF_UNIX;
|
sockaddr.sun_family = AF_UNIX;
|
||||||
|
|
|
||||||
|
|
@ -344,7 +344,7 @@ PWTEST(logger_debug_env_invalid)
|
||||||
/* The error message during pw_init() will go to stderr because no
|
/* The error message during pw_init() will go to stderr because no
|
||||||
* logger has been set up yet. Intercept that in our temp file */
|
* logger has been set up yet. Intercept that in our temp file */
|
||||||
pwtest_mkstemp(fname);
|
pwtest_mkstemp(fname);
|
||||||
fd = open(fname, O_RDWR);
|
fd = open(fname, O_RDWR | O_CLOEXEC);
|
||||||
pwtest_errno_ok(fd);
|
pwtest_errno_ok(fd);
|
||||||
rc = dup2(fd, STDERR_FILENO);
|
rc = dup2(fd, STDERR_FILENO);
|
||||||
setlinebuf(stderr);
|
setlinebuf(stderr);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue