From 242689c7f93de72693979f877dd31b3ef7178eea Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 28 Sep 2009 18:29:02 +0200 Subject: ls: with -LR, exit with status 2 upon detecting a cycle * src/ls.c (print_dir): Diagnosing the cycle is not enough. Also set exit status to 2. This is what Solaris' /bin/ls does, too. * tests/ls/infloop: Rework test: match both expected stdout and stderr. Require an exit status of 2 in this case. * doc/coreutils.texi (ls invocation): Mention that a loop provokes in an exit status of 2. * NEWS (Bug fixes): Mention it. Reported by Yang Ren in http://bugzilla.redhat.com/525402. * THANKS: Correct ordering of Yang Ren's names. --- tests/ls/infloop | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'tests/ls/infloop') diff --git a/tests/ls/infloop b/tests/ls/infloop index 419d7a9f7..b77f88cdb 100755 --- a/tests/ls/infloop +++ b/tests/ls/infloop @@ -1,7 +1,7 @@ #!/bin/sh # show that the following no longer makes ls infloop # mkdir loop; cd loop; ln -s ../loop sub; ls -RL - +# Also ensure ls exits with status = 2 in that case. # Copyright (C) 2001-2002, 2004, 2006-2009 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify @@ -27,21 +27,22 @@ fi mkdir loop || framework_failure ln -s ../loop loop/sub || framework_failure -fail=0 - -ls -RL loop 2>err | head -n 7 > out -# With an inf-looping ls, out will contain these 7 lines: -cat < bad +cat <<\EOF > exp-out || framework_failure loop: sub +EOF -loop/sub: -sub - -loop/sub/sub: +cat <<\EOF > exp-err || framework_failure +ls: loop/sub: not listing already-listed directory EOF -# Make sure we don't get the "bad" output. -compare out bad > /dev/null 2>&1 && fail=1 +fail=0 + +timeout 1 ls -RL loop 2>err > out +# Ensure that ls exits with status 2 upon detecting a cycle +test $? = 2 || fail=1 + +compare err exp-err || fail=1 +compare out exp-out || fail=1 Exit $fail -- cgit v1.2.3-70-g09d2