From c854094fc05b61c02db21abb796bafba2508ced6 Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Mon, 30 Oct 2017 10:16:51 +0100 Subject: [PATCH] sigaltstack.2: Add use os sigaction() to example code Signed-off-by: Michael Kerrisk --- man2/sigaltstack.2 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/man2/sigaltstack.2 b/man2/sigaltstack.2 index 189db1b3a..38342ef0e 100644 --- a/man2/sigaltstack.2 +++ b/man2/sigaltstack.2 @@ -288,7 +288,13 @@ different struct, and had the major disadvantage that the caller had to know the direction of stack growth. .SH EXAMPLE The following code segment demonstrates the use of -.BR sigaltstack (): +.BR sigaltstack () +(and +.BR sigaction (2)) +to install an alternate signal stack that is employed by a handler +for the +.BR SIGSEGV +signal: .PP .in +4n .EX @@ -306,6 +312,14 @@ if (sigaltstack(&ss, NULL) == \-1) perror("sigaltstack"); exit(EXIT_FAILURE); } + +sa.sa_flags = SA_ONSTACK; +sa.sa_handler = handler(); /* Address of a signal handler */ +sigemptyset(&sa.sa_mask); +if (sigaction(SIGSEGV, &sa, NULL) == -1) { + perror("sigaction"); + exit(EXIT_FAILURE); +} .EE .in .SH BUGS