Open sockets, files etc with FD_CLOEXEC

This commit is contained in:
Daniel Eklöf 2024-10-23 09:36:59 +02:00
parent 650d1f13f9
commit a367895dc6
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
12 changed files with 32 additions and 32 deletions

View file

@ -112,13 +112,13 @@ readint_from_fd(int fd)
static int
initialize(struct private *m)
{
int backlight_fd = open("/sys/class/backlight", O_RDONLY);
int backlight_fd = open("/sys/class/backlight", O_RDONLY | O_CLOEXEC);
if (backlight_fd == -1) {
LOG_ERRNO("/sys/class/backlight");
return -1;
}
int base_dir_fd = openat(backlight_fd, m->device, O_RDONLY);
int base_dir_fd = openat(backlight_fd, m->device, O_RDONLY | O_CLOEXEC);
close(backlight_fd);
if (base_dir_fd == -1) {
@ -126,7 +126,7 @@ initialize(struct private *m)
return -1;
}
int max_fd = openat(base_dir_fd, "max_brightness", O_RDONLY);
int max_fd = openat(base_dir_fd, "max_brightness", O_RDONLY | O_CLOEXEC);
if (max_fd == -1) {
LOG_ERRNO("/sys/class/backlight/%s/max_brightness", m->device);
close(base_dir_fd);
@ -136,7 +136,7 @@ initialize(struct private *m)
m->max_brightness = readint_from_fd(max_fd);
close(max_fd);
int current_fd = openat(base_dir_fd, "brightness", O_RDONLY);
int current_fd = openat(base_dir_fd, "brightness", O_RDONLY | O_CLOEXEC);
close(base_dir_fd);
if (current_fd == -1) {