macOS: Fix shell not starting in login mode on some computers. Fixes #247

This commit is contained in:
Kovid Goyal 2018-03-05 13:30:09 +05:30
parent 7254a880dc
commit 8db838da9f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 5 deletions

View File

@ -42,8 +42,8 @@ static PyObject*
spawn(PyObject *self UNUSED, PyObject *args) { spawn(PyObject *self UNUSED, PyObject *args) {
PyObject *argv_p, *env_p; PyObject *argv_p, *env_p;
int master, slave, stdin_read_fd, stdin_write_fd; int master, slave, stdin_read_fd, stdin_write_fd;
char* cwd; char *cwd, *exe;
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; 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}; char name[2048] = {0};
if (ttyname_r(slave, name, sizeof(name) - 1) != 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } if (ttyname_r(slave, name, sizeof(name) - 1) != 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; }
char **argv = serialize_string_tuple(argv_p); char **argv = serialize_string_tuple(argv_p);
@ -76,7 +76,7 @@ spawn(PyObject *self UNUSED, PyObject *args) {
close(tfd); close(tfd);
environ = env; environ = env;
execvp(argv[0], argv); execvp(exe, argv);
// Report the failure and exec a shell instead, so that we are not left // Report the failure and exec a shell instead, so that we are not left
// with a forked but not exec'ed process // with a forked but not exec'ed process
write_to_stderr("Failed to launch child: "); write_to_stderr("Failed to launch child: ");

View File

@ -7,7 +7,7 @@ import os
import kitty.fast_data_types as fast_data_types 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): def cwd_of_process(pid):
@ -70,7 +70,13 @@ class Child:
if os.path.isdir(terminfo_dir): if os.path.isdir(terminfo_dir):
env['TERMINFO'] = terminfo_dir env['TERMINFO'] = terminfo_dir
env = tuple('{}={}'.format(k, v) for k, v in env.items()) 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) os.close(slave)
self.pid = pid self.pid = pid
self.child_fd = master self.child_fd = master