Deleted Added
full compact
listener.c (110560) listener.c (111823)
1/*
1/*
2 * Copyright (c) 1999-2002 Sendmail, Inc. and its suppliers.
2 * Copyright (c) 1999-2003 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 *
9 */
10
11#include <sm/gen.h>
3 * All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 *
9 */
10
11#include <sm/gen.h>
12SM_RCSID("@(#)$Id: listener.c,v 8.85.2.7 2002/12/10 04:02:25 ca Exp $")
12SM_RCSID("@(#)$Id: listener.c,v 8.85.2.9 2003/01/03 22:14:40 ca Exp $")
13
14/*
15** listener.c -- threaded network listener
16*/
17
18#include "libmilter.h"
19#include <sm/errstring.h>
13
14/*
15** listener.c -- threaded network listener
16*/
17
18#include "libmilter.h"
19#include <sm/errstring.h>
20#include <sm/fdset.h>
21
22
23# if NETINET || NETINET6
24# include <arpa/inet.h>
25# endif /* NETINET || NETINET6 */
26
27static smutex_t L_Mutex;
28static int L_family;

--- 40 unchanged lines hidden (view full) ---

69 if (!ValidSocket(listenfd))
70 {
71 smi_log(SMI_LOG_FATAL,
72 "%s: Unable to create listening socket on conn %s",
73 smfi->xxfi_name, conn);
74 (void) smutex_unlock(&L_Mutex);
75 return MI_FAILURE;
76 }
20
21
22# if NETINET || NETINET6
23# include <arpa/inet.h>
24# endif /* NETINET || NETINET6 */
25
26static smutex_t L_Mutex;
27static int L_family;

--- 40 unchanged lines hidden (view full) ---

68 if (!ValidSocket(listenfd))
69 {
70 smi_log(SMI_LOG_FATAL,
71 "%s: Unable to create listening socket on conn %s",
72 smfi->xxfi_name, conn);
73 (void) smutex_unlock(&L_Mutex);
74 return MI_FAILURE;
75 }
76#if !_FFR_USE_POLL
77 if (!SM_FD_OK_SELECT(listenfd))
78 {
79 smi_log(SMI_LOG_ERR, "%s: fd %d is larger than FD_SETSIZE %d",
80 smfi->xxfi_name, listenfd, FD_SETSIZE);
81 (void) smutex_unlock(&L_Mutex);
82 return MI_FAILURE;
83 }
77 if (!SM_FD_OK_SELECT(listenfd))
78 {
79 smi_log(SMI_LOG_ERR, "%s: fd %d is larger than FD_SETSIZE %d",
80 smfi->xxfi_name, listenfd, FD_SETSIZE);
81 (void) smutex_unlock(&L_Mutex);
82 return MI_FAILURE;
83 }
84#endif /* !_FFR_USE_POLL */
84 return MI_SUCCESS;
85}
86
87/*
88** MI_MILTEROPEN -- setup socket to listen on
89**
90** Parameters:
91** conn -- connection description

--- 572 unchanged lines hidden (view full) ---

664 int tcnt = 0; /* error count for thread_create() failures */
665 int acnt = 0; /* error count for accept() failures */
666 int scnt = 0; /* error count for select() failures */
667 int save_errno = 0;
668 sthread_t thread_id;
669 _SOCK_ADDR cliaddr;
670 SOCKADDR_LEN_T clilen;
671 SMFICTX_PTR ctx;
85 return MI_SUCCESS;
86}
87
88/*
89** MI_MILTEROPEN -- setup socket to listen on
90**
91** Parameters:
92** conn -- connection description

--- 572 unchanged lines hidden (view full) ---

665 int tcnt = 0; /* error count for thread_create() failures */
666 int acnt = 0; /* error count for accept() failures */
667 int scnt = 0; /* error count for select() failures */
668 int save_errno = 0;
669 sthread_t thread_id;
670 _SOCK_ADDR cliaddr;
671 SOCKADDR_LEN_T clilen;
672 SMFICTX_PTR ctx;
672 fd_set readset, excset;
673 FD_RD_VAR(rds, excs);
673 struct timeval chktime;
674
675 if (mi_opensocket(conn, backlog, dbg, smfi) == MI_FAILURE)
676 return MI_FAILURE;
677
678 clilen = L_socksize;
679 (void) smutex_unlock(&L_Mutex);
680 while (mi_stop() == MILTER_CONT)
681 {
682 (void) smutex_lock(&L_Mutex);
683 if (!ValidSocket(listenfd))
684 {
685 (void) smutex_unlock(&L_Mutex);
686 break;
687 }
688
689 /* select on interface ports */
674 struct timeval chktime;
675
676 if (mi_opensocket(conn, backlog, dbg, smfi) == MI_FAILURE)
677 return MI_FAILURE;
678
679 clilen = L_socksize;
680 (void) smutex_unlock(&L_Mutex);
681 while (mi_stop() == MILTER_CONT)
682 {
683 (void) smutex_lock(&L_Mutex);
684 if (!ValidSocket(listenfd))
685 {
686 (void) smutex_unlock(&L_Mutex);
687 break;
688 }
689
690 /* select on interface ports */
690 FD_ZERO(&readset);
691 FD_ZERO(&excset);
692 FD_SET((unsigned int) listenfd, &readset);
693 FD_SET((unsigned int) listenfd, &excset);
691 FD_RD_INIT(listenfd, rds, excs);
694 chktime.tv_sec = MI_CHK_TIME;
695 chktime.tv_usec = 0;
692 chktime.tv_sec = MI_CHK_TIME;
693 chktime.tv_usec = 0;
696 r = select(listenfd + 1, &readset, NULL, &excset, &chktime);
694 r = FD_RD_READY(listenfd, rds, excs, &chktime);
697 if (r == 0) /* timeout */
698 {
699 (void) smutex_unlock(&L_Mutex);
700 continue; /* just check mi_stop() */
701 }
702 if (r < 0)
703 {
704 save_errno = errno;

--- 8 unchanged lines hidden (view full) ---

713 MI_SLEEP(scnt);
714 if (scnt >= MAX_FAILS_S)
715 {
716 ret = MI_FAILURE;
717 break;
718 }
719 continue;
720 }
695 if (r == 0) /* timeout */
696 {
697 (void) smutex_unlock(&L_Mutex);
698 continue; /* just check mi_stop() */
699 }
700 if (r < 0)
701 {
702 save_errno = errno;

--- 8 unchanged lines hidden (view full) ---

711 MI_SLEEP(scnt);
712 if (scnt >= MAX_FAILS_S)
713 {
714 ret = MI_FAILURE;
715 break;
716 }
717 continue;
718 }
721 if (!FD_ISSET(listenfd, &readset))
719 if (!FD_IS_RD_RDY(listenfd, rds, excs))
722 {
723 /* some error: just stop for now... */
724 ret = MI_FAILURE;
725 (void) smutex_unlock(&L_Mutex);
726 smi_log(SMI_LOG_ERR,
720 {
721 /* some error: just stop for now... */
722 ret = MI_FAILURE;
723 (void) smutex_unlock(&L_Mutex);
724 smi_log(SMI_LOG_ERR,
727 "%s: select() returned exception for socket, abort",
728 smfi->xxfi_name);
725 "%s: %s() returned exception for socket, abort",
726 smfi->xxfi_name, MI_POLLSELECT);
729 break;
730 }
731 scnt = 0; /* reset error counter for select() */
732
733 memset(&cliaddr, '\0', sizeof cliaddr);
734 connfd = accept(listenfd, (struct sockaddr *) &cliaddr,
735 &clilen);
736 save_errno = errno;

--- 12 unchanged lines hidden (view full) ---

749# endif /* BSD4_4_SOCKADDR */
750 cliaddr.sa.sa_family != L_family))
751 {
752 (void) closesocket(connfd);
753 connfd = INVALID_SOCKET;
754 save_errno = EINVAL;
755 }
756
727 break;
728 }
729 scnt = 0; /* reset error counter for select() */
730
731 memset(&cliaddr, '\0', sizeof cliaddr);
732 connfd = accept(listenfd, (struct sockaddr *) &cliaddr,
733 &clilen);
734 save_errno = errno;

--- 12 unchanged lines hidden (view full) ---

747# endif /* BSD4_4_SOCKADDR */
748 cliaddr.sa.sa_family != L_family))
749 {
750 (void) closesocket(connfd);
751 connfd = INVALID_SOCKET;
752 save_errno = EINVAL;
753 }
754
755#if !_FFR_USE_POLL
757 /* check if acceptable for select() */
758 if (ValidSocket(connfd) && !SM_FD_OK_SELECT(connfd))
759 {
760 (void) closesocket(connfd);
761 connfd = INVALID_SOCKET;
762 save_errno = ERANGE;
763 }
756 /* check if acceptable for select() */
757 if (ValidSocket(connfd) && !SM_FD_OK_SELECT(connfd))
758 {
759 (void) closesocket(connfd);
760 connfd = INVALID_SOCKET;
761 save_errno = ERANGE;
762 }
763#endif /* !_FFR_USE_POLL */
764
765 if (!ValidSocket(connfd))
766 {
767 if (save_errno == EINTR)
768 continue;
769 acnt++;
770 smi_log(SMI_LOG_ERR,
771 "%s: accept() returned invalid socket (%s), %s",

--- 89 unchanged lines hidden ---
764
765 if (!ValidSocket(connfd))
766 {
767 if (save_errno == EINTR)
768 continue;
769 acnt++;
770 smi_log(SMI_LOG_ERR,
771 "%s: accept() returned invalid socket (%s), %s",

--- 89 unchanged lines hidden ---