On Fri, Oct 23, 2015 at 8:05 AM, Rob Landley <[email protected]> wrote: > On 10/21/2015 11:47 PM, enh wrote: >> I pasted this into a thread "smack support" on 2015-09-19, but it >> looks like it got lost. >> >> diff --git a/toys/pending/ps.c b/toys/pending/ps.c >> index 29111d5..2bd7bcb 100644 >> --- a/toys/pending/ps.c >> +++ b/toys/pending/ps.c >> @@ -238,11 +238,12 @@ void ps_main(void) >> TT.width--; >> >> // find controlling tty, falling back to /dev/tty if none >> - for (i = fd = 0; i < 4; i++) { >> + for (i = 0; i < 4; i++) { >> struct stat st; >> >> - if (i != 3 || -1 != (i = fd = open("/dev/tty", O_RDONLY))) { >> - if (isatty(i) && !fstat(i, &st)) { >> + fd = i; >> + if (i != 3 || -1 != (fd = open("/dev/tty", O_RDONLY))) { >> + if (isatty(fd) && !fstat(fd, &st)) { >> TT.tty = st.st_rdev; >> break; >> > > Infinite loop... If you haven't got a /dev/tty it would return -1 and > reset the loop. Right. My fault, sorry. But a few lines down there's an > if (fd!=-1) close(fd) that probably shouldn't trigger on stdin/out/err, > so I still need to fix... > > Query: if you haven't got a controlling tty on stdin, stdout, stderr, or > /dev/tty, what should the default behavior of ps _be_? In theory it > lists processes attached to the current tty, but tty 0 is reserved > (lanana.org says it's the null device, but not /dev/null because that's > 1:3).
$ ssh localhost ps PID TTY TIME CMD 1194 ? 00:05:44 chrome 3441 ? 00:00:00 gnome-keyring-d 3478 ? 00:00:04 init 3537 ? 00:00:01 ssh-agent 3651 ? 00:01:54 dbus-daemon 3660 ? 00:00:02 upstart-event-b 3665 ? 00:00:01 window-stack-br 3683 ? 00:00:35 upstart-dbus-br ... > I guess with no tty, act like -A maybe? (That seems to be what toolbox > ps did...) > > Hmmm, I installed a terminal on my phone and toolbox ps is going: > > USER PID PPID VSIZE RSS WCHAN PC NAME > > Except between C and NAME it's got "S" which I'm guessing is STAT elided > from the title field for space. This doesn't quite map to the default, > -l, or -f outputs, and "-o name" isn't recognized by psutils (I'm > guessing cmd?) > > Lemme finish implementing the posix+obvious bits of psutils behavior > before worrying about that... yeah, i'm not even thinking about the Android-specific behaviors yet. ps is probably the worst case, where the traditional Android behavior is quite different from the traditional Unix behavior *and* it's heavily used and makes some amount of sense for a system where terminals aren't particularly meaningful (or even common). > Rob -- Elliott Hughes - http://who/enh - http://jessies.org/~enh/ Android native code/tools questions? Mail me/drop by/add me as a reviewer. _______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
