Back to index

courier  0.68.2
Functions
libfilter.c File Reference
#include "config.h"
#include "courier.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <sys/socket.h>
#include <sys/un.h>
#include "libfilter.h"

Go to the source code of this file.

Functions

int lf_init (const char *modfile, const char *allname, const char *alltmpname, const char *notallname, const char *notalltmpname)
void lf_init_completed (int sockfd)
int lf_accept (int listensock)

Function Documentation

int lf_accept ( int  listensock)

Definition at line 104 of file libfilter.c.

{
struct sockaddr_un ssun;
fd_set fd0;
int    fd;
socklen_t     sunlen;

       for (;;)
       {
              FD_ZERO(&fd0);
              FD_SET(0, &fd0);
              FD_SET(listensock, &fd0);

              if (select(listensock+1, &fd0, 0, 0, 0) < 0)
              {
                     perror("select");
                     return (-1);
              }

              if (FD_ISSET(0, &fd0))
              {
              char    buf[16];

                     if (read(0, buf, sizeof(buf)) <= 0)
                            return (-1);  /* Shutting down */
              }

              if (!FD_ISSET(listensock, &fd0))   continue;

              sunlen=sizeof(ssun);
              if ((fd=accept(listensock, (struct sockaddr *)&ssun, &sunlen))
                     < 0)
                        continue;

              fcntl(fd, F_SETFL, 0);      /* Take out of NDELAY mode */
              break;
       }
       return (fd);
}

Here is the caller graph for this function:

int lf_init ( const char *  modfile,
const char *  allname,
const char *  alltmpname,
const char *  notallname,
const char *  notalltmpname 
)

Definition at line 37 of file libfilter.c.

{
int    all=0;
const  char *sockname, *tmpsockname;
struct sockaddr_un ssun;
int    listensock;

       if (chdir(courierdir()))
       {
              perror(courierdir());
              return (-1);
       }

       {
       char   *fn=config_localfilename(modfile);
       char   *f;

              f=config_read1l(fn);
              free(fn);
              if (f)
              {
                     if (strcmp(f, "all") == 0)
                            all=1;
                     free(f);
              }
       }

       if (all)
       {
              sockname=allname;
              tmpsockname=alltmpname;
              unlink(notallname);
       }
       else
       {
              sockname=notallname;
              tmpsockname=notalltmpname;
              unlink(allname);
       }

       ssun.sun_family=AF_UNIX;
       strcpy(ssun.sun_path, tmpsockname);
       unlink(ssun.sun_path);
       if ((listensock=socket(PF_UNIX, SOCK_STREAM, 0)) < 0 ||
              bind(listensock, (struct sockaddr *)&ssun, sizeof(ssun)) < 0 ||
              listen(listensock, SOMAXCONN) < 0 ||
              chmod(ssun.sun_path, 0660) ||
              rename (tmpsockname, sockname) ||
              fcntl(listensock, F_SETFL, O_NDELAY) < 0
              )
       {
              perror("socket");
              return (-1);
       }
       return (listensock);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void lf_init_completed ( int  sockfd)

Definition at line 99 of file libfilter.c.

{
       if (sockfd != 3)     close(3);
}

Here is the caller graph for this function: