Skip to content

Commit 3291a99

Browse files
apocelipesCarterLi
authored andcommitted
Global: add missing O_CLOEXEC to open()
1 parent 68fd21d commit 3291a99

File tree

17 files changed

+26
-26
lines changed

17 files changed

+26
-26
lines changed

src/common/io/io_unix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ bool ffSuppressIO(bool suppress)
290290

291291
void listFilesRecursively(uint32_t baseLength, FFstrbuf* folder, uint8_t indentation, const char* folderName, bool pretty)
292292
{
293-
FF_AUTO_CLOSE_FD int dfd = open(folder->chars, O_RDONLY);
293+
FF_AUTO_CLOSE_FD int dfd = open(folder->chars, O_RDONLY | O_CLOEXEC);
294294
if (dfd < 0)
295295
return;
296296

src/detection/battery/battery_nbsd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* results)
1818
{
19-
FF_AUTO_CLOSE_FD int fd = open(_PATH_SYSMON, O_RDONLY);
20-
if (fd < 0) return "open(_PATH_SYSMON, O_RDONLY) failed";
19+
FF_AUTO_CLOSE_FD int fd = open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC);
20+
if (fd < 0) return "open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC) failed";
2121

2222
prop_dictionary_t root = NULL;
2323
if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &root) < 0)

src/detection/battery/battery_obsd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* result)
1010
{
11-
FF_AUTO_CLOSE_FD int devfd = open("/dev/apm", O_RDONLY);
11+
FF_AUTO_CLOSE_FD int devfd = open("/dev/apm", O_RDONLY | O_CLOEXEC);
1212

13-
if (devfd < 0) return "open(dev/apm, O_RDONLY) failed";
13+
if (devfd < 0) return "open(dev/apm, O_RDONLY | O_CLOEXEC) failed";
1414

1515
struct apm_power_info info = {};
1616

src/detection/bootmgr/bootmgr_bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
const char* ffDetectBootmgr(FFBootmgrResult* result)
2222
{
23-
FF_AUTO_CLOSE_FD int efifd = open("/dev/efi", O_RDWR);
23+
FF_AUTO_CLOSE_FD int efifd = open("/dev/efi", O_RDWR | O_CLOEXEC);
2424
if (efifd < 0) return "open(/dev/efi) failed";
2525

2626
uint8_t buffer[2048];

src/detection/brightness/brightness_obsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFl
1212
for (char i = '0'; i <= '9'; ++i) {
1313
path[strlen("/dev/ttyC")] = i;
1414

15-
FF_AUTO_CLOSE_FD int devfd = open(path, O_RDONLY);
15+
FF_AUTO_CLOSE_FD int devfd = open(path, O_RDONLY | O_CLOEXEC);
1616

1717
if (devfd < 0) {
1818
if (errno == EACCES && i == '0')

src/detection/camera/camera_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const char* ffDetectCamera(FFlist* result)
2020
for (uint32_t i = 0; i <= 9; ++i)
2121
{
2222
path[ARRAY_SIZE(path) - 2] = (char) (i + '0');
23-
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY);
23+
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
2424
if (fd < 0)
2525
{
2626
if (errno == ENOENT)

src/detection/cpu/cpu_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ FF_MAYBE_UNUSED static const char* detectCPUX86(const FFCPUOptions* options, FFC
474474

475475
static const char* detectPhysicalCores(FFCPUResult* cpu)
476476
{
477-
int dfd = open("/sys/devices/system/cpu/", O_RDONLY | O_DIRECTORY);
477+
int dfd = open("/sys/devices/system/cpu/", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
478478
if (dfd < 0) return "open(\"/sys/devices/system/cpu/\") failed";
479479

480480
FF_AUTO_CLOSE_DIR DIR* dir = fdopendir(dfd);

src/detection/cpu/cpu_nbsd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ static void freePropDict(prop_dictionary_t* pdict)
1818

1919
static const char* detectCpuTemp(double* current)
2020
{
21-
FF_AUTO_CLOSE_FD int fd = open(_PATH_SYSMON, O_RDONLY);
22-
if (fd < 0) return "open(_PATH_SYSMON, O_RDONLY) failed";
21+
FF_AUTO_CLOSE_FD int fd = open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC);
22+
if (fd < 0) return "open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC) failed";
2323

2424
__attribute__((__cleanup__(freePropDict))) prop_dictionary_t root = NULL;
2525
if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &root) < 0)

src/detection/gpu/gpu_bsd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static const char* detectByDrm(const FFGPUOptions* options, FFlist* gpus)
9696
break;
9797
}
9898

99-
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY);
99+
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
100100
if (fd < 0) continue;
101101

102102
char driverName[64];
@@ -147,9 +147,9 @@ static const char* detectByDrm(const FFGPUOptions* options, FFlist* gpus)
147147

148148
static const char* detectByPci(const FFGPUOptions* options, FFlist* gpus)
149149
{
150-
FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY, 0);
150+
FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY | O_CLOEXEC, 0);
151151
if (fd < 0)
152-
return "open(\"/dev/pci\", O_RDONLY, 0) failed";
152+
return "open(\"/dev/pci\", O_RDONLY | O_CLOEXEC, 0) failed";
153153

154154
struct pci_conf confs[128];
155155
struct pci_match_conf match = {

src/detection/gpu/gpu_drm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, const char* renderPath)
1818
{
19-
FF_AUTO_CLOSE_FD int fd = open(renderPath, O_RDONLY);
19+
FF_AUTO_CLOSE_FD int fd = open(renderPath, O_RDONLY | O_CLOEXEC);
2020
if (fd < 0) return "Failed to open DRM render device";
2121

2222
uint32_t value;
@@ -86,7 +86,7 @@ const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, con
8686
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_query_heap_info)
8787
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_device_deinitialize)
8888

89-
FF_AUTO_CLOSE_FD int fd = open(renderPath, O_RDONLY);
89+
FF_AUTO_CLOSE_FD int fd = open(renderPath, O_RDONLY | O_CLOEXEC);
9090
if (fd < 0) return "Failed to open DRM render device";
9191

9292
amdgpu_device_handle handle;

0 commit comments

Comments
 (0)