Introduce acpi-listener example application. This provides both an example of how to use the (netlink acpi) module, and a useful tool for debugging ACPI messages which the Linux kernel doles out. * .gitignore: the build acpi-listener does not go in GIT * Makefile.am: build, install, and clean up the acpi-listener script * acpi-listener.in: new file * pre-inst-env.in: NETLINK_UNINSTALLED exported so acpi-listener runs from the build directory
.gitignore
| 1 | + | *~ | |
| 1 | 2 | *.go | |
| 2 | 3 | *.info | |
| 3 | 4 | *.html | |
… | |||
| 13 | 14 | missing | |
| 14 | 15 | mdate-sh | |
| 15 | 16 | pre-inst-env | |
| 17 | + | acpi-listener | |
| 16 | 18 | texinfo.tex | |
| 17 | 19 | doc/version.texi | |
| 18 | 20 | doc/stamp-vti | |
Makefile.am
| 20 | 20 | ip/utils.scm | |
| 21 | 21 | ||
| 22 | 22 | info_TEXINFOS= doc/guile-netlink.texi | |
| 23 | + | ||
| 24 | + | bin_SCRIPTS = acpi-listener | |
| 25 | + | ||
| 26 | + | do_subst = sed -e 's,%PREFIX%,${prefix},g' \ | |
| 27 | + | -e 's,%sbindir%,${sbindir},g' \ | |
| 28 | + | -e 's,%libexecdir%,${libexecdir},g' \ | |
| 29 | + | -e 's,%modsrcdir%,${guilesitedir},g' \ | |
| 30 | + | -e 's,%modbuilddir%,${guilesitegodir},g' \ | |
| 31 | + | -e 's,%localstatedir%,${localstatedir},g' \ | |
| 32 | + | -e 's,%pkglibdir%,${pkglibdir},g' \ | |
| 33 | + | -e 's,%sysconfdir%,${sysconfdir},g' \ | |
| 34 | + | -e 's,%localedir%,${localedir},g' \ | |
| 35 | + | -e 's,%VERSION%,@VERSION@,g' \ | |
| 36 | + | -e 's,%PACKAGE_BUGREPORT%,@PACKAGE_BUGREPORT@,g' \ | |
| 37 | + | -e 's,%PACKAGE_NAME%,@PACKAGE_NAME@,g' \ | |
| 38 | + | -e 's,%PACKAGE_URL%,@PACKAGE_URL@,g' \ | |
| 39 | + | -e 's,%GUILE%,$(GUILE),g' | |
| 40 | + | ||
| 41 | + | acpi-listener : acpi-listener.in Makefile | |
| 42 | + | $(AM_V_GEN)$(MKDIR_P) bin ; \ | |
| 43 | + | $(do_subst) $< > $@ ; \ | |
| 44 | + | chmod a+x $@ | |
| 45 | + | ||
| 46 | + | CLEANFILES += acpi-listener |
acpi-listener.in unknown status 1
| 1 | + | #!%GUILE% --no-auto-compile | |
| 2 | + | -*- scheme -*- | |
| 3 | + | !# | |
| 4 | + | ||
| 5 | + | ||
| 6 | + | ;;;; This file is part of Guile Netlink | |
| 7 | + | ;;;; | |
| 8 | + | ;;;; Copyright (C) 2025 Dale Mellor | |
| 9 | + | ;;;; | |
| 10 | + | ;;;; This library is free software: you can redistribute it and/or modify | |
| 11 | + | ;;;; it under the terms of the GNU General Public License as published by | |
| 12 | + | ;;;; the Free Software Foundation, either version 3 of the License, or | |
| 13 | + | ;;;; (at your option) any later version. | |
| 14 | + | ;;;; | |
| 15 | + | ;;;; This library is distributed in the hope that it will be useful, | |
| 16 | + | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | + | ;;;; GNU General Public License for more details. | |
| 19 | + | ;;;; | |
| 20 | + | ;;;; You should have received a copy of the GNU General Public License | |
| 21 | + | ;;;; along with this library. If not, see <https://www.gnu.org/licenses/>. | |
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | (unless (getenv "NETLINK_UNINSTALLED") | |
| 26 | + | (set! %load-path (cons "%modsrcdir%" %load-path)) | |
| 27 | + | (set! %load-compiled-path (cons "%modbuilddir%" %load-compiled-path))) | |
| 28 | + | ||
| 29 | + | ||
| 30 | + | ;; This is both an example of use of guile-netlink??s ACPI notifications | |
| 31 | + | ;; interface???it being the simplest such application that we can think of???, and | |
| 32 | + | ;; a useful diagnostic tool in its own right to help fathom the meaning of the | |
| 33 | + | ;; messages coming out of the Linux kernel, as these are not at all well | |
| 34 | + | ;; documented and depend critically on the nature of the physical computer | |
| 35 | + | ;; system and the kernel build configuration. | |
| 36 | + | ;; | |
| 37 | + | ;; There are no command-line arguments; the program will simply sit and listen | |
| 38 | + | ;; for kernel ACPI events to be broadcast, and then report the data returned | |
| 39 | + | ;; on the screen. It is left as an exercise to the end user (hah!) to work | |
| 40 | + | ;; out the actual meanings of these data. | |
| 41 | + | ||
| 42 | + | ||
| 43 | + | ;; Use guile-netlink??s ACPI interface. The use of a prefix is discretionary; | |
| 44 | + | ;; it is useful to have in example code. | |
| 45 | + | (use-modules ((netlink acpi) #:prefix ACPI::)) | |
| 46 | + | ||
| 47 | + | ||
| 48 | + | (define (event-action event) | |
| 49 | + | "Print the contents of the EVENT object in a line on the screen." | |
| 50 | + | ((@ (ice-9 format) format) | |
| 51 | + | #t | |
| 52 | + | "device: ~20a, bus ID: ~15a, type: ~8,'0x, data: ~8,'0x\n" | |
| 53 | + | (ACPI::event-device-class event) | |
| 54 | + | (ACPI::event-bus-id event) | |
| 55 | + | (ACPI::event-kind event) | |
| 56 | + | (ACPI::event-data event))) | |
| 57 | + | ||
| 58 | + | ||
| 59 | + | ;; Connect to the kernel??s Netlink ACPI notifier and obtain the three control | |
| 60 | + | ;; procedures for this connection. | |
| 61 | + | ((@ (ice-9 receive) receive) | |
| 62 | + | (ACPI::read-selector ACPI::process-events ACPI::close-connection) | |
| 63 | + | (ACPI::connect-events) | |
| 64 | + | ||
| 65 | + | ;; In a tight loop use the first procedure in a (select _) call to wait | |
| 66 | + | ;; for data from the connection, then use the second procedure to actually | |
| 67 | + | ;; read and interpret those data and call the above event-action function | |
| 68 | + | ;; on any ACPI event data found there. | |
| 69 | + | (let loop () | |
| 70 | + | (select (list (ACPI::read-selector)) '() '()) | |
| 71 | + | (ACPI::process-events event-action) | |
| 72 | + | (loop)) | |
| 73 | + | ||
| 74 | + | ;; We won??t ever get here, but if for some reason we did... use the third | |
| 75 | + | ;; procedure given us from the connection to shut that connection down. | |
| 76 | + | (ACPI::close-connection)) |
pre-inst-env.in
| 11 | 11 | PATH="$abs_top_builddir:$PATH" | |
| 12 | 12 | export PATH | |
| 13 | 13 | ||
| 14 | + | # Define $NETLINK_UNINSTALLED to prevent 'acpi-listener' from prepending | |
| 15 | + | # @moduledir@ to the Guile load paths. | |
| 16 | + | NETLINK_UNINSTALLED=1 | |
| 17 | + | export NETLINK_UNINSTALLED | |
| 18 | + | ||
| 14 | 19 | exec "$@" |