Back to index

courier  0.68.2
lcclog3.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2006 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "courier.h"
00007 #include      "courier_lib_config.h"
00008 #include      "sbindir.h"
00009 #include      <string.h>
00010 #include      <stdio.h>
00011 #include      <signal.h>
00012 #include      <errno.h>
00013 #if    HAVE_UNISTD_H
00014 #include      <unistd.h>
00015 #endif
00016 #include      <fcntl.h>
00017 #include      "waitlib/waitlib.h"
00018 
00019 void clog_start_logger(const char *progname)
00020 {
00021 pid_t  p;
00022 int    waitstat;
00023 int    pipefd[2];
00024 
00025        if (pipe(pipefd) < 0)
00026        {
00027               perror("pipe");
00028               return;
00029        }
00030 
00031        signal(SIGCHLD, SIG_DFL);
00032        while ((p=fork()) == -1)
00033        {
00034               sleep(5);
00035        }
00036 
00037        if (p == 0)
00038        {
00039               dup2(pipefd[0], 0);
00040               close(pipefd[0]);
00041               close(pipefd[1]);
00042               close(1);
00043               open("/dev/null", O_WRONLY);
00044               dup2(1, 2);
00045               if (chdir(courierdir()))
00046                      _exit(5);
00047               while ((p=fork()) == -1)
00048               {
00049                      sleep(5);
00050               }
00051               if (p == 0)
00052               {
00053                      execl(COURIERLOGGER,
00054                            COURIERLOGGER, progname, (char *)0);
00055                      _exit(5);
00056               }
00057               _exit(0);
00058        }
00059        dup2(pipefd[1], 2);
00060        close(pipefd[0]);
00061        close(pipefd[1]);
00062        while (wait(&waitstat) != p)
00063               ;
00064 }