summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authormarck <marck@FreeBSD.org>2008-06-29 16:56:18 +0000
committermarck <marck@FreeBSD.org>2008-06-29 16:56:18 +0000
commitd97ee39b6076b326ab7fdf5789df34204a18008f (patch)
tree2f50245b25c5f51c1b0c3809d42a7e953264bd00 /usr.sbin
parent67ff1e3090142c9dccc3139d6839a78d9324d96f (diff)
downloadFreeBSD-src-d97ee39b6076b326ab7fdf5789df34204a18008f.zip
FreeBSD-src-d97ee39b6076b326ab7fdf5789df34204a18008f.tar.gz
Add -m option to cron(8), overriding default mail recipient for cron mails,
unless explicitly provided by MAILTO= line in crontab. This feature can be useful in massive hosting environment, where most users do not care about autogenerated mails. Setting recipient to null string disables default mails at all. Approved by: yar MFC after: 4 weeks
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/cron/cron/cron.820
-rw-r--r--usr.sbin/cron/cron/cron.c7
-rw-r--r--usr.sbin/cron/cron/cron.h6
-rw-r--r--usr.sbin/cron/cron/do_command.c20
4 files changed, 36 insertions, 17 deletions
diff --git a/usr.sbin/cron/cron/cron.8 b/usr.sbin/cron/cron/cron.8
index b0d1a91..5d5a8d9 100644
--- a/usr.sbin/cron/cron/cron.8
+++ b/usr.sbin/cron/cron/cron.8
@@ -17,7 +17,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd June 17, 2007
+.Dd June 29, 2008
.Dt CRON 8
.Os
.Sh NAME
@@ -27,6 +27,7 @@
.Nm
.Op Fl j Ar jitter
.Op Fl J Ar rootjitter
+.Op Fl m Ar mailto
.Op Fl s
.Op Fl o
.Op Fl x Ar debugflag Ns Op , Ns Ar ...
@@ -114,6 +115,23 @@ Enable time jitter for superuser jobs.
The same as
.Fl j
except that it will affect jobs run by the superuser only.
+.It Fl m Ar mailto
+Overrides the default recipient for
+.Nm
+mail.
+Each
+.Xr crontab 5
+without
+.Ev MAILTO
+explicitly set will send mail to the
+.Ar mailto
+mailbox.
+Sending mail will be disabled by default if
+.Ar mailto
+set to a null string, usually specified in a shell as
+.Li ''
+or
+.Li \*q\*q .
.It Fl s
Enable special handling of situations when the GMT offset of the local
timezone changes, such as the switches between the standard time and
diff --git a/usr.sbin/cron/cron/cron.c b/usr.sbin/cron/cron/cron.c
index 46d2fdf..101989c 100644
--- a/usr.sbin/cron/cron/cron.c
+++ b/usr.sbin/cron/cron/cron.c
@@ -53,7 +53,7 @@ usage() {
char **dflags;
fprintf(stderr, "usage: cron [-j jitter] [-J rootjitter] "
- "[-s] [-o] [-x debugflag[,...]]\n");
+ "[-m mailto] [-s] [-o] [-x debugflag[,...]]\n");
fprintf(stderr, "\ndebugflags: ");
for(dflags = DebugFlagNames; *dflags; dflags++) {
@@ -443,7 +443,7 @@ parse_args(argc, argv)
int argch;
char *endp;
- while ((argch = getopt(argc, argv, "j:J:osx:")) != -1) {
+ while ((argch = getopt(argc, argv, "j:J:m:osx:")) != -1) {
switch (argch) {
case 'j':
Jitter = strtoul(optarg, &endp, 10);
@@ -457,6 +457,9 @@ parse_args(argc, argv)
errx(ERROR_EXIT,
"bad value for root jitter: %s", optarg);
break;
+ case 'm':
+ defmailto = optarg;
+ break;
case 'o':
dst_enabled = 0;
break;
diff --git a/usr.sbin/cron/cron/cron.h b/usr.sbin/cron/cron/cron.h
index 35f75e8..e58cd85 100644
--- a/usr.sbin/cron/cron/cron.h
+++ b/usr.sbin/cron/cron/cron.h
@@ -268,7 +268,8 @@ char *DowNames[] = {
NULL
};
-char *ProgramName;
+char *ProgramName,
+ *defmailto;
int LineNumber;
unsigned Jitter,
RootJitter;
@@ -285,7 +286,8 @@ char *DebugFlagNames[] = { /* sync with #defines */
extern char *copyright[],
*MonthNames[],
*DowNames[],
- *ProgramName;
+ *ProgramName,
+ *defmailto;
extern int LineNumber;
extern unsigned Jitter,
RootJitter;
diff --git a/usr.sbin/cron/cron/do_command.c b/usr.sbin/cron/cron/do_command.c
index b224880..f5ab5b5 100644
--- a/usr.sbin/cron/cron/do_command.c
+++ b/usr.sbin/cron/cron/do_command.c
@@ -459,18 +459,14 @@ child_process(e, u)
/* get name of recipient. this is MAILTO if set to a
* valid local username; USER otherwise.
*/
- if (mailto) {
- /* MAILTO was present in the environment
+ if (mailto == NULL) {
+ /* MAILTO not present, set to USER,
+ * unless globally overriden.
*/
- if (!*mailto) {
- /* ... but it's empty. set to NULL
- */
- mailto = NULL;
- }
- } else {
- /* MAILTO not present, set to USER.
- */
- mailto = usernm;
+ if (defmailto)
+ mailto = defmailto;
+ else
+ mailto = usernm;
}
/* if we are supposed to be mailing, MAILTO will
@@ -478,7 +474,7 @@ child_process(e, u)
* up the mail command and subjects and stuff...
*/
- if (mailto) {
+ if (mailto && *mailto != '\0') {
register char **env;
auto char mailcmd[MAX_COMMAND];
auto char hostname[MAXHOSTNAMELEN];
OpenPOWER on IntegriCloud