From 24ff8bca573440bcb2620cd27fd35da0c972caf6 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sun, 19 Apr 2009 14:51:01 +0200 Subject: [PATCH] mail support --- daemon/alix-usvd.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/daemon/alix-usvd.c b/daemon/alix-usvd.c index f00dccf..0fcd6d3 100644 --- a/daemon/alix-usvd.c +++ b/daemon/alix-usvd.c @@ -44,6 +44,7 @@ #define DEFAULT_LOGFILE "alix-usvd.log" #define DEFAULT_PIDFILE "alix-usvd.pid" #define DEFAULT_SOCKET "alix-usvd.sock" +#define SENDMAIL "/usr/sbin/sendmail" enum { REG_STATUS = 0x00, @@ -246,8 +247,34 @@ static int alix_state = -1; 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)); - /* 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)