Simple kill-signall message acceptor for sbcl.
A simple way to send messages to LISP services.
This code needs:
lfp.h
(provided bylibfixposix-dev
package in Debian),- simple-log – needed for debugging/logging, and
- lisp-goodies (CL package named
:shalaev
and version.el),
so LISP should be able to require
these two packages.
For example, if quicklisp
resides in ~/quicklisp/
,
these two packages can be installed as follows:
tar xjfv cl-shalaev.tbz –directory=$HOME/quicklisp/local-projects/
tar xjfv simple-log.tbz –directory=$HOME/quicklisp/local-projects/
make
compiles the binary example.bin
and launches it in background.
It is a server that will "listen" for kill
signals for a few seconds.
Here is a typical make output.
LISP services may register one or more hooks
using (sh:register dir func)
, where dir
is the name of the lock (sub)directory.
The shell script tell is a client that
- creates lock directory to let other clients know that they should not interfere until the current conversation with the server is over,
- saves a message in a file "by", and
- sends
kill
signal to the server thus letting it know that the message is ready to be read.
After receiving the kill
signal, signal-handler
package checks every hook it has. A hook is a cons
; its car
is the sub-directory name.
If this sub-directory exists, the hook is activated, and its cdr
(which is a function) is called with a single argument: the sub-directory name.
After that the file "by" is erased by the LISP code (client that uses signal-handler
package).
In this way the client (shell script tell) is notified that the message has been received, and now the server is ready to accept another request.
The sender deletes the sub-directory sdir
in order to allow others to send messages to LISP code.
- signal-handler.org is the main file containing most of the code with comments,
- Makefile compiles generated/example.lisp into
generated/example.bin
and launches it, and - packaged/signal-handler.tbz is the package archive.
dbus might have many fancy features, but on my computer (ql:quickload :dbus)
downloads 55 other packages to satisfy dbus'es requirements,
which is much more than I need to satisfy my modest needs: I just need simple text message exchange between sbcl
and other programs (including shell scripts).
This code is released under MIT license.