xref: /illumos-gate/usr/src/test/os-tests/tests/i386/badseg.sh (revision b8052df9f609edb713f6828c9eecc3d7be19dfb3)
1#!/bin/bash
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12# Copyright 2019 Joyent, Inc.
13# Copyright 2021 Oxide Computer Company
14#
15
16#
17# badseg intentionally core-dumps. It does a setrlimit(), but we need to
18# prevent global core dumps too: we'll do this by blocking the path for
19# badseg_exec, but let other processes core dump still just in case.
20#
21
22set -e
23set -x
24
25old_enabled=$(/usr/bin/svcprop -p config_params/global_enabled coreadm)
26old_pattern=$(/usr/bin/svcprop -p config_params/global_pattern coreadm)
27old_log=$(/usr/bin/svcprop -p config_params/global_log_enabled coreadm)
28
29mkfile 1m /var/cores/badseg_exec
30coreadm -e global -d log -g /var/cores/%f/%p
31# let it settle
32sleep 3
33
34$(dirname $0)/badseg_exec || true
35
36#
37# If this property is set to the empty string (e.g. unset, but the property is
38# present), svcprop will return that as "". If we don't special case this, we
39# will then pass that literal string back to coreadm as an actual path, which is
40# invalid.
41#
42if [[ "$old_pattern" == '""' ]]; then
43	coreadm -g ''
44else
45	coreadm -g "$old_pattern"
46fi
47
48if [[ "$old_enabled" == "true" ]]; then
49       coreadm -e global
50fi
51
52if [[ "$old_log" == "true" ]]; then
53       coreadm -e log
54fi
55
56rm -f /var/cores/badseg_exec
57