aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/pty_process_unix.c
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2020-07-31 01:17:24 -0400
committerJames McCoy <jamessan@jamessan.com>2021-01-31 07:54:20 -0500
commit7f50c692685c92d47e6ba6c3ee5f6fdccb78fec5 (patch)
tree2d1eda8d6437d4d339c244681fdb5b7ff5418c21 /src/nvim/os/pty_process_unix.c
parent55add1c1c8a9a040f02a880096ca153f7db3e501 (diff)
downloadrneovim-7f50c692685c92d47e6ba6c3ee5f6fdccb78fec5.tar.gz
rneovim-7f50c692685c92d47e6ba6c3ee5f6fdccb78fec5.tar.bz2
rneovim-7f50c692685c92d47e6ba6c3ee5f6fdccb78fec5.zip
Use dict_T to pass env vars to process spawning code
Co-authored-by: Matthieu Coudron <mattator@gmail.com>
Diffstat (limited to 'src/nvim/os/pty_process_unix.c')
-rw-r--r--src/nvim/os/pty_process_unix.c79
1 files changed, 58 insertions, 21 deletions
diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c
index 4d7d9a45df..a3c9e726c5 100644
--- a/src/nvim/os/pty_process_unix.c
+++ b/src/nvim/os/pty_process_unix.c
@@ -20,6 +20,10 @@
# include <pty.h>
#endif
+#ifdef __APPLE__
+# include <crt_externs.h>
+#endif
+
#include <uv.h>
#include "nvim/lib/klist.h"
@@ -151,31 +155,24 @@ void pty_process_teardown(Loop *loop)
uv_signal_stop(&loop->children_watcher);
}
+static const char *ignored_env_vars[] = {
+ "COLUMNS",
+ "LINES",
+ "TERMCAP",
+ "COLORFGBG"
+};
+
static void init_child(PtyProcess *ptyproc)
FUNC_ATTR_NONNULL_ALL
{
+#if defined(HAVE__NSGETENVIRON)
+ char **environ = *_NSGetEnviron();
+#else
+ extern char **environ;
+#endif
// New session/process-group. #6530
setsid();
- os_unsetenv("COLUMNS");
- os_unsetenv("LINES");
- os_unsetenv("TERMCAP");
- os_unsetenv("COLORFGBG");
- // setting COLORTERM to "truecolor" if termguicolors is set and 256
- // otherwise, but only if it was set in the parent terminal at all
- if (os_env_exists("COLORTERM")) {
- const char *colorterm = os_getenv("COLORTERM");
- if (colorterm != NULL) {
- if (p_tgc) {
- os_setenv("COLORTERM", "truecolor", 1);
- } else {
- os_setenv("COLORTERM", "256", 1);
- }
- } else {
- os_unsetenv("COLORTERM");
- }
- }
-
signal(SIGCHLD, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGINT, SIG_DFL);
@@ -190,9 +187,49 @@ static void init_child(PtyProcess *ptyproc)
}
char *prog = ptyproc->process.argv[0];
- os_setenv("TERM", ptyproc->term_name ? ptyproc->term_name : "ansi", 1);
- execvp(prog, ptyproc->process.argv);
+ if (proc->env) {
+ for (size_t i = 0; i < ARRAY_SIZE(ignored_env_vars); i++) {
+ dictitem_T *dv = tv_dict_find(proc->env, ignored_env_vars[i], -1);
+ if (dv) {
+ tv_dict_item_remove(proc->env, dv);
+ }
+ }
+ tv_dict_add_str(proc->env, S_LEN("TERM"), ptyproc->term_name ? ptyproc->term_name : "ansi");
+
+ // setting COLORTERM to "truecolor" if termguicolors is set and 256
+ // otherwise, but only if it was set in the parent terminal at all
+ dictitem_T *dv = tv_dict_find(proc->env, S_LEN("COLORTERM"));
+ if (dv) {
+ tv_dict_item_remove(proc->env, dv);
+ tv_dict_add_str(proc->env, S_LEN("COLORTERM"), p_tgc ? "truecolor" : "256");
+ }
+
+ environ = tv_dict_to_env(proc->env);
+ } else {
+ for (size_t i = 0; i < ARRAY_SIZE(ignored_env_vars); i++) {
+ os_unsetenv(ignored_env_vars[i]);
+ }
+
+ // setting COLORTERM to "truecolor" if termguicolors is set and 256
+ // otherwise, but only if it was set in the parent terminal at all
+ if (os_env_exists("COLORTERM")) {
+ const char *colorterm = os_getenv("COLORTERM");
+ if (colorterm != NULL) {
+ if (p_tgc) {
+ os_setenv("COLORTERM", "truecolor", 1);
+ } else {
+ os_setenv("COLORTERM", "256", 1);
+ }
+ } else {
+ os_unsetenv("COLORTERM");
+ }
+ }
+
+ os_setenv("TERM", ptyproc->term_name ? ptyproc->term_name : "ansi", 1);
+ }
+ execvp(prog, proc->argv);
ELOG("execvp failed: %s: %s", strerror(errno), prog);
+
_exit(122); // 122 is EXEC_FAILED in the Vim source.
}