1*697c0e2aSkre# $NetBSD: t_pgrep.sh,v 1.2 2017/02/21 21:22:45 kre Exp $ 267cef682Skre# 367cef682Skre# Copyright (c) 2016 The NetBSD Foundation, Inc. 467cef682Skre# All rights reserved. 567cef682Skre# 667cef682Skre# Redistribution and use in source and binary forms, with or without 767cef682Skre# modification, are permitted provided that the following conditions 867cef682Skre# are met: 967cef682Skre# 1. Redistributions of source code must retain the above copyright 1067cef682Skre# notice, this list of conditions and the following disclaimer. 1167cef682Skre# 2. Redistributions in binary form must reproduce the above copyright 1267cef682Skre# notice, this list of conditions and the following disclaimer in the 1367cef682Skre# documentation and/or other materials provided with the distribution. 1467cef682Skre# 1567cef682Skre# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1667cef682Skre# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1767cef682Skre# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1867cef682Skre# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1967cef682Skre# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2067cef682Skre# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2167cef682Skre# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2267cef682Skre# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2367cef682Skre# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2467cef682Skre# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2567cef682Skre# POSSIBILITY OF SUCH DAMAGE. 2667cef682Skre# 2767cef682Skre 2867cef682Skreatf_test_case pr50934 2967cef682Skrebasic_shift_test_head() { 3067cef682Skre atf_set "descr" "Test fix for PR bin/50934 (null argv[0])" 3167cef682Skre} 3267cef682Skrepr50934_body() { 3367cef682Skre atf_require_prog pgrep 3467cef682Skre atf_require_prog cc 3567cef682Skre 3667cef682Skre cat > t.c <<'!' 3767cef682Skre#include <stdlib.h> 3867cef682Skre#include <unistd.h> 3967cef682Skre 40*697c0e2aSkreint 4167cef682Skremain(int argc, char **argv) 4267cef682Skre{ 4367cef682Skre sleep(2); 4467cef682Skre argv[0] = 0; 4567cef682Skre pause(); 4667cef682Skre exit(0); 4767cef682Skre} 4867cef682Skre! 4967cef682Skre 5067cef682Skre cc -o t0123456789abcdefg-beef t.c || atf_fail "t.c compile failed" 5167cef682Skre 5267cef682Skre ./t0123456789abcdefg-beef & 5367cef682Skre PID=$! 5467cef682Skre 5567cef682Skre pgrep -l t0123456 >OUT ; # should find the process 5667cef682Skre pgrep -l beef >>OUT ; # should find the process 5767cef682Skre 5867cef682Skre sleep 5 ; # allow time for sleep in t.c and argv[0]=0 5967cef682Skre 6067cef682Skre pgrep -l t0123456 >>OUT ; # should find the process 6167cef682Skre pgrep -l beef >>OUT ; # should find nothing 6267cef682Skre 6367cef682Skre kill -9 $PID 6467cef682Skre cat OUT ; # just for the log 6567cef682Skre 6667cef682Skre # note that pgrep -l only ever prints p_comm which is of limited sicze 6767cef682Skre atf_check_equal "$(cat OUT)" \ 6867cef682Skre "$PID t0123456789abcde $PID t0123456789abcde $PID t0123456789abcde" 6967cef682Skre 7067cef682Skre return 0 7167cef682Skre} 7267cef682Skre 7367cef682Skreatf_init_test_cases() { 7467cef682Skre atf_add_test_case pr50934 7567cef682Skre} 76