This script is the heart of the entire system, and is essentially a spooling system that queues up incoming messages and writes them to disk.
As may be seen in the simplified flow chart (Fig. 3), notabene.pl creates a pipe and forks into two processes after some initialization. The parent of this first fork then sets up a TCP/IP socket and waits for clients to connect, at which time it forks a child to handle each client. These children then read the messages from the socket, and after appending the IP address of the client and the current time, write the events to the pipe.
The child of the first fork sets up non-blocking I/O on the pipe and reads it periodically to see if there are
any new events. If so, the event is read, parsed and added to a list of events waiting to be written to disk. If
the message starts with the tag
MAILTO:user@system
, it is further parsed to extract the address of the
person to be notified of the event, and an email containing the message information is sent to that user.
When either a specified number of events have been received or a time-out period has elapsed, or if the
incoming message was a
SYNC
command, the event list is appended to the log file on disk.
Because it was estimated that the system could be required to handle as much as 1Mb per day of information, it was decided to have a separate log file for each week. A small subroutine, getendofweek(), was written such that given either a UNIX time code, or a year, month and day, it would return the year, month and day of the last day of that week. This could then be used to create the name of the log file.