aboutsummaryrefslogtreecommitdiff
path: root/slave.c (unfollow)
Commit message (Collapse)AuthorLines
2025-07-30slave: remove more environment variables set by other terminalsDaniel Eklöf-2/+48
This ensures applications don't mistake foot for another terminal emulator. Not that applications _should_ rely on environment variables, but some do anyway...
2024-08-09slave: prefix user notifications with 'foot'Daniel Eklöf-1/+3
To make it clearer _who_ is emitting the warning/errors
2024-08-03xmalloc: remove delim param from xstrjoin() and add separate xstrjoin3()Craig Barnes-2/+2
This avoids the need for an unused third argument for most xstrjoin() calls and replaces the cases where it's needed with a more flexible function. Code generation is the same in both cases, when there are 2 string params and a compile-time known delimiter. This commit also converts 4 uses of xasprintf() to use xstrjoin*(). See also: https://godbolt.org/z/xsjrhv9b6
2024-08-02Remove a number of unused includesDaniel Eklöf-1/+0
2024-06-07meson: auto-detect execvpe on FreeBSDJan Beich-3/+3
https://github.com/freebsd/freebsd-src/commit/0667d0e0e365
2024-02-05util: add streq() function and use in place of strcmp(...) == 0Craig Barnes-1/+2
2024-01-16slave: fix typoArtturin-1/+1
``` ../slave.c: In function 'slave_spawn': ../slave.c:441:21: error: 'custom_envp' undeclared (first use in this function); did you mean 'custom_env'? 441 | add_to_env(&custom_envp, "TERMINFO", FOOT_TERMINFO_PATH); | ^~~~~~~~~~~ | custom_env ../slave.c:441:21: note: each undeclared identifier is reported only once for each function it appears in ```
2024-01-11slave: don't skip setting environment variables when using a custom environmentDaniel Eklöf-11/+92
When launching footclient with -E,--client-environment the environment variables that should be set by foot, wasn't. Those variables are: * TERM * COLORTERM * PWD * SHELL and all variables defined by the user in the [environment] section in foot.ini. In the same way, we did not *unset* TERM_PROGRAM and TERM_PROGRAM_VERSION. This patch fixes it by "cloning" the custom environment, making it mutable, and then adding/removing the variables above from it. Instead of calling setenv()/unsetenv() directly, we add the wrapper functions add_to_env() and del_from_env(). When *not* using a custom environment, they simply call setenv()/unsetenv(). When we *are* using a custom environment, add_to_env() first loops all existing variables, looking for a match. If a match is found, it's updated with the new value. If it's not found, a new entry is added. del_from_env() loops all entries, and removes it when a match is found. If no match is found, nothing is done. The mutable environment is allocated on the heap, but never free:d. We don't need to free it, since it's only allocated after forking, in the child process. Closes #1568
2024-01-05slave: ignore return value of chdir()Daniel Eklöf-1/+1
It's not critical. Fixes ../slave.c: In function ‘slave_spawn’: ../slave.c:410:9: error: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 410 | chdir("/"); | ^~~~~~~~~~
2024-01-03slave: chdir to / after spawning the client applicationDaniel Eklöf-0/+8
With this patch, the terminal process now changes PWD to / after spawning the client application. This ensures the terminal process itself does not "lock" a directory. For example, we may keep a mount point from being unmounted. Closes #1528
2023-05-18slave: unset TERM_PROGRAM{,_VERSION}Daniel Eklöf-3/+3
Foot’s policy is to not set environment variables that identifies it (except the well-known and established `TERM` variable). We encourage applications to use terminfo to determine capabilities, or terminal queries, when available. Or, at least use terminal queries to detect the terminal and its version. Setting environment variables is a bad idea since they are inherited by all applications started by the terminal (which is the whole point). But, this includes other terminal emulators, making it very possible a terminal emulator gets mis-detected just because it was started from another terminal. Since there are a couple of terminal emulators that _do_ set TERM_PROGRAM and TERM_PROGRAM_VERSION, unset these environment variables to avoid being misdetected. Closes #1349
2023-03-20slave: set $TERM_PROGRAM and $TERM_PROGRAM_VERSION environment variablesCraig Barnes-0/+3
These are already being set by iTerm2, WezTerm, tmux and likely some others. Even though using yet more environment variables seems rather questionable, if we don't set these we run the risk of inheriting them from other terminals. See also: * https://gitlab.com/gnachman/iterm2/-/blob/97a6078df8e822da165e91737a01c0b9e115dd16/sources/PTYSession.m#L2568-2570 * https://github.com/tmux/tmux/blob/1d0f68dee9f71c504e03616fa472a408a6caa49b/environ.c#L263-L264 * https://github.com/search?q=TERM_PROGRAM&type=code
2022-12-06slave: unsetenv() env vars that have been set to the empty stringDaniel Eklöf-2/+9
That is, users can now *clear* environment variables by doing: [environment] VAR=”” Note that the quotes are required. Closes #1225
2022-10-02slave: spawn: set PWD environment variableDaniel Eklöf-0/+1
This improves handling of symlinks (in CWD) when launching a new terminal instance, either through ctrl+shift+n, or using the --working-directory command line option. Closes #1179
2022-06-13config: add a new ‘environment’ sectionDaniel Eklöf-2/+8
This section allows the user to define custom environment variables to be set in the child process: [environment] name=value
2022-04-12slave: roll our own ‘execvpe()’ on FreeBSDDaniel Eklöf-1/+58
2022-04-12client/slave: explictly add ‘extern char **environ’Daniel Eklöf-0/+2
It’s not in any header files on FreeBSD.
2022-04-12client: add -E,--client-environmentDaniel Eklöf-6/+7
When this option is used, the child process in the new terminal instance will inherit its environment from the footclient process, instead of the foot server’s. Implemented by sending (yet another) dynamic string list as part of the client -> server setup packet. When the new option is *not* used, the setup packet is now 2 bytes larger than before. On the server side, the slave process now uses execvpe() instead of execvp(). There’s plumbing to propagate a new ‘envp’ argument from term_init() all the way down to slave_exec(). If ‘envp’ is NULL, we use ‘environ’ instead (thus matching the old behavior of execvp()). Closes #1004
2022-02-12Explicitly initialize sigaction::sa_mask members with sigemptyset(3)Craig Barnes-1/+2
Not doing so before calling sigaction(3) is "undefined" according to POSIX[1]: > Applications shall call either sigemptyset() or sigfillset() at least > once for each object of type sigset_t prior to any other use of that > object. If such an object is not initialized in this way, but is > nonetheless supplied as an argument to any of pthread_sigmask(), > sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), > sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or > sigwaitinfo(), the results are undefined. The use of designated initializers means that sa_mask members were still being initialized, but sigset_t is an opaque type and implicit initialization doesn't necessarily produce the same results as using sigemptyset(3) (although it typically does on most implementations). [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaddset.html
2021-12-18slave: re-use ‘struct sigaction’ variable when resetting SIGHUP+SIGPIPEDaniel Eklöf-2/+4
2021-12-18slave: restore SIGPIPEDaniel Eklöf-1/+2
2021-08-30slave: log _which_ CWD we failed to change toDaniel Eklöf-1/+1
2021-08-18slave: set TERMINFO instead of TERMINFO_DIRSDaniel Eklöf-9/+1
This seems to be slightly better supported than TERMINFO_DIRS. It also simplifies our code, since it’s no longer an issue of whether to append or not - we just set TERMINFO, and ignore whatever it was set to before. Also closes #687
2021-08-17terminfo: install to $datadir/foot/terminfo by default, append to TERMINFO_DIRSDaniel Eklöf-0/+12
As of 2021-07-31, ncurses ships its own version of foot’s terminfo. Since: * It doesn’t have the non-standard Sync,Tc,setrgbf,setrgbb capabilities. * It doesn’t set hs,fsl,dsl (statusbar). * We want to be able to update our termminfo without waiting for an ncurses release. * Foot should be installable and usable on Linux systems that doesn’t have the latest ncurses. we still want to ship our own version. We can however not install it to the default terminfo location (e.g. /usr/share/terminfo), since it will collide with the ncurses provided files. Our options are to either rename our terminfo to something else, or to keep the name, but install our terminfo files somewhere else. The first option would be the easy one. However, I think it makes sense to use the same name. For example, a user that SSH’s into a remote system that does *not* have our own version installed, but *does* have the ncurses one, will gracefully fall back to that one, which is better than manually having to set e.g. TERM=xterm-256color. Now, if we want to use the same name, we need to install it somewhere else. But where? And how do we ensure our version is preferred over the ncurses one? I opted to $datadir/foot/terminfo (e.g. /usr/share/foot/terminfo) by default. It makes it namespaced to foot (i.e. we’re not introducing a new “standard” terminfo location), thus guaranteeing it wont collide with ncurses. To enable applications to find it, we export TERMINFO_DIRS. This is a list of *additional* directories to search for terminfo files. If it’s already defined, we *append* to it. The nice thing with this is, if there’s no terminfo in that location (e.g. when you SSH into a remote), the default terminfo location is *also* searched. But only *after* having searched through TERMINFO_DIRS. In short: our version is preferred, but the ncurses one (or an older version of our terminfo package!) will be used if ours cannot be found. To enable packagers full control over the new behavior, the existing meson command line options have been modified, and a new option added: -Dterminfo=disabled|enabled|auto: *build* and *install* the terminfo files. -Dcustom-terminfo-install-location=<path>: *where* the terminfo files are expected to be found. This *needs* to be set *even* if -Dterminfo=disabled. For example, if the packaging script builds and packages the terminfo files separate from the regular foot build. The path is *relative to $prefix*, and defaults to $datadir/foot/terminfo. This is the value that will be appended to TERMINFO_DIRS. Note that you can set it to ‘no’, in which case foot will *not* set/modify TERMINFO_DIRS. Only do this if you don’t intend to package foot’s terminfo files at all (i.e. you plan on using the ncurses ones only). -Ddefault-terminfo=foot. Allows overriding the default TERM value. This should only be changed if the target platform doesn’t support terminfo files. Closes #671
2021-06-20tokenize: strdup() each individual argvDaniel Eklöf-3/+1
Instead of referencing the un-tokenized “raw” command string, strdup() each argv. This way, the input string can be ‘const’.
2021-06-02slave/spawn: restore SIGHUP handler after fork(), before exec()Daniel Eklöf-2/+4
Foot installs a SIG_IGN handler for SIGHUP. Ignored signals are inherited in sub-processes. Thus, we need to restore it to SIG_DFL before exec:ing.
2021-05-20notifications: use \e[22m to disable boldDaniel Eklöf-3/+3
\e[21m was previously used to disable bold. That changed a while ago, to align foot with the majority of other terminal emulators. \e[22m now disables both bold and dim. When this change was done, the user notifications were not updated, meaning the ‘message’ part was always in bold. This was never the intended behavior.
2021-02-21errno: don’t use ‘_errno’ as a variable name; _ are reserved for use as identifiersDaniel Eklöf-11/+11
2021-02-21spawn/slave: restore signal mask after forkDaniel Eklöf-7/+2
slave: no need to restore signal handlers; they are automatically restored as long as they are not SIG_IGN (which they never are in foot). spawn(): restore signal mask after fork. This fixes an issue where a terminal spawned with ctrl+shift+n did not terminate when its shell exited. Closes #366
2021-02-10Mark slave_exec() as "noreturn" and convert xassert(false) to BUG(...)Craig Barnes-2/+3
2021-01-23slave: skip e310487dae99 if not supportedJan Beich-0/+2
slave.c:188:26: error: use of undeclared identifier 'IUTF8' flags.c_iflag |= IUTF8; ^
2021-01-21slave: skip e310487dae99 if not supportedJan Beich-0/+2
slave.c:188:26: error: use of undeclared identifier 'IUTF8' flags.c_iflag |= IUTF8; ^
2021-01-16debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes-2/+2
2021-01-16Print stack trace on assert() failure or when calling fatal_error()Craig Barnes-1/+1
Note: this uses the __sanitizer_print_stack_trace() function from the AddressSanitizer runtime, so it only works when AddressSanitizer is in use.
2020-10-10selection: use appropriate check for PRIMARY pasteSergey Nazaryev-258/+38
Assume it could be a copy-paste typo. We should check PRIMARY, not CLIPBOARD. Without this fix, we can't use PRIMARY until we copy anything to CLIPBOARD.
2020-08-23log: include 'fmt' in __VA_ARGS__Daniel Eklöf-2/+3
This ensures all calls have at least one __VA_ARGS__ argument, thus making them ISO C99 compliant.
2020-08-23slave: set $COLORTERM environment variable to "truecolor"Craig Barnes-0/+1
This is also done by libvte, alacritty, kitty and several other terminal emulators as a way to indicate support for 24-bit RGB colors. It generally also implies support for the xterm 256-color palette and basic ECMA-48 colors.
2020-08-08Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes-4/+5
2020-08-02Replace non-portable "\e" escape in string literals with "\033"Craig Barnes-4/+4
2020-08-01Revert "slave: use an event FD to communicate errors after fork before exec"Daniel Eklöf-17/+20
This reverts commit 027a8de6f547115fd90b8ee612fc616b61d5000c. I was a bit quick on this one, and only tested error cases. Turns out, this causes foot to hang in a blocking read(3) on the event FD. This is because while the FD has FD_CLOEXEC, that flag is per file descriptor. I.e. the forked copy of the event fd is closed when we exec(), but since this isn't a pipe, nothing is signaled to the parent process, which thus remains blocking in read(3) since its copy of the event fd hasn't been closed. We _could_ write a dummy value on the event fd just before exec(), but then we wouldn't be able to catch errors from exec() self - only errors *before* exec().
2020-08-01slave: use an event FD to communicate errors after fork before execDaniel Eklöf-20/+17
Replace the pipe we used to communicate errors after fork(), but before exec() to the parent process with an event FD. The overhead in the kernel is much lower to setup an event fd, compared to a pipe.
2020-08-01slave: emit user-notifications before dup:ing stdin/stdout/stderrDaniel Eklöf-40/+43
Since we need to restore the status flags anyway, there's nothing to gain from emitting the user notifications after dup:ing the pts file descriptor. On the other hand, emitting user notifications *before* dup:ing means we can still print error messages for e.g. write(3) errors.
2020-07-31slave: user-notifications: skip the O_NONBLOCK dance when there aren't any notificationsDaniel Eklöf-1/+1
2020-07-31slave: restore pts file status flags after emitting user-notificationsDaniel Eklöf-3/+5
We (need to) set O_NONBLOCK on the pts file description before emitting the user-notifications, to ensure we don't block in write(3). However, since file status flags are per *file*, not per file *descriptor*, this ends up setting O_NONBLOCK on the dup:ed stdin/stdout/stderr file descriptors too. Not all clients want this, or can handle this. Thus we need to restore the original flags before exec:ing the client. This fixes "makepkg" build failures.
2020-07-31slave: user-notifications: don't block in write(3)Daniel Eklöf-0/+18
The main process is blocking and waiting for us to close the error pipe (in exec(3), via O_CLOEXEC). Thus, pts data will *not* be processed until we've exec:d the shell. Because of this we must not write too much and block in write(3). Do this by setting O_NONBLOCK on the pts fd (*after* dup:ing it to stdin/stderr/sdout) and watch for EAGAIN EWOULDBLOCK.
2020-07-31slave: user-notifications: emit errors first, then warnings and last deprecationsDaniel Eklöf-2/+21
2020-07-30user-notification: 'productify' the user-warning systemDaniel Eklöf-38/+48
* Rename user_warning to user_notification * Add warning and error types (in addition to the existing deprecated) * Simplify logic when emitting a user notification after forking; we don't need to copy the notification data since we're in a new process and have total control over that memory.
2020-07-29slave: don't ignore write(3) errorsDaniel Eklöf-3/+14
2020-07-29term: add capability to print warnings *inside* the terminalDaniel Eklöf-3/+31
This is intended to be used to print e.g. deprecation warnings inside the terminal, *before* the shell is started.
2020-05-26slave: set IUTF8Daniel Eklöf-0/+14
2020-05-21slave: restore signal maskDaniel Eklöf-1/+4
2020-05-13slave: configure pts to be the controlling terminal of the forked processDaniel Eklöf-0/+7
2020-03-02slave: set $SHELL when command line is a shell listed in /etc/shellsDaniel Eklöf-0/+51
2020-02-20slave: check return value of chdir()Daniel Eklöf-1/+6
2020-02-20slave: prefix argv[0] with a '-' when spawning a login-shellDaniel Eklöf-5/+26
2019-12-21term: term_init: add 'cwd' argumentDaniel Eklöf-1/+3
This is used when spawning the slave, to set its current working directory just before we exec() the client. In a regular foot instance, we set the cwd from getcwd(). In a foot server instance, each connecting client sends its cwd to the server, and we use that.
2019-12-21term: term_spawn_new(): new function, spawns a new foot/footclient processDaniel Eklöf-0/+1
Bind ctrl+shift+return to it
2019-11-03slave: restore signals before calling exec()Daniel Eklöf-1/+13
2019-11-03slave: remove unneeded defineDaniel Eklöf-1/+0
2019-11-03slave: turn on FD_CLOEXEC after slave has been spawnedDaniel Eklöf-0/+9
This ensures that our ptmx FD isn't carried over to other terminals spawned later.
2019-11-01slave: set TERM environment variable in slave processDaniel Eklöf-1/+4
2019-10-30slave: log child's errno, not parentsDaniel Eklöf-2/+2
2019-10-30slave: fix debug logging (no 'term' variable)Daniel Eklöf-2/+2
2019-10-30term: move client startup to a new function, slave_spawn()Daniel Eklöf-2/+70
2019-10-30slave: rename slave_spawn() -> slave_exec()Daniel Eklöf-1/+1
2019-07-17main: allow user to override shell on the command lineDaniel Eklöf-8/+1
2019-07-17slave: break out command line tokenizerDaniel Eklöf-79/+1
2019-07-17slave: report exec() failure back to main processDaniel Eklöf-1/+2
2019-07-17slave: exec shell from confDaniel Eklöf-2/+87
2019-07-03logging: disable debug logging by defaultDaniel Eklöf-1/+1
2019-06-29slave: remove initial debug codeDaniel Eklöf-16/+0
2019-06-15wip: vt parsing: initial csi/osc dispatchingDaniel Eklöf-0/+5
2019-06-13Initial handling of multi byte charactersDaniel Eklöf-1/+1
Use mblen() to calculate the byte count for each character.
2019-06-13Render cursorDaniel Eklöf-0/+3
2019-06-13Use frame callback to rate-limit surface updatesDaniel Eklöf-0/+3
2019-06-13initial grid implementationDaniel Eklöf-1/+2
This allows us to render *something*, even though it's inefficient, stupid and far far away from the real thing.
2019-06-13Set up pseudo terminal and fork slaveDaniel Eklöf-0/+67