[Toybox] ps -t is cheating.

Rob Landley rob at landley.net
Wed Oct 21 19:31:16 PDT 2015



On 10/20/2015 12:43 AM, lamiaworks wrote:
> 
>> Message: 1
>> Date: Mon, 19 Oct 2015 00:09:17 -0500
>> From: Rob Landley <rob at landley.net>
>> To: toybox at lists.landley.net
>> Subject: [Toybox] ps -t is cheating.
>> Message-ID: <56247AFD.5050806 at landley.net>
>> Content-Type: text/plain; charset=utf-8
>>
>> So posix says this:
>>
>> -t  termlist
>>    Write information for processes associated with terminals given in
>>    termlist. The application shall ensure that the termlist is a single
>>    argument in the form of a <blank> or <comma>-separated list. Terminal
>>    identifiers shall be given in an implementation-defined format. [XSI]
>>    [Option Start]  On XSI-conformant systems, they shall be given in one
>>    of two forms: the device's filename (for example, tty04) or, if the
>>    device's filename starts with tty, just the identifier following the
>>    characters tty (for example, "04" ). [Option End]
>>
>> And once again posix is somewhere back before the 1980's because
>> pseudo-terminals do not start with "/dev/tty". In the case of linux,
>> they've been /dev/pts/12 since, apparently, 1998.
>>
>> The ps man page says:
>>
>>    -t ttylist
>>         Select by tty.  This selects the processes associated with the
>>         terminals given in ttylist.  Terminals (ttys, or screens for
>>         text output) can be specified in several forms: /dev/ttyS1,
>>         ttyS1, S1.  A plain "-" may be used to select processes not
>>         attached to any terminal.
>>
>> Which is, once again, outright lying, because "-t 41" matches pts/41 but
>> -t 5 does _not_ match tty5. You have to say "-t tty5" to get the getty
>> instance on there.
> 
> You just brought an old nightmare back to the surface...
> 
> Try -t 05, if setup 'properly' you should get tty05 and that nowadays
> should be equating to tty5's inode / character settings.

  $ ps -t 05
  error: TTY could not be found

Linux hasn't got a /dev/tty05. It's got a /dev/tty5. But what procps's
version of ps does (and thus what people are going to expect) is show
pts/5 for digits.

I checked in code that treats purely numeric "-t 1" as a request for
/dev/pts/1 instead of /dev/tty1. To get tty1 say "-t tty1".

I dunno about "right" behavior. I just know that posix is decades behind
what linux is actually _doing_...

> My first Mainframes (1970's) had tty0 to ttyf for systems consoles I/O
> ONLY, and tty00 to ttyff for user terminals.

That would be the decades behind part. :)

> The problem was of course
> cost for the extra user i/o cards so any tty above tty3 were often
> assigned to users terminals and the relevant code 'fudged' to remove the
> console level access and assign user inodes, which in turn fudged other
> bits of code....et al...

Lovely.

I doubt android is providing any tty devices at all, with the possible
exception of an adb console, just pts devices to instances of the
"terminal" program. (Which isn't a default app on any of my phones yet,
but I live in hope that _someday_ I won't have to install a third party
app to get what seems to be built-in functionality.)

That said, the -t I checked in (yesterday?) is whitelisting specific
names, and if the adb terminal isn't among them I need to either stop
whitelisting (I worry that -t /dev/urandom or -t ../some/random/path
will somehow be exploitable, even though all I'm really doing is
stat-ing it) or add the new name...

>> Meanwhile procutils "ps -t pts/41" works as does "ps -t pts/../tty5"
>> which is just _creepy_ and I'm not doing that bit. And -tty S0 is of
>> course /dev/ttyS0 not /dev/pts/S0.
>>
>> I pine for a spec that means something,

Which means I really should _write_ the documentation I wanted to read,
yet again. Write a properly detailed "this is what toybox implements" as
an actual spec in the model of posix. Then wave it at the android and
tizen guys and have them frown and disagree with bits of it. And of
course fill in the tests; I haven't done proper ps tests yet because the
values change, from PIDs to %cpu output, but _how_ to do so is pretty
straightforward. Finite list of command line options and -o selections...

Alas, my open source stuff is not my day job. (I get to do some of it on
the clock, but the past couple week's been debugging nommu toolchains
and such...) Going as fast as I can in the time I have...

Rob

 1445481076.0


More information about the Toybox mailing list