[BACK]Return to signal.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/signal.c, Revision 1.11

1.11    ! nicm        1: /* $OpenBSD: signal.c,v 1.10 2016/10/10 21:29:23 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.9       nicm        4:  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1       nicm        5:  * Copyright (c) 2010 Romain Francoise <rfrancoise@debian.org>
                      6:  *
                      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.
                     10:  *
                     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.
                     18:  */
1.7       nicm       19:
                     20: #include <sys/types.h>
1.1       nicm       21:
1.3       nicm       22: #include <string.h>
1.1       nicm       23: #include <signal.h>
                     24:
                     25: #include "tmux.h"
                     26:
1.10      nicm       27: static struct event    ev_sighup;
                     28: static struct event    ev_sigchld;
                     29: static struct event    ev_sigcont;
                     30: static struct event    ev_sigterm;
                     31: static struct event    ev_sigusr1;
1.11    ! nicm       32: static struct event    ev_sigusr2;
1.10      nicm       33: static struct event    ev_sigwinch;
1.1       nicm       34:
                     35: void
1.8       nicm       36: set_signals(void (*handler)(int, short, void *), void *arg)
1.1       nicm       37: {
                     38:        struct sigaction        sigact;
                     39:
                     40:        memset(&sigact, 0, sizeof sigact);
                     41:        sigemptyset(&sigact.sa_mask);
                     42:        sigact.sa_flags = SA_RESTART;
                     43:        sigact.sa_handler = SIG_IGN;
                     44:        if (sigaction(SIGINT, &sigact, NULL) != 0)
                     45:                fatal("sigaction failed");
                     46:        if (sigaction(SIGPIPE, &sigact, NULL) != 0)
                     47:                fatal("sigaction failed");
                     48:        if (sigaction(SIGUSR2, &sigact, NULL) != 0)
                     49:                fatal("sigaction failed");
                     50:        if (sigaction(SIGTSTP, &sigact, NULL) != 0)
                     51:                fatal("sigaction failed");
                     52:
1.8       nicm       53:        signal_set(&ev_sighup, SIGHUP, handler, arg);
1.4       jsing      54:        signal_add(&ev_sighup, NULL);
1.8       nicm       55:        signal_set(&ev_sigchld, SIGCHLD, handler, arg);
1.1       nicm       56:        signal_add(&ev_sigchld, NULL);
1.8       nicm       57:        signal_set(&ev_sigcont, SIGCONT, handler, arg);
1.1       nicm       58:        signal_add(&ev_sigcont, NULL);
1.8       nicm       59:        signal_set(&ev_sigterm, SIGTERM, handler, arg);
1.1       nicm       60:        signal_add(&ev_sigterm, NULL);
1.8       nicm       61:        signal_set(&ev_sigusr1, SIGUSR1, handler, arg);
1.1       nicm       62:        signal_add(&ev_sigusr1, NULL);
1.11    ! nicm       63:        signal_set(&ev_sigusr2, SIGUSR2, handler, arg);
        !            64:        signal_add(&ev_sigusr2, NULL);
1.8       nicm       65:        signal_set(&ev_sigwinch, SIGWINCH, handler, arg);
1.1       nicm       66:        signal_add(&ev_sigwinch, NULL);
                     67: }
                     68:
                     69: void
1.6       nicm       70: clear_signals(int after_fork)
1.1       nicm       71: {
                     72:        struct sigaction        sigact;
                     73:
                     74:        memset(&sigact, 0, sizeof sigact);
                     75:        sigemptyset(&sigact.sa_mask);
                     76:        sigact.sa_flags = SA_RESTART;
                     77:        sigact.sa_handler = SIG_DFL;
                     78:        if (sigaction(SIGINT, &sigact, NULL) != 0)
                     79:                fatal("sigaction failed");
                     80:        if (sigaction(SIGPIPE, &sigact, NULL) != 0)
                     81:                fatal("sigaction failed");
                     82:        if (sigaction(SIGUSR2, &sigact, NULL) != 0)
                     83:                fatal("sigaction failed");
                     84:        if (sigaction(SIGTSTP, &sigact, NULL) != 0)
                     85:                fatal("sigaction failed");
                     86:
1.6       nicm       87:        if (after_fork) {
                     88:                if (sigaction(SIGHUP, &sigact, NULL) != 0)
                     89:                        fatal("sigaction failed");
                     90:                if (sigaction(SIGCHLD, &sigact, NULL) != 0)
                     91:                        fatal("sigaction failed");
                     92:                if (sigaction(SIGCONT, &sigact, NULL) != 0)
                     93:                        fatal("sigaction failed");
                     94:                if (sigaction(SIGTERM, &sigact, NULL) != 0)
                     95:                        fatal("sigaction failed");
                     96:                if (sigaction(SIGUSR1, &sigact, NULL) != 0)
                     97:                        fatal("sigaction failed");
1.11    ! nicm       98:                if (sigaction(SIGUSR2, &sigact, NULL) != 0)
        !            99:                        fatal("sigaction failed");
1.6       nicm      100:                if (sigaction(SIGWINCH, &sigact, NULL) != 0)
                    101:                        fatal("sigaction failed");
                    102:        } else {
                    103:                event_del(&ev_sighup);
                    104:                event_del(&ev_sigchld);
                    105:                event_del(&ev_sigcont);
                    106:                event_del(&ev_sigterm);
                    107:                event_del(&ev_sigusr1);
1.11    ! nicm      108:                event_del(&ev_sigusr2);
1.6       nicm      109:                event_del(&ev_sigwinch);
                    110:        }
1.1       nicm      111: }