aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-04-03 12:35:57 +0200
committerGitHub <noreply@github.com>2024-04-03 12:35:57 +0200
commitab0d3c4098b6c3fba4de3d9eb46c8b0692db902f (patch)
tree2ddb512265a5dc3809a7e670f30edb3ca05cff0f /src
parente74cd1d9ffa935914905c6fc666c5bbf0cba36b7 (diff)
parentb400b947f3683036ce74f404a0daec3455bb7637 (diff)
downloadrneovim-ab0d3c4098b6c3fba4de3d9eb46c8b0692db902f.tar.gz
rneovim-ab0d3c4098b6c3fba4de3d9eb46c8b0692db902f.tar.bz2
rneovim-ab0d3c4098b6c3fba4de3d9eb46c8b0692db902f.zip
Merge pull request #28157 from fredizzimo/fsundvik/fix-io
fix: prevent child processes from inheriting ui channel file descriptors
Diffstat (limited to 'src')
-rw-r--r--src/nvim/channel.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/nvim/channel.c b/src/nvim/channel.c
index 0222a134a7..b64edae2bf 100644
--- a/src/nvim/channel.c
+++ b/src/nvim/channel.c
@@ -544,8 +544,12 @@ uint64_t channel_from_stdio(bool rpc, CallbackReader on_output, const char **err
}
#else
if (embedded_mode) {
- stdin_dup_fd = dup(STDIN_FILENO);
- stdout_dup_fd = dup(STDOUT_FILENO);
+ // In embedded mode redirect stdout and stdin to stderr, since they are used for the UI channel.
+ // NOTE: fnctl with F_DUPFD_CLOEXEC is used instead of dup to prevent child processes from
+ // inheriting the file descriptors, which make it impossible for UIs to detect when nvim exits
+ // while one or more of its child processes are still running.
+ stdin_dup_fd = fcntl(STDIN_FILENO, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
+ stdout_dup_fd = fcntl(STDOUT_FILENO, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
dup2(STDERR_FILENO, STDOUT_FILENO);
dup2(STDERR_FILENO, STDIN_FILENO);
}