chalaev / cl-signal-handler

Handles "kill -s USR1 $pid" signals sent to LISP code in order to receive messages from other programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Table of Contents

  1. Description
  2. Prerequisites
  3. Quick start – usage example
  4. Files
  5. Motivation
  6. License

Simple kill-signall message acceptor for sbcl.

Description

A simple way to send messages to LISP services.

Prerequisites

This code needs:

  1. lfp.h (provided by libfixposix-dev package in Debian),
  2. simple-log – needed for debugging/logging, and
  3. 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/

Quick start – usage example

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

  1. creates lock directory to let other clients know that they should not interfere until the current conversation with the server is over,
  2. saves a message in a file "by", and
  3. 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.

Files

  1. signal-handler.org is the main file containing most of the code with comments,
  2. Makefile compiles generated/example.lisp into generated/example.bin and launches it, and
  3. packaged/signal-handler.tbz is the package archive.

Motivation

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).

License

This code is released under MIT license.

About

Handles "kill -s USR1 $pid" signals sent to LISP code in order to receive messages from other programs

License:MIT License


Languages

Language:Common Lisp 55.5%Language:Makefile 29.8%Language:Shell 12.5%Language:NewLisp 2.3%