[imapfilter-devel] daemon mode
David DeSimone
fox at verio.net
Tue Nov 2 23:58:09 EET 2010
Phil Osipher <phlosipher at yahoo.com> wrote:
>
> The line "abcd" is being printed every 30 seconds as I have asked, but
> the "test" and "a" lines are being printed 3 times, and they should
> only be printed once. It looks as though when the script is being
> "demonized" it is "re-executed" two more times prior to a transition
> to the "forever" function. Can you clarify what is going on?
You are running into some file buffering behavior that comes out of the
daemonizing process. A daemon process will normally fork, creating a
child process, and then the parent exits, thus giving control back to
the invoking shell that ran the imapfilter command.
Files writing to a terminal follow different behavior than files writing
to disk files. The latter perform more buffering of output before it is
written to disk. What's likely happening is that your "abcd" text is
not yet written to the disk, but is waiting in a memory buffer at the
time of the fork system call. This leads to two processes, the parent
and the child, both having unwritten data in their buffers. When the
parent exits, it flushes the buffer, causing the first copy of "abcd" to
be written to disk. Then later, the child calls its forever function,
which includes a flush that forces the second copy of "abcd" to disk,
along with the "b" output.
I believe you'd see this behavior disappear if you included an extra
call to fout:flush(), just before you invoke daemon_mode().
--
David DeSimone == Network Admin == fox at verio.net
"I don't like spinach, and I'm glad I don't, because if I
liked it I'd eat it, and I just hate it." -- Clarence Darrow
This email message is intended for the use of the person to whom it has been sent, and may contain information that is confidential or legally protected. If you are not the intended recipient or have received this message in error, you are not authorized to copy, distribute, or otherwise use this message or its attachments. Please notify the sender immediately by return e-mail and permanently delete this message and any attachments. Verio, Inc. makes no warranty that this email is error or virus free. Thank you.
More information about the Imapfilter-devel
mailing list