summaryrefslogtreecommitdiffstats
path: root/src/shared/ptyfwd.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* ptyfwd: ellipsize overly long window titlesLennart Poettering2024-11-131-4/+20
| | | | | | | | | | Apparently some terminal emulators have problems with overly long titles, hence truncate them at some safe length (128). Also, when parsing ANSI sequences ourselves accept longer sequences (192), after all we should be fine when parsing our own title sequences. Fixes: #35104
* terminal-util: define ANSI_OSC as macro for the OSC terminal sequence prefixLennart Poettering2024-10-311-2/+2
|
* ptyfwd: document why we only honour two of the three kinds of STLennart Poettering2024-10-311-5/+10
|
* tree-wide: prefer generating 0x1B 0x5C as ANSI sequence "ST"Lennart Poettering2024-10-311-2/+2
| | | | | | | | | | | | | | | | | OSC sequences can be closed with one of three terminators: 1. ASCII code 7, aka BEL, aka ^G, aka \x07, aka \a 2. ASCII code 156, aka \x9c 2. Pair of ASCII code 27 followed by ASCII code 92, aka \x1b\x5c Of these, in some corner case scenarios BEL makes problem (see #34604). Hence switch away from that wherever we use it, and prefer the \x1b\x5c instead. That's preferable over \x9c, since the latter is also a valid UTF-8 codepoint. See discussion here for example: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#the-escape-sequence Fixes: #34604
* tree-wide: make sigprocmask() changes more automaticLennart Poettering2024-09-131-1/+1
| | | | | | | | | | | | | This tries to get rid of most manual sigprocmask() changes, in favour of: 1. The SD_EVENT_SIGNAL_PROCMASK flag to sd_event_add_signal() 2. The sd_event_set_signal_exit() call for handling SIGTERM/SIGINT 3. Move masking of SIGWINCH into ptyfwd, out of nspawn/vmspawn/run And while we are at it get rid of a bunch of event source fields whose lifetime is bound to the sd_event object they belong to anyway, and make use of the "floating" event source feature of sd-event instead.
* terminal-util: split out color macros/helpers into its own headerLennart Poettering2024-07-191-0/+1
| | | | | | | | | This is a lot of stuff, and sometimes quite wild, let's turn this into its own header. All stuff color-related that just generates sequences is now in ansi-color.h (no .c file!), and everything more complex that probes/ineracts with terminals remains in termina-util.[ch]
* ptyfwd: reset color after two tty reset sequences, tooLennart Poettering2024-07-181-1/+19
| | | | | | | | When we patch in a bg color we must make sure that when certain "reset" sequences are transferred we fix up the bg color again. Do so for \033[!p ("soft terminal reset") and \033c ("reset to initial state" aka "full reset").
* run: add environment variable to prevent the setting of terminal titleMantas MikulÄ—nas2024-06-251-0/+16
| | | | | | This goes together with the existing SYSTEMD_TINT_BACKGROUND. Closes https://github.com/systemd/systemd/issues/33301
* ptyfwd: add missing assertions for pty_forward_newMike Yuan2024-05-211-0/+3
|
* ptyfwd: trivial coding style and log cleanupsMike Yuan2024-05-191-13/+16
|
* various: drop unnecessary DISABLE_WARNING_FORMAT_NONLITERALMike Yuan2024-04-281-2/+0
| | | | | We use _printf_ for these functions, so there shouldn't be a warning in the first place.
* Use IN_SET() moreFrantisek Sumsal2024-04-021-1/+1
|
* ptyfwd: drop redundant bracketsYu Watanabe2024-03-141-9/+3
|
* ptyfwd: do not erase line after NLYu Watanabe2024-03-141-39/+6
| | | | | | Otherwise, moving upwards in 'less' does not work. Follow-up for d0aa368c85adf2efa29c363a6671927fe7e8e76f.
* ptyfwd: fix typoYu Watanabe2024-03-141-1/+1
| | | | Follow-up for d0aa368c85adf2efa29c363a6671927fe7e8e76f.
* fs-utils: new wrapper fd_reopen_propagate_append_and_position()Lars Ellenberg2024-03-121-3/+8
| | | | | | | | | | | | | | | | | | | | We may want to propagate O_APPEND, or (try to) keep the current file position, even if we use fd_reopen() to re-initialize (and "unshare") other file description status. For now, used only with --pty to keep/propagate O_APPEND (and/or) position if set on stdin/stdout. If we re-open stdout and "drop" the O_APPEND, we get rather "unexpected" behavior, for example with repeated "systemd-run --pty >> some-log". If someone carefully pre-positioned the passed in original file descriptors, we avoid surprises if we do not reset file postition to zero. fcntl F_GETFL first, and propagate O_APPEND if present in the existing flags. Then use lseek to propagate the file position.
* stat-util: introduce fd_inode_sameMike Yuan2024-03-111-1/+1
|
* shared/ptyfwd: detect String Terminator or BEL when parsing an OSC sequenceSam Leonard2024-02-281-3/+9
|
* shared/ptyfwd: allow window title but not background color as a valid stateSam Leonard2024-02-281-2/+6
| | | | | | | | | | | | | | | Previously if a PTYForward instance had the window title set but no background color set then it would crash in an assertion as pty_forward_ansi_process didn't require both to be present. systemd-vmspawn could get into this state if it failed to get the terminal tint color. Now any method that would have called background_color_sequence now becomes just a NOP if the background color is not set. This allows keeping the functionality to set window titles even if the terminal doesn't support the background coloring.
* ptyfwd: optionally prefix window title with colored dotLennart Poettering2024-02-231-3/+66
| | | | | | | | | | | | | | in uid0/systemd-run/nspawn we already set a window title with a colorful unicode dot indicating the changed privileges/execution context. This typically gets overriden by the shell inside the environment however. Let's tweak this a bit: when we see the window title OSC ANSI sequence passing through, let's patch in the unicode dot as a prefix to the title. This is super pretty, since it makes sure root sessions via 0ad are really easily recognizable as such, because the window title carries an 🔴 red dot as prefix then.
* Merge pull request #30380 from keszybz/tmpfiles-dry-runLennart Poettering2024-02-131-1/+1
|\ | | | | Make tmpfiles/sysusers nicer with local files and implement tmpfiles --dry-run
| * tree-wide: use normal spelling of "reopen"Zbigniew Jędrzejewski-Szmek2024-02-091-1/+1
| | | | | | | | It's a commonly used verb meaning "to open again".
* | ptyfwd: automatically turn off tinting/window title logic on dumb terminalsLennart Poettering2024-02-091-1/+12
| | | | | | | | | | If we are not talking to a reasonable terminal let's not try to set the window title or tint the background.
* | ptyfwd: simplify error handling in shovel()Lennart Poettering2024-02-091-23/+27
| | | | | | | | | | | | | | We treat all errors the same, hence let's just have a common handling for that, and normalize how we propagate errors from shovel(). No change in behaviour, just some refactoring.
* | ptyfwd: optionally update window title if we are running a ptyfwd sessionLennart Poettering2024-02-091-10/+60
| |
* | ptyfwd: tweaks to background tinting logicLennart Poettering2024-02-091-15/+52
|/ | | | | | | | | | | | | | This makes two changes: 1. it resets the background color not only on NL (aka LF) but also on CR, but without erasing things to the end of the line. This increases compatbility with tools such as "less" which use CR to jump back to the beginning of the line. 2. previously we'd not process series of newlines or ansi sequences without intermediate other characters correctly, we'd always assume what follows is regular text. Fix that, and correctly determine the right state from the subsequent character.
* ptyfwd: when leaving a session with tinted background, clear to end of screenLennart Poettering2024-01-201-1/+1
| | | | | | | | | | So if we tint the background of a ptyfwd session with a color and the session ends, then so far we reset the bg color and clear till the end of line. Let's instead clear till the end of the screen. This is nicer since it means that any follow-up output will not be affected by the changed background color anymore.
* ptyfwd: optionally, change ANSI background color of forwarded terminalsLennart Poettering2023-12-211-3/+272
| | | | | | | | | | | | | | | | | | | As the bytes flow through our terminal forwarder we can color the background of the terminal with a color of our choices, if that's desired. This will later allow us to color the background of the uid0 tool when running as root with a slightly alarming red color. This does two things: 1. When an ANSI sequence is seen that resets the background color, it is extended to immediately set the color to our choice. 2. When a newline is seen it is immeidately extended to set the background color again and clear the current line till the end. Net effect: all lines written while we forward the ttys will be shown with the background color of choice.
* ptyfwd: make sure pty_forward_free() follows our usual semantics regarding NULLLennart Poettering2023-12-201-0/+2
|
* ptyfwd: reset colors when we exit the pty forwarding logicLennart Poettering2023-12-201-0/+5
| | | | Just in case there was still a color set, make sure to reset things.
* ptyfwd: don't reset TTY twice if stdin/stdout point to same TTYLennart Poettering2023-11-241-4/+14
| | | | And in particular don't save/restore an already reset TTY state.
* ptyfwd: trivial format cleanupsYu Watanabe2023-11-241-9/+6
|
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-3/+3
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* tree-wide: use ASSERT_PTR moreDavid Tardon2022-09-131-8/+4
|
* tree-wide: use UINT64_MAX or friendsYu Watanabe2021-03-041-6/+6
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* tree-wide: drop if braces around single line expressions as wellFrantisek Sumsal2020-10-091-3/+1
|
* ptyfwd: reopen stdin/sdout before setting O_NONBLOCKLennart Poettering2020-10-021-32/+81
| | | | | | | | | | | | | | If we set O_NONBLOCK on stdin/stdout directly this means the flag is left set when we abort abnormally, as we don't get the chance to reset it again on exit. This might confuse progrms invoking us. Moreover, if programs invoking us continue to write to the stdout passed to us, they might be confused by non-blocking mode too. Hence, let's avoid this if possible: let's reopen stdin/stdout and set O_NONBLOCK only on the reopend fds, leaving the original fds as they are. Prompted-by: https://github.com/systemd/systemd/pull/17070#issuecomment-702304802
* ptyfwd: use ERRNO_IS_DISCONNECT() when checking for disconnection on foreign fdsLennart Poettering2020-09-221-2/+3
|
* ptyfwd: don't set prio if event source that might not existLennart Poettering2020-09-041-3/+5
| | | | | | We support read-only ptyfwd options, and on those the input event source won't be allocated. Deal with that and don't invoke a function on it that will then instantly fail.
* ptyfwd: optionally override terminal width/heightLennart Poettering2018-11-291-2/+44
|
* ptyfwd: when we can't copy the window size from caller, use $LINES and $COLUMNSLennart Poettering2018-10-091-2/+12
| | | | | | This way users can directly influence the tty size if they like when nspawn is invoked as a service and thus stdin/stdout/stderr are not connected to a TTY.
* ptyfwd: voidify more calls (#10310)Lennart Poettering2018-10-081-2/+2
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-04-051-2/+1
|
* run: run pty forwarder at higher event priority than the busLennart Poettering2017-12-051-0/+23
| | | | | We want any tty I/O to happen before we look at service messages, hence let's set priorities on them, and give tty I/O a higher priority.
* ptyfwd: before deciding that a pty is fully drained, ask the kernel againLennart Poettering2017-12-051-3/+26
| | | | | | | | | | | | Apparently there's no guarantee that EPOLLIN is immediately propagated from a pty slave to the master when data is written to it, hence it's not sufficient to check EPOLLIN to decide whether the pty device is drained. Let's fix this by asking the kernel directly through SIOCINQ + SIOCOUTQ, if there's anything buffered left. Fixes: #7531
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.