Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/io/io_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ bool ffSuppressIO(bool suppress)

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

Expand Down
4 changes: 2 additions & 2 deletions src/detection/battery/battery_nbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

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

prop_dictionary_t root = NULL;
if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &root) < 0)
Expand Down
4 changes: 2 additions & 2 deletions src/detection/battery/battery_obsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

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

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

struct apm_power_info info = {};

Expand Down
2 changes: 1 addition & 1 deletion src/detection/bootmgr/bootmgr_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

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

uint8_t buffer[2048];
Expand Down
2 changes: 1 addition & 1 deletion src/detection/brightness/brightness_obsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFl
for (char i = '0'; i <= '9'; ++i) {
path[strlen("/dev/ttyC")] = i;

FF_AUTO_CLOSE_FD int devfd = open(path, O_RDONLY);
FF_AUTO_CLOSE_FD int devfd = open(path, O_RDONLY | O_CLOEXEC);

if (devfd < 0) {
if (errno == EACCES && i == '0')
Expand Down
2 changes: 1 addition & 1 deletion src/detection/camera/camera_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const char* ffDetectCamera(FFlist* result)
for (uint32_t i = 0; i <= 9; ++i)
{
path[ARRAY_SIZE(path) - 2] = (char) (i + '0');
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0)
{
if (errno == ENOENT)
Expand Down
2 changes: 1 addition & 1 deletion src/detection/cpu/cpu_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ FF_MAYBE_UNUSED static const char* detectCPUX86(const FFCPUOptions* options, FFC

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

FF_AUTO_CLOSE_DIR DIR* dir = fdopendir(dfd);
Expand Down
4 changes: 2 additions & 2 deletions src/detection/cpu/cpu_nbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ static void freePropDict(prop_dictionary_t* pdict)

static const char* detectCpuTemp(double* current)
{
FF_AUTO_CLOSE_FD int fd = open(_PATH_SYSMON, O_RDONLY);
if (fd < 0) return "open(_PATH_SYSMON, O_RDONLY) failed";
FF_AUTO_CLOSE_FD int fd = open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC);
if (fd < 0) return "open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC) failed";

__attribute__((__cleanup__(freePropDict))) prop_dictionary_t root = NULL;
if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &root) < 0)
Expand Down
6 changes: 3 additions & 3 deletions src/detection/gpu/gpu_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static const char* detectByDrm(const FFGPUOptions* options, FFlist* gpus)
break;
}

FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) continue;

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

static const char* detectByPci(const FFGPUOptions* options, FFlist* gpus)
{
FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY, 0);
FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY | O_CLOEXEC, 0);
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, drop the redundant mode parameter (0) from open() when not creating a file.

Suggested change
FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY | O_CLOEXEC, 0);
FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY | O_CLOEXEC);

Copilot uses AI. Check for mistakes.
if (fd < 0)
return "open(\"/dev/pci\", O_RDONLY, 0) failed";
return "open(\"/dev/pci\", O_RDONLY | O_CLOEXEC, 0) failed";

struct pci_conf confs[128];
struct pci_match_conf match = {
Expand Down
4 changes: 2 additions & 2 deletions src/detection/gpu/gpu_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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

uint32_t value;
Expand Down Expand Up @@ -85,7 +85,7 @@ const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, con
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_query_heap_info)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, amdgpu_device_deinitialize)

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

amdgpu_device_handle handle;
Expand Down
2 changes: 1 addition & 1 deletion src/detection/gpu/gpu_haiku.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus)
{
FF_AUTO_CLOSE_FD int pokefd = open(POKE_DEVICE_FULLNAME, O_RDWR);
FF_AUTO_CLOSE_FD int pokefd = open(POKE_DEVICE_FULLNAME, O_RDWR | O_CLOEXEC);
if (pokefd < 0) return "open(POKE_DEVICE_FULLNAME) failed";

pci_info dev;
Expand Down
4 changes: 2 additions & 2 deletions src/detection/gpu/gpu_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey,
#if FF_HAVE_DRM
ffStrbufSetS(buffer, "/dev/dri/");
ffStrbufAppendS(buffer, drmKey);
FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY);
FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY | O_CLOEXEC);
if (fd < 0) return "Failed to open drm device";

if (ffStrbufEqualS(&gpu->driver, "xe"))
Expand Down Expand Up @@ -412,7 +412,7 @@ FF_MAYBE_UNUSED static const char* drmDetectAsahiSpecific(FFGPUResult* gpu, cons
#if FF_HAVE_DRM_ASAHI
ffStrbufSetS(buffer, "/dev/dri/");
ffStrbufAppendS(buffer, drmKey);
FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY);
FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
return ffDrmDetectAsahi(gpu, fd);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/detection/physicaldisk/physicaldisk_haiku.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

static const char* detectDisk(FFstrbuf* path, const char* diskType, FFlist* result)
{
FF_AUTO_CLOSE_FD int rawfd = open(path->chars, O_RDONLY);
FF_AUTO_CLOSE_FD int rawfd = open(path->chars, O_RDONLY | O_CLOEXEC);
if (rawfd < 0) return "detectDisk: open(rawfd) failed";

device_geometry geometry;
Expand Down
2 changes: 1 addition & 1 deletion src/detection/sound/sound_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const char* ffDetectSound(FFlist* devices)
for (int idev = 0; idev <= info.nummixers; ++idev)
{
path[strlen("/dev/mixer")] = (char) ('0' + idev);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR | O_CLOEXEC);
if (fd < 0) break;

if (idev == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/detection/sound/sound_nbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const char* ffDetectSound(FFlist* devices)
for (int idev = 0; idev < 9; ++idev)
{
path[strlen("/dev/audio")] = (char) ('0' + idev);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR | O_CLOEXEC);
if (fd < 0) break;

audio_device_t ad;
Expand Down
2 changes: 1 addition & 1 deletion src/util/binary_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const char* ffBinaryExtractStrings(const char* elfFile, bool (*cb)(const char* s
return "load libelf failed";

// Open the ELF file
FF_AUTO_CLOSE_FD int fd = open(elfFile, O_RDONLY, 0);
FF_AUTO_CLOSE_FD int fd = open(elfFile, O_RDONLY | O_CLOEXEC, 0);
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the unnecessary third mode argument (0) from this open() call since no O_CREAT flag is used.

Suggested change
FF_AUTO_CLOSE_FD int fd = open(elfFile, O_RDONLY | O_CLOEXEC, 0);
FF_AUTO_CLOSE_FD int fd = open(elfFile, O_RDONLY | O_CLOEXEC);

Copilot uses AI. Check for mistakes.
if (fd < 0) return "open() failed";

Elf* elf = elfData.ffelf_begin(fd, ELF_C_READ, NULL);
Expand Down
6 changes: 3 additions & 3 deletions src/util/smbiosHelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
}
FF_DEBUG("Parsed SMBIOS entry address: 0x%lx", (unsigned long)entryAddress);

FF_AUTO_CLOSE_FD int fd = open("/dev/mem", O_RDONLY);
FF_AUTO_CLOSE_FD int fd = open("/dev/mem", O_RDONLY | O_CLOEXEC);
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider introducing a small wrapper or macro for open-with-cloexec to reduce repetition and avoid forgetting the flag in future calls.

Suggested change
FF_AUTO_CLOSE_FD int fd = open("/dev/mem", O_RDONLY | O_CLOEXEC);
FF_AUTO_CLOSE_FD int fd = open_with_cloexec("/dev/mem", O_RDONLY);

Copilot uses AI. Check for mistakes.
if (fd < 0) {
FF_DEBUG("Failed to open /dev/mem: %s", strerror(errno));
return NULL;
Expand Down Expand Up @@ -219,7 +219,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
#endif
);

FF_AUTO_CLOSE_FD int fd = open("/dev/smbios", O_RDONLY);
FF_AUTO_CLOSE_FD int fd = open("/dev/smbios", O_RDONLY | O_CLOEXEC);
if (fd < 0) {
FF_DEBUG("Failed to open /dev/smbios: %s", strerror(errno));
return NULL;
Expand Down Expand Up @@ -328,7 +328,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
#else
"/dev/mem" // kern.securelevel must be -1
#endif
, O_RDONLY);
, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
FF_DEBUG("Failed to open memory device: %s", strerror(errno));
return NULL;
Expand Down
Loading