Annotation of embedaddon/tmux/signal.c, revision 1.1.1.1

1.1       misho       1: /* $OpenBSD$ */
                      2: 
                      3: /*
                      4:  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
                      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:  */
                     19: 
                     20: #include <sys/types.h>
                     21: 
                     22: #include <string.h>
                     23: #include <signal.h>
                     24: 
                     25: #include "tmux.h"
                     26: 
                     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;
                     33: 
                     34: void
                     35: set_signals(void (*handler)(int, short, void *), void *arg)
                     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: 
                     52:        signal_set(&ev_sighup, SIGHUP, handler, arg);
                     53:        signal_add(&ev_sighup, NULL);
                     54:        signal_set(&ev_sigchld, SIGCHLD, handler, arg);
                     55:        signal_add(&ev_sigchld, NULL);
                     56:        signal_set(&ev_sigcont, SIGCONT, handler, arg);
                     57:        signal_add(&ev_sigcont, NULL);
                     58:        signal_set(&ev_sigterm, SIGTERM, handler, arg);
                     59:        signal_add(&ev_sigterm, NULL);
                     60:        signal_set(&ev_sigusr1, SIGUSR1, handler, arg);
                     61:        signal_add(&ev_sigusr1, NULL);
                     62:        signal_set(&ev_sigwinch, SIGWINCH, handler, arg);
                     63:        signal_add(&ev_sigwinch, NULL);
                     64: }
                     65: 
                     66: void
                     67: clear_signals(int after_fork)
                     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: 
                     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:        }
                    105: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>