]> granicus.if.org Git - cronie/commitdiff
Option -m was added: it's possible to use something else then sendmail.
authormmaslano <mmaslano@redhat.com>
Fri, 17 Aug 2007 13:13:20 +0000 (15:13 +0200)
committermmaslano <mmaslano@redhat.com>
Fri, 24 Aug 2007 13:06:00 +0000 (15:06 +0200)
cron.8
cron.c
do_command.c
globals.h

diff --git a/cron.8 b/cron.8
index ab47564a3455c1a4d71a9fa206616f76079811ca..7bc5a22e60655bb91b7ca3fd0762028d7c9521b7 100644 (file)
--- a/cron.8
+++ b/cron.8
@@ -29,6 +29,7 @@ cron \- daemon to execute scheduled commands (ISC Cron V4.1)
 .IR load_avg ]
 .RB [ \-n ]
 .RB [ \-p ]
+.RB [ \-m <mail command> ]
 .SH DESCRIPTION
 .I Cron
 should be started from /etc/rc or /etc/rc.local.  It will return immediately,
@@ -63,6 +64,16 @@ need not be restarted whenever a crontab file is modified.  Note that the
 .IR Crontab (1)
 command updates the modtime of the spool directory whenever it changes a
 crontab.
+.PP 
+The
+.B -m
+option allows you to specify a shell command string to use for sending
+cron mail output instead of 
+.IR sendmail (8).
+This command must accept a fully
+formatted mail message (with headers) on stdin and send it as a mail
+message to the recipients specified in the mail headers.
+.PP 
 .SS Daylight Saving Time and other time changes
 Local time changes of less than three hours, such as those caused
 by the start or end of Daylight Saving Time, are handled specially.
diff --git a/cron.c b/cron.c
index 0fc1d38d0cd5520ab209bf1bf245a79278ddcd2e..44912974418517d385c849e3f01da225bbce0972 100644 (file)
--- a/cron.c
+++ b/cron.c
@@ -48,7 +48,7 @@ static void
 usage(void) {
        const char **dflags;
 
-       fprintf(stderr, "usage:  %s [-n] [-p] [-x [", ProgramName);
+       fprintf(stderr, "usage:  %s [-n] [-p] [-m <mail command>] [-x [", ProgramName);
        for (dflags = DebugFlagNames; *dflags; dflags++)
                fprintf(stderr, "%s%s", *dflags, dflags[1] ? "," : "]");
        fprintf(stderr, "]\n");
@@ -437,7 +437,7 @@ static void
 parse_args(int argc, char *argv[]) {
        int argch;
 
-       while (-1 != (argch = getopt(argc, argv, "npx:"))) {
+       while (-1 != (argch = getopt(argc, argv, "npx:m:"))) {
                switch (argch) {
                default:
                        usage();
@@ -451,6 +451,9 @@ parse_args(int argc, char *argv[]) {
                case 'p':
                        PermitAnyCrontab=1;
                        break;
+               case 'm':
+                       strncpy(MailCmd, optarg, MAX_COMMAND);
+                       break;
                }
        }
 }
index ee17b44f71348052fdfbb4a1efd8e5afa72431de..9574df4b2f50d4f07b6c51ac85b8d1e60f21e526 100644 (file)
@@ -508,16 +508,24 @@ child_process(entry *e, user *u) {
                                char    hostname[MAXHOSTNAMELEN];
 
                                gethostname(hostname, MAXHOSTNAMELEN);
-                               if (strlens(MAILFMT, MAILARG, NULL) + 1
-                                   >= sizeof mailcmd) {
-                                       fprintf(stderr, "mailcmd too long\n");
-                                       (void) _exit(ERROR_EXIT);
+                               
+                               if ( MailCmd[0] == '\0' )
+                               {
+                                       if (strlens(MAILFMT, MAILARG, NULL) + 1
+                                           >= sizeof mailcmd) {
+                                               fprintf(stderr, "mailcmd too long\n");
+                                               (void) _exit(ERROR_EXIT);
+                                       }
+                                       (void)sprintf(mailcmd, MAILFMT, MAILARG);
+                               }else
+                               {
+                                       strncpy( mailcmd, MailCmd, MAX_COMMAND );
                                }
-                               (void)sprintf(mailcmd, MAILFMT, MAILARG);
                                if (!(mail = cron_popen(mailcmd, "w", e->pwd))) {
                                        perror(mailcmd);
                                        (void) _exit(ERROR_EXIT);
                                }
+                               
                                fprintf(mail, "From: root (Cron Daemon)\n");
                                fprintf(mail, "To: %s\n", mailto);
                                fprintf(mail, "Subject: Cron <%s@%s> %s\n",
index 22bfae03a4b8f31488e44d274777e38fd8a82f36..a31bec54d04ac4d16ae42c556041d49ba3b5c222 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -65,6 +65,7 @@ XTRN time_t   StartTime INIT(0);
 XTRN int       NoFork INIT(0);
 XTRN int        PermitAnyCrontab INIT(0);
 XTRN int        ValidateMailRcpts INIT(0);
+XTRN char       MailCmd[MAX_COMMAND] INIT("");
 
 #if DEBUGGING
 XTRN int       DebugFlags INIT(0);