[MUD-Dev] Mail from mud Zoran's final Imp

Shawn Halpenny malachai at iname.com
Fri Jan 2 11:05:55 CET 1998


On Thu, 1 Jan 1998 coder at ibm.net wrote:

> On 01/01/98 at 01:55 PM, Stephen Zepp <zoran at enid.com> said:
> >  sprintf( mailbuf, "mail -s \"%s\" %s <%s%s",
> >     m_subject, m_address, MAIL_DIR, mfilename );
> ...
> >  system( mailbuf );
> >  sprintf( delbuf, "rm %s%s", MAIL_DIR, mfilename );
> >  system( delbuf );
> 
> A lurking and insidious problem here is that you don't detect when mail
> delivery fails.  This can be a bitch to a) notice when it happens, and b)
> determine the cause when it does
> 
> I'd suggest putting in a signal handler which triggers on the child
> dieing, and then reports an appropriate response to the user if the
> delivery failed.  It's fairly trivial to do: you can use any of your
> standard IPC calls to handle reporting the failure/success code (I do it
> with threads instead of full processes via, so I do the report back via
> the thread object for the mailer thread).

Isn't it easier to check the return value from system(), since the
wait() call inside system() is already waiting for the child to exit?
Checking whether it exited successfully, failed because of something
user-controllable, or died on some nasty signal is where the WIFxxxx
macros come in handy (see /usr/include/sys/wait.h).  Since you're
using system() instead of doing the fork() and exec() yourself,
remember that there can be a difference in the returned status if it
was the shell that was abnormally terminated instead of the command
process.

Also, the two system() calls can be done in one, if you (in pseudocode):
    system(mailbuf + ';' + delbuf);
(2 fork()s instead of 3...and provided your shell supports
multi-command command lines of that sort)

In any case, JC's right about the error reporting...especially with mail.

--
Shawn





More information about the mud-dev-archive mailing list