1 | |
---|
2 | |
---|
3 | #ifndef lint |
---|
4 | static char rcsid[] = "$Id: nullmail.c,v 3.2 1999-01-22 23:16:01 ghudson Exp $"; |
---|
5 | #endif |
---|
6 | |
---|
7 | #include <stdio.h> |
---|
8 | #include "bellcore-copyright.h" |
---|
9 | #include "mit-copyright.h" |
---|
10 | |
---|
11 | #define LINELN 256 |
---|
12 | |
---|
13 | extern FILE *popen(); |
---|
14 | /* |
---|
15 | ** program to swollow null message, but exec mail if necessary |
---|
16 | */ |
---|
17 | main(argc,argv) |
---|
18 | int argc; |
---|
19 | char **argv; |
---|
20 | { |
---|
21 | int buf,i,tmpstat; |
---|
22 | char errline[LINELN],mailcmd[LINELN]; |
---|
23 | static char errmsg[LINELN] = ""; |
---|
24 | FILE *paper,*mailpipe; |
---|
25 | |
---|
26 | if ((buf = getc(stdin))!= EOF) |
---|
27 | { |
---|
28 | if (argc < 2) |
---|
29 | { |
---|
30 | sprintf(errmsg,"not enough arguments"); |
---|
31 | goto trouble; |
---|
32 | } |
---|
33 | strcpy(mailcmd,"/bin/mail"); |
---|
34 | for (i=1;i<argc;i++) |
---|
35 | { |
---|
36 | strcat(mailcmd," "); |
---|
37 | strcat(mailcmd,argv[i]); |
---|
38 | } |
---|
39 | if ((mailpipe = popen(mailcmd, "w")) == NULL) |
---|
40 | { |
---|
41 | sprintf(errmsg,"can't execute mail command"); |
---|
42 | goto trouble; |
---|
43 | } |
---|
44 | putc(buf,mailpipe); /* output first char */ |
---|
45 | /* |
---|
46 | ** keep reading and writing |
---|
47 | */ |
---|
48 | while((buf =getc(stdin)) != EOF ) |
---|
49 | { |
---|
50 | putc(buf,mailpipe); |
---|
51 | } |
---|
52 | /* |
---|
53 | ** mail swollows an unfinished line - damn. |
---|
54 | ** stick an extra newline |
---|
55 | */ |
---|
56 | putc('\n',mailpipe); |
---|
57 | if ((tmpstat = pclose(mailpipe)) != 0) |
---|
58 | { |
---|
59 | sprintf(errmsg,"bad return code octal -- %o",tmpstat); |
---|
60 | goto trouble; |
---|
61 | } |
---|
62 | exit(0); |
---|
63 | |
---|
64 | /* |
---|
65 | ** shouldn't get here . . . complain like hell |
---|
66 | */ |
---|
67 | trouble:; |
---|
68 | sprintf(errline, |
---|
69 | "\n\r\t\tWARNING %s FAILED -- %s\n\r\t\t\tmail from automatic software installation probably lost\n\r", |
---|
70 | argv[0],errmsg); |
---|
71 | if ((paper = fopen("/dev/console","w")) != NULL) |
---|
72 | { |
---|
73 | fprintf(paper,"%s\n",errline); |
---|
74 | } |
---|
75 | fprintf(stderr,"%s\n",errline); |
---|
76 | exit(1); |
---|
77 | } |
---|
78 | exit(0); |
---|
79 | } |
---|