[imapfilter-devel] daemon mode

Phil Osipher phlosipher at yahoo.com
Wed Nov 3 05:30:00 EET 2010


Thanks David DeSimone,

That explanation helps a lot. The extra flush does straighten out the duplicate messages.

I certainly have more to learn, but am making progress.

Phil



--- On Tue, 11/2/10, Phil Osipher <phlosipher at yahoo.com> wrote:

From: Phil Osipher <phlosipher at yahoo.com>
Subject: Re: [imapfilter-devel] daemon mode
To: "Lefteris Chatzimparmpas" <lefcha at hellug.gr>
Cc: imapfilter-devel at lists.hellug.gr
Date: Tuesday, November 2, 2010, 9:10 AM

OK,
It makes sense that you have closed stdout. But I am still puzzled. I have converted my script to write to a file, and I attach it to this email. It just replaces the print statements with a write, after opening a log file. But there is still some unexpected behavior.
Here are the log file contents after the script has run for a minute. The lines surrounding the file "open" are printed multiple times.------------------testatestatestaabcd <-- babcd <-- b----------------
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?
Note that in the "real script" (not this test script) I wish to query the user for the password, and then daermonize the forever function to keep it checking the mailbox, so it is important that some of the script is run "interactively". and I need to be able to exclude those code fragments from being executed multiple times. Do you have a suggestion?
Thanks
Phil

--- On Tue, 11/2/10, Lefteris Chatzimparmpas <lefcha at hellug.gr> wrote:

From: Lefteris Chatzimparmpas <lefcha at hellug.gr>
Subject: Re: [imapfilter-devel] daemon mode
To: "Phil Osipher" <phlosipher at yahoo.com>
Cc:
 imapfilter-devel at lists.hellug.gr
Date: Tuesday, November 2, 2010, 2:19 AM

Hello,

Basically you are right that there is something simple that you missed
and confuses you. When in daemon mode imapfilter detaches itself from
the controlling terminal (closes stdin/stdout/stderr) and goes in the
background.  So all the print() you do inside forever will never be
printed anywhere.

For testing you could try opening a file and then writing to that
file instead.

L.


On 11/02/2010 05:52 AM, Phil Osipher wrote:
> Please forgive the following very stupid question.
> 
> In learning imapfilte rand lua I have written some reasonably complex imapfilter and lua scripts, and although I am new to them, they seem to work fine when executed "once". 
> 
> But I am puzzled over the use of the "daemon mode". 
> 
> Here is the issue. My employer does not
 allow me to store password in scripts, or files accessed by scripts. (Encrypted or not). So to filter a mailbox, I have decided to start an imapfilter script interactively in  the console, query for a password, and then switch to daemon mode to occasionally access a mailbox folder for days or weeks continuously and do some stuff to it (which I may post later to ask for advice/improvements about at a later date). 
> 
> But I am not having any luck with using the tools in daemon mode.
> 
> Here is a simple example of a script, simplified to get to the essence of the problem and make  it easy for you to help me 
> 
> --------------------------------
> function forever()
> account1 = IMAP {
>     server = 'server.domain.com',
>     username = 'user at domain.com',
>     password = passwd,
> }
> print("b")
> end
> 
> passwd = "abcd"
> 
> print("a")
> 
> 
> --daemon_mode(10,forever)
> become_daemon(10,forever)
> --forever()
> print("c")
> --------------------------
> 
> The script behaves predictably if I enable the line that invokes function "forever" explicitly.
> e.g. invokng the script with "imapfilter -c test.lua" when I enalbe the line "forever()" produces output
> 
> a
> b
> c
> 
> 
> But if I modify the script to use the line with "daemon_mode" or "become_deamon" it prints 
> "a", then hangs. I expected it to repeat "b" repeatedly every 10 seconds, and never reach the line to print "c".
> 
> What am I doing wrong? It must be something very simple. So sorry to be
 missing something basic. I have tried "flushing" stdout (not shown) but that doesn't seem to help. I must be missing something else that is simple.
> 
> Also, what is the difference between "become_daemon" and "daemon_mode"?
> 
> 
> Thanks for the help
> 
> Phil
> 
> 
> 
> 
> 
> 
>       
> 
> 
> 
> _______________________________________________
> Imapfilter-devel mailing list
> Imapfilter-devel at lists.hellug.gr
> http://lists.hellug.gr/mailman/listinfo/imapfilter-devel



      
-----Inline Attachment Follows-----

_______________________________________________
Imapfilter-devel mailing list
Imapfilter-devel at lists.hellug.gr
http://lists.hellug.gr/mailman/listinfo/imapfilter-devel


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hellug.gr/pipermail/imapfilter-devel/attachments/20101102/e640a133/attachment-0001.html>


More information about the Imapfilter-devel mailing list