Dont rely on existence of sh to report exec failure
This commit is contained in:
parent
bc73273cb3
commit
45b0788f28
@ -81,8 +81,9 @@ static PyObject*
|
||||
spawn(PyObject *self UNUSED, PyObject *args) {
|
||||
PyObject *argv_p, *env_p, *handled_signals_p;
|
||||
int master, slave, stdin_read_fd, stdin_write_fd, ready_read_fd, ready_write_fd;
|
||||
const char *kitten_exe;
|
||||
char *cwd, *exe;
|
||||
if (!PyArg_ParseTuple(args, "ssO!O!iiiiiiO!", &exe, &cwd, &PyTuple_Type, &argv_p, &PyTuple_Type, &env_p, &master, &slave, &stdin_read_fd, &stdin_write_fd, &ready_read_fd, &ready_write_fd, &PyTuple_Type, &handled_signals_p)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "ssO!O!iiiiiiO!s", &exe, &cwd, &PyTuple_Type, &argv_p, &PyTuple_Type, &env_p, &master, &slave, &stdin_read_fd, &stdin_write_fd, &ready_read_fd, &ready_write_fd, &PyTuple_Type, &handled_signals_p, &kitten_exe)) 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);
|
||||
@ -151,14 +152,14 @@ spawn(PyObject *self UNUSED, PyObject *args) {
|
||||
|
||||
environ = env;
|
||||
execvp(exe, argv);
|
||||
// Report the failure and exec a shell instead, so that we are not left
|
||||
// Report the failure and exec kitten instead, so that we are not left
|
||||
// with a forked but not exec'ed process
|
||||
write_to_stderr("Failed to launch child: ");
|
||||
write_to_stderr(exe);
|
||||
write_to_stderr("\nWith error: ");
|
||||
write_to_stderr(strerror(errno));
|
||||
write_to_stderr("\nPress Enter to exit.\n");
|
||||
execlp("sh", "sh", "-c", "read w", NULL);
|
||||
write_to_stderr("\n");
|
||||
execlp(kitten_exe, "kitten", "__hold_till_enter__", NULL);
|
||||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, DefaultDict, Dict, Generator, List, Optional,
|
||||
|
||||
import kitty.fast_data_types as fast_data_types
|
||||
|
||||
from .constants import handled_signals, is_freebsd, is_macos, kitty_base_dir, shell_path, terminfo_dir
|
||||
from .constants import handled_signals, is_freebsd, is_macos, kitten_exe, kitty_base_dir, shell_path, terminfo_dir
|
||||
from .types import run_once
|
||||
from .utils import log_error, which
|
||||
|
||||
@ -320,7 +320,7 @@ class Child:
|
||||
else:
|
||||
pid = fast_data_types.spawn(
|
||||
self.final_exe, self.cwd, tuple(argv), env, master, slave, stdin_read_fd, stdin_write_fd,
|
||||
ready_read_fd, ready_write_fd, tuple(handled_signals))
|
||||
ready_read_fd, ready_write_fd, tuple(handled_signals), kitten_exe())
|
||||
os.close(slave)
|
||||
self.pid = pid
|
||||
self.child_fd = master
|
||||
|
||||
@ -1313,6 +1313,7 @@ def spawn(
|
||||
ready_read_fd: int,
|
||||
ready_write_fd: int,
|
||||
handled_signals: Tuple[int, ...],
|
||||
kitten_exe: str,
|
||||
) -> int:
|
||||
pass
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user