Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 33747:b0ec4c9d595b legacy-trunk
Patch #975056 - fixes for restartable signals on *BSD. In addition,
a few remaining calls to signal() were converted to PyOS_setsig().
| author | Anthony Baxter <anthonybaxter@gmail.com> |
|---|---|
| date | Wed, 13 Oct 2004 14:48:50 +0000 |
| parents | a46b76eb9053 |
| children | 28892e6512ba 3785610ff763 |
comparison
equal
deleted
inserted
replaced
| 33746:a27b0271711b | 33747:b0ec4c9d595b |
|---|---|
| 1574 | 1574 |
| 1575 static void | 1575 static void |
| 1576 initsigs(void) | 1576 initsigs(void) |
| 1577 { | 1577 { |
| 1578 #ifdef SIGPIPE | 1578 #ifdef SIGPIPE |
| 1579 signal(SIGPIPE, SIG_IGN); | 1579 PyOS_setsig(SIGPIPE, SIG_IGN); |
| 1580 #endif | 1580 #endif |
| 1581 #ifdef SIGXFZ | 1581 #ifdef SIGXFZ |
| 1582 signal(SIGXFZ, SIG_IGN); | 1582 PyOS_setsig(SIGXFZ, SIG_IGN); |
| 1583 #endif | 1583 #endif |
| 1584 #ifdef SIGXFSZ | 1584 #ifdef SIGXFSZ |
| 1585 signal(SIGXFSZ, SIG_IGN); | 1585 PyOS_setsig(SIGXFSZ, SIG_IGN); |
| 1586 #endif | 1586 #endif |
| 1587 PyOS_InitInterrupts(); /* May imply initsignal() */ | 1587 PyOS_InitInterrupts(); /* May imply initsignal() */ |
| 1588 } | 1588 } |
| 1589 | 1589 |
| 1590 | 1590 |
| 1644 PyOS_sighandler_t | 1644 PyOS_sighandler_t |
| 1645 PyOS_getsig(int sig) | 1645 PyOS_getsig(int sig) |
| 1646 { | 1646 { |
| 1647 #ifdef HAVE_SIGACTION | 1647 #ifdef HAVE_SIGACTION |
| 1648 struct sigaction context; | 1648 struct sigaction context; |
| 1649 /* Initialize context.sa_handler to SIG_ERR which makes about as | 1649 if (sigaction(sig, NULL, &context) == -1) |
| 1650 * much sense as anything else. It should get overwritten if | 1650 return SIG_ERR; |
| 1651 * sigaction actually succeeds and otherwise we avoid an | |
| 1652 * uninitialized memory read. | |
| 1653 */ | |
| 1654 context.sa_handler = SIG_ERR; | |
| 1655 sigaction(sig, NULL, &context); | |
| 1656 return context.sa_handler; | 1651 return context.sa_handler; |
| 1657 #else | 1652 #else |
| 1658 PyOS_sighandler_t handler; | 1653 PyOS_sighandler_t handler; |
| 1659 handler = signal(sig, SIG_IGN); | 1654 handler = signal(sig, SIG_IGN); |
| 1660 signal(sig, handler); | 1655 if (handler != SIG_ERR) |
| 1656 signal(sig, handler); | |
| 1661 return handler; | 1657 return handler; |
| 1662 #endif | 1658 #endif |
| 1663 } | 1659 } |
| 1664 | 1660 |
| 1665 PyOS_sighandler_t | 1661 PyOS_sighandler_t |
| 1666 PyOS_setsig(int sig, PyOS_sighandler_t handler) | 1662 PyOS_setsig(int sig, PyOS_sighandler_t handler) |
| 1667 { | 1663 { |
| 1668 #ifdef HAVE_SIGACTION | 1664 #ifdef HAVE_SIGACTION |
| 1669 struct sigaction context; | 1665 struct sigaction context, ocontext; |
| 1666 context.sa_handler = handler; | |
| 1667 sigemptyset(&context.sa_mask); | |
| 1668 context.sa_flags = 0; | |
| 1669 if (sigaction(sig, &context, &ocontext) == -1) | |
| 1670 return SIG_ERR; | |
| 1671 return ocontext.sa_handler; | |
| 1672 #else | |
| 1670 PyOS_sighandler_t oldhandler; | 1673 PyOS_sighandler_t oldhandler; |
| 1671 /* Initialize context.sa_handler to SIG_ERR which makes about as | 1674 oldhandler = signal(sig, handler); |
| 1672 * much sense as anything else. It should get overwritten if | 1675 #ifdef HAVE_SIGINTERRUPT |
| 1673 * sigaction actually succeeds and otherwise we avoid an | 1676 siginterrupt(sig, 1); |
| 1674 * uninitialized memory read. | 1677 #endif |
| 1675 */ | |
| 1676 context.sa_handler = SIG_ERR; | |
| 1677 sigaction(sig, NULL, &context); | |
| 1678 oldhandler = context.sa_handler; | |
| 1679 context.sa_handler = handler; | |
| 1680 sigaction(sig, &context, NULL); | |
| 1681 return oldhandler; | 1678 return oldhandler; |
| 1682 #else | 1679 #endif |
| 1683 return signal(sig, handler); | 1680 } |
| 1684 #endif | |
| 1685 } |
