xref: /freebsd/usr.sbin/bsdinstall/runconsoles/common.c (revision a2464ee12761660f50d0b6f59f233949ebcacc87)
1*a2464ee1SJessica Clarke /*-
2*a2464ee1SJessica Clarke  * SPDX-License-Identifier: BSD-2-Clause
3*a2464ee1SJessica Clarke  *
4*a2464ee1SJessica Clarke  * Copyright (c) 2022 Jessica Clarke <jrtc27@FreeBSD.org>
5*a2464ee1SJessica Clarke  *
6*a2464ee1SJessica Clarke  * Redistribution and use in source and binary forms, with or without
7*a2464ee1SJessica Clarke  * modification, are permitted provided that the following conditions
8*a2464ee1SJessica Clarke  * are met:
9*a2464ee1SJessica Clarke  * 1. Redistributions of source code must retain the above copyright
10*a2464ee1SJessica Clarke  *    notice, this list of conditions and the following disclaimer.
11*a2464ee1SJessica Clarke  * 2. Redistributions in binary form must reproduce the above copyright
12*a2464ee1SJessica Clarke  *    notice, this list of conditions and the following disclaimer in the
13*a2464ee1SJessica Clarke  *    documentation and/or other materials provided with the distribution.
14*a2464ee1SJessica Clarke  *
15*a2464ee1SJessica Clarke  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*a2464ee1SJessica Clarke  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*a2464ee1SJessica Clarke  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*a2464ee1SJessica Clarke  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*a2464ee1SJessica Clarke  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*a2464ee1SJessica Clarke  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*a2464ee1SJessica Clarke  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*a2464ee1SJessica Clarke  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*a2464ee1SJessica Clarke  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*a2464ee1SJessica Clarke  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*a2464ee1SJessica Clarke  * SUCH DAMAGE.
26*a2464ee1SJessica Clarke  */
27*a2464ee1SJessica Clarke 
28*a2464ee1SJessica Clarke #include <sys/param.h>
29*a2464ee1SJessica Clarke #include <sys/resource.h>
30*a2464ee1SJessica Clarke 
31*a2464ee1SJessica Clarke #include <err.h>
32*a2464ee1SJessica Clarke #include <errno.h>
33*a2464ee1SJessica Clarke #include <signal.h>
34*a2464ee1SJessica Clarke #include <sysexits.h>
35*a2464ee1SJessica Clarke #include <unistd.h>
36*a2464ee1SJessica Clarke 
37*a2464ee1SJessica Clarke #include "common.h"
38*a2464ee1SJessica Clarke 
39*a2464ee1SJessica Clarke void
reproduce_signal_death(int sig)40*a2464ee1SJessica Clarke reproduce_signal_death(int sig)
41*a2464ee1SJessica Clarke {
42*a2464ee1SJessica Clarke 	struct rlimit rl;
43*a2464ee1SJessica Clarke 
44*a2464ee1SJessica Clarke 	if (signal(sig, SIG_DFL) == SIG_ERR)
45*a2464ee1SJessica Clarke 		err(EX_OSERR,
46*a2464ee1SJessica Clarke 		    "cannot set action to reproduce signal %d",
47*a2464ee1SJessica Clarke 		    sig);
48*a2464ee1SJessica Clarke 	rl.rlim_cur = 0;
49*a2464ee1SJessica Clarke 	rl.rlim_max = 0;
50*a2464ee1SJessica Clarke 	if (setrlimit(RLIMIT_CORE, &rl) == -1)
51*a2464ee1SJessica Clarke 		err(EX_OSERR,
52*a2464ee1SJessica Clarke 		    "cannot disable core dumps to reproduce signal %d",
53*a2464ee1SJessica Clarke 		    sig);
54*a2464ee1SJessica Clarke 	kill(getpid(), sig);
55*a2464ee1SJessica Clarke }
56*a2464ee1SJessica Clarke 
57