[Toybox] [CLEANUP] rfkill

Rob Landley rob at landley.net
Wed Jun 11 04:47:24 PDT 2014


Forgot to post my cleanup notes for commit
http://landley.net/hg/toybox/rev/1344

We don't need a separate argument parsing function, it only happens
twice and the first is just "what's my position within this array". (I
also lean towards using ARRAY_LEN() rather than a null terminator on
these sorts of things.)

Changed argument parsing logic: idx != -1 means we have a numeric index,
tid left at default (RFKILL_TYPE_ALL) so testing tid == -1 isn't useful.
Also, testing both if tid is set or if idx is set in the non-list case
isn't useful because we wouldn't have made it that far if _one_ of them
wasn't set, test one and have the other be the "else" case.

Why is the code creating /dev/rfkill as a regular file if the device
node isn't there? (And why is it O_NONBLOCK?)

This code trusts the kernel a bit more than I do, xstrdup(strchr(line,
'=')+1) assumes there will be an = in the line the kernel returned.
Rewriting that bit to use strstart() instead. (Yes that would stop
working if the kernel started returning a space between RFKILL_TYPE and
=, but I'm ok with that. And I guess I'm ok printing out a null if
name/type didn't get parsed because printf catches that and says (null).)


More information about the Toybox mailing list