-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.c
62 lines (49 loc) · 1.1 KB
/
mailer.c
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
/*
* $Id$
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include "mailer_config.h"
/* mailer listfile message_file from@host [path to mpp] */
char *messagebody,*mailfrom,*myhostname;
int messagebody_size;
void readmessage();
char *messagefile,*mpppath;
void do_list(char *fname);
void usage(char *prog)
{
fprintf(stderr,
"Usage: %s listfile[+line] message_file from@host [path to mpp] \n",
prog);
exit(1);
}
int main(int argc, char *argv[])
{
int status;
if(argc != 4 && argc != 5) usage(argv[0]);
if(!(myhostname=strrchr((mailfrom=argv[3]),'@'))) usage(argv[0]);
myhostname++;
messagefile = argv[2];
mpppath = (argc==4 ? MPP : argv[4]);
readmessage();
/* become a process group and session leader */
switch(fork()) {
case -1:
perror("fork");
exit(1);
case 0: /* child continues */
break;
default: /* parent waits for the child */
wait(&status);
exit WEXITSTATUS(status);
}
if(setsid() == -1) {
perror("setsid");
}
do_list(argv[1]);
return 0;
}