apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mathihalli, Madhusudan" <mad...@hp.com>
Subject [PATCH] New api's apr_block_signal and apr_unblock_signal
Date Tue, 20 Apr 2004 01:31:50 GMT
Hi,
	Since a lot of the async signals are blocked by default, I thought
it'll be good to provide a apr_(un)block_signal() api for those who want to block/unblock
only select signals. Here's a patch to do that.

Any comments -

-Madhu

Index: signals.c
===================================================================
RCS file: /home/cvs/apr/threadproc/unix/signals.c,v
retrieving revision 1.57
diff -u -r1.57 signals.c
--- signals.c   13 Feb 2004 09:38:37 -0000      1.57
+++ signals.c   20 Apr 2004 01:27:17 -0000
@@ -423,4 +423,50 @@
     return rv;
 }
 
+APR_DECLARE(apr_status_t) apr_block_signal(int signum)
+{
+    sigset_t sig_mask;
+    int rv;
+
+    sigemptyset(&sig_mask);
+
+    sigaddset(&sig_mask, signum);
+
+#if defined(SIGPROCMASK_SETS_THREAD_MASK)
+    if ((rv = sigprocmask(SIG_BLOCK, &sig_mask, NULL)) != 0) {
+        rv = errno;
+    }
+#else
+    if ((rv = pthread_sigmask(SIG_BLOCK, &sig_mask, NULL)) != 0) {
+#ifdef PTHREAD_SETS_ERRNO
+        rv = errno;
+#endif
+    }
+#endif
+    return rv;
+}
+
+APR_DECLARE(apr_status_t) apr_unblock_signal(int signum)
+{
+    sigset_t sig_mask;
+    int rv;
+
+    sigemptyset(&sig_mask);
+
+    sigaddset(&sig_mask, signum);
+
+#if defined(SIGPROCMASK_SETS_THREAD_MASK)
+    if ((rv = sigprocmask(SIG_UNBLOCK, &sig_mask, NULL)) != 0) {
+        rv = errno;
+    }
+#else
+    if ((rv = pthread_sigmask(SIG_UNBLOCK, &sig_mask, NULL)) != 0) {
+#ifdef PTHREAD_SETS_ERRNO
+        rv = errno;
+#endif
+    }
+#endif
+    return rv;
+}
+
 #endif

Mime
View raw message