Commit 6fd4f472 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(checkstatus): Send mail by opening a pipe to "sendmail -t". That is

	more portable than pipeing a message into "mail".  Turn off
	mail delivery completely if "sendmail path" is set to ":".
parent 5ce9182c
/*
* $Id: updateLysKOM.c,v 1.23 2003/08/16 11:28:54 ceder Exp $
* $Id: updateLysKOM.c,v 1.24 2003/08/20 13:44:49 ceder Exp $
* Copyright (C) 1994-1995, 1998-1999, 2001-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -76,8 +76,9 @@ checkstatus(FILE *fp,
char *progname)
{
char lbuf[80];
char buf2[300];
struct stat sbuf;
char *sendmail;
FILE *sendfp;
if (fstat(fileno(fp), &sbuf) < 0)
{
......@@ -124,7 +125,8 @@ checkstatus(FILE *fp,
/* The first line of the file should be a mail address to send
a reminder to. */
if (fgets(lbuf, sizeof(lbuf), fp) == NULL)
if (fgets(lbuf, sizeof(lbuf), fp) == NULL
|| strcmp(param.sendmail_path, ":") == 0)
{
fprintf(stderr,
"updateLysKOM: LysKOM has been down for a short while\n");
......@@ -132,13 +134,35 @@ checkstatus(FILE *fp,
}
if (strchr(lbuf, '\n'))
*strchr(lbuf, '\n') = '\0';
/* FIXME (bug 185): "Reminder:" is taken to be an email address. */
sprintf(buf2, "echo 'Reminder: LysKOM is still not running.'|mail %s",
lbuf);
if (system(buf2) != 0)
sendmail = smalloc(strlen(param.sendmail_path) + 4);
strcpy(sendmail, param.sendmail_path);
strcat(sendmail, " -t");
sendfp = popen(sendmail, "w");
if (sendfp == NULL)
{
perror("updateLysKOM: system failed");
exit(1);
fprintf(stderr, "updateLysKOM: failed to open pipe to ");
perror(sendmail);
exit(2);
}
fprintf(sendfp, "From: %s\n", lbuf);
fprintf(sendfp, "To: %s\n", lbuf);
fprintf(sendfp, "Subject: lyskomd is down\n");
fprintf(sendfp, "\n");
fprintf(sendfp, "Reminder: LysKOM is still not running.\n");
fprintf(sendfp, ".\n");
fflush(sendfp);
if (ferror(sendfp))
{
fprintf(stderr, "writing to sendmail failed.\n");
exit(2);
}
if (pclose(sendfp) != 0)
{
perror("updateLysKOM: sending mail might have failed");
exit(2);
}
}
else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment