Lines 1-76
Link Here
|
1 |
--- report.c.orig 2000-09-30 23:41:10 UTC |
|
|
2 |
+++ report.c |
3 |
@@ -45,6 +45,8 @@ struct rtentry; |
4 |
|
5 |
#include <ctype.h> |
6 |
#include <errno.h> |
7 |
+#include <fcntl.h> |
8 |
+#include <paths.h> |
9 |
#include <signal.h> |
10 |
#include <stdio.h> |
11 |
#include <stdlib.h> |
12 |
@@ -70,6 +72,8 @@ struct rtentry; |
13 |
|
14 |
#define PLURAL(n) ((n) == 1 || (n) == -1 ? "" : "s") |
15 |
|
16 |
+extern char *Watcher; |
17 |
+ |
18 |
static int cdepth; /* number of outstanding children */ |
19 |
|
20 |
static char *fmtdate(time_t); |
21 |
@@ -240,7 +244,7 @@ report(register char *title, register u_ |
22 |
register FILE *f; |
23 |
char tempfile[64], cpu[64], os[64]; |
24 |
char *fmt = "%20s: %s\n"; |
25 |
- char *watcher = WATCHER; |
26 |
+ char *watcher = Watcher ? Watcher : WATCHER; |
27 |
char *watchee = WATCHEE; |
28 |
char *sendmail = PATH_SENDMAIL; |
29 |
char *unknown = "<unknown>"; |
30 |
@@ -251,6 +255,11 @@ report(register char *title, register u_ |
31 |
if (initializing) |
32 |
return; |
33 |
|
34 |
+ /* No mail for 0.0.0.0 if -z */ |
35 |
+ if (zeroflag == 1 && strncmp("0.0.0.0",intoa(a),16) == 0 ) { |
36 |
+ dosyslog(LOG_NOTICE, title, a, e1, e2); |
37 |
+ return; |
38 |
+ } |
39 |
if (debug) { |
40 |
if (debug > 1) { |
41 |
dosyslog(LOG_NOTICE, title, a, e1, e2); |
42 |
@@ -303,7 +312,7 @@ report(register char *title, register u_ |
43 |
(void)fprintf(f, "From: %s\n", watchee); |
44 |
(void)fprintf(f, "To: %s\n", watcher); |
45 |
hn = gethname(a); |
46 |
- if (!isdigit(*hn)) |
47 |
+ if (hn != NULL) |
48 |
(void)fprintf(f, "Subject: %s (%s)\n", title, hn); |
49 |
else { |
50 |
(void)fprintf(f, "Subject: %s\n", title); |
51 |
@@ -344,6 +353,25 @@ report(register char *title, register u_ |
52 |
exit(1); |
53 |
} |
54 |
/* XXX Need to freopen()? */ |
55 |
+ |
56 |
+ /* |
57 |
+ * Open /dev/null as stdout and stderr so that sendmail 8.12.1 (and |
58 |
+ * above ?) won't complain about missing file descriptors. |
59 |
+ */ |
60 |
+ if ((fd = open(_PATH_DEVNULL, O_RDWR)) == -1) { |
61 |
+ syslog(LOG_ERR, "Cannot open %s: %m", _PATH_DEVNULL); |
62 |
+ exit(1); |
63 |
+ } |
64 |
+ if (dup2(fd, STDOUT_FILENO) == -1) { |
65 |
+ syslog(LOG_ERR, "Cannot dup2 %s to stdout: %m", _PATH_DEVNULL); |
66 |
+ exit(1); |
67 |
+ } |
68 |
+ if (dup2(fd, STDERR_FILENO) == -1) { |
69 |
+ syslog(LOG_ERR, "Cannot dup2 %s to stderr: %m", _PATH_DEVNULL); |
70 |
+ exit(1); |
71 |
+ } |
72 |
+ close(fd); |
73 |
+ |
74 |
/* Always Deliver interactively (pause when child depth gets large) */ |
75 |
execl(sendmail, "sendmail", "-odi", watcher, NULL); |
76 |
syslog(LOG_ERR, "execl: %s: %m", sendmail); |