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