1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or https://opensource.org/licenses/CDDL-1.0. 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# DESCRIPTION: 24# Verify ZEDLETs only inherit the fds specified in the manpage 25# 26# STRATEGY: 27# 1. Inject a ZEDLET that dumps the fds it gets to a file. 28# 2. Generate some events. 29# 3. Read back the generated files and assert that there is no fd past 3, 30# and there are exactly 4 fds. 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/events/events_common.kshlib 34 35verify_runnable "both" 36 37function cleanup 38{ 39 log_must rm -rf "$logdir" 40 log_must rm "/tmp/zts-zed_fd_spill-logdir" 41 log_must zed_stop 42} 43 44log_assert "Verify ZEDLETs inherit only the fds specified" 45log_onexit cleanup 46 47logdir="$(mktemp -d)" 48log_must ln -s "$logdir" /tmp/zts-zed_fd_spill-logdir 49 50 51zedlet="$(command -v zed_fd_spill-zedlet)" 52log_must ln -s "$zedlet" "${ZEDLET_DIR}/all-dumpfds" 53 54# zed will cry foul and refuse to run it if this isn't true 55sudo chown root "$zedlet" 56sudo chmod 700 "$zedlet" 57 58log_must zpool events -c 59log_must zed_stop 60log_must zed_start 61 62log_must truncate -s 0 $ZED_DEBUG_LOG 63log_must zpool scrub $TESTPOOL 64log_must zfs set compression=off $TESTPOOL/$TESTFS 65log_must wait_scrubbed $TESTPOOL 66log_must file_wait $ZED_DEBUG_LOG 3 67 68if [ -n "$(find "$logdir" -maxdepth 0 -empty)" ]; then 69 log_fail "Our ZEDLET didn't run!" 70fi 71log_must awk ' 72 !/^[0123]$/ { 73 print FILENAME ": " $0 74 err=1 75 } 76 END { 77 exit err 78 } 79' "$logdir"/* 80wc -l "$logdir"/* | log_must awk '$1 != "4" && $2 != "total" {print; exit 1}' 81 82log_pass "ZED doesn't leak fds to ZEDLETs" 83