mail support

This commit is contained in:
Olaf Rempel 2009-04-19 14:51:01 +02:00
parent 996a101f50
commit 24ff8bca57

View File

@ -44,6 +44,7 @@
#define DEFAULT_LOGFILE "alix-usvd.log" #define DEFAULT_LOGFILE "alix-usvd.log"
#define DEFAULT_PIDFILE "alix-usvd.pid" #define DEFAULT_PIDFILE "alix-usvd.pid"
#define DEFAULT_SOCKET "alix-usvd.sock" #define DEFAULT_SOCKET "alix-usvd.sock"
#define SENDMAIL "/usr/sbin/sendmail"
enum { enum {
REG_STATUS = 0x00, REG_STATUS = 0x00,
@ -246,8 +247,34 @@ static int alix_state = -1;
static void alix_state_change(int old_state, int new_state) static void alix_state_change(int old_state, int new_state)
{ {
static const char *mail_from;
static const char *mail_to;
static int mail_data;
if (mail_data == 0) {
mail_from = config_get_string("global", "mail-from", NULL);
mail_to = config_get_string("global", "mail-to", NULL);
mail_data = 1;
}
log_print(LOG_INFO, "usv state changed: %s => %s", state2str(old_state), state2str(new_state)); log_print(LOG_INFO, "usv state changed: %s => %s", state2str(old_state), state2str(new_state));
/* TODO: send email */
if (mail_to == NULL)
return;
FILE *mail = popen(SENDMAIL, "w");
if (mail == NULL)
return;
fprintf(mail, "From: %s\n", mail_from);
fprintf(mail, "To: %s\n", mail_to);
fprintf(mail, "Subject: alix-usvd state change: %s => %s\n\n",
state2str(old_state), state2str(new_state));
fprintf(mail, "Faithfully yours, etc.\n");
fclose(mail);
return;
} }
static int unix_read_cb(int fd, void *privdata) static int unix_read_cb(int fd, void *privdata)