msg (in) temp file containing message to send
tempfile (out) if sendmail is put in the background, this points
to the temporary file containing the stdout of the
- child process */
+ child process. If it is NULL, stderr and stdout
+ are not redirected. */
static int
send_msg (const char *path, char **args, const char *msg, char **tempfile)
{
sigaddset (&set, SIGTSTP);
sigprocmask (SIG_BLOCK, &set, NULL);
- if (SendmailWait >= 0)
+ if (SendmailWait >= 0 && tempfile)
{
char tmp[_POSIX_PATH_MAX];
setsid ();
/* next we close all open files */
+ close (0);
#if defined(OPEN_MAX)
- for (fd = 0; fd < OPEN_MAX; fd++)
+ for (fd = tempfile ? 1 : 3; fd < OPEN_MAX; fd++)
close (fd);
#elif defined(_POSIX_OPEN_MAX)
- for (fd = 0; fd < _POSIX_OPEN_MAX; fd++)
+ for (fd = tempfile ? 1 : 3; fd < _POSIX_OPEN_MAX; fd++)
close (fd);
#else
- close (0);
- close (1);
- close (2);
+ if (tempfile)
+ {
+ close (1);
+ close (2);
+ }
#endif
/* now the second fork() */
}
unlink (msg);
- if (SendmailWait >= 0)
+ if (SendmailWait >= 0 && tempfile)
{
/* *tempfile will be opened as stdout */
if (open (*tempfile, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0600) < 0)
if (dup (1) < 0)
_exit (S_ERR);
}
- else
+ else if (tempfile)
{
if (open ("/dev/null", O_WRONLY | O_APPEND) < 0) /* stdout */
_exit (S_ERR);
else if (pid == -1)
{
unlink (msg);
- FREE (tempfile); /* __FREE_CHECKED__ */
+ if (tempfile)
+ FREE (tempfile); /* __FREE_CHECKED__ */
_exit (S_ERR);
}
if (waitpid (pid, &st, 0) > 0)
{
st = WIFEXITED (st) ? WEXITSTATUS (st) : S_ERR;
- if (SendmailWait && st == (0xff & EX_OK))
+ if (SendmailWait && st == (0xff & EX_OK) && tempfile)
{
unlink (*tempfile); /* no longer needed */
FREE (tempfile); /* __FREE_CHECKED__ */
{
st = (SendmailWait > 0 && errno == EINTR && SigAlrm) ?
S_BKG : S_ERR;
- if (SendmailWait > 0)
+ if (SendmailWait > 0 && tempfile)
{
unlink (*tempfile);
FREE (tempfile); /* __FREE_CHECKED__ */
alarm (0);
sigaction (SIGALRM, &oldalrm, NULL);
- if (kill (ppid, 0) == -1 && errno == ESRCH)
+ if (kill (ppid, 0) == -1 && errno == ESRCH && tempfile)
{
/* the parent is already dead */
unlink (*tempfile);
args[argslen++] = NULL;
- if ((i = send_msg (path, args, msg, &childout)) != (EX_OK & 0xff))
+ if ((i = send_msg (path, args, msg, option(OPTNOCURSES) ? NULL : &childout)) != (EX_OK & 0xff))
{
if (i != S_BKG)
{