]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ptyfwd: when we can't copy the window size from caller, use $LINES and $COLUMNS
authorLennart Poettering <lennart@poettering.net>
Mon, 30 Jul 2018 18:57:22 +0000 (20:57 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 9 Oct 2018 08:28:42 +0000 (10:28 +0200)
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.

src/shared/ptyfwd.c

index 942c3f31dc9d21ced2963e88f61e61849eb334ed..1cb7ea3a197f9c251fb0e38724d3e605e721bdc2 100644 (file)
@@ -20,6 +20,7 @@
 #include "log.h"
 #include "macro.h"
 #include "ptyfwd.h"
+#include "terminal-util.h"
 #include "time-util.h"
 
 struct PTYForward {
@@ -421,8 +422,17 @@ int pty_forward_new(
 
         f->master = master;
 
-        if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) >= 0)
-                (void) ioctl(master, TIOCSWINSZ, &ws);
+        if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) {
+                /* If we can't get the resolution from the output fd, then use our internal, regular width/height,
+                 * i.e. something derived from $COLUMNS and $LINES if set. */
+
+                ws = (struct winsize) {
+                        .ws_row = lines(),
+                        .ws_col = columns(),
+                };
+        }
+
+        (void) ioctl(master, TIOCSWINSZ, &ws);
 
         if (!(flags & PTY_FORWARD_READ_ONLY)) {
                 if (tcgetattr(STDIN_FILENO, &f->saved_stdin_attr) >= 0) {