Skip to content

Commit dbd1681

Browse files
authored
linux: Open files with O_CLOEXEC to not leak fds to child processes (signal11#446)
Motivation described here: libusb/hidapi#446
1 parent 15a7114 commit dbd1681

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

linux/hid.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static int get_hid_report_descriptor(const char *rpt_path, struct hidraw_report_
384384
int rpt_handle;
385385
ssize_t res;
386386

387-
rpt_handle = open(rpt_path, O_RDONLY);
387+
rpt_handle = open(rpt_path, O_RDONLY | O_CLOEXEC);
388388
if (rpt_handle < 0) {
389389
register_global_error_format("open failed (%s): %s", rpt_path, strerror(errno));
390390
return -1;
@@ -473,7 +473,7 @@ static int parse_hid_vid_pid_from_uevent_path(const char *uevent_path, unsigned
473473
int handle;
474474
ssize_t res;
475475

476-
handle = open(uevent_path, O_RDONLY);
476+
handle = open(uevent_path, O_RDONLY | O_CLOEXEC);
477477
if (handle < 0) {
478478
register_global_error_format("open failed (%s): %s", uevent_path, strerror(errno));
479479
return 0;
@@ -981,7 +981,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
981981

982982
dev = new_hid_device();
983983

984-
dev->device_handle = open(path, O_RDWR);
984+
dev->device_handle = open(path, O_RDWR | O_CLOEXEC);
985985

986986
/* If we have a good handle, return it. */
987987
if (dev->device_handle >= 0) {

0 commit comments

Comments
 (0)