1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22/* 23 * Copyright 1998-2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27#pragma ident "%Z%%M% %I% %E% SMI" 28 29#include <sys/types.h> 30#include <signal.h> 31#include <stdio.h> 32 33#include "snmp_msg.h" 34#include "signals.h" 35#include "error.h" 36 37/* 38 * SIGQUIT: do not trap it to be able to generate a core 39 */ 40 41int 42signals_init(void signals_sighup(), void signals_exit(), char *error_label) 43{ 44 45 struct sigaction act; 46 act.sa_flags = 0; 47 error_label[0] = '\0'; 48 49 act.sa_handler = signals_sighup; 50 if (sigaction(SIGHUP, &act, NULL) == -1) { 51 (void) sprintf(error_label, ERR_MSG_SIGACT, SIGHUP, 52 "signals_sighup()", errno_string()); 53 return (-1); 54 } else { 55 act.sa_handler = signals_exit; 56 if (sigaction(SIGINT, &act, NULL) == -1) { 57 (void) sprintf(error_label, ERR_MSG_SIGACT, SIGINT, 58 "signals_exit()", errno_string()); 59 return (-1); 60 } else if (sigaction(SIGTERM, &act, NULL) == -1) { 61 (void) sprintf(error_label, ERR_MSG_SIGACT, SIGTERM, 62 "signals_exit()", errno_string()); 63 return (-1); 64 } else if (sigaction(SIGUSR1, &act, NULL) == -1) { 65 (void) sprintf(error_label, ERR_MSG_SIGACT, SIGUSR1, 66 "signals_exit()", errno_string()); 67 return (-1); 68 } else if (sigaction(SIGUSR2, &act, NULL) == -1) { 69 (void) sprintf(error_label, ERR_MSG_SIGACT, SIGUSR2, 70 "signals_exit()", errno_string()); 71 return (-1); 72 73 } else { 74 act.sa_handler = SIG_IGN; 75 if (sigaction(SIGCHLD, &act, NULL) == -1) { 76 (void) sprintf(error_label, ERR_MSG_SIGACT, 77 SIGCHLD, "SIG_IGN", errno_string()); 78 return (-1); 79 } else { 80 return (0); 81 } 82 } 83 } 84} 85