|
Home > Archive > Unix Programming > May 2004 > automatic signal that a file is ready to read
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
automatic signal that a file is ready to read
|
|
|
| I am doing a program in C that checks the email inbox file in the
/var/spool directory and extract each of the emails in that file. I
created a daemon for that because the program should continously check
the inbox file for new emails. Currently, I'm calling the sleep
function then used stat to check if the file is not empty (the file is
being emptied once all the emails are extracted already). My problem
is that I want the signal in the checking of the file if there's new
email(ie. not empty anymore) to be automatic. Ie. if there is a new
email, it will give a signal to the system that a new email is in the
inbox file. I've tried using select() but it seems that select() still
returns a read fd even if the file is empty.
Any help would be greatly appreciated. Thanks.
| |
| SM Ryan 2004-05-11, 11:36 pm |
| # email(ie. not empty anymore) to be automatic. Ie. if there is a new
# email, it will give a signal to the system that a new email is in the
# inbox file. I've tried using select() but it seems that select() still
# returns a read fd even if the file is empty.
In general, you can't get there from here. Some Unix variants like IRIX
file monitor provide this capability, but when it is provided, it's done
on system idiosyncratic basis.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
JUSTICE!
Justice is dead.
| |
| Chuck Dillon 2004-05-12, 10:39 am |
| esi wrote:
> I am doing a program in C that checks the email inbox file in the
> /var/spool directory and extract each of the emails in that file. I
> created a daemon for that because the program should continously check
> the inbox file for new emails. Currently, I'm calling the sleep
> function then used stat to check if the file is not empty (the file is
> being emptied once all the emails are extracted already). My problem
> is that I want the signal in the checking of the file if there's new
> email(ie. not empty anymore) to be automatic. Ie. if there is a new
> email, it will give a signal to the system that a new email is in the
> inbox file. I've tried using select() but it seems that select() still
> returns a read fd even if the file is empty.
>
> Any help would be greatly appreciated. Thanks.
You are treating the inboxes as fifos so have you considered actually
changing them to fifos (named pipes) and putting your program on the
other side? I have no idea if the mail system will tolerate this but
in theory it could be done.
-- ced
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
| |
| Bill Marcum 2004-05-12, 2:56 pm |
| ["Followup-To:" header set to comp.unix.questions.]
On 11 May 2004 19:09:05 -0700, esi
<iamesi@yahoo.com> wrote:
> I am doing a program in C that checks the email inbox file in the
> /var/spool directory and extract each of the emails in that file. I
> created a daemon for that because the program should continously check
> the inbox file for new emails. Currently, I'm calling the sleep
>...
> Any help would be greatly appreciated. Thanks.
If your mail server allows it, you could use a pipe in your .forward
file.
--
Now KEN and BARBIE are PERMANENTLY ADDICTED to MIND-ALTERING DRUGS ...
| |
| Mark Rafn 2004-05-12, 2:56 pm |
| Chuck Dillon <spam@nimblegen.com> wrote:
>You are treating the inboxes as fifos so have you considered actually
>changing them to fifos (named pipes) and putting your program on the
>other side? I have no idea if the mail system will tolerate this but
>in theory it could be done.
Almost all mail systems have the option of delivering to a program rather than
to to a file. This is probably a bit easier than creating a named pipe in the
mail spool, and saves you hassles about finding the end of messages and such.
At the simplest, many times you can create a .forward file in your home
directory with something like:
| some_program
in it, and some_program will be invoked for each incoming message, with the
message contents on stdin.
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>
| |
| Konstantin Sorokin 2004-05-13, 12:52 pm |
| esi <iamesi@yahoo.com> wrote:
> I am doing a program in C that checks the email inbox file in the
> /var/spool directory and extract each of the emails in that file. I
> created a daemon for that because the program should continously check
> the inbox file for new emails. Currently, I'm calling the sleep
> function then used stat to check if the file is not empty (the file is
> being emptied once all the emails are extracted already). My problem
> is that I want the signal in the checking of the file if there's new
> email(ie. not empty anymore) to be automatic. Ie. if there is a new
> email, it will give a signal to the system that a new email is in the
> inbox file. I've tried using select() but it seems that select() still
> returns a read fd even if the file is empty.
>
FreeBSD (OpenBSD and future NetBSD 2.0) kqueue has such functionality.
See EVFILT_READ in kqueue man page.
--
Konstantin Sorokin
| |
| Chuck Dillon 2004-05-14, 12:49 pm |
| Mark Rafn wrote:
> Chuck Dillon <spam@nimblegen.com> wrote:
>
>
>
> Almost all mail systems have the option of delivering to a program rather than
> to to a file. This is probably a bit easier than creating a named pipe in the
> mail spool, and saves you hassles about finding the end of messages and such.
>
> At the simplest, many times you can create a .forward file in your home
> directory with something like:
> | some_program
> in it, and some_program will be invoked for each incoming message, with the
> message contents on stdin.
> --
> Mark Rafn dagon@dagon.net <http://www.dagon.net/>
Agreed if the problem is to be solved from one or more user
perspectives. I'm guessing from the question that the OP is looking
for something at a lower level. Color me crazy but sometime I just
respond to the question as asked and fight the urge to read the OPs mind.
-- ced
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
|
|
|
|
|