summaryrefslogtreecommitdiff
path: root/src/shared/ptyfwd.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* tree-wide: use IN_SET where possibleAndreas Rammhold2017-10-021-5/+5
| | | | | In addition to the changes from #6933 this handles cases that could be matched with the included cocci file.
* run: exit early in --pty if service failedLennart Poettering2017-02-031-0/+21
| | | | | | | | | | | | | | | | | | | | This reworks systemd-run so that in --pty mode we watch the unit state the way we do it in --wait mode. Whenever we notice that the service is in failed or inactive state finish right-away, but first write all unwritten characters we can read from the master TTY device. This makes sure that when the TTY service fails before it opens the slave PTY device we properly notice that and exit early, so that borked start parameters result in immediate systemd-run failure. Previously, we'd not notice this at all, as a PTY slave that never was opened won't result in POLLHUP events, and we'd hence simply keep reading from it forever. In essence, --pty now enables the same unit watching logic that --wait enables. However, unless --wait is specified we won#t show the final summary, hence the effective difference should be pretty minimal. Fixes: #3915
* ptyfwd: set event source description strings for all event sources of a ↵Lennart Poettering2017-02-021-0/+9
| | | | ptyfwd object
* tree-wide: use mfree moreZbigniew Jędrzejewski-Szmek2016-10-161-2/+1
|
* run: optionally, wait for the service to finish and show its resultLennart Poettering2016-08-221-32/+70
|
* tree-wide: use SET_FLAG() macro to make code more clearAlexander Kuleshov2016-03-051-4/+1
|
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* shared: include what we useThomas Hindoe Paaboel Andersen2015-12-061-1/+13
| | | | | The next step of a general cleanup of our includes. This one mostly adds missing includes but there are a few removals as well.
* tree-wide: sort includesThomas Hindoe Paaboel Andersen2015-11-161-1/+1
| | | | Sort the includes accoding to the new coding style.
* nspawn: fix minor memory leakLennart Poettering2015-10-311-0/+1
| | | | | When rebooting nspawn containers about 400 times we'd otherwise hit the fd limit and refuse further reboots.
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-0/+1
|
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-1/+2
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* machinectl: fix race when opening new shells with "machinectl shell"Lennart Poettering2015-10-071-17/+32
| | | | | | | | | | | | | | | | | Previously, we'd allocate the TTY, spawn a service on it, but immediately start processing the TTY and forwarding it to whatever the commnd was started on. This is however problematic, as the TTY might get actually opened only much later by the service. We'll hence first get EIOs on the master as the other side is still closed, and hence considered it hung up and terminated the session. With this change we add a flag to the pty forwarding logic: PTY_FORWARD_IGNORE_INITIAL_VHANGUP. If set, we'll ignore all hangups (i.e. EIOs) on the master PTY until the first byte is successfully read. From that point on we consider a hangup/EIO a regular connection termination. This way, we handle the race: when we get EIO initially we'll ignore it, until the connection is properly set up, at which time we start honouring it.
* Use space after a silencing (void)Zbigniew Jędrzejewski-Szmek2015-03-131-1/+1
| | | | | We were using a space more often than not, and this way is codified in CODING_STYLE.
* remove unused includesThomas Hindoe Paaboel Andersen2015-02-231-1/+0
| | | | | | This patch removes includes that are not used. The removals were found with include-what-you-use which checks if any of the symbols from a header is in use.
* nspawn: when connected to pipes for stdin/stdout, pass them as-is to PID 1Lennart Poettering2015-02-181-31/+44
| | | | | | | | | | | Previously we always invoked the container PID 1 on /dev/console of the container. With this change we do so only if nspawn was invoked interactively (i.e. its stdin/stdout was connected to a TTY). In all other cases we directly pass through the fds unmodified. This has the benefit that nspawn can be added into shell pipelines. https://bugs.freedesktop.org/show_bug.cgi?id=87732
* ptyfw: add missing error checkLennart Poettering2015-01-141-1/+3
|
* ptyfwd: simplify how we handle vhangups a bitLennart Poettering2015-01-071-32/+20
|
* machinectl: make sure that "machinectl login" exits immediately when the ↵Lennart Poettering2015-01-071-9/+51
| | | | machine it is connected to dies
* run: add a new "-t" mode for invoking a binary on an allocated TTYLennart Poettering2014-12-231-4/+29
|
* treewide: use log_*_errno whenever %m is in the format stringMichal Schmidt2014-11-281-4/+4
| | | | | | | | | | | If the format string contains %m, clearly errno must have a meaningful value, so we might as well use log_*_errno to have ERRNO= logged. Using: find . -name '*.[ch]' | xargs sed -r -i -e \ 's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/' Plus some whitespace, linewrap, and indent adjustments.
* shared: ptyfwd - make coverity happyTom Gundersen2014-11-051-2/+2
| | | | | | Explicitly ignore return value of ioctl to set window size. Fixes CID#1250804 and CID#1250800.
* ptyforward: rework PTY forwarder logic used by nspawn to utilize the normal ↵Lennart Poettering2014-10-311-265/+269
| | | | | | | event loop We really should not run manual event loops anymore, but standardize on sd_event, so that we can run sd_bus connections from it eventually.
* ptyfwd: reset nonblocking modeLennart Poettering2014-02-211-3/+8
| | | | | | | | Apparently bash doesn't turn off non-blocking mode on stdin/stdout when reading from it, so be nice to bash. Ideally bash would do this on its own for robustness reasons, though. https://bugs.freedesktop.org/show_bug.cgi?id=70622
* Revert "ptyfwd: make master terminal attributes raw, too"Lennart Poettering2013-12-181-7/+2
| | | | | | | This reverts commit e7d43b3cc30764138c90eaaf95d3d8f49e448890. This broke the console terminal when booting up a container, so let's not do this.
* ptyfwd: make master terminal attributes raw, tooLennart Poettering2013-12-181-2/+7
|
* ptyfwd: Don't set the output prop of stdin, nor the input props of stdout.Luke Shumaker2013-12-111-12/+23
| | | | | | | It was calling cfmakeraw(3) on the properties for STDIN_FILENO; cfmakeraw sets both input and output properties. If (and only if) stdin and stdout are the same device is this correct. Otherwise, we must change only the input properties of stdin, and only the output properties of stdout.
* ptyfwd: Set the size of the PTY base on the size of stdout, not stdin.Luke Shumaker2013-12-111-2/+2
|
* machinectl: add new command to spawn a getty inside a containerLennart Poettering2013-10-311-52/+170
|
* nspawn: split out pty forwaring logic into ptyfwd.cLennart Poettering2013-10-311-0/+252