ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/Mail/SpamUpdate.c
(Generate patch)

Comparing FreeBSDAdmin/Mail/SpamUpdate.c (file contents):
Revision 835 by douglas, 2006-07-07T07:27:48-07:00 vs.
Revision 836 by douglas, 2006-07-10T00:55:02-07:00

# Line 47 | Line 47 | static void *mcheck(void *value, jmp_buf
47          return value;
48   }
49  
50 + static char *fcheck(char *value, FILE *stream, jmp_buf environment)
51 + {
52 +        if (!value)
53 +        {
54 +                if (ferror(stream))
55 +                        longjmp(environment, 1);
56 +                else
57 +                {
58 +                        clearerr(stream);
59 +
60 +                        if (stream == stdin)
61 +                                printf("\n");
62 +
63 +                        return "";
64 +                }
65 +        }
66 +
67 +        return value;
68 + }
69 +
70   static void learn()
71   {
72          typedef struct { const char *verb, *learn, *collab, *mailbox; } Job;
# Line 63 | Line 83 | static void learn()
83  
84                  const unsigned long *messages_ = messages[job - jobs];
85                  const size_t count = counts[job - jobs];
86 <                size_t learned = 0;
86 >                size_t learned = 0, collabed = 0;
87  
88                  for (size_t index = 0; index != count; ++index)
89                  {
# Line 76 | Line 96 | static void learn()
96                          check(lseek(file_, 0, SEEK_SET), environment);
97  
98                          pid_t learn;
99 +                        int pipe_[2][2];
100 +
101 +                        check(pipe(pipe_[0]), environment);
102  
103                          if (!(learn = check(fork(), environment)))
104                          {
105                                  check(dup2(file_, 0), environment);
106 +                                check(dup2(pipe_[0][1], 1), environment);
107 +                                check(close(pipe_[0][0]), environment);
108                                  check(execl(SPAMC, "spamc", "-L", job->learn, "-U", SPAMD, NULL), environment);
109                          }
110  
111 +                        check(close(pipe_[0][1]), environment);
112 +
113                          pid_t collab;
114  
115 +                        check(pipe(pipe_[1]), environment);
116 +
117                          if (!(collab = check(fork(), environment)))
118                          {
119                                  check(dup2(file_, 0), environment);
120 +                                check(dup2(pipe_[1][1], 1), environment);
121 +                                check(close(pipe_[1][0]), environment);
122                                  check(execl(SPAMC, "spamc", "-L", job->collab, "-U", SPAMD, NULL), environment);
123                          }
124  
125                          check(close(file_), environment);
126                          check(unlink(file), environment);
127 +                        check(close(pipe_[1][1]), environment);
128  
129 <                        int status;
130 <
131 <                        check(waitpid(learn, &status, 0), environment);
129 >                        FILE *learn_ = fdopen(pipe_[0][0], "r");
130 >                        size_t size_;
131 >                        char *line = fcheck(fgetln(learn_, &size_), learn_, environment);
132  
133 <                        if (WEXITSTATUS(status) == 5)
133 >                        if (strncmp(line, "Message successfully un/learned\n", size_) == 0)
134                                  ++learned;
135  
136 +                        fclose(learn_);
137 +
138 +                        FILE *collab_ = fdopen(pipe_[1][0], "r");
139 +
140 +                        line = fcheck(fgetln(collab_, &size_), collab_, environment);
141 +
142 +                        if (strncmp(line, "Message successfully reported/revoked\n", size_) == 0)
143 +                                ++collabed;
144 +
145 +                        fclose(collab_);
146 +
147 +                        int status;
148 +
149 +                        check(waitpid(learn, &status, 0), environment);
150                          check(waitpid(collab, &status, 0), environment);
151                  }
152  
153 <                printf("    %u message(s) learned and %u message(s) %sed.\n", learned, count, job->verb);
153 >                printf("    %u message(s) learned and %u message(s) %sed.\n", learned, collabed, job->verb);
154          }
155   }
156  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines