]> git.donarmstrong.com Git - deb_pkgs/spamass-milter.git/blob - debian/patches/disabled_15_write_to_pid_file.patch
Load spamass-milter-0.3.0 into spamass-milter/trunk.
[deb_pkgs/spamass-milter.git] / debian / patches / disabled_15_write_to_pid_file.patch
1 --- spamass-milt/spamass-milter.cpp:1.69        Fri Sep 12 05:45:05 2003
2 +++ spamass-milt/spamass-milter.cpp     Tue Oct 21 21:40:32 2003
3 @@ -174,7 +174,7 @@
4  main(int argc, char* argv[])
5  {
6     int c, err = 0;
7 -   const char *args = "p:fd:mr:u:D:i:b:B:";
8 +   const char *args = "fd:mp:P:r:u:D:i:b:B:";
9     char *sock = NULL;
10     bool dofork = false;
11
12 @@ -177,15 +177,14 @@
13     const char *args = "p:fd:mr:u:D:i:b:B:";
14     char *sock = NULL;
15     bool dofork = false;
16 +   char *pidfilename = NULL;
17 +   FILE *pidfile = NULL;
18  
19     openlog("spamass-milter", LOG_PID, LOG_MAIL);
20  
21         /* Process command line options */
22         while ((c = getopt(argc, argv, args)) != -1) {
23                 switch (c) {
24 -                       case 'p':
25 -                               sock = strdup(optarg);
26 -                               break;
27                         case 'f':
28                                 dofork = true;
29                                 break;
30 @@ -215,6 +209,12 @@
31                                 dontmodifyspam = true;
32                                 smfilter.xxfi_flags &= ~(SMFIF_CHGBODY|SMFIF_CHGHDRS);
33                                 break;
34 +                       case 'p':
35 +                               sock = strdup(optarg);
36 +                               break;
37 +                       case 'P':
38 +                               pidfilename = strdup(optarg);
39 +                               break;
40                         case 'r':
41                                 flag_reject = true;
42                                 reject_score = atoi(optarg);
43 @@ -287,18 +287,37 @@
44        exit(EX_USAGE);
45     }
46  
47 -       if (dofork == true) {
48 -               switch(fork()) {
49 -         case -1: /* Uh-oh, we have a problem forking. */
50 -            fprintf(stderr, "Uh-oh, couldn't fork!\n");
51 -                               exit(errno);
52 -                               break;
53 -                       case 0: /* Child */
54 -                               break;
55 -                       default: /* Parent */
56 -                               exit(0);
57 +       if (pidfilename)
58 +       {
59 +               unlink(pidfilename);
60 +               pidfile = fopen(pidfilename,"w");
61 +               if (!pidfile)
62 +               {
63 +                       fprintf(stderr, "Could not open pidfile: %s\n", strerror(errno));
64 +                       exit(1);
65 +               }
66 +               /* leave the file open through the fork, since we don't know our pid
67 +                  yet
68 +               */
69 +       }
70 +
71 +
72 +       if (dofork == true) 
73 +       {
74 +               if (daemon(0, 0) == -1)
75 +               {
76 +            fprintf(stderr, "daemon() failed: %s\n", strerror(errno));
77 +            exit(1);
78                 }
79         }
80 +       
81 +       if (pidfile)
82 +       {
83 +               fprintf(pidfile, "%ld\n", (long)getpid());
84 +               fclose(pidfile);
85 +               pidfile = NULL;
86 +       }       
87 +       
88     {
89        struct stat junk;
90        if (stat(sock,&junk) == 0) unlink(sock);
91 @@ -314,7 +333,9 @@
92         debug(D_ALWAYS, "spamass-milter %s starting", PACKAGE_VERSION);
93         err = smfi_main();
94         debug(D_ALWAYS, "spamass-milter %s exiting", PACKAGE_VERSION);
95 +       if (pidfilename)
96 +               unlink(pidfilename);
97         return err;
98  }
99