Merging serial model from branch; converting to the hideous indentation style of...
[lwes-journaller.git] / src / sig.c
blob5fcf1c9842c096db4454856e53dccbed7351abe1
1 /*======================================================================*
2 * Copyright (C) 2008 Light Weight Event System *
3 * All rights reserved. *
4 * *
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. *
9 * *
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. *
14 * *
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 *======================================================================*/
21 #include "config.h"
23 #include "sig.h"
25 #include "log.h"
26 #include "perror.h"
28 #include <signal.h>
29 #include <stdio.h>
30 #include <stdlib.h>
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)
38 gbl_done = signo;
41 static void rotate_signal_handler(int signo)
43 (void)signo; /* appease -Wall -Werror */
44 gbl_rotate = 1;
47 static void rotate_log_signal_handler(int signo)
49 (void)signo; /* appease -Wall -Werror */
50 gbl_rotate_log = 1;
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);
62 sigact.sa_flags = 0;
64 if ( sigaction(signo, &sigact, NULL) < 0 )
66 PERROR("sigaction");
67 exit(EXIT_FAILURE);
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);
86 sigact.sa_flags = 0;
88 if ( sigaction(SIGPIPE, &sigact, NULL) < 0 )
90 PERROR("sigaction");
91 exit(EXIT_FAILURE);
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);