>From an internal bug:

    $ adb shell
    # set terminal width to 68 chars
    sailfish:/ $ ps -A | grep init
    root             1     0   12344   1556 SyS_epoll+          0 S init
    # reduce terminal width to 67 chars
    sailfish:/ $ ps -A | grep init
    1|sailfish:/ $

Patch attached to check isatty(1) before getting the terminal size.
From 2f289334ba5d262080a9da1186f0530a5aec1c79 Mon Sep 17 00:00:00 2001
From: Josh Gao <jm...@google.com>
Date: Mon, 27 Mar 2017 15:53:03 -0700
Subject: [PATCH] ps: don't query for terminal size if not a tty.

`ps -A | cat` shouldn't have different output depending on the size of
your terminal window.
---
 toys/posix/ps.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 0d79b5c..f690671 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1149,8 +1149,10 @@ static void shared_main(void)
     TT.width = 80;
     TT.height = 25;
     // If ps can't query terminal size pad to 80 but do -w
-    if (!terminal_size(&TT.width, &TT.height) && toys.which->name[1] == 's')
-      toys.optflags |= FLAG_w;
+    if (toys.which->name[1] == 's') {
+      if (!isatty(1) || !terminal_size(&TT.width, &TT.height))
+        toys.optflags |= FLAG_w;
+    }
   }

   // find controlling tty, falling back to /dev/tty if none
--
2.12.2.564.g063fe858b8-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to