aboutsummaryrefslogtreecommitdiff
path: root/slave.c (follow)
Commit message (Collapse)AuthorAgeLines
* slave: prefix user notifications with 'foot'Daniel Eklöf2024-08-09-1/+3
| | | | To make it clearer _who_ is emitting the warning/errors
* xmalloc: remove delim param from xstrjoin() and add separate xstrjoin3()Craig Barnes2024-08-03-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
* Remove a number of unused includesDaniel Eklöf2024-08-02-1/+0
|
* meson: auto-detect execvpe on FreeBSDJan Beich2024-06-07-3/+3
| | | | https://github.com/freebsd/freebsd-src/commit/0667d0e0e365
* util: add streq() function and use in place of strcmp(...) == 0Craig Barnes2024-02-05-1/+2
|
* slave: fix typoArtturin2024-01-16-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 ```
* slave: don't skip setting environment variables when using a custom environmentDaniel Eklöf2024-01-11-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
* slave: ignore return value of chdir()Daniel Eklöf2024-01-05-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("/"); | ^~~~~~~~~~
* slave: chdir to / after spawning the client applicationDaniel Eklöf2024-01-03-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
* slave: unset TERM_PROGRAM{,_VERSION}Daniel Eklöf2023-05-18-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
* slave: set $TERM_PROGRAM and $TERM_PROGRAM_VERSION environment variablesCraig Barnes2023-03-20-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
* slave: unsetenv() env vars that have been set to the empty stringDaniel Eklöf2022-12-06-2/+9
| | | | | | | | | | | That is, users can now *clear* environment variables by doing: [environment] VAR=”” Note that the quotes are required. Closes #1225
* slave: spawn: set PWD environment variableDaniel Eklöf2022-10-02-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
* config: add a new ‘environment’ sectionDaniel Eklöf2022-06-13-2/+8
| | | | | | | | This section allows the user to define custom environment variables to be set in the child process: [environment] name=value
* slave: roll our own ‘execvpe()’ on FreeBSDDaniel Eklöf2022-04-12-1/+58
|
* client/slave: explictly add ‘extern char **environ’Daniel Eklöf2022-04-12-0/+2
| | | | It’s not in any header files on FreeBSD.
* client: add -E,--client-environmentDaniel Eklöf2022-04-12-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
* Explicitly initialize sigaction::sa_mask members with sigemptyset(3)Craig Barnes2022-02-12-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
* slave: re-use ‘struct sigaction’ variable when resetting SIGHUP+SIGPIPEDaniel Eklöf2021-12-18-2/+4
|
* slave: restore SIGPIPEDaniel Eklöf2021-12-18-1/+2
|
* slave: log _which_ CWD we failed to change toDaniel Eklöf2021-08-30-1/+1
|
* slave: set TERMINFO instead of TERMINFO_DIRSDaniel Eklöf2021-08-18-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
* terminfo: install to $datadir/foot/terminfo by default, append to TERMINFO_DIRSDaniel Eklöf2021-08-17-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
* tokenize: strdup() each individual argvDaniel Eklöf2021-06-20-3/+1
| | | | | Instead of referencing the un-tokenized “raw” command string, strdup() each argv. This way, the input string can be ‘const’.
* slave/spawn: restore SIGHUP handler after fork(), before exec()Daniel Eklöf2021-06-02-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.
* notifications: use \e[22m to disable boldDaniel Eklöf2021-05-20-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.
* errno: don’t use ‘_errno’ as a variable name; _ are reserved for use as identifiersDaniel Eklöf2021-02-21-11/+11
|
* spawn/slave: restore signal mask after forkDaniel Eklöf2021-02-21-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
* Mark slave_exec() as "noreturn" and convert xassert(false) to BUG(...)Craig Barnes2021-02-10-2/+3
|
* slave: skip e310487dae99 if not supportedJan Beich2021-01-21-0/+2
| | | | | | slave.c:188:26: error: use of undeclared identifier 'IUTF8' flags.c_iflag |= IUTF8; ^
* debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes2021-01-16-2/+2
|
* Print stack trace on assert() failure or when calling fatal_error()Craig Barnes2021-01-16-1/+1
| | | | | | Note: this uses the __sanitizer_print_stack_trace() function from the AddressSanitizer runtime, so it only works when AddressSanitizer is in use.
* log: include 'fmt' in __VA_ARGS__Daniel Eklöf2020-08-23-2/+3
| | | | | This ensures all calls have at least one __VA_ARGS__ argument, thus making them ISO C99 compliant.
* slave: set $COLORTERM environment variable to "truecolor"Craig Barnes2020-08-23-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.
* Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes2020-08-08-4/+5
|
* Replace non-portable "\e" escape in string literals with "\033"Craig Barnes2020-08-02-4/+4
|
* Revert "slave: use an event FD to communicate errors after fork before exec"Daniel Eklöf2020-08-01-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().
* slave: use an event FD to communicate errors after fork before execDaniel Eklöf2020-08-01-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.
* slave: emit user-notifications before dup:ing stdin/stdout/stderrDaniel Eklöf2020-08-01-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.
* slave: user-notifications: skip the O_NONBLOCK dance when there aren't any notificationsDaniel Eklöf2020-07-31-1/+1
|
* slave: restore pts file status flags after emitting user-notificationsDaniel Eklöf2020-07-31-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.
* slave: user-notifications: don't block in write(3)Daniel Eklöf2020-07-31-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.
* slave: user-notifications: emit errors first, then warnings and last deprecationsDaniel Eklöf2020-07-31-2/+21
|
* user-notification: 'productify' the user-warning systemDaniel Eklöf2020-07-30-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.
* slave: don't ignore write(3) errorsDaniel Eklöf2020-07-29-3/+14
|
* term: add capability to print warnings *inside* the terminalDaniel Eklöf2020-07-29-3/+31
| | | | | This is intended to be used to print e.g. deprecation warnings inside the terminal, *before* the shell is started.
* slave: set IUTF8Daniel Eklöf2020-05-26-0/+14
|
* slave: restore signal maskDaniel Eklöf2020-05-21-1/+4
|
* slave: configure pts to be the controlling terminal of the forked processDaniel Eklöf2020-05-13-0/+7
|
* slave: set $SHELL when command line is a shell listed in /etc/shellsDaniel Eklöf2020-03-02-0/+51
|
* slave: check return value of chdir()Daniel Eklöf2020-02-20-1/+6
|
* slave: prefix argv[0] with a '-' when spawning a login-shellDaniel Eklöf2020-02-20-5/+26
|
* term: term_init: add 'cwd' argumentDaniel Eklöf2019-12-21-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.
* term: term_spawn_new(): new function, spawns a new foot/footclient processDaniel Eklöf2019-12-21-0/+1
| | | | Bind ctrl+shift+return to it
* slave: restore signals before calling exec()Daniel Eklöf2019-11-03-1/+13
|
* slave: remove unneeded defineDaniel Eklöf2019-11-03-1/+0
|
* slave: turn on FD_CLOEXEC after slave has been spawnedDaniel Eklöf2019-11-03-0/+9
| | | | | This ensures that our ptmx FD isn't carried over to other terminals spawned later.
* slave: set TERM environment variable in slave processDaniel Eklöf2019-11-01-1/+4
|
* slave: log child's errno, not parentsDaniel Eklöf2019-10-30-2/+2
|
* slave: fix debug logging (no 'term' variable)Daniel Eklöf2019-10-30-2/+2
|
* term: move client startup to a new function, slave_spawn()Daniel Eklöf2019-10-30-2/+70
|
* slave: rename slave_spawn() -> slave_exec()Daniel Eklöf2019-10-30-1/+1
|
* main: allow user to override shell on the command lineDaniel Eklöf2019-07-17-8/+1
|
* slave: break out command line tokenizerDaniel Eklöf2019-07-17-79/+1
|
* slave: report exec() failure back to main processDaniel Eklöf2019-07-17-1/+2
|
* slave: exec shell from confDaniel Eklöf2019-07-17-2/+87
|
* logging: disable debug logging by defaultDaniel Eklöf2019-07-03-1/+1
|
* slave: remove initial debug codeDaniel Eklöf2019-06-29-16/+0
|
* wip: vt parsing: initial csi/osc dispatchingDaniel Eklöf2019-06-15-0/+5
|
* Initial handling of multi byte charactersDaniel Eklöf2019-06-13-1/+1
| | | | Use mblen() to calculate the byte count for each character.
* Render cursorDaniel Eklöf2019-06-13-0/+3
|
* Use frame callback to rate-limit surface updatesDaniel Eklöf2019-06-13-0/+3
|
* initial grid implementationDaniel Eklöf2019-06-13-1/+2
| | | | | This allows us to render *something*, even though it's inefficient, stupid and far far away from the real thing.
* Set up pseudo terminal and fork slaveDaniel Eklöf2019-06-13-0/+67