Package: bsd-mailx / 8.1.2-0.20141216cvs-2

18-Wait-for-sendmail.patch Patch series | download
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From: Robert Luberda <robert@debian.org>
Date: Sat, 24 Aug 2002 22:18:00 +0200
Subject: 18 Wait for sendmail.

* send.c: Always wait for a sendmail process, check its exit code
  and if non-zero, print a warning message to user and save original
  message to ~/dead.letter (closes: #145379).

* popen.c: Make wait_child() return an exit code of the child.
---
 popen.c | 12 +++++++++---
 send.c  | 15 +++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/popen.c b/popen.c
index dfd66cd..691827e 100644
--- a/popen.c
+++ b/popen.c
@@ -291,8 +291,12 @@ prepare_child(sigset_t *nset, int infd, int outfd)
 int
 wait_command(pid_t pid)
 {
-
-	if (wait_child(pid) < 0) {
+	int ret;
+	ret = wait_child(pid);
+	if (ret > 0) {
+		printf("Fatal error, process exited with code %d.\n", ret);
+		return(-1);
+	} else if (ret < 0) {
 		puts("Fatal error in process.");
 		return(-1);
 	}
@@ -388,7 +392,9 @@ wait_child(pid_t pid)
 	if (cp != NULL)
 		delchild(cp);
 	sigprocmask(SIG_SETMASK, &oset, NULL);
-	if (rv == -1 || (WIFEXITED(wait_status) && WEXITSTATUS(wait_status)))
+	if (rv >= 0 && (WIFEXITED(wait_status)))
+		return (WEXITSTATUS(wait_status));
+	else
 		return(-1);
 	else
 		return(0);
diff --git a/send.c b/send.c
index 4b31a61..10091fe 100644
--- a/send.c
+++ b/send.c
@@ -331,6 +331,7 @@ mail1(struct header *hp, int printheaders)
 	char **namelist;
 	struct name *to;
 	FILE *mtf;
+	int w;
 
 	/*
 	 * Collect user's mail from standard input.
@@ -414,10 +415,24 @@ mail1(struct header *hp, int printheaders)
 		warn("%s", cp);
 		_exit(1);
 	}
+#ifndef DEBIAN
 	if (value("verbose") != NULL)
 		(void)wait_child(pid);
 	else
 		free_child(pid);
+#else
+       /*
+	* Always wait for sendmail and check its error code.
+	* See: Bug#145379
+	*/
+	if ((w = wait_child(pid))) {
+		fprintf(stderr, "Can't send mail: sendmail process failed");
+		if (w > 0)
+			fprintf(stderr, " with error code %d", w);
+		fprintf(stderr, "\n");
+		savedeadletter(mtf);
+	}
+#endif
 out:
 	(void)Fclose(mtf);
 }