Skip to content
Myr

main: open all FDs with O_CLOEXEC

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 1031211 · Browse files · 1 file+6 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−6 removed

  • other:+6 added−6 removed

1 file+6 added−6 removed

modified:main.c+6 added-6 removed
84 unmodified lines
85 LOG_WARN("failed to get cache directory: not saving popularity cache");86 return;87 }8889 int cache_dir_fd = open(path, O_DIRECTORY);89 int cache_dir_fd = open(path, O_DIRECTORY | O_CLOEXEC);90 if (cache_dir_fd == -1) {91 LOG_ERRNO("%s: failed to open", path);92 return;93 }9495 int fd = -1;96 if (fstatat(cache_dir_fd, "fuzzel", &st, 0) < 0 ||97 (fd = openat(cache_dir_fd, "fuzzel", O_RDONLY)) < 0 ||97 (fd = openat(cache_dir_fd, "fuzzel", O_RDONLY | O_CLOEXEC)) < 0 ||98 (f = fdopen(fd, "r")) == NULL)99 {100 close(cache_dir_fd);101 if (fd >= 0)
4 unmodified lines
106 return;107 }108 close(cache_dir_fd);109 } else {110 if (stat(path, &st) < 0 || (f = fopen(path, "r")) == NULL)110 if (stat(path, &st) < 0 || (f = fopen(path, "re")) == NULL)111 {112 if (errno != ENOENT)113 LOG_ERRNO("%s: failed to open", path);114 return;
97 unmodified lines
212 LOG_WARN("failed to get cache directory: not saving popularity cache");213 return;214 }215216 int cache_dir_fd = open(path, O_DIRECTORY);216 int cache_dir_fd = open(path, O_DIRECTORY | O_CLOEXEC);217 if (cache_dir_fd == -1) {218 LOG_ERRNO("%s: failed to open", path);219 return;220 }221222 fd = openat(cache_dir_fd, "fuzzel", O_WRONLY | O_CREAT | O_TRUNC, 0644);222 fd = openat(cache_dir_fd, "fuzzel", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);223 close(cache_dir_fd);224 } else {225 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);225 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);226 }227228 if (fd == -1) {229 LOG_ERRNO("%s/fuzzel: failed to open", path);
1841 unmodified lines