Skip to content

Commit 01118e2

Browse files
aescolarkartben
authored andcommitted
drivers can_native_linux: Set socket to be closed on exec
If the process does an exec() (or fork, or..) all descriptors are kept open by default, unless O_CLOEXEC is set for them. (This default behaviour is usefull for stdin/out/err so that new process is kept connected to them, but it is very rare for it to be usefull for any other descriptor) In general this leads to descriptors being kept open unnecessarily, which either will block other process from using them (for example if the child survives the parent but it does something else while keeping a port open). Or for a "leak" which unnecessarily uses descriptors and memory in the child process. Let's ensure we do not leak it for this component as we do not need it. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent a8f10c9 commit 01118e2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/can/can_native_linux_adapt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int linux_socketcan_iface_open(const char *if_name)
4747
struct ifreq ifr;
4848
int fd, opt, ret = -EINVAL;
4949

50-
fd = socket(PF_CAN, SOCK_RAW, CAN_RAW);
50+
fd = socket(PF_CAN, SOCK_RAW | SOCK_CLOEXEC, CAN_RAW);
5151
if (fd < 0) {
5252
return -errno;
5353
}

0 commit comments

Comments
 (0)