Annotation of src/usr.bin/tmux/signal.c, Revision 1.1
1.1 ! nicm 1: /* $OpenBSD$ */
! 2:
! 3: /*
! 4: * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
! 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 <signal.h>
! 23: #include <string.h>
! 24:
! 25: #include "tmux.h"
! 26:
! 27: struct event ev_sigchld;
! 28: struct event ev_sigcont;
! 29: struct event ev_sigterm;
! 30: struct event ev_sigusr1;
! 31: struct event ev_sigwinch;
! 32:
! 33: void
! 34: set_signals(void(*handler)(int, short, void *))
! 35: {
! 36: struct sigaction sigact;
! 37:
! 38: memset(&sigact, 0, sizeof sigact);
! 39: sigemptyset(&sigact.sa_mask);
! 40: sigact.sa_flags = SA_RESTART;
! 41: sigact.sa_handler = SIG_IGN;
! 42: if (sigaction(SIGINT, &sigact, NULL) != 0)
! 43: fatal("sigaction failed");
! 44: if (sigaction(SIGPIPE, &sigact, NULL) != 0)
! 45: fatal("sigaction failed");
! 46: if (sigaction(SIGUSR2, &sigact, NULL) != 0)
! 47: fatal("sigaction failed");
! 48: if (sigaction(SIGTSTP, &sigact, NULL) != 0)
! 49: fatal("sigaction failed");
! 50: if (sigaction(SIGHUP, &sigact, NULL) != 0)
! 51: fatal("sigaction failed");
! 52:
! 53: signal_set(&ev_sigchld, SIGCHLD, handler, NULL);
! 54: signal_add(&ev_sigchld, NULL);
! 55: signal_set(&ev_sigcont, SIGCONT, handler, NULL);
! 56: signal_add(&ev_sigcont, NULL);
! 57: signal_set(&ev_sigterm, SIGTERM, handler, NULL);
! 58: signal_add(&ev_sigterm, NULL);
! 59: signal_set(&ev_sigusr1, SIGUSR1, handler, NULL);
! 60: signal_add(&ev_sigusr1, NULL);
! 61: signal_set(&ev_sigwinch, SIGWINCH, handler, NULL);
! 62: signal_add(&ev_sigwinch, NULL);
! 63: }
! 64:
! 65: void
! 66: clear_signals(void)
! 67: {
! 68: struct sigaction sigact;
! 69:
! 70: memset(&sigact, 0, sizeof sigact);
! 71: sigemptyset(&sigact.sa_mask);
! 72: sigact.sa_flags = SA_RESTART;
! 73: sigact.sa_handler = SIG_DFL;
! 74: if (sigaction(SIGINT, &sigact, NULL) != 0)
! 75: fatal("sigaction failed");
! 76: if (sigaction(SIGPIPE, &sigact, NULL) != 0)
! 77: fatal("sigaction failed");
! 78: if (sigaction(SIGUSR2, &sigact, NULL) != 0)
! 79: fatal("sigaction failed");
! 80: if (sigaction(SIGTSTP, &sigact, NULL) != 0)
! 81: fatal("sigaction failed");
! 82: if (sigaction(SIGHUP, &sigact, NULL) != 0)
! 83: fatal("sigaction failed");
! 84:
! 85: event_del(&ev_sigchld);
! 86: event_del(&ev_sigcont);
! 87: event_del(&ev_sigterm);
! 88: event_del(&ev_sigusr1);
! 89: event_del(&ev_sigwinch);
! 90: }