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.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> |
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 } |
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 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", |
492 name, (int) len, sm_errstring(errno)); |
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, \ |
640 "MI_SLEEP(): select() returned non-zero result %d, errno = %d", \ |
641 rs, errno); \ 642 } \ |
643 break; \ |
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; |
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 } --- 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 |
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 --- |