Deleted Added
full compact
listener.c (102528) listener.c (110560)
1/*
2 * Copyright (c) 1999-2002 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>
1/*
2 * Copyright (c) 1999-2002 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>
12SM_RCSID("@(#)$Id: listener.c,v 8.85.2.1 2002/08/09 22:13:36 gshapiro Exp $")
12SM_RCSID("@(#)$Id: listener.c,v 8.85.2.7 2002/12/10 04:02:25 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>
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 }
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 }
76
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 return MI_SUCCESS;
78}
79
80/*
81** MI_MILTEROPEN -- setup socket to listen on
82**
83** Parameters:
84** conn -- connection description

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

477
478 sockpath = (char *) malloc(len);
479 if (sockpath != NULL)
480 (void) sm_strlcpy(sockpath, colon, len);
481 else
482 {
483 smi_log(SMI_LOG_ERR,
484 "%s: can't malloc(%d) for sockpath: %s",
84 return MI_SUCCESS;
85}
86
87/*
88** MI_MILTEROPEN -- setup socket to listen on
89**
90** Parameters:
91** conn -- connection description

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

484
485 sockpath = (char *) malloc(len);
486 if (sockpath != NULL)
487 (void) sm_strlcpy(sockpath, colon, len);
488 else
489 {
490 smi_log(SMI_LOG_ERR,
491 "%s: can't malloc(%d) for sockpath: %s",
485 name, len, sm_errstring(errno));
492 name, (int) len, sm_errstring(errno));
486 (void) closesocket(sock);
487 return INVALID_SOCKET;
488 }
489 }
490#endif /* NETUNIX */
491 L_family = addr.sa.sa_family;
492 return sock;
493}

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

625 for (;;) \
626 { \
627 rs = select(0, NULL, NULL, NULL, &st); \
628 if (rs < 0 && errno == EINTR) \
629 continue; \
630 if (rs != 0) \
631 { \
632 smi_log(SMI_LOG_ERR, \
493 (void) closesocket(sock);
494 return INVALID_SOCKET;
495 }
496 }
497#endif /* NETUNIX */
498 L_family = addr.sa.sa_family;
499 return sock;
500}

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

632 for (;;) \
633 { \
634 rs = select(0, NULL, NULL, NULL, &st); \
635 if (rs < 0 && errno == EINTR) \
636 continue; \
637 if (rs != 0) \
638 { \
639 smi_log(SMI_LOG_ERR, \
633 "MI_SLEEP(): select() returned non-zero result %d, errno = %d", \
640 "MI_SLEEP(): select() returned non-zero result %d, errno = %d", \
634 rs, errno); \
635 } \
641 rs, errno); \
642 } \
643 break; \
636 } \
637 } \
638}
639#else /* BROKEN_PTHREAD_SLEEP */
640# define MI_SLEEP(s) sleep((s))
641#endif /* BROKEN_PTHREAD_SLEEP */
642
643int

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

663 SMFICTX_PTR ctx;
664 fd_set readset, excset;
665 struct timeval chktime;
666
667 if (mi_opensocket(conn, backlog, dbg, smfi) == MI_FAILURE)
668 return MI_FAILURE;
669
670 clilen = L_socksize;
644 } \
645 } \
646}
647#else /* BROKEN_PTHREAD_SLEEP */
648# define MI_SLEEP(s) sleep((s))
649#endif /* BROKEN_PTHREAD_SLEEP */
650
651int

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

671 SMFICTX_PTR ctx;
672 fd_set readset, excset;
673 struct timeval chktime;
674
675 if (mi_opensocket(conn, backlog, dbg, smfi) == MI_FAILURE)
676 return MI_FAILURE;
677
678 clilen = L_socksize;
671
672 if (listenfd >= FD_SETSIZE)
673 {
674 smi_log(SMI_LOG_ERR, "%s: fd %d is larger than FD_SETSIZE %d",
675 smfi->xxfi_name, listenfd, FD_SETSIZE);
676 (void) smutex_unlock(&L_Mutex);
677 return MI_FAILURE;
678 }
679 (void) smutex_unlock(&L_Mutex);
679 (void) smutex_unlock(&L_Mutex);
680
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 }

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

750# endif /* BSD4_4_SOCKADDR */
751 cliaddr.sa.sa_family != L_family))
752 {
753 (void) closesocket(connfd);
754 connfd = INVALID_SOCKET;
755 save_errno = EINVAL;
756 }
757
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 }

--- 61 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
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 }
764
758 if (!ValidSocket(connfd))
759 {
760 if (save_errno == EINTR)
761 continue;
762 acnt++;
763 smi_log(SMI_LOG_ERR,
764 "%s: accept() returned invalid socket (%s), %s",
765 smfi->xxfi_name, sm_errstring(save_errno),

--- 88 unchanged lines hidden ---
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",
772 smfi->xxfi_name, sm_errstring(save_errno),

--- 88 unchanged lines hidden ---