On 2007-08-22 21:44:26 +0200, Sydney Bogaert wrote:
> > 
> > I wrote some small helper scripts for parsing logs.  Would they be
> > useful enough to include in qpsmtpd?
> > 
> > 
> > --
> > JT Moree
> 
> You assume here that the process numbers are different for each message.
> While it will work for forkserver and tcpserver, that is not the case
> with prefork or Apache (also preforking).

It doesn't even work for forkserver and tcpserver. On a busy system PIDs
have a rather high probability of repeating within a single log file. Of
course you can try to detect the end of one connection or the start of
another one. 

In the logging/file_connection I chose this approach:

In register, choose a prefix which should be unique to every running
"instance" of qpsmtpd (in the case of forkserver, that's the parent
process):

    $self->{_log_session_id_prefix} = sprintf("%08x%04x", time(), $$);

(that may not be safe for tcpserver: It is possible that two processes
get the same pid within one second - use check_earlytalker to prevent
this :-))

then, in the pre-connection hook, just increment a counter:

    $self->{_log_session_id} =
        $self->{_log_session_id_prefix} . "." .
        ++$self->{_log_session_id_counter};

and use the concatenation as the session id which is written to log
files. 

So entries look like this:

2007-08-25T10:26:07+0200 46cfde417471.124  Accepted connection 0/15 from 
70.84.4.138 / virtual.virtualtoolsets.com
2007-08-25T10:26:07+0200 46cfde417471.124  Connection from 
virtual.virtualtoolsets.com [70.84.4.138]
2007-08-25T10:26:08+0200 46cfde417471.124  check_earlytalker plugin: remote 
host said nothing spontaneous, proceeding
2007-08-25T10:26:08+0200 46cfde417471.124  220 mx.luga.at ESMTP qpsmtpd 0.40 
ready; send us your mail, but not your spam.

In this example the first line is written by the parent process of
forkserver before the fork, the others by the child process after the
fork - the session id stays the same.

But note that this is a session/connection id, not a message id: If the
client sends several messages within a single connection, they will be
recorded with the same id. That's what I want, but if you want a unique
transaction id, it should be easy to add another counter which is
incremented for each transaction.

        hp


-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | [EMAIL PROTECTED]         |
__/   | http://www.hjp.at/ |    -- Sam in "Freefall"

Attachment: signature.asc
Description: Digital signature

Reply via email to