Jonathan Hammer:
> Hi,
> 
> We are running Postfix on macOS and making use of `maillog_file = 
> /dev/stdout` and `postfix start-fg` to send our logs to stdout. Not using 
> Docker.
> 
> We would like to pipe the logs from stdout to another process to do some 
> analysis and post-processing, like so:
> 
>       $ postfix start-fg | our-custom-log-analyzer?
> 
> However, in this configuration, Postfix fails to start and logs this error:
> 
>       fatal: open logfile ?/dev/stdout?: file has 0 hard links

Here is one suggestion to make this more robust. Insteead of

        postfix start-fg  | analyzer

which requires restarting Postfix when the analyzer needs to be restarted.
use a named pipe, like thisL

        test -e /path/to/fifo || mkfifo /path/to/fifo

        analyzer < /path/to/fifo &

        postfix start-fg >  /path/to/fifo

With this, you can restart the analyzer independently from Postfix.

It also avoids the nonsense with stdout having a zero link count.

Quick demo on Macos:

    $ mkfifo fifo
    $ cat <fifo&
    [1] 45582
    $ ls -lL /dev/stdout >fifo
    prw-r--r--  1 wietse  eng  0 Sep 24 10:22 /dev/stdout
    [1]+  Done                    cat < fifo
    $

Note the link count of '1'.

That said, stdout logging is intended for containers that don't run
other programs. It does not work when a non-root user runs a Postfix
command; in that case, stdout logging may be intermingled with
normal command output.

        Wietse

Reply via email to