summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-01-18 18:51:45 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-01-18 18:51:45 +0000
commitba6d491b7f303f0be747395034088afc6fde7a64 (patch)
tree10a13243cd355d38a1a9bbba5d0230dfa398e9ab /lib
parent8dc6f7494792459cb3f382bfdf78a16fc74acc7d (diff)
Provide examples showing how to convert old code to use sigprocmask(2).
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/compat-43/sigblock.338
-rw-r--r--lib/libc/compat-43/sigsetmask.361
2 files changed, 97 insertions, 2 deletions
diff --git a/lib/libc/compat-43/sigblock.3 b/lib/libc/compat-43/sigblock.3
index 7689d03f184..a143b5685ee 100644
--- a/lib/libc/compat-43/sigblock.3
+++ b/lib/libc/compat-43/sigblock.3
@@ -29,7 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $OpenBSD: sigblock.3,v 1.8 1999/07/09 13:35:15 aaron Exp $
+.\" $OpenBSD: sigblock.3,v 1.9 2001/01/18 18:51:44 millert Exp $
.\"
.Dd March 10, 1991
.Dt SIGBLOCK 3
@@ -68,6 +68,42 @@ or
.Dv SIGSTOP ;
this restriction is silently
imposed by the system.
+.Sh EXAMPLES
+The following example utilizing
+.Fn sigblock :
+.Bd -literal -offset indent
+int omask;
+
+omask = sigblock(sigmask(SIGINT) | sigmask(SIGHUP));
+.Ed
+.Pp
+Becomes:
+.Bd -literal -offset indent
+sigset_t set, oset;
+
+sigemptyset(&set);
+sigaddset(&set, SIGINT);
+sigaddset(&set, SIGHUP);
+sigprocmask(SIG_BLOCK, &set, &oset);
+omask = sigblock(sigmask(SIGINT) | sigmask(SIGHUP));
+.Ed
+.Pp
+Another use of
+.Fn sigblock
+is to get the current set of masked signals without changing what
+is actually blocked. Instead of:
+.Bd -literal -offset indent
+int set;
+
+set = sigblock(0);
+.Ed
+.Pp
+Use the following:
+.Bd -literal -offset indent
+sigset_t set;
+
+sigprocmask(SIG_BLOCK, NULL, &set);
+.Ed
.Sh RETURN VALUES
The previous set of masked signals is returned.
.Sh SEE ALSO
diff --git a/lib/libc/compat-43/sigsetmask.3 b/lib/libc/compat-43/sigsetmask.3
index 79f7e9b75f0..613ef08670a 100644
--- a/lib/libc/compat-43/sigsetmask.3
+++ b/lib/libc/compat-43/sigsetmask.3
@@ -29,7 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $OpenBSD: sigsetmask.3,v 1.9 2000/01/06 07:29:08 d Exp $
+.\" $OpenBSD: sigsetmask.3,v 1.10 2001/01/18 18:51:44 millert Exp $
.\"
.Dd March 10, 1991
.Dt SIGSETMASK 3
@@ -64,6 +64,65 @@ quietly disallows
or
.Dv SIGSTOP
to be blocked.
+.Sh EXAMPLES
+The following example utilizing
+.Fn sigsetmask :
+.Bd -literal -offset indent
+int omask;
+
+omask = sigblock(sigmask(SIGINT) | sigmask(SIGHUP));
+
+\&...
+
+sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP)));
+.Ed
+.Pp
+Could be converted literally to:
+.Bd -literal -offset indent
+sigset_t set, oset;
+
+sigemptyset(&set);
+sigaddset(&set, SIGINT);
+sigaddset(&set, SIGHUP);
+sigprocmask(SIG_BLOCK, &set, &oset);
+
+\&...
+
+sigdelset(&oset, SIGINT);
+sigdelset(&oset, SIGHUP);
+sigprocmask(SIG_SETMASK, &oset, NULL);
+.Ed
+.Pp
+Another, clearer, alternative is:
+.Bd -literal -offset indent
+sigset_t set;
+
+sigemptyset(&set);
+sigaddset(&set, SIGINT);
+sigaddset(&set, SIGHUP);
+sigprocmask(SIG_BLOCK, &set, NULL);
+
+\&...
+
+sigprocmask(SIG_UNBLOCK, &set, NULL);
+.Ed
+.Pp
+To completely clear the signal mask using
+.Fn sigsetmask
+one can do:
+.Bd -literal -offset indent
+(void) sigsetmask(0);
+.Ed
+.Pp
+Which can be expressed via
+.Xr sigprocmask 2
+as:
+.Bd -literal -offset indent
+sigset_t eset;
+
+sigemptyset(&eset);
+(void) sigprocmask(SIG_SETMASK, &eset, NULL);
+.Ed
.Sh RETURN VALUES
The previous set of masked signals is returned.
.Sh SEE ALSO