Changeset 131 for trunk/src/sh_mail.c
- Timestamp:
- Oct 22, 2007, 11:19:15 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_mail.c
r34 r131 654 654 /* The mailer. 655 655 */ 656 static int sh_mail_end_conn (FILE * connfile );657 static FILE * sh_mail_start_conn (int aFlag );656 static int sh_mail_end_conn (FILE * connfile, int fd); 657 static FILE * sh_mail_start_conn (int aFlag, int * fd); 658 658 659 659 static … … 797 797 798 798 static int ma_block = 0; 799 800 int ma_socket = -1; 799 801 800 802 SH_FIFO * fifo_temp = NULL; … … 1065 1067 while (address_list[i] != NULL && i < address_num) 1066 1068 { 1067 connfile = sh_mail_start_conn (i );1069 connfile = sh_mail_start_conn (i, &ma_socket); 1068 1070 1069 1071 if (NULL != connfile) … … 1073 1075 wrlen -= sl_strlen(mailMsg); 1074 1076 if (wrlen == 0) 1075 status = sh_mail_end_conn (connfile );1077 status = sh_mail_end_conn (connfile, ma_socket); 1076 1078 else 1077 1079 status = -1; … … 1101 1103 else 1102 1104 { 1103 connfile = sh_mail_start_conn ( -9 );1105 connfile = sh_mail_start_conn ( -9 , &ma_socket); 1104 1106 1105 1107 if (NULL != connfile) … … 1108 1110 wrlen -= sl_strlen(mailMsg); 1109 1111 if (wrlen == 0) 1110 status = sh_mail_end_conn (connfile );1112 status = sh_mail_end_conn (connfile, ma_socket); 1111 1113 else 1112 1114 status = -1; … … 1287 1289 static time_t time_wait = 300; 1288 1290 1289 static FILE * sh_mail_start_conn (int aFlag )1291 static FILE * sh_mail_start_conn (int aFlag, int * ma_socket) 1290 1292 { 1291 1293 char * address; … … 1302 1304 FILE * connFile = NULL; 1303 1305 struct tm * my_tm; 1306 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_LOCALTIME_R) 1307 struct tm time_tm; 1308 #endif 1304 1309 time_t my_time; 1305 1310 char my_tbuf[128]; … … 1312 1317 SL_ENTER(_("sh_mail_start_conn")); 1313 1318 1314 time_wait = 300; 1319 *ma_socket = -1; 1320 time_wait = 300; 1315 1321 1316 1322 if (aFlag >= 0) … … 1416 1422 /* say HELO to the other socket 1417 1423 */ 1418 if (0 == sh_mail_wait (220, connFile))1424 if (0 == sh_mail_wait (220, fd)) 1419 1425 { 1420 1426 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_NET, … … 1446 1452 (void) fflush(connFile); 1447 1453 1448 if (0 == sh_mail_wait(250, connFile))1454 if (0 == sh_mail_wait(250, fd)) 1449 1455 { 1450 1456 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_NET, … … 1479 1485 (void) fflush(connFile); 1480 1486 1481 if (0 == sh_mail_wait(250, connFile))1487 if (0 == sh_mail_wait(250, fd)) 1482 1488 { 1483 1489 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_NET, … … 1500 1506 (void) fflush(connFile); 1501 1507 1502 if (0 == sh_mail_wait(250, connFile))1508 if (0 == sh_mail_wait(250, fd)) 1503 1509 { 1504 1510 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_NET, … … 1524 1530 (void) fflush(connFile); 1525 1531 1526 if (0 == sh_mail_wait(250, connFile))1532 if (0 == sh_mail_wait(250, fd)) 1527 1533 { 1528 1534 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_NET, … … 1549 1555 (void) fflush(connFile); 1550 1556 1551 if (0 == sh_mail_wait(354, connFile))1557 if (0 == sh_mail_wait(354, fd)) 1552 1558 { 1553 1559 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_NET, … … 1561 1567 1562 1568 my_time = time(NULL); 1569 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_LOCALTIME_R) 1570 my_tm = localtime_r(&my_time, &time_tm); 1571 #else 1563 1572 my_tm = localtime(&my_time); 1573 #endif 1564 1574 (void) strftime(my_tbuf, 127, _("%a, %d %b %Y %H:%M:%S %Z"), my_tm); 1565 1575 … … 1576 1586 my_tbuf, 13, 10); 1577 1587 1588 *ma_socket = fd; 1578 1589 SL_RETURN( connFile, _("sh_mail_start_conn")); 1579 1590 } … … 1585 1596 */ 1586 1597 1587 static int sh_mail_end_conn (FILE * connFile )1598 static int sh_mail_end_conn (FILE * connFile, int fd) 1588 1599 { 1589 1600 SL_ENTER(_("sh_mail_end_conn")); … … 1597 1608 TPT(( 0, FIL__, __LINE__, _("msg=<message end written>\n"))); 1598 1609 1599 if (0 != sh_mail_wait(250, connFile))1610 if (0 != sh_mail_wait(250, fd)) 1600 1611 { 1601 1612 (void) fflush(connFile); … … 1625 1636 */ 1626 1637 1627 static jmp_buf wait_timeout; 1628 1629 static void sh_mail_alarmhandle (int mysignal) 1630 { 1631 /*@-noeffect@*/ 1632 (void) mysignal; /* avoid compiler warning */ 1633 /*@+noeffect@*/ 1634 1635 longjmp(wait_timeout, 1); 1636 } 1637 1638 static int sh_mail_wait(int code, FILE * ma_socket) 1638 static int sh_mail_wait(int code, int ma_socket) 1639 1639 { 1640 1640 int rcode, g; 1641 1642 char c; 1641 1643 1642 1644 char errmsg[128]; … … 1651 1653 time_t waited_time; 1652 1654 1653 struct sigaction old_act;1654 volatile unsigned int old_alarm = 0;1655 1656 struct sigaction new_act;1657 sigset_t unblock;1658 1659 (void) sigemptyset(&unblock);1660 (void) sigaddset (&unblock, SIGALRM);1661 1662 new_act.sa_handler = sh_mail_alarmhandle;1663 (void) sigemptyset( &new_act.sa_mask ); /* set an empty mask */1664 new_act.sa_flags = 0; /* init sa_flags */1665 1666 1655 SL_ENTER(_("mail_wait")); 1667 1656 1668 /* alarm was triggered1669 */1670 if (setjmp(wait_timeout) != 0)1671 {1672 (void) alarm(0);1673 (void) sigaction (SIGALRM, &old_act, NULL);1674 (void) alarm(old_alarm);1675 (void) sigprocmask(SIG_UNBLOCK, &unblock, NULL);1676 TPT((0, FIL__, __LINE__, _("msg=<mail_wait: timeout>\n")));1677 SL_RETURN( 0, _("mail_wait"));1678 }1679 1680 1657 waited_time = time(NULL); 1681 1658 1682 1659 /* timeout after 5 minutes 1683 1660 */ 1684 old_alarm = alarm(0);1685 (void) sigaction (SIGALRM, &new_act, &old_act);1686 (void) alarm((unsigned int) time_wait);1687 1661 1688 1662 rcode = 0; 1689 1663 state = WAIT_CODE_START; 1690 1664 1691 while (0 == feof(ma_socket) && 0 == ferror(ma_socket)) { 1665 while (sl_read_timeout_fd (ma_socket, &c, 1, time_wait, SL_FALSE) > 0) { 1666 1667 g = (int) c; 1692 1668 1693 1669 if ( (g=fgetc(ma_socket)) == EOF) 1694 1670 { 1695 (void) alarm(0);1696 (void) sigaction (SIGALRM, &old_act, NULL);1697 (void) alarm(old_alarm);1698 (void) sigprocmask(SIG_UNBLOCK, &unblock, NULL);1699 1671 TPT((0, FIL__, __LINE__, _("msg=<mail_wait: EOF>\n"))); 1700 1672 SL_RETURN( 0, _("mail_wait")); … … 1733 1705 break; 1734 1706 /*@-charintliteral@*/ 1735 (void) alarm(0);1736 (void) sigaction (SIGALRM, &old_act, NULL);1737 (void) alarm(old_alarm);1738 (void) sigprocmask(SIG_UNBLOCK, &unblock, NULL);1739 1707 1740 1708 TPT((0, FIL__, __LINE__, … … 1769 1737 1770 1738 default: 1771 (void) alarm(0);1772 (void) sigaction (SIGALRM, &old_act, NULL);1773 (void) alarm(old_alarm);1774 (void) sigprocmask(SIG_UNBLOCK, &unblock, NULL);1775 1739 1776 1740 TPT((0, FIL__, __LINE__, _("msg=<mail_wait: bad>\n"))); … … 1779 1743 } 1780 1744 } 1781 1782 (void) alarm(0); /* Disable alarm */1783 (void) sigaction (SIGALRM, &old_act, NULL);1784 (void) alarm(old_alarm);1785 (void) sigprocmask(SIG_UNBLOCK, &unblock, NULL);1786 1745 1787 1746 TPT((0, FIL__, __LINE__, _("msg=<mail_wait: failed>\n")));
Note:
See TracChangeset
for help on using the changeset viewer.