From 8db838da9f50cf1fb6ef045eceb782b5e0964f4c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 5 Mar 2018 13:30:09 +0530 Subject: [PATCH] macOS: Fix shell not starting in login mode on some computers. Fixes #247 --- kitty/child.c | 6 +++--- kitty/child.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/kitty/child.c b/kitty/child.c index 3fb3f8861..a95d25a41 100644 --- a/kitty/child.c +++ b/kitty/child.c @@ -42,8 +42,8 @@ static PyObject* spawn(PyObject *self UNUSED, PyObject *args) { PyObject *argv_p, *env_p; int master, slave, stdin_read_fd, stdin_write_fd; - char* cwd; - if (!PyArg_ParseTuple(args, "sO!O!iiii", &cwd, &PyTuple_Type, &argv_p, &PyTuple_Type, &env_p, &master, &slave, &stdin_read_fd, &stdin_write_fd)) return NULL; + char *cwd, *exe; + if (!PyArg_ParseTuple(args, "ssO!O!iiii", &exe, &cwd, &PyTuple_Type, &argv_p, &PyTuple_Type, &env_p, &master, &slave, &stdin_read_fd, &stdin_write_fd)) return NULL; char name[2048] = {0}; if (ttyname_r(slave, name, sizeof(name) - 1) != 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } char **argv = serialize_string_tuple(argv_p); @@ -76,7 +76,7 @@ spawn(PyObject *self UNUSED, PyObject *args) { close(tfd); environ = env; - execvp(argv[0], argv); + execvp(exe, argv); // Report the failure and exec a shell instead, so that we are not left // with a forked but not exec'ed process write_to_stderr("Failed to launch child: "); diff --git a/kitty/child.py b/kitty/child.py index 69aab53c3..dfd363aa7 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -7,7 +7,7 @@ import os import kitty.fast_data_types as fast_data_types -from .constants import terminfo_dir, is_macos +from .constants import is_macos, shell_path, terminfo_dir def cwd_of_process(pid): @@ -70,7 +70,13 @@ class Child: if os.path.isdir(terminfo_dir): env['TERMINFO'] = terminfo_dir env = tuple('{}={}'.format(k, v) for k, v in env.items()) - pid = fast_data_types.spawn(self.cwd, tuple(self.argv), env, master, slave, stdin_read_fd, stdin_write_fd) + argv = list(self.argv) + exe = argv[0] + if is_macos and exe == shell_path: + # Some macOS machines need the shell to have argv[0] prefixed by + # hyphen, see https://github.com/kovidgoyal/kitty/issues/247 + argv[0] = ('-' + exe.split('/')[-1]) + pid = fast_data_types.spawn(exe, self.cwd, tuple(argv), env, master, slave, stdin_read_fd, stdin_write_fd) os.close(slave) self.pid = pid self.child_fd = master