# sysfsutils: libsysfs + the systool device/bus/class query utility. # # systool resolves the sysfs mount point by scanning /proc/mounts ONCE # (sysfs_get_mnt_path -> setmntent("/proc/mounts")) and then reads sysfs # directories. That single /proc read is in the reliable class on wasm32-hwjs: # the procps tools that hang on brintos/linux#9 (top/vmstat/pgrep/sysctl) read # dozens of /proc files per run, which is what trips the EINTR-not-restarted # path. systool is therefore safe to execute here, unlike those. . "$BST_LIB" require systool sysfsutils/present # -h prints usage on stdout and exits 0 from inside the getopt loop, BEFORE # systool checks for a sysfs mount point -- so this case asserts the binary # itself loads and runs even on an image where sysfs is absent. check_out sysfsutils/usage "Usage: systool" systool -h # Everything below needs sysfs actually mounted. systool's own failure mode is # "Unable to find sysfs mount point!" on stderr with rc=1, so an unmounted /sys # would otherwise show up as five identical rc=1 failures with no root cause. # Assert the precondition once, explicitly, and skip the rest if it is missing. if grep -q ' sysfs ' /proc/mounts 2>/dev/null; then bst_ok sysfsutils/sysfs-mounted else bst_notok sysfsutils/sysfs-mounted "no sysfs line in /proc/mounts; systool can query nothing" for c in buses classes class-query; do bst_skip "sysfsutils/$c" "sysfs not mounted on /sys" done exit 0 fi # With no bus/class/module argument systool runs show_default_info(), which # lists the bus, class and root-device directories it finds under the sysfs # mount. Both headers are unconditional once sysfs is readable. check_out sysfsutils/buses "Supported sysfs buses:" systool check_out sysfsutils/classes "Supported sysfs classes:" systool # The ticket's acceptance check: systool -c lists a device class. The class is # discovered at runtime rather than hard-coded -- the wasm32-hwjs kernel's # device model is minimal and its class set is not a desktop kernel's, so # naming e.g. "net" here would encode an assumption this image need not meet. # show_sysfs_class() prints Class = "" on stdout and returns 0. cls=$(ls /sys/class 2>/dev/null | head -1) if [ -n "$cls" ]; then check_out sysfsutils/class-query "Class = \"$cls\"" systool -c "$cls" else bst_notok sysfsutils/class-query "/sys/class is empty -- kernel exposes no device class" fi