]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ptyfwd: optionally override terminal width/height
authorLennart Poettering <lennart@poettering.net>
Tue, 24 Jul 2018 15:15:33 +0000 (17:15 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 29 Nov 2018 19:21:39 +0000 (20:21 +0100)
src/shared/ptyfwd.c
src/shared/ptyfwd.h

index 1cb7ea3a197f9c251fb0e38724d3e605e721bdc2..fe17b3781aafc730a381d3dfbe1389a0bd9addf5 100644 (file)
@@ -392,11 +392,14 @@ int pty_forward_new(
         struct winsize ws;
         int r;
 
-        f = new0(PTYForward, 1);
+        f = new(PTYForward, 1);
         if (!f)
                 return -ENOMEM;
 
-        f->flags = flags;
+        *f = (struct PTYForward) {
+                .flags = flags,
+                .master = -1,
+        };
 
         if (event)
                 f->event = sd_event_ref(event);
@@ -587,3 +590,42 @@ int pty_forward_set_priority(PTYForward *f, int64_t priority) {
 
         return 0;
 }
+
+int pty_forward_set_width_height(PTYForward *f, unsigned width, unsigned height) {
+        struct winsize ws;
+
+        assert(f);
+
+        if (width == (unsigned) -1 && height == (unsigned) -1)
+                return 0; /* noop */
+
+        if (width != (unsigned) -1 &&
+            (width == 0 || width > USHRT_MAX))
+                return -ERANGE;
+
+        if (height != (unsigned) -1 &&
+            (height == 0 || height > USHRT_MAX))
+                return -ERANGE;
+
+        if (width == (unsigned) -1 || height == (unsigned) -1) {
+                if (ioctl(f->master, TIOCGWINSZ, &ws) < 0)
+                        return -errno;
+
+                if (width != (unsigned) -1)
+                        ws.ws_col = width;
+                if (height != (unsigned) -1)
+                        ws.ws_row = height;
+        } else
+                ws = (struct winsize) {
+                        .ws_row = height,
+                        .ws_col = width,
+                };
+
+        if (ioctl(f->master, TIOCSWINSZ, &ws) < 0)
+                return -errno;
+
+        /* Make sure we ignore SIGWINCH window size events from now on */
+        f->sigwinch_event_source = sd_event_source_unref(f->sigwinch_event_source);
+
+        return 0;
+}
index e4a083ac2414944a23f3cfccb273f87f954b6c3f..4ebddcd72019decc8e5c513c282c26cfc6b84000 100644 (file)
@@ -37,4 +37,6 @@ bool pty_forward_drain(PTYForward *f);
 
 int pty_forward_set_priority(PTYForward *f, int64_t priority);
 
+int pty_forward_set_width_height(PTYForward *f, unsigned width, unsigned height);
+
 DEFINE_TRIVIAL_CLEANUP_FUNC(PTYForward*, pty_forward_free);