]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdmonitor: use MAILFROM to set sendmail envelope sender address main master
authorMartin Wilck <mwilck@suse.com>
Wed, 7 May 2025 15:49:05 +0000 (17:49 +0200)
committerMariusz Tkaczyk <mtkaczyk@kernel.org>
Thu, 19 Jun 2025 14:42:37 +0000 (16:42 +0200)
Modern mail relays may reject emails with unknown envelope sender
address.

Use the MAILFROM address also as envelope sender address to work
around this issue.

Signed-off-by: Martin Wilck <mwilck@suse.com>
mdmonitor.c

index d51617cd0981ec4a98e19d28bc25e40205d05c72..ea35d98ede303e1418fa355f784a9deaafb014b6 100644 (file)
@@ -639,11 +639,20 @@ static void execute_alert_cmd(const struct event_data *data)
  */
 static void send_event_email(const struct event_data *data)
 {
-       FILE *mp, *mdstat;
+       FILE *mp = NULL, *mdstat;
        char buf[BUFSIZ];
        int n;
 
-       mp = popen(Sendmail, "w");
+       if (info.mailfrom) {
+               char cmd[1024];
+               int rc = snprintf(cmd, sizeof(cmd), "%s -f%s",
+                                 Sendmail, info.mailfrom);
+
+               if (rc >= 0 && (unsigned int)rc < sizeof(cmd))
+                       mp = popen(cmd, "w");
+       }
+       if (mp == NULL)
+               mp = popen(Sendmail, "w");
        if (!mp) {
                pr_err("Cannot open pipe stream for sendmail.\n");
                return;