Sync usage with man page.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / killme_after.c
blob92717dc9c11ffa20b223bea428660c607f53bb34
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* killme_after 3
6 /* SUMMARY
7 /* programmed death
8 /* SYNOPSIS
9 /* #include <killme_after.h>
11 /* void killme_after(seconds)
12 /* unsigned int seconds;
13 /* DESCRIPTION
14 /* The killme_after() function does a best effort to terminate
15 /* the process after the specified time, should it still exist.
16 /* It is meant to be used in a signal handler, as an insurance
17 /* against getting stuck somewhere while preparing for exit.
18 /* DIAGNOSTICS
19 /* None. This routine does a best effort, damn the torpedoes.
20 /* LICENSE
21 /* .ad
22 /* .fi
23 /* The Secure Mailer license must be distributed with this software.
24 /* AUTHOR(S)
25 /* Wietse Venema
26 /* IBM T.J. Watson Research
27 /* P.O. Box 704
28 /* Yorktown Heights, NY 10598, USA
29 /*--*/
31 /* System library. */
33 #include <sys_defs.h>
34 #include <signal.h>
35 #include <unistd.h>
37 /* Utility library. */
39 #include <killme_after.h>
41 /* killme_after - self-assured death */
43 void killme_after(unsigned int seconds)
45 struct sigaction sig_action;
48 * Schedule an ALARM signal, and make sure the signal will be delivered
49 * even if we are being called from a signal handler and SIGALRM delivery
50 * is blocked.
52 alarm(0);
53 sigemptyset(&sig_action.sa_mask);
54 sig_action.sa_flags = 0;
55 sig_action.sa_handler = SIG_DFL;
56 sigaction(SIGALRM, &sig_action, (struct sigaction *) 0);
57 alarm(seconds);
58 sigaddset(&sig_action.sa_mask, SIGALRM);
59 sigprocmask(SIG_UNBLOCK, &sig_action.sa_mask, (sigset_t *) 0);