/[imapfilter]/imapfilter/imapfilter.c
ViewVC logotype

Diff of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.54.2.3 by lefcha, Tue Jan 20 02:06:09 2004 UTC revision 1.54.2.4 by lefcha, Mon Jan 26 21:38:51 2004 UTC
# Line 5  Line 5 
5  #include <string.h>  #include <string.h>
6  #include <errno.h>  #include <errno.h>
7  #include <limits.h>  #include <limits.h>
8    #include <fcntl.h>
9  #include <setjmp.h>  #include <setjmp.h>
10  #include <locale.h>  #include <locale.h>
11    
# Line 47  void version(void); Line 48  void version(void);
48  int  int
49  main(int argc, char *argv[])  main(int argc, char *argv[])
50  {  {
51          int c, r, f;          int c, r;
         pid_t pid;  
52          char *conffile;         /* Configuration file. */          char *conffile;         /* Configuration file. */
53          account_t *ca;          /* Current account. */          account_t *ca;          /* Current account. */
54          mbox_t *cm;             /* Current mailbox. */          mbox_t *cm;             /* Current mailbox. */
55    
56          setlocale(LC_ALL, "");          setlocale(LC_ALL, "");
57    
         f = 0;  
58          home = getenv("HOME");          home = getenv("HOME");
59          options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE | OPTION_PEEK);          options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE | OPTION_PEEK);
60          *charset = 0;          *charset = 0;
# Line 148  main(int argc, char *argv[]) Line 147  main(int argc, char *argv[])
147          init_buffer(&obuf);          init_buffer(&obuf);
148    
149          if (options & OPTION_DAEMON_MODE) {          if (options & OPTION_DAEMON_MODE) {
                 f = 1;  
150                  options &= ~(OPTION_DETAILS_QUIET |                  options &= ~(OPTION_DETAILS_QUIET |
151                      OPTION_DETAILS_NORMAL | OPTION_DETAILS_VERBOSE);                      OPTION_DETAILS_NORMAL | OPTION_DETAILS_VERBOSE);
152                  options |= OPTION_DETAILS_QUIET;                  options |= OPTION_DETAILS_QUIET;
# Line 218  main(int argc, char *argv[]) Line 216  main(int argc, char *argv[])
216                  }                  }
217    
218                  /* Fork if in daemon mode. */                  /* Fork if in daemon mode. */
219                  if (f) {                  if (options & OPTION_DAEMON_MODE &&
220                          f = 0;                      !(flags & FLAG_DAEMON_MODE)) {
221                          pid = fork();  
222                          switch (pid) {                          close_logfile();
223    
224                            switch (fork()) {
225                            case -1:
226                                    fatal(ERROR_FORK, "forking; %s\n",
227                                        strerror(errno));
228                                    break;
229                            case 0:
230                                    break;
231                            default:
232                                    secmem_clear();
233                                    exit(0);
234                                    break;
235                            }
236    
237                            if (setsid() == -1)
238                                    fatal(ERROR_FORK, "creating session; %s\n",
239                                        strerror(errno));
240    
241                            switch (fork()) {
242                          case -1:                          case -1:
243                                  fatal(ERROR_FORK, "forking; %s\n",                                  fatal(ERROR_FORK, "forking; %s\n",
244                                      strerror(errno));                                      strerror(errno));
245                                  break;                                  break;
246                          case 0:                          case 0:
                                 lockfile_create();  
                                 corefile_disable();  
                                 flags |= FLAG_DAEMON_MODE;  
247                                  break;                                  break;
248                          default:                          default:
249                                  secmem_clear();                                  secmem_clear();
                                 close_logfile();  
250                                  exit(0);                                  exit(0);
251                                  break;                                  break;
252                          }                          }
253    
254                            close(STDIN_FILENO);
255                            close(STDOUT_FILENO);
256                            close(STDERR_FILENO);
257                            if (open("/dev/null", O_RDWR) != -1) {
258                                    dup(STDIN_FILENO);
259                                    dup(STDIN_FILENO);
260                            }
261                            open_logfile();
262                            lockfile_create();
263                            corefile_disable();
264    
265                            flags |= FLAG_DAEMON_MODE;
266                  }                  }
267                  if (options & OPTION_DAEMON_MODE &&                  if (options & OPTION_DAEMON_MODE &&
268                      flags & FLAG_SIGUSR1_RECEIVED) {                      flags & FLAG_SIGUSR1_RECEIVED) {

Legend:
Removed from v.1.54.2.3  
changed lines
  Added in v.1.54.2.4

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26