Print this page
374 cron should send more useful mail
@@ -70,10 +70,11 @@
#include <time.h>
#include <unistd.h>
#include <libzoneinfo.h>
#include "cron.h"
+#include "cron_scf.h"
/*
* #define DEBUG
*/
@@ -144,10 +145,11 @@
#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 CRONOUTNEW "Subject: Cron <%s@%s>: %s\n\n"
#define MALLOCERR "out of space, cannot create new string\n"
#define DIDFORK didfork
#define NOFORK !didfork
@@ -355,10 +357,16 @@
static int refresh;
static sigset_t defmask, sigmask;
/*
+ * Configuration from smf(5)
+ */
+static int legacy_subject;
+static int extra_headers;
+
+/*
* BSM hooks
*/
extern int audit_cron_session(char *, char *, uid_t, gid_t, char *);
extern void audit_cron_new_job(char *, int, void *);
extern void audit_cron_bad_user(char *);
@@ -673,10 +681,11 @@
{
#ifdef DEBUG
(void) fprintf(stderr, "in initialize\n");
#endif
if (firstpass) {
+ int val;
/* for mail(1), make sure messages come from root */
if (putenv("LOGNAME=root") != 0) {
crabort("cannot expand env variable",
REMOVE_FIFO|CONSOLE_MSG);
}
@@ -703,11 +712,26 @@
* init respawning this quickly
*/
}
crabort("cannot start cron; FIFO exists", CONSOLE_MSG);
}
+ switch (init_scf()) {
+ case 0:
+ val = get_config_boolean("legacy_subject");
+ legacy_subject = (val < 0 ? 0 : val);
+ val = get_config_boolean("extra_headers");
+ extra_headers = (val < 0 ? 1 : val);
+ break;
+ case -2:
+ crabort("cron not running under smf(5)",
+ REMOVE_FIFO|CONSOLE_MSG);
+ break;
+ default:
+ crabort("could not initialise libscf",
+ REMOVE_FIFO|CONSOLE_MSG);
}
+ }
if ((msgfd = open(FIFO, O_RDWR)) < 0) {
perror("! open");
crabort("cannot open fifo queue", REMOVE_FIFO|CONSOLE_MSG);
}
@@ -2722,12 +2746,25 @@
mailpipe = popen(cmd, "w");
free(cmd);
if (mailpipe == NULL)
exit(127);
(void) fprintf(mailpipe, "To: %s\n", p->name);
+ if (extra_headers) {
+ (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",
+ (pr->jobtype == CRONEVENT ? "cron" : "at"));
+ }
if (pr->jobtype == CRONEVENT) {
+ if (legacy_subject)
(void) fprintf(mailpipe, CRONOUT);
+ else
+ (void) fprintf(mailpipe, CRONOUTNEW,
+ p->name, name.nodename, pr->jobname);
(void) fprintf(mailpipe, "Your \"cron\" job on %s\n",
name.nodename);
if (pr->jobname != NULL) {
(void) fprintf(mailpipe, "%s\n\n", pr->jobname);
}