diff options
author | Joshua M. Clulow <josh@sysmgr.org> | 2013-01-21 12:21:50 -0800 |
---|---|---|
committer | Dan McDonald <danmcd@nexenta.com> | 2013-02-11 11:29:09 -0500 |
commit | 42c141d3747f50c9bfb13e3cf5f32828312a7b79 (patch) | |
tree | 5f455b85e66c840f998032fcf458a243201d2a8c /usr/src/cmd/cron | |
parent | 1f9f06cf154565efc5425d8e2c4d511ea99b0a58 (diff) | |
download | illumos-gate-42c141d3747f50c9bfb13e3cf5f32828312a7b79.tar.gz |
374 cron should send more useful mail
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Approved by: Dan McDonald <danmcd@nexenta.com>
Diffstat (limited to 'usr/src/cmd/cron')
-rw-r--r-- | usr/src/cmd/cron/cron.c | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/usr/src/cmd/cron/cron.c b/usr/src/cmd/cron/cron.c index c6277a1f52..54d3c9d971 100644 --- a/usr/src/cmd/cron/cron.c +++ b/usr/src/cmd/cron/cron.c @@ -21,6 +21,8 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2013 Joshua M. Clulow <josh@sysmgr.org> */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ @@ -145,7 +147,6 @@ error for each of your commands." #define CLOCK_DRIFT "clock time drifted backwards after event!\n" #define PIDERR "unexpected pid returned %d (ignored)" #define CRONTABERR "Subject: Your crontab file has an error in it\n\n" -#define CRONOUT "Subject: Output from \"cron\" command\n\n" #define MALLOCERR "out of space, cannot create new string\n" #define DIDFORK didfork @@ -2711,6 +2712,7 @@ mail_result(struct usr *p, struct runinfo *pr, size_t filesize) int nbytes; char iobuf[BUFSIZ]; char *cmd; + char *lowname = (pr->jobtype == CRONEVENT ? "cron" : "at"); (void) uname(&name); if ((ruser_ids = getpwnam(p->name)) == NULL) @@ -2724,31 +2726,40 @@ mail_result(struct usr *p, struct runinfo *pr, size_t filesize) if (mailpipe == NULL) exit(127); (void) fprintf(mailpipe, "To: %s\n", p->name); - if (pr->jobtype == CRONEVENT) { - (void) fprintf(mailpipe, CRONOUT); - (void) fprintf(mailpipe, "Your \"cron\" job on %s\n", - name.nodename); - if (pr->jobname != NULL) { - (void) fprintf(mailpipe, "%s\n\n", pr->jobname); - } - } else { - (void) fprintf(mailpipe, "Subject: Output from \"at\" job\n\n"); - (void) fprintf(mailpipe, "Your \"at\" job on %s\n", - name.nodename); - if (pr->jobname != NULL) { - (void) fprintf(mailpipe, "\"%s\"\n\n", pr->jobname); - } - } - /* Tmp. file is fopen'ed w/ "r", secure open */ + (void) fprintf(mailpipe, "Subject: %s <%s@%s> %s\n", + (pr->jobtype == CRONEVENT ? "Cron" : "At"), + p->name, name.nodename, pr->jobname); + + /* + * RFC3834 (Section 5) defines the Auto-Submitted header to prevent + * vacation replies, et al, from being sent in response to + * machine-generated mail. + */ + (void) fprintf(mailpipe, "Auto-Submitted: auto-generated\n"); + + /* + * Additional headers for mail filtering and diagnostics: + */ + (void) fprintf(mailpipe, "X-Mailer: cron (%s %s)\n", name.sysname, + name.release); + (void) fprintf(mailpipe, "X-Cron-User: %s\n", p->name); + (void) fprintf(mailpipe, "X-Cron-Host: %s\n", name.nodename); + (void) fprintf(mailpipe, "X-Cron-Job-Name: %s\n", pr->jobname); + (void) fprintf(mailpipe, "X-Cron-Job-Type: %s\n", lowname); + + /* + * Message Body: + * + * (Temporary file is fopen'ed with "r", secure open.) + */ + (void) fprintf(mailpipe, "\n"); if (filesize > 0 && (st = fopen(pr->outfile, "r")) != NULL) { - (void) fprintf(mailpipe, - "produced the following output:\n\n"); while ((nbytes = fread(iobuf, sizeof (char), BUFSIZ, st)) != 0) (void) fwrite(iobuf, sizeof (char), nbytes, mailpipe); (void) fclose(st); } else { - (void) fprintf(mailpipe, "completed.\n"); + (void) fprintf(mailpipe, "Job completed with no output.\n"); } (void) pclose(mailpipe); exit(0); |