1#!/bin/sh 2# Test the --pid option of tail. 3 4# Copyright (C) 2003-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ tail 21getlimits_ 22 23touch empty here || framework_failure_ 24 25# Terminate any background tail process 26cleanup_() { kill $pid 2>/dev/null && wait $pid; } 27 28for mode in '' '---disable-inotify'; do 29 # Use tail itself to create a background process to monitor, 30 # which will auto exit when "here" is removed. 31 tail -f $mode here & pid=$! 32 33 # Ensure that tail --pid=PID does not exit when PID is alive. 34 returns_ 124 timeout 1 tail -f -s.1 --pid=$pid $mode here || fail=1 35 36 # Ensure that tail --pid=PID does not exit when at least one PID is alive. 37 returns_ 124 timeout 1 tail -f -s.1 --pid=$PID_T_MAX --pid=$pid $mode here \ 38 || fail=1 39 40 cleanup_ 41 42 # Ensure that tail --pid=PID exits with success status when PID is dead. 43 # Use an unlikely-to-be-live PID 44 timeout 10 tail -f -s.1 --pid=$PID_T_MAX $mode empty 45 ret=$? 46 test $ret = 124 && skip_ "pid $PID_T_MAX present or tail too slow" 47 test $ret = 0 || fail=1 48 49 # Ensure tail doesn't wait for data when PID is dead 50 returns_ 124 timeout 10 tail -f -s10 --pid=$PID_T_MAX $mode empty && fail=1 51done 52 53Exit $fail 54