[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[mpop-users] [PATCH 7/9] Support catching Ctrl+C on systems with signal() but without sigaction()
Mainly added for Windows support, since all non-ancient *nix support
the POSIX sigaction() interface, which is much preferable.
---
configure.ac | 2 +-
src/mpop.c | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 28e8467..20218f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@ AM_GNU_GETTEXT([external])
dnl Headers and functions
AC_CHECK_HEADERS([sysexits.h netdb.h arpa/inet.h sys/socket.h sys/wait.h])
-AC_CHECK_FUNCS([fseeko fseeko64 getpass getservbyname link mkstemp sigaction strndup syslog vasprintf])
+AC_CHECK_FUNCS([fseeko fseeko64 getpass getservbyname link mkstemp sigaction signal strndup syslog vasprintf])
AC_SEARCH_LIBS([nanosleep], [rt posix4])
AC_SEARCH_LIBS([socket], [socket])
diff --git a/src/mpop.c b/src/mpop.c
index 6ab59be..ce76b1e 100644
--- a/src/mpop.c
+++ b/src/mpop.c
@@ -1690,6 +1690,10 @@ int main(int argc, char *argv[])
struct sigaction old_sigterm_handler;
struct sigaction old_sighup_handler;
struct sigaction old_sigint_handler;
+#elif HAVE_SIGNAL
+ void (*old_sigterm_handler)(int);
+ void (*old_sighup_handler)(int);
+ void (*old_sigint_handler)(int);
#endif
/* misc */
#if HAVE_GETSERVBYNAME
@@ -2801,6 +2805,12 @@ int main(int argc, char *argv[])
(void)sigaction(SIGTERM, &signal_handler, &old_sigterm_handler);
(void)sigaction(SIGHUP, &signal_handler, &old_sighup_handler);
(void)sigaction(SIGINT, &signal_handler, &old_sigint_handler);
+#elif HAVE_SIGNAL
+ old_sigterm_handler = signal(SIGTERM, mpop_retrmail_signal_handler);
+ old_sigint_handler = signal(SIGINT, mpop_retrmail_signal_handler);
+#ifdef SIGHUP /* Windows supports SIGTERM and SIGINT, but not SIGHUP */
+ old_sighup_handler = signal(SIGHUP, mpop_retrmail_signal_handler);
+#endif
#endif
if ((error_code = mpop_retrmail(canonical_hostname, local_user,
account, debug, print_status, print_progress,
--
2.1.1