146 Commits

Author SHA1 Message Date
Jeffrey C. Ollie
2f8b0dc899 build: options to enable/disable terminfo & termcap install (take 2)
Fixes #5253

Add -Demit-terminfo and -Demit-termcap build options to enable/disable
installation of source terminfo and termcap files.
2025-01-24 10:06:39 -06:00
Mitchell Hashimoto
0d6a1d3fdb Prevent fd leaks to the running shell or command
Multiple fixes to prevent file descriptor leaks:

- libxev eventfd now uses CLOEXEC
- linux: cgroup clone now uses CLOEXEC for the cgroup fd
- termio pipe uses pipe2 with CLOEXEC
- pty master always sets CLOEXEC because the child doesn't need it
- termio exec now closes pty slave fd after fork

There still appear to be some fd leaks happening. They seem related to
GTK, they aren't things we're accessig directly. I still want to
investigate them but this at least cleans up the major sources of fd
leakage.
2025-01-23 22:12:58 -08:00
Mitchell Hashimoto
c0eb6985ee Revert "build: options to enable/disable terminfo & termcap install"
This reverts commit 8f49a227b7c352083b0815e7818db900402513e0.
2025-01-23 19:38:13 -08:00
Jeffrey C. Ollie
8f49a227b7 build: options to enable/disable terminfo & termcap install
Fixes #5253

Add `-Demit-terminfo` and `-Demit-termcap` build options to
enable/disable installtion of source terminfo and termcap files.
2025-01-23 14:17:33 -06:00
Mitchell Hashimoto
c3ef4d2908 fix(flatpak): construct null-terminated array for arguments (#5213)
The variant format string `^aay` is said to be equivalent to
`g_variant_new_bytestring_array`. Given that no length parameter is
provided, glib assumed a null-terminated array, causing a crash as glib
exceed the read boundaries to copy arbitrary memory.

This commit replaces the array construction code to use its arena
equivalents instead of glib, and make sure that the resulting array is
null-terminated.

Fixes #3616.
2025-01-20 10:22:18 -08:00
Leorize
ecad3e75ff fix(flatpak): construct null-terminated array for arguments
The variant format string `^aay` is said to be equivalent to
g_variant_new_bytestring_array. Given that no length parameter is
provided, g_variant_new assumed a null-terminated array, but the array
constructed by the code was not, causing a crash as glib exceed the read
boundaries to copy arbitrary memory.

This commit replaces the array construction code to use its arena
equivalents instead of trying to build one using glib, and make sure
that the resulting array is null-terminated.
2025-01-18 13:47:18 -06:00
Jeffrey C. Ollie
c85c277415 core: add docs for ShellEscapeWriter 2025-01-08 13:19:00 -06:00
Jeffrey C. Ollie
e7c71df0b7 gtk: implement dropping files and strings 2025-01-08 08:39:28 -06:00
Jeffrey C. Ollie
6d90a181ce core: improve desktop environment detection 2025-01-06 10:38:07 -06:00
Mitchell Hashimoto
e03c428728 os: directory functions should prefer cached home if available
This fixes tests as well if env vars are set.
2025-01-03 10:39:03 -08:00
Jeffrey C. Ollie
c89df01e13 core: prohibit checking for the desktop environment on linux during comptime 2025-01-02 18:29:33 -06:00
Jeffrey C. Ollie
5c39d09053 core: detect what desktop environment the user is using 2025-01-02 18:29:31 -06:00
Mitchell Hashimoto
263146ebe2 core: if we change RLIMIT_NOFILE, reset it when executing commands (#4241)
Fixes #4232 .
2025-01-02 15:19:52 -08:00
Mitchell Hashimoto
8e47d0267b Move resource limits to a dedicated struct, restore before preexec 2025-01-02 15:05:10 -08:00
Mitchell Hashimoto
a94cf4b3a2 config: make diagnostic if homedir expansion fails 2025-01-02 12:44:03 -08:00
z-jxy
7bd842a530 add test for expandHomeUnix 2025-01-02 12:33:34 -08:00
z-jxy
5ae2cc01ac move current expandHome functionality into separate expandHomeUnix function 2025-01-02 12:33:34 -08:00
z-jxy
138a8f1602 move tilde expansion functionality to os/homedir 2025-01-02 12:33:34 -08:00
Mitchell Hashimoto
57af5f3106 crash: prefer XDG cache dir if available 2025-01-02 11:50:22 -08:00
Bryan Lee
6fca26972b Remove the redundant check and directly use dir() 2025-01-03 00:24:14 +08:00
Bryan Lee
9f44ec7c21 Use bundle ID for macOS cache directory path 2025-01-03 00:24:14 +08:00
Bryan Lee
67794d3f6f Respect XDG_CACHE_HOME and useNSFileManager for cache paths 2025-01-03 00:24:14 +08:00
Bryan Lee
1941a440d8 Use $HOME/Library/Caches on macOS instead of $HOME/.cache 2025-01-03 00:24:14 +08:00
Jeffrey C. Ollie
9ea0aa4934 core: if we change RLIMIT_NOFILE, reset it when executing commands 2025-01-01 14:31:15 -06:00
Mitchell Hashimoto
e9edd21bed os: don't return stack memory
A regression from adcaff7137ef
2024-12-30 12:21:28 -08:00
Mitchell Hashimoto
adcaff7137 config: edit opens AppSupport over XDG on macOS, prefers non-empty paths
Fixes #3953
Fixes #3284

This fixes two issues. In fixing one issue, the other became apparent so
I fixed both in this one commit.

The first issue is that on macOS, the `open` command should take the
`-t` flag to open text files in a text editor. To do this, the `os.open`
function now takes a type hint that is used to better do the right
thing.

Second, the order of the paths that we attempt to open when editing a
config on macOS is wrong. Our priority when loading configs is well documented:
https://ghostty.org/docs/config#macos-specific-path-(macos-only). But
open_config does the opposite. This makes it too easy for people to have
configs that are being overridden without them realizing it.

This commit changes the order of the paths to match the documented
order. If neither path exists, we prefer AppSupport.
2024-12-30 08:43:59 -08:00
Yorick Peterse
50f7632d81 Fix building with -Dflatpak=true
While running a Ghostty instance built with this option currently
crashes under Flatpak, at least it ensures we're able to build it again.
2024-12-27 16:27:19 +01:00
Jon Parise
f141f4b2b0 os: add prependEnv(), like appendEnv()
We can use this function in setupXdgDataDirs() to simplify the
XDG_DATA_DIRS environment variable code in a more standardized way.
2024-12-16 10:56:27 -05:00
Mitchell Hashimoto
a482224da8 renderer: set QoS class of the renderer thread on macOS
This sets the macOS QoS class of the renderer thread. Apple
recommends[1] that all threads should have a QoS class set, and there
are many benefits[2] to that, mainly around power management moreso than
performance I'd expect.

In this commit, I start by setting the QoS class of the renderer thread.
By default, the renderer thread is set to user interactive, because it
is a UI thread after all. But under some conditions we downgrade:

  - If the surface is not visible at all (i.e. another window is fully
    covering it or its minimized), we set the QoS class to utility. This
    is lower than the default, previous QoS and should help macOS
    unschedule the workload or move it to a different core.

  - If the surface is visible but not focused, we set the QoS class to
    user initiated. This is lower than user interactive but higher than
    default. The renderer should remain responsive but not consume as
    much time as it would if it was user interactive.

I'm unable to see any noticable difference in anything from these
changes. Unfortunately it doesn't seem like Apple provides good tools to
play around with this.

We should continue to apply QoS classes to our other threads on macOS.

[1]: https://developer.apple.com/documentation/apple-silicon/tuning-your-code-s-performance-for-apple-silicon?preferredLanguage=occl
[2]: https://blog.xoria.org/macos-tips-threading/
2024-11-26 15:43:35 -08:00
Mitchell Hashimoto
b9345e8d6a try to abstract bundle ID to a zig file 2024-11-25 16:11:02 -08:00
Mitchell Hashimoto
adc59be977 os: more error handling on reading the app support dir 2024-11-25 16:04:41 -08:00
Kyaw
10e37a3dee config: support loading from "Application Support" directory on macOS 2024-11-24 17:08:07 +07:00
Jon Parise
433b6b4fe2 os: replace PATH_SEP with std.fs.path.delimiter
This standard library symbol is equivalent.
2024-11-19 10:51:02 -05:00
Mitchell Hashimoto
75fe0b2dfb Merge pull request #2617 from ghostty-org/pagelist-wip
chore: rename fields in PageList, move data structures to package, move PageList to intrusive linked list
2024-11-07 15:49:08 -08:00
Kristófer R
84707932d2 os/hostname: fix mac address handling when last section starts with '0'
I hit an edge case when using Private Wi-Fi addressing on macOS where
the last section of the randomized mac address starts with a '0'. The
hostname parsing for the shell integration didn't handle this case, so
issue #2512 reappeared.

This fixes that by explicitly handling port numbers < 10.
2024-11-07 18:17:51 -05:00
Mitchell Hashimoto
a436bd0af6 move datastructures to dedicated "datastruct" package 2024-11-07 14:39:10 -08:00
Mitchell Hashimoto
c8b99f7891 remove refalldecls test 2024-11-05 10:36:16 -08:00
Mitchell Hashimoto
4a263f43af stylistic changes 2024-11-05 10:30:56 -08:00
Kristófer R
9c2f260351 os/hostname: add and use explicit error structs 2024-11-04 19:26:29 -05:00
Kristófer R
e85b114031 os/hostname: add better validation for mac-address hostnames 2024-11-04 18:59:42 -05:00
Kristófer R
9ae6806e30 os/hostname: test bufPrintHostnameFromFileUri
Note that this includes some failing tests because I want to make the
uri handling better and more specific. It's a little bit too general
right now so I want to lock it down to:

1. macOS only; and
2. valid mac address values

because that's how the macOS private Wi-Fi address thing works;
randomizes your mac address and sets that as your hostname.
2024-11-04 18:59:41 -05:00
Kristófer R
78abd051a2 os/hostname: test isLocalHostname 2024-11-04 18:59:41 -05:00
Kristófer R
03bb16fcec Move hostname helpers to src/os/hostname.zig 2024-11-04 16:54:38 -05:00
Mitchell Hashimoto
115e14f19f macos: NSProcessInfo-based arg iterator
Fixes #2432

On macOS, processes with an NSApplicationMain entrypoint do not have
access to libc argc/argv. Instead, we must use NSProcessInfo. This
commit introduces an args iterator that uses NSProcessInfo, giving us
access to the args.

This also fixes an issue where we were not properly skipping argv0 when
iterating over the args. This happened to be fine because we happened to
ignore invalid args but it introduces a config error.
2024-10-14 17:08:33 -07:00
Mitchell Hashimoto
2abdf291f4 implement sentry transport to write crash reports to XDG_STATE_HOME 2024-08-28 21:43:18 -07:00
Mitchell Hashimoto
7f143d9df4 os: add xdg cache dir function 2024-08-28 21:43:17 -07:00
Mitchell Hashimoto
677f0376a0 os: yeet usingns 2024-08-16 14:29:08 -07:00
Mitchell Hashimoto
d0ca949c09 os: start yeeting 2024-08-16 10:57:19 -07:00
Mitchell Hashimoto
a158a1d45f os: unify memory/processes cgroup limiting func 2024-08-11 15:37:54 -07:00
Christian Kugler
ba41f142ed Add Config Option to Limit Number of Processes
To protect your system and ghostty from misbehaving programs that launch
too many processes for the system to handle (e.g. like a fork bomb),
this implements an option to limit the number of processes that can be
started in a surface.

A fork bomb for example or other misbehaving program would then only
take down one surface and not the entire system.

Side node:
If I am right in issue #2084, this feature does not actually work on a
per surface basis but on all surfaces. If this is the case, it could
probably be fixed together. Chances are, that I am wrong though 😉

Further improvements that could be done:
- unify way to set cgroup attributes
- set sane default: 10% of system max?
2024-08-11 23:37:57 +02:00