Identical behaviour to select-prompt can now be obtained with
[tmux-openbsd.git] / signal.c
blobb84d90bee7986b1904b852ee3b7d3f662498eef5
1 /* $Id$ */
3 /*
4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
5 * Copyright (c) 2010 Romain Francoise <rfrancoise@debian.org>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
16 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
17 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <string.h>
21 #include <signal.h>
23 #include "tmux.h"
25 struct event ev_sigchld;
26 struct event ev_sigcont;
27 struct event ev_sigterm;
28 struct event ev_sigusr1;
29 struct event ev_sigwinch;
31 void
32 set_signals(void(*handler)(int, short, unused void *))
34 struct sigaction sigact;
36 memset(&sigact, 0, sizeof sigact);
37 sigemptyset(&sigact.sa_mask);
38 sigact.sa_flags = SA_RESTART;
39 sigact.sa_handler = SIG_IGN;
40 if (sigaction(SIGINT, &sigact, NULL) != 0)
41 fatal("sigaction failed");
42 if (sigaction(SIGPIPE, &sigact, NULL) != 0)
43 fatal("sigaction failed");
44 if (sigaction(SIGUSR2, &sigact, NULL) != 0)
45 fatal("sigaction failed");
46 if (sigaction(SIGTSTP, &sigact, NULL) != 0)
47 fatal("sigaction failed");
48 if (sigaction(SIGHUP, &sigact, NULL) != 0)
49 fatal("sigaction failed");
51 signal_set(&ev_sigchld, SIGCHLD, handler, NULL);
52 signal_add(&ev_sigchld, NULL);
53 signal_set(&ev_sigcont, SIGCONT, handler, NULL);
54 signal_add(&ev_sigcont, NULL);
55 signal_set(&ev_sigterm, SIGTERM, handler, NULL);
56 signal_add(&ev_sigterm, NULL);
57 signal_set(&ev_sigusr1, SIGUSR1, handler, NULL);
58 signal_add(&ev_sigusr1, NULL);
59 signal_set(&ev_sigwinch, SIGWINCH, handler, NULL);
60 signal_add(&ev_sigwinch, NULL);
63 void
64 clear_signals(void)
66 struct sigaction sigact;
68 memset(&sigact, 0, sizeof sigact);
69 sigemptyset(&sigact.sa_mask);
70 sigact.sa_flags = SA_RESTART;
71 sigact.sa_handler = SIG_DFL;
72 if (sigaction(SIGINT, &sigact, NULL) != 0)
73 fatal("sigaction failed");
74 if (sigaction(SIGPIPE, &sigact, NULL) != 0)
75 fatal("sigaction failed");
76 if (sigaction(SIGUSR2, &sigact, NULL) != 0)
77 fatal("sigaction failed");
78 if (sigaction(SIGTSTP, &sigact, NULL) != 0)
79 fatal("sigaction failed");
80 if (sigaction(SIGHUP, &sigact, NULL) != 0)
81 fatal("sigaction failed");
83 event_del(&ev_sigchld);
84 event_del(&ev_sigcont);
85 event_del(&ev_sigterm);
86 event_del(&ev_sigusr1);
87 event_del(&ev_sigwinch);