1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301 USA. *
19 *======================================================================*/
32 volatile int gbl_done
= 0;
33 volatile int gbl_rotate
= 0;
34 volatile int gbl_rotate_log
= 0;
36 static void terminate_signal_handler(int signo
)
41 static void rotate_signal_handler(int signo
)
43 (void)signo
; /* appease -Wall -Werror */
47 static void rotate_log_signal_handler(int signo
)
49 (void)signo
; /* appease -Wall -Werror */
53 static void install(int signo
, void (*handler
)(int signo
))
55 struct sigaction sigact
;
57 memset(&sigact
, 0, sizeof(sigact
));
59 sigact
.sa_handler
= handler
;
61 sigemptyset(&sigact
.sa_mask
);
64 if ( sigaction(signo
, &sigact
, NULL
) < 0 )
71 void install_signal_handlers()
73 struct sigaction sigact
;
75 /* Any of these signals shuts us down. */
76 LOG_PROG("Installing termination signal handlers.\n");
78 install(SIGINT
, terminate_signal_handler
);
79 install(SIGQUIT
, terminate_signal_handler
);
80 install(SIGTERM
, terminate_signal_handler
);
82 memset(&sigact
, 0, sizeof(sigact
));
83 sigact
.sa_handler
= SIG_IGN
;
85 sigemptyset(&sigact
.sa_mask
);
88 if ( sigaction(SIGPIPE
, &sigact
, NULL
) < 0 )
95 void install_rotate_signal_handlers()
97 LOG_PROG("Installing rotate signal handlers.\n");
99 /* This one triggers a journal rotate. */
100 install(SIGHUP
, rotate_signal_handler
);
102 /* This one triggers a log rotate. */
103 install(SIGUSR1
, rotate_log_signal_handler
);