1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-18 02:42:05 +03:00
Commit Graph

101 Commits

Author SHA1 Message Date
Wez Furlong
a0cbea2703 term: ignore first OSC title change sequence on Windows
ConPTY emits a sequence that sets the title to the name of the
program that is initially launched into it.

This commit tries to ignore that sequence in that circumstance,
so that the logic in b5d156c282
can more dynamically set the tab title.
2021-12-25 01:10:37 -07:00
Wez Furlong
019de77fcf pty: fix weird cross-compile issue
For some reason, winapi's HANDLE type isn't compatible with the core
rust ffi HANDLE type when cross compiling.

This commit adds some casts.

```
cd pty
cargo build --release --target x86_64-pc-windows-msvc
```

refs: #1389
2021-12-12 09:46:17 -07:00
Wez Furlong
7250237b9a pty: actually fix win32 build 2021-12-11 10:03:43 -07:00
Wez Furlong
a65a4af9a7 pty: speculative fixup of win32 build 2021-12-11 09:30:51 -07:00
Wez Furlong
7926c31209 pty: introduce ChildKiller trait
In the mux layer, we have some code that takes a `Child` and then
does a bit of naughty reaching through the abstraction to get at
the pid/handle of the child so that we can send it signals even
if the child is itself mutably (and thus exclusively) borrowed
for the purposes of waiting.

That worked fine for local processes spawned in the mux, but we also
use LocalPane to wrap around arbitrary `Child`ren, such as Ssh,
that are not local and that don't have a local process id, which
meant that this hack wouldn't work for them.

To make things a bit worse, those ssh ptys were used to ssh2 days
where we didn't have a way to signal the remote process and just
did nothing, leading to confusing situations such as
https://github.com/wez/wezterm/issues/1197

This commit graduates the hack mentioned in the first paragraph
to its own ChildKiller trait.  This makes the concept of waiting
for the Child distinct from signalling it and explicitly allows
getting a separate object that can be used for signalling.

With that in place, we're forced to implement something appropriate
for the ssh pty implementations; one in the pty crate itself,
one in wezterm-ssh and the wrapper that we use in the mux crate.

The upshot of this is that the `CloseCurrentPane` action now operates
correctly on panes that were the result of split operations.
2021-12-11 08:40:26 -07:00
Wez Furlong
955b37ff64 mux server: redirect stdout,stderr to log file on Windows
This got lost somewhere along the way.

Importantly, we need to explicitly set the pty to use invalid stdio
handles for the spawned child in order to avoid a weird situation
where eg: cmd or powershell would end up writing to the log file
despite it being spawned into its own PTY.

refs: #1358
2021-12-05 10:11:43 -08:00
Wez Furlong
30cb55a7bd pty: bump version
The changes in #1275 introduce an API change, so let's not forget to
bump this.
2021-11-23 05:22:32 -07:00
Waleed Khan
cda28fa0ad pty: add CommandBuilder::env_clear, CommandBuilder::env_remove functions 2021-11-23 05:16:55 -07:00
Wez Furlong
1f97a8324e pty: tweak EIO matching for Rust 1.55 and up
The release notes suggest never matching ErrorKind::Other,
so let's avoid that.
2021-09-09 09:16:34 -07:00
Wez Furlong
935c1f4829 pty: use locally set PATH when searching PATH
refs: https://github.com/wez/wezterm/issues/1029
2021-08-16 08:52:56 -07:00
Wez Furlong
ab21910d80 deps: update bitflags -> 1.3 2021-08-15 18:21:17 -07:00
Wez Furlong
690d1e3f5e pty: resolve relative to configured cwd
Otherwise `wezterm start --cwd foo ./something` will refuse to launch

refs: #1005
2021-08-12 10:11:09 -07:00
Wez Furlong
4d4f780f8b pty: unix: return an error if the executable doesn't exist
Without this check, something, presumably in the guts of rust itself,
generates `fatal runtime error: assertion failed:
output.write(&bytes).is_ok()` on the output stream of the spawned child
when attempting to spawn `wsl.exe` on linux.

refs: #1005
2021-08-08 15:21:41 -07:00
kas
91ae9bcbaf Always provide an absolute path for the working directory to CreateProcessW() 2021-07-19 08:36:08 -07:00
Wez Furlong
7cd3dcaee4 tidy up cwd vs. home dir on Windows
Looking at #900; the unconditional directory change on startup
is "bad" because it only happens on Windows.

This commit removes it and instead puts the logic into the pty
layer to match the unix behavior.

The behavior is:

* If the command specifies the cwd, use that.
* Otherwise, use the home directory
2021-07-18 14:57:33 -07:00
Wez Furlong
3f6ff534d3 windows: fix lingering cmd.exe panes
Since removing the regular periodic background tasks, we're now
prone to not noticing child processes exiting.

This commit explicictly schedules a thread to do that on Windows
so that we can close a tab as soon as it exits.
2021-05-28 15:11:29 -07:00
Wez Furlong
b5bfec6510 update conpty to v1.9.1445.0
refs: https://github.com/microsoft/terminal/issues/376

This also enables as the conpty layer the new win32 mode discussed in
https://github.com/wez/wezterm/issues/318
wezterm itself is not able to use this mode yet.
2021-05-28 15:11:29 -07:00
Wez Furlong
f78190ec9c filedescriptor: remove anyhow from public interface
Use thiserror instead
2021-05-23 14:24:01 -07:00
Wez Furlong
bc0766396d use -$SHELL rather than $SHELL -l to trigger a login shell
Since the original code was written, Rust grew and stabilized
an interface for specifying argv0 for the child process, so
we can remove the fragile `-l` argument passing.

refs: https://github.com/wez/wezterm/issues/753
2021-05-01 07:31:35 -07:00
Wez Furlong
5b9be21165 prep for pty 0.4 release 2021-04-30 10:17:25 -07:00
Wez Furlong
5aef725171 pty: unconditionally export some unix+ssh specific things
These were gated to the ssh feature, but I want to use them
with wezterm-ssh, and externally defined ssh pty implementation.
2021-03-27 07:25:00 -07:00
Wez Furlong
3cf7c9c3c2 refine skip_close_confirmation_for_processes_named to look at proc tree
That means that we won't be fooled by a shell with a backgrounded
editor.

refs: https://github.com/wez/wezterm/issues/562
2021-03-22 21:34:10 -07:00
Wez Furlong
38e6a1bc4c window: fix ToggleFullScreen on Windows
closes: https://github.com/wez/wezterm/issues/177
2021-02-26 19:39:35 -08:00
Benoit de Chezelles
84a45f28e5 Send SIGHUP when terminating the pty child
This commit first delivers SIGHUP, then follows up with a regular
kill after a grace period.  This should allow processes an opportunity
to clean up when eg: the terminal window is closed.

Co-authored-by: Wez Furlong <wez@wezfurlong.org>

closes: #490
2021-02-18 10:00:47 -08:00
Benoit de Chezelles
322fb5ee83 fmt 👀 2021-02-18 09:50:50 -08:00
Benoit de Chezelles
dc9784e0db Add comment 2021-02-18 09:50:50 -08:00
Benoit de Chezelles
18e8d48171 unix: Correctly signal child process on exit 2021-02-18 09:50:50 -08:00
Ives van Hoorne
80d486ef03
Add Sync marker to child process created through pty spawn (#437)
* Add Sync marker to child process created through pty spawn

* Add 'Sync' to Windows build of pty

* Wrap proc in WinChild in a Mutex

* Make sure the Mutex is not locked for long by cloning
2021-01-31 10:09:18 -08:00
Dylan Frankland
3793ff2587
Add config option to specify default current working directory (#438)
* Add config option to specify default current working directory

* Make `cwd` of CLI take precedence over `default_cwd`

* Update docs for `default_cwd` and Launching Programs

Explains the `default_cwd` property more succinctly on the `Config` struct.

Adds documentation on the various ways to set the working directory and the logic used to decide the working directory.
2021-01-26 10:40:22 -08:00
Wez Furlong
713da95a02 fix build on windows
refs: #416
2021-01-07 09:38:45 -08:00
Wez Furlong
db0d54cf44 Take care to restore the original umask
wezterm sets a more restrictive umask (`0o077`) by default so that any files
that it creates (eg: unix domain socket, log files) are more secure
by default.

However, some environments rely on the more general default of (`0o022`)
without checking that it is set.

This matters because programs spawned by wezterm inherit its more
restricted umask.

I hadn't noticed this because I've had `umask 022` in my shell RC files
since sometime in the 1990's.

This commit adds some plumbing to the pty layer to specify an optional
umask for the child process, and some more to our umask saver helper
so that any thread can determine the saved umask without needing a
reference to the saver itself, which may be in a different crate.

The logic in the config crate has been adjusted to connect the saved
value to the default command builder arguments.

The net result of this is that running `wezterm -n start bash -- --norc`
and typing `umask` in the resultant window now prints `0022`.

refs: #416
2021-01-07 09:20:13 -08:00
Wez Furlong
1c0817b2b2 mux: factor out server bits to helper crate 2020-12-29 15:25:15 -08:00
Wez Furlong
7cf68365a5 deps: misc updates 2020-12-29 09:24:34 -08:00
Wez Furlong
e831032c72 wezterm: close random fds when starting wezterm-gui
Let's try to eliminate garbage that the OS gui system leaks into
us when it spawns wezterm.
2020-12-20 11:46:59 -08:00
Wez Furlong
44729a7e89 pty: avoid leaking fds from the parent process on all unices
I noticed that wezterm is picking up garbage from gnome too,
so let's trigger the random fd closing function on all unix
systems.

It turns out that iterating the entries in /dev/fd works on
BSD and Linux which is nice.
2020-12-20 11:37:03 -08:00
Wez Furlong
592dbffa22 pty: avoid leaking random fds to children on macOS Big Sur
I'm assuming this is Big Sur specified, as I hadn't noticed
this until upgrading; there are a bunch of gui related files
inherited by my shell:

```
$ lsof -p $$
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF                NODE NAME
zsh     66016  wez  cwd    DIR   1,16     1760              396092 /Users/wez/wez-personal/wezterm
zsh     66016  wez  txt    REG   1,16  1331248 1152921500312774717 /bin/zsh
zsh     66016  wez  txt    REG   1,16   138640 1152921500312777271 /usr/lib/zsh/5.8/zsh/terminfo.so
zsh     66016  wez  txt    REG   1,16   174352 1152921500312777285 /usr/lib/zsh/5.8/zsh/zutil.so
zsh     66016  wez  txt    REG   1,16   138128 1152921500312777261 /usr/lib/zsh/5.8/zsh/rlimits.so
zsh     66016  wez  txt    REG   1,16   579888 1152921500312777275 /usr/lib/zsh/5.8/zsh/zle.so
zsh     66016  wez  txt    REG   1,16   341904 1152921500312777223 /usr/lib/zsh/5.8/zsh/complete.so
zsh     66016  wez  txt    REG   1,16   174752 1152921500312777257 /usr/lib/zsh/5.8/zsh/parameter.so
zsh     66016  wez  txt    REG   1,16   211584 1152921500312777225 /usr/lib/zsh/5.8/zsh/complist.so
zsh     66016  wez  txt    REG   1,16   208768 1152921500312777227 /usr/lib/zsh/5.8/zsh/computil.so
zsh     66016  wez  txt    REG   1,16  2528384 1152921500312776994 /usr/lib/dyld
zsh     66016  wez    0u   CHR   16,1 0t158834                1019 /dev/ttys001
zsh     66016  wez    1u   CHR   16,1 0t158834                1019 /dev/ttys001
zsh     66016  wez    2u   CHR   16,1 0t158834                1019 /dev/ttys001
zsh     66016  wez    8r   REG   1,16   273022 1152921500312217452 /System/Library/Extensions/AppleMetalGLRenderer.bundle/Contents/Resources/default.metallib
zsh     66016  wez   10u   CHR   16,1  0t20923                1019 /dev/ttys001
zsh     66016  wez   11u   REG   1,16    65536              576611 /private/var/folders/mg/hk5n1_9x7014sm0syzqzzn640000gn/C/com.github.wez.wezterm/com.apple.metal/16777235_322/functions.data
zsh     66016  wez   12u   REG   1,16     1276             2360034 /private/var/folders/mg/hk5n1_9x7014sm0syzqzzn640000gn/C/com.github.wez.wezterm/com.apple.metal/16777235_322/functions.list
zsh     66016  wez   13r   REG   1,16   215992             2354718 /Library/Application Support/CrashReporter/SubmitDiagInfo.domains
zsh     66016  wez   14u   REG   1,16     5232             2360053 /Users/wez/Library/Saved Application State/com.github.wez.wezterm.savedState/window_2.data
zsh     66016  wez   15u   REG   1,16    59040             2360054 /Users/wez/Library/Saved Application State/com.github.wez.wezterm.savedState/data.data
zsh     66016  wez   16w   REG   1,16     4716             2360055 /Users/wez/Library/Saved Application State/com.github.wez.wezterm.savedState/windows.plist
```

This commit iterates the list of open descriptors just prior
to calling exec and closes any that aren't the stdio (0-2) descriptors.
2020-12-19 14:01:39 -08:00
Wez Furlong
18e010f1df deps: normalize the lazy-static version 2020-11-13 08:15:35 -08:00
Wez Furlong
b239801085 wezterm: fixup wezterm ssh host
Needed to re-order a couple of things to match recent changes.

Also: don't hard fail if the ssh server rejects a setenv request,
just log the error instead.
2020-10-31 11:45:30 -07:00
Wez Furlong
233adb5fe9 pty: update async example for more recent smol release 2020-10-03 11:15:57 -07:00
Wez Furlong
2d3f4f9bf9 wezterm: guess at cwd associated with pty on linux
We still prefer to consume the OSC 7 value, but can fall back
to guessing the cwd for a target process.
2020-09-26 11:51:21 -07:00
Wez Furlong
9d8839a6d9 pty: adjust examples for macOS Catalina
Seems that you need to have read everything you want before you
call waitpid, otherwise the pending data seems to be snipped and
prevented from being read.

closes: https://github.com/wez/wezterm/issues/187
2020-09-25 09:20:22 -07:00
Wez Furlong
ec468acb40 panes: adopt zipper based bintree for managing panes
This simplifies the logic in the tab.rs module
2020-09-20 10:20:40 -07:00
Wez Furlong
fb890cbaf0 pty: bump version ready for publishing
refs: https://github.com/wez/wezterm/pull/258
refs: https://github.com/TimeToogo/tunshell/issues/8
2020-09-08 21:27:01 -07:00
Elliot Levin
86d66dae54
portable_pty - fix build on x86_64-unknown-freebsd target (#258)
* portable_pty - support for x86_64-unknown-freebsd target

* Update TIOCGWINSZ type conversion to use cast syntax and apply same logic to TIOCSWINSZ
2020-09-08 08:50:43 -07:00
john01dav
f2327de74d Fixed bug where setting the current directory was impossible on UNIX for non-default terminal commands 2020-07-18 08:40:58 -07:00
Wez Furlong
954a05919d pty: remove dead code 2020-06-05 07:33:23 -07:00
Wez Furlong
1d154a3109 pty: bump for 0.3.0 release
Since the last release we've migrated from failure -> anyhow,
added more functions to the command builder, improved windows
support and have compatibility with the `smol` crate.

refs: https://github.com/wez/wezterm/issues/166
2020-05-17 12:14:55 -07:00
Wez Furlong
2ef985aa18 pty: async example using smol
refs: https://github.com/wez/wezterm/issues/166
2020-05-09 11:24:14 -07:00
Wez Furlong
e2d044bb14 pty: add MasterPty::try_clone_writer 2020-05-09 11:24:14 -07:00
Wez Furlong
c54c64f395 pty: remove experimental awaitable bits 2020-05-09 11:24:14 -07:00