File: Dont-fail-on-missing-MTA.patch

package info (click to toggle)
cron 3.0pl1-198
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,824 kB
  • sloc: ansic: 54,879; xml: 1,600; perl: 733; sh: 495; makefile: 446; python: 43
file content (60 lines) | stat: -rw-r--r-- 1,643 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From: Christian Kastner <ckk@kvr.at>
Date: Fri, 15 Jan 2016 22:10:20 +0100
Subject: Don't fail on missing MTA

Author: Christian Kastner <debian@kvr.at>
Last-Update: 2010-04-22

Don't fail silently when MTA is not installed. When this is the case (MAILCMD
is not available), the attempted piping of job output to the MTA fails fatally
as soon as the pipe's buffer is full.

This adds a check to see if MAILCMD is available before proceeding to pipe
output to it.

Bug-Debian: https://bugs.debian.org/577133
Forwarded: no
Last-Update: 2016-01-15
---
 do_command.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/do_command.c b/do_command.c
index cbca2d1..923e507 100644
--- a/do_command.c
+++ b/do_command.c
@@ -23,6 +23,8 @@ static char rcsid[] = "$Id: do_command.c,v 2.12 1994/01/15 20:43:43 vixie Exp $"
 #include "cron.h"
 #include <signal.h>
 #include <grp.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #if defined(sequent)
 # include <sys/universe.h>
 #endif
@@ -476,6 +478,7 @@ child_process(e, u)
 // status.
 
 	long pos;
+	struct stat	mcsb;
 
 	fseek(tmpout, 0, SEEK_END);
 	pos = ftell(tmpout);
@@ -492,6 +495,17 @@ child_process(e, u)
 	else if (!*mailto)
                 goto mail_finished;
 
+	/* Don't send mail if MAILCMD is not available */
+	if (stat(MAILCMD, &mcsb) != 0) {
+		Debug(DPROC|DEXT, ("%s not found, not sending mail\n", MAILCMD))
+		if (pos > 0) {
+			log_it("CRON", getpid(), "info", "No MTA installed, discarding output");
+		}
+		goto mail_finished;
+	} else {
+		Debug(DPROC|DEXT, ("%s found, will send mail\n", MAILCMD))
+	}
+
 	register FILE	*mail = NULL;
 	register int	bytes = 0;