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