Commit Graph

42 Commits

Author SHA1 Message Date
Lennart Poettering fce93d7aa3 ptyfwd: use ERRNO_IS_DISCONNECT() when checking for disconnection on foreign fds 2020-09-22 16:25:22 +02:00
Lennart Poettering 1ba37106b3 ptyfwd: don't set prio if event source that might not exist
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.
2020-09-04 23:52:41 +02:00
Lennart Poettering d435a18244 ptyfwd: optionally override terminal width/height 2018-11-29 20:21:39 +01:00
Lennart Poettering da22bdbc05 ptyfwd: when we can't copy the window size from caller, use $LINES and $COLUMNS
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.
2018-10-09 10:28:42 +02:00
Lennart Poettering 4b3c721234 ptyfwd: voidify more calls (#10310) 2018-10-08 11:53:35 -07:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
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.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
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.
2018-06-14 10:20:20 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
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.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Lennart Poettering d147457cc9 run: run pty forwarder at higher event priority than the bus
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.
2017-12-05 18:33:24 +01:00
Lennart Poettering e22e69a31e ptyfwd: before deciding that a pty is fully drained, ask the kernel again
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
2017-12-05 18:33:24 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Andreas Rammhold 3742095b27
tree-wide: use IN_SET where possible
In addition to the changes from #6933 this handles cases that could be
matched with the included cocci file.
2017-10-02 13:09:54 +02:00
Lennart Poettering 95f1d6bfec run: exit early in --pty if service failed
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
2017-02-03 11:51:57 +01:00
Lennart Poettering 9a1c8f2d24 ptyfwd: set event source description strings for all event sources of a ptyfwd object 2017-02-02 20:59:43 +01:00
Zbigniew Jędrzejewski-Szmek 6b430fdb7c tree-wide: use mfree more 2016-10-16 23:35:39 -04:00
Lennart Poettering 2a453c2ee3 run: optionally, wait for the service to finish and show its result 2016-08-22 16:14:21 +02:00
Alexander Kuleshov 5883ff6017 tree-wide: use SET_FLAG() macro to make code more clear 2016-03-05 18:26:01 +06:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Thomas Hindoe Paaboel Andersen a8fbdf5424 shared: include what we use
The next step of a general cleanup of our includes. This one mostly
adds missing includes but there are a few removals as well.
2015-12-06 13:49:33 +01:00
Thomas Hindoe Paaboel Andersen cf0fbc49e6 tree-wide: sort includes
Sort the includes accoding to the new coding style.
2015-11-16 22:09:36 +01:00
Lennart Poettering 3c747da38c nspawn: fix minor memory leak
When rebooting nspawn containers about 400 times we'd otherwise hit the
fd limit and refuse further reboots.
2015-10-31 19:09:20 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering ae3dde8012 machinectl: fix race when opening new shells with "machinectl shell"
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.
2015-10-07 20:10:48 +02:00
Zbigniew Jędrzejewski-Szmek dc75168823 Use space after a silencing (void)
We were using a space more often than not, and this way is
codified in CODING_STYLE.
2015-03-13 23:42:17 -04:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
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.
2015-02-23 23:53:42 +01:00
Lennart Poettering 9c857b9d16 nspawn: when connected to pipes for stdin/stdout, pass them as-is to PID 1
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
2015-02-18 23:36:20 +01:00
Lennart Poettering 679bc6cb90 ptyfw: add missing error check 2015-01-14 23:18:33 +01:00
Lennart Poettering da054c3782 ptyfwd: simplify how we handle vhangups a bit 2015-01-07 14:47:10 +01:00
Lennart Poettering 0ec5543c4c machinectl: make sure that "machinectl login" exits immediately when the machine it is connected to dies 2015-01-07 03:08:00 +01:00
Lennart Poettering 9b15b7846d run: add a new "-t" mode for invoking a binary on an allocated TTY 2014-12-23 03:26:24 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
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.
2014-11-28 19:49:27 +01:00
Tom Gundersen 7c63b23f49 shared: ptyfwd - make coverity happy
Explicitly ignore return value of ioctl to set window size.

Fixes CID#1250804 and CID#1250800.
2014-11-05 16:54:22 +01:00
Lennart Poettering 023fb90b83 ptyforward: rework PTY forwarder logic used by nspawn to utilize the normal 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.
2014-10-31 16:55:04 +01:00
Lennart Poettering d60473c7ba ptyfwd: reset nonblocking mode
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
2014-02-21 18:42:14 +01:00
Lennart Poettering 8674debc67 Revert "ptyfwd: make master terminal attributes raw, too"
This reverts commit e7d43b3cc3.

This broke the console terminal when booting up a container, so let's
not do this.
2013-12-18 19:26:10 +01:00
Lennart Poettering e7d43b3cc3 ptyfwd: make master terminal attributes raw, too 2013-12-18 18:21:28 +01:00
Luke Shumaker 90d14d2015 ptyfwd: Don't set the output prop of stdin, nor the input props of stdout.
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.
2013-12-11 01:04:21 +00:00
Luke Shumaker eaf73b0616 ptyfwd: Set the size of the PTY base on the size of stdout, not stdin. 2013-12-11 01:01:40 +00:00
Lennart Poettering 04d3927924 machinectl: add new command to spawn a getty inside a container 2013-10-31 01:43:38 +01:00
Lennart Poettering 4ba9328022 nspawn: split out pty forwaring logic into ptyfwd.c 2013-10-31 01:43:38 +01:00