Blame SOURCES/cronie-1.4.11-anacron-mailto.patch

c587ab
diff -up cronie-1.4.11/anacron/runjob.c.mailto cronie-1.4.11/anacron/runjob.c
c587ab
--- cronie-1.4.11/anacron/runjob.c.mailto	2013-07-18 14:27:08.000000000 +0200
c587ab
+++ cronie-1.4.11/anacron/runjob.c	2017-03-07 14:00:06.968348389 +0100
c587ab
@@ -88,10 +88,18 @@ static char *
c587ab
 username(void)
c587ab
 {
c587ab
     struct passwd *ps;
c587ab
+    static char *user;
c587ab
+
c587ab
+    if (user)
c587ab
+	return user;
c587ab
 
c587ab
     ps = getpwuid(geteuid());
c587ab
-    if (ps == NULL) die_e("getpwuid() error");
c587ab
-    return ps->pw_name;
c587ab
+    if (ps == NULL || ps->pw_name == NULL) die_e("getpwuid() error");
c587ab
+
c587ab
+    user = strdup(ps->pw_name);
c587ab
+    if (user == NULL) die_e("memory allocation error");
c587ab
+
c587ab
+    return user;
c587ab
 }
c587ab
 
c587ab
 static void
c587ab
@@ -167,6 +175,12 @@ launch_mailer(job_rec *jr)
c587ab
     pid_t pid;
c587ab
     struct stat buf;
c587ab
 
c587ab
+    if (jr->mailto == NULL)
c587ab
+    {
c587ab
+	explain("Empty MAILTO set, not mailing output");
c587ab
+	return;
c587ab
+    }
c587ab
+
c587ab
     /* Check that we have a way of sending mail. */
c587ab
     if(stat(SENDMAIL, &buf))
c587ab
     {
c587ab
@@ -245,14 +259,12 @@ launch_job(job_rec *jr)
c587ab
     }
c587ab
 
c587ab
     setup_env(jr);
c587ab
-   
c587ab
+
c587ab
     /* Get the destination email address if set, or current user otherwise */
c587ab
     mailto = getenv("MAILTO");
c587ab
 
c587ab
-    if (mailto)
c587ab
-	    jr->mailto = mailto;
c587ab
-    else
c587ab
-	    jr->mailto = username ();
c587ab
+    if (mailto == NULL)
c587ab
+	mailto = username();
c587ab
 
c587ab
     /* create temporary file for stdout and stderr of the job */
c587ab
     temp_file(jr); fd = jr->output_fd;
c587ab
@@ -262,11 +274,7 @@ launch_job(job_rec *jr)
c587ab
     xwrite(fd, username());
c587ab
     xwrite(fd, ">\n");
c587ab
     xwrite(fd, "To: ");
c587ab
-    if (mailto) {
c587ab
-       xwrite(fd, mailto);
c587ab
-    } else {
c587ab
-       xwrite(fd, username());
c587ab
-    }
c587ab
+    xwrite(fd, mailto);
c587ab
     xwrite(fd, "\n");
c587ab
     xwrite(fd, "Content-Type: text/plain; charset=\"");
c587ab
     xwrite(fd, nl_langinfo(CODESET));
c587ab
@@ -277,6 +285,12 @@ launch_job(job_rec *jr)
c587ab
     xwrite(fd, hostname);
c587ab
     xwrite(fd, "\n\n");
c587ab
 
c587ab
+    if (*mailto == '\0')
c587ab
+	jr->mailto = NULL;
c587ab
+    else
c587ab
+	/* ugly but works without strdup() */
c587ab
+	jr->mailto = mailto;
c587ab
+
c587ab
     jr->mail_header_size = file_size(fd);
c587ab
 
c587ab
     pid = xfork();
c587ab
@@ -305,7 +319,7 @@ tend_job(job_rec *jr, int status)
c587ab
     if (file_size(jr->output_fd) > jr->mail_header_size) mail_output = 1;
c587ab
     else mail_output = 0;
c587ab
 
c587ab
-    m = mail_output ? " (mailing output)" : "";
c587ab
+    m = mail_output ? " (produced output)" : "";
c587ab
     if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
c587ab
 	explain("Job `%s' terminated%s", jr->ident, m);
c587ab
     else if (WIFEXITED(status))