A new panel created via single instance now runs in the working
directory of the invocation, rather than that of the first instance, as
commands run in existing panels and other single instance commands
already do. The environment of the invocation is cleaned up with
process_env() as for other single instance commands, so that variables
such as XDG_ACTIVATION_TOKEN and VTE_VERSION are not passed to the
commands.
Commands sent to an already running panel or quick access terminal, both
in existing panels and in newly created ones, are now user launches
passed to the launch wrapper. They have no source window, since they are
not run from any window in the panel. A new panel without a command runs
the shell instead of the run-shell kitten, so the wrapper sees the actual
shell, as for a panel started without single instance.
Closes#10900
On macOS the default shell is run via /usr/bin/login and the run-shell
kitten, with the user wrapper placed inside login, so the expected argv
differs from Linux.
A user launch wrapper can start a persistent helper before the command. Use a lone, unmatched child for the current lookup and cache the child only once its command line matches the launch arguments.
A wrapper that runs the command as a child, rather than exec-ing it, can
run other children before, after or alongside it, such as a script that
runs some setup commands first. Re-check that the cached child of a
wrapper is still its live child, so that root_pid does not get stuck on
an exited helper, or on the command after it exits while the wrapper
keeps running. When a wrapper has several children, prefer the one
running the wrapped command, and only cache the choice if it is certain.
Match wrappers specified by name when their argv[0] is the path they
were found at, as is the case when run by the hold kitten, and wrappers
specified by path only by that exact path.
Compare the wrapper argv and the script arguments with empty arguments
dropped, as cmdline_of_pid() does on Linux, in one place, so that
binary wrappers with empty arguments are also matched.
Add tests for wrappers that run other commands, that exec after being
seen, with prefix and empty arguments, run via the hold kitten, and for
matches_cmdline() and runs_command().
The cmdline, environment and working directory of a window, as reported
by kitten @ ls, used for matching windows and saved in the window state,
now come from the root process, skipping over wrappers kitty inserts
such as /usr/bin/login on macOS. Previously on macOS these described the
login process. Cache the resolved root process so that this is cheap.
On Linux /proc/<pid>/task/<pid>/children only lists the children
created by the main thread, so children created by other threads of
multi-threaded programs were missed. Read the children lists of all
threads instead. On kernels without per thread children lists, build
the full parent to children map once instead of finding nothing. Also
avoid computing the descendants twice when the cgroup contains
processes outside the tree.
When the root process was not in the foreground, cwd=root used the cwd
of the foreground process instead of the root process. Also skip over
wrapper processes that kitty itself inserts, such as /usr/bin/login on
macOS and the run-shell kitten used for --hold, using their first child
as the root process instead. Previously on macOS cwd=root always
resolved to the home directory, the cwd of login.
On Linux, read the children of all threads of a process, since
multi-threaded programs such as kitten can create children from any
thread.
Make cwd_of_child and modify_argv_for_launch_with_cwd use the same
logic for deciding when the reported cwd applies to cwd=root.
Closes#10720