4 * signal() managing functions
8 * Copyright (C) 1999-2000 Riccardo Facchetti <riccardo@master.oasi.gpa.it>
9 * Copyright (C) 1996-99 Andre M. Hedrick <andre@suse.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General
13 * Public License as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the Free
22 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29 static void *terminate(void *arg
)
31 // Create signal set containing SIGHUP, SIGINT, and SIGTERM
34 sigaddset(&sigset
, SIGHUP
);
35 sigaddset(&sigset
, SIGINT
);
36 sigaddset(&sigset
, SIGTERM
);
38 // Wait for signal delivery
42 err
= sigwait(&sigset
, &signum
);
46 // Caught a signal; invoke handler
47 void (*handler
) (int) = (void (*) (int))arg
;
53 void init_signals(void (*handler
) (int))
56 // Block SIGPIPE and termination signals
59 sigaddset(&sigset
, SIGPIPE
); // Don't care
60 sigaddset(&sigset
, SIGHUP
); // Will be handled by terminate thread
61 sigaddset(&sigset
, SIGINT
); // Will be handled by terminate thread
62 sigaddset(&sigset
, SIGTERM
); // Will be handled by terminate thread
63 pthread_sigmask(SIG_BLOCK
, &sigset
, NULL
);
65 // Launch thread to synchronously wait for termination signals
67 pthread_create(&tid
, NULL
, terminate
, (void*)handler
);