#ifndef lint
static char *RCSid = "$Header: /usr/brule/guest/empire/empire/emprcs/lib/gen/send_mail.c,v 2.0 1995/07/27 05:56:17 empire Exp $";
#endif

/*
 * send_mail.c
 *
 * given a user and a file descriptor, fork off a
 * mail job.
 *
 */

#include "misc.h"

int
send_mail(dest, fd)
	s_char	*dest;
	int	fd;
{
	int	pid;
	int	i;

	pid = fork();
	if (pid < 0)
		return 0;
	if (pid > 0) {
		close(fd);
		while (wait(0) != pid)
			;
	} else {
		dup2(fd, 0);
		dup2(open("/dev/null", 1), 1);
		for (i=getfdtablesize()-1; i > 3; i--)
			close(i);
		execl("/bin/mail", "mail", dest, 0);
		/* failed! */
		exit(0);
		/*NOTREACHED*/
	}
	return 1;
}
