[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.10

1.10    ! nicm        1: /* $OpenBSD: signal.c,v 1.9 2016/01/19 15:59:12 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;
        !            32: static struct event    ev_sigwinch;
1.1       nicm       33:
                     34: void
1.8       nicm       35: set_signals(void (*handler)(int, short, void *), void *arg)
1.1       nicm       36: {
                     37:        struct sigaction        sigact;
                     38:
                     39:        memset(&sigact, 0, sizeof sigact);
                     40:        sigemptyset(&sigact.sa_mask);
                     41:        sigact.sa_flags = SA_RESTART;
                     42:        sigact.sa_handler = SIG_IGN;
                     43:        if (sigaction(SIGINT, &sigact, NULL) != 0)
                     44:                fatal("sigaction failed");
                     45:        if (sigaction(SIGPIPE, &sigact, NULL) != 0)
                     46:                fatal("sigaction failed");
                     47:        if (sigaction(SIGUSR2, &sigact, NULL) != 0)
                     48:                fatal("sigaction failed");
                     49:        if (sigaction(SIGTSTP, &sigact, NULL) != 0)
                     50:                fatal("sigaction failed");
                     51:
1.8       nicm       52:        signal_set(&ev_sighup, SIGHUP, handler, arg);
1.4       jsing      53:        signal_add(&ev_sighup, NULL);
1.8       nicm       54:        signal_set(&ev_sigchld, SIGCHLD, handler, arg);
1.1       nicm       55:        signal_add(&ev_sigchld, NULL);
1.8       nicm       56:        signal_set(&ev_sigcont, SIGCONT, handler, arg);
1.1       nicm       57:        signal_add(&ev_sigcont, NULL);
1.8       nicm       58:        signal_set(&ev_sigterm, SIGTERM, handler, arg);
1.1       nicm       59:        signal_add(&ev_sigterm, NULL);
1.8       nicm       60:        signal_set(&ev_sigusr1, SIGUSR1, handler, arg);
1.1       nicm       61:        signal_add(&ev_sigusr1, NULL);
1.8       nicm       62:        signal_set(&ev_sigwinch, SIGWINCH, handler, arg);
1.1       nicm       63:        signal_add(&ev_sigwinch, NULL);
                     64: }
                     65:
                     66: void
1.6       nicm       67: clear_signals(int after_fork)
1.1       nicm       68: {
                     69:        struct sigaction        sigact;
                     70:
                     71:        memset(&sigact, 0, sizeof sigact);
                     72:        sigemptyset(&sigact.sa_mask);
                     73:        sigact.sa_flags = SA_RESTART;
                     74:        sigact.sa_handler = SIG_DFL;
                     75:        if (sigaction(SIGINT, &sigact, NULL) != 0)
                     76:                fatal("sigaction failed");
                     77:        if (sigaction(SIGPIPE, &sigact, NULL) != 0)
                     78:                fatal("sigaction failed");
                     79:        if (sigaction(SIGUSR2, &sigact, NULL) != 0)
                     80:                fatal("sigaction failed");
                     81:        if (sigaction(SIGTSTP, &sigact, NULL) != 0)
                     82:                fatal("sigaction failed");
                     83:
1.6       nicm       84:        if (after_fork) {
                     85:                if (sigaction(SIGHUP, &sigact, NULL) != 0)
                     86:                        fatal("sigaction failed");
                     87:                if (sigaction(SIGCHLD, &sigact, NULL) != 0)
                     88:                        fatal("sigaction failed");
                     89:                if (sigaction(SIGCONT, &sigact, NULL) != 0)
                     90:                        fatal("sigaction failed");
                     91:                if (sigaction(SIGTERM, &sigact, NULL) != 0)
                     92:                        fatal("sigaction failed");
                     93:                if (sigaction(SIGUSR1, &sigact, NULL) != 0)
                     94:                        fatal("sigaction failed");
                     95:                if (sigaction(SIGWINCH, &sigact, NULL) != 0)
                     96:                        fatal("sigaction failed");
                     97:        } else {
                     98:                event_del(&ev_sighup);
                     99:                event_del(&ev_sigchld);
                    100:                event_del(&ev_sigcont);
                    101:                event_del(&ev_sigterm);
                    102:                event_del(&ev_sigusr1);
                    103:                event_del(&ev_sigwinch);
                    104:        }
1.1       nicm      105: }