Skip to content

Commit 07987cc

Browse files
aescolarkartben
authored andcommitted
drivers/serial/uart_native_pty: Set PTY 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 when opening them. This is usefull for stdin/out/err so that new process is 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 getting them (for example if the child survives the parent but it does something else). 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 b850715 commit 07987cc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/serial/uart_native_pty_bottom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int np_uart_open_pty(const char *uart_name, const char *auto_attach_cmd,
139139
int ret;
140140
int flags;
141141

142-
master_pty = posix_openpt(O_RDWR | O_NOCTTY);
142+
master_pty = posix_openpt(O_RDWR | O_NOCTTY | O_CLOEXEC);
143143
if (master_pty == -1) {
144144
ERROR("Could not open a new PTY for the UART\n");
145145
}
@@ -214,7 +214,7 @@ int np_uart_open_pty(const char *uart_name, const char *auto_attach_cmd,
214214
* The connection of the client would cause the HUP flag to be
215215
* cleared, and in turn set again at disconnect.
216216
*/
217-
ret = open(slave_pty_name, O_RDWR | O_NOCTTY);
217+
ret = open(slave_pty_name, O_RDWR | O_NOCTTY | O_CLOEXEC);
218218
if (ret == -1) {
219219
err_nbr = errno;
220220
ERROR("%s: Could not open terminal from the slave side (%i,%s)\n",

0 commit comments

Comments
 (0)