[Toybox] [PATCH] lspci: use a different default location for pci.ids on Android.
Rob Landley
rob at landley.net
Fri Feb 11 00:19:25 PST 2022
On 2/10/22 9:12 PM, enh via Toybox wrote:
+ if (!TT.i) TT.i = CFG_TOYBOX_ON_ANDROID ? "/vendor/pci.ids" :
+ "/usr/share/misc/pci.ids";
Applied. Heads up that there's another one in lsusb.c.
My head scratch is I added the usb.ids one to /etc (because it seemed the
obvious place for me to add it going back to Unix v7, alongside /etc/services),
but the lspci contributor (Isaac Dunham) put it in /usr/share/misc presumably
because the Linux Foundation's FHS said so. Which is a directory I don't even
bother to create in mkroot...
Either location is "policy". I just checked where busybox's lspci looks and the
answer is "it doesn't". No support for a pci.ids file that I can spot. So no
help there...
Meanwhile, on Debian:
$ ls -l /usr/share/misc/usb.ids
lrwxrwxrwx 1 root root 25 Aug 3 2019 /usr/share/misc/usb.ids ->
/var/lib/usbutils/usb.ids
So A) it's not consistent, B) they patch it with symlinks. Which one does strace
say debian's lsusb is using...? Neither:
readlink("/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/subsystem", "../
../../../../../bus/usb", 1024) = 25
openat(AT_FDCWD, "/run/udev/data/+usb:1-2:1.0", O_RDONLY|O_CLOEXEC) = 9
fstat(9, {st_mode=S_IFREG|0644, st_size=102, ...}) = 0
read(9, "I:743051238083\nE:ID_MODEL_FROM_DATABASE=Nexus 4/5/7/10
(tether)\nE:ID_VENDOR_FROM_DATABASE=Google Inc.\n", 4096) = 102
It's fetching cached data written out by whichever udev variant this system is
using. Because of course it is.
I think I want to move the non-android location to /etc for consistency. (FHS,
like LSB, is an interesting point of reference but not a compelling
well-maintained standard. Simple minimal system says /etc, not
/usr/share/opt/local/thingy. Then again, I'm biased:
http://landley.net/writing/hackermonthly-issue022-pg33.pdf )
Also, given that pci.ids is a megabyte and usb.ids is 3/4 of a megabyte, I think
I want to let it read a .gz version if present because uncompressed that's a lot
of initramfs ballast.
(No, I am not adding a menuconfig item for this.)
You know, I _could_ use find_in_path(), since it's already there in lib/lib.c:
char *path = "/vendor:/etc:/usr/share/misc";
struct string_list *sl;
int fd = -1, pid = 0;
if ((sl = find_in_path(path, "pci.ids.gz"))
pid = xpopen((char *[]){"zcat", sl->str, 0}, &fd, 1);
if (pid<1 && (sl = find_in_path(path, "pci.ids")))
fd = xopen(sl->str, O_RDONLY);
if (fd != -1) {
FILE *fp = fdopen(fd);
// read contents
fclose(fp);
}
Hmmm... Might still need some CFG_ANDROID tests to avoid twigging weird selinux
rules searching for nonexistent stuff? (Android's not likely to want the gz
version, Saving a megabyte is a rounding error there, it's probably on a
compressed flash filesystem anyway, and keeping it be directly human readable
may count as a slight win in that context. So it would check /etc and
/usr/share/misc for pci.ids.gz before finding /vendor/pci.ids...)
But if I do that I need to teach pci.ids to read the data into memory in one
pass the way usb.ids does, or else it'll try to lseek() a pipe.
Rob
More information about the Toybox
mailing list