ls -LR exits with status 2, not 0, when it encounters a cycle(#525402), ls:

print ?, not 0 as inode of dereferenced dangling symlink(#525400), call
    the install-info on .gz info files
This commit is contained in:
Ondrej Vasik 2009-10-02 14:41:18 +00:00
parent 066fd3a5cb
commit ae3959bffe
2 changed files with 177 additions and 7 deletions

161
coreutils-ls-inode.patch Normal file
View File

@ -0,0 +1,161 @@
diff -urNp coreutils-7.6-orig/doc/coreutils.texi coreutils-7.6/doc/coreutils.texi
--- coreutils-7.6-orig/doc/coreutils.texi 2009-09-22 15:12:55.000000000 +0200
+++ coreutils-7.6/doc/coreutils.texi 2009-10-02 16:09:57.000000000 +0200
@@ -6114,7 +6114,8 @@ Exit status:
specified as a command line argument. This happens when listing a
directory in which entries are actively being removed or renamed.)
2 serious trouble (e.g., memory exhausted, invalid option or failure
- to access file or directory specified as a command line argument)
+ to access file or directory specified as a command line argument
+ or a directory loop)
@end display
Also see @ref{Common options}.
diff -urNp coreutils-7.6-orig/src/ls.c coreutils-7.6/src/ls.c
--- coreutils-7.6-orig/src/ls.c 2009-09-22 15:12:55.000000000 +0200
+++ coreutils-7.6/src/ls.c 2009-10-02 16:19:54.000000000 +0200
@@ -2494,6 +2494,7 @@ print_dir (char const *name, char const
error (0, 0, _("%s: not listing already-listed directory"),
quotearg_colon (name));
closedir (dirp);
+ set_exit_status (true);
return;
}
@@ -3582,6 +3583,18 @@ format_user_width (uid_t u)
return format_user_or_group_width (numeric_ids ? NULL : getuser (u), u);
}
+/* Return a pointer to a formatted version of F->stat.st_ino,
+ possibly using buffer, BUF, of length BUFLEN, which must be at least
+ INT_BUFSIZE_BOUND (uintmax_t) bytes. */
+static char *
+format_inode (char *buf, size_t buflen, const struct fileinfo *f)
+{
+ assert (INT_BUFSIZE_BOUND (uintmax_t) <= buflen);
+ return (f->stat_ok && f->stat.st_ino != NOT_AN_INODE_NUMBER
+ ? umaxtostr (f->stat.st_ino, buf)
+ : (char *) "?");
+}
+
/* Likewise, for groups. */
static int
@@ -3712,9 +3725,7 @@ print_long_format (const struct fileinfo
{
char hbuf[INT_BUFSIZE_BOUND (uintmax_t)];
sprintf (p, "%*s ", inode_number_width,
- (f->stat.st_ino == NOT_AN_INODE_NUMBER
- ? "?"
- : umaxtostr (f->stat.st_ino, hbuf)));
+ format_inode (hbuf, sizeof hbuf, f));
/* Increment by strlen (p) here, rather than by inode_number_width + 1.
The latter is wrong when inode_number_width is zero. */
p += strlen (p);
@@ -4104,12 +4115,13 @@ print_file_name_and_frills (const struct
if (print_inode)
printf ("%*s ", format == with_commas ? 0 : inode_number_width,
- umaxtostr (f->stat.st_ino, buf));
+ format_inode (buf, sizeof buf, f));
if (print_block_size)
printf ("%*s ", format == with_commas ? 0 : block_size_width,
- human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
- ST_NBLOCKSIZE, output_block_size));
+ ! f->stat_ok ? "?"
+ : human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
+ ST_NBLOCKSIZE, output_block_size));
size_t width = print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f),
f->linkok, f->stat_ok, f->filetype,
@@ -4320,9 +4332,10 @@ length_of_file_name_and_frills (const st
if (print_block_size)
len += 1 + (format == with_commas
- ? strlen (human_readable (ST_NBLOCKS (f->stat), buf,
- human_output_opts, ST_NBLOCKSIZE,
- output_block_size))
+ ? strlen (! f->stat_ok ? "?"
+ : human_readable (ST_NBLOCKS (f->stat), buf,
+ human_output_opts, ST_NBLOCKSIZE,
+ output_block_size))
: block_size_width);
quote_name (NULL, f->name, filename_quoting_options, &name_width);
diff -urNp coreutils-7.6-orig/tests/ls/dangle coreutils-7.6/tests/ls/dangle
--- coreutils-7.6-orig/tests/ls/dangle 2009-09-01 13:01:16.000000000 +0200
+++ coreutils-7.6/tests/ls/dangle 2009-10-02 16:21:06.000000000 +0200
@@ -26,6 +26,10 @@ fi
ln -s no-such-file dangle || framework_failure
mkdir -p dir/sub || framework_failure
ln -s dir slink-to-dir || framework_failure
+mkdir d || framework_failure
+ln -s no-such d/dangle || framework_failure
+printf '? dangle\n' > subdir_Li_exp || framework_failure
+printf 'total 0\n? dangle\n' > subdir_Ls_exp || framework_failure
fail=0
@@ -50,4 +54,14 @@ EOF
compare out exp || fail=1
+# Ensure that ls -Li prints "?" as the inode of a dangling symlink.
+rm -f out
+ls -Li d > out 2>/dev/null && fail=1
+compare out subdir_Li_exp || fail=1
+
+# Ensure that ls -Ls prints "?" as the allocation of a dangling symlink.
+rm -f out
+ls -Ls d > out 2>/dev/null && fail=1
+compare out subdir_Ls_exp || fail=1
+
Exit $fail
diff -urNp coreutils-7.6-orig/tests/ls/infloop coreutils-7.6/tests/ls/infloop
--- coreutils-7.6-orig/tests/ls/infloop 2009-09-01 13:01:16.000000000 +0200
+++ coreutils-7.6/tests/ls/infloop 2009-10-02 16:12:11.000000000 +0200
@@ -1,6 +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.
@@ -27,21 +28,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 <<EOF > 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

View File

@ -1,7 +1,7 @@
Summary: A set of basic GNU tools commonly used in shell scripts
Name: coreutils
Version: 7.6
Release: 5%{?dist}
Release: 6%{?dist}
License: GPLv3+
Group: System Environment/Base
Url: http://www.gnu.org/software/coreutils/
@ -20,6 +20,7 @@ Source203: coreutils-runuser-l.pamd
# From upstream
Patch1: coreutils-cpxattrreadonly.patch
Patch2: coreutils-7.6-lzipcolor.patch
Patch3: coreutils-ls-inode.patch
# Our patches
Patch100: coreutils-6.10-configuration.patch
@ -111,6 +112,7 @@ Libraries for coreutils package.
# From upstream
%patch1 -p1 -b .roxattr
%patch2 -p1 -b .lzip
%patch3 -p1 -b .inode
# Our patches
%patch100 -p1 -b .configure
@ -254,15 +256,15 @@ rm -rf $RPM_BUILD_ROOT
# coreutils.info. else their postun'll be run too late
# and install-info will fail badly because of duplicates
for file in sh-utils textutils fileutils; do
if [ -f %{_infodir}/$file.info ]; then
/sbin/install-info --delete %{_infodir}/$file.info --dir=%{_infodir}/dir &> /dev/null || :
if [ -f %{_infodir}/$file.info.gz ]; then
/sbin/install-info --delete %{_infodir}/$file.info.gz --dir=%{_infodir}/dir &> /dev/null || :
fi
done
%preun
if [ $1 = 0 ]; then
if [ -f %{_infodir}/%{name}.info ]; then
/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || :
if [ -f %{_infodir}/%{name}.info.gz ]; then
/sbin/install-info --delete %{_infodir}/%{name}.info.gz %{_infodir}/dir || :
fi
fi
@ -270,8 +272,8 @@ fi
/bin/grep -v '(sh-utils)\|(fileutils)\|(textutils)' %{_infodir}/dir > \
%{_infodir}/dir.rpmmodify || exit 0
/bin/mv -f %{_infodir}/dir.rpmmodify %{_infodir}/dir
if [ -f %{_infodir}/%{name}.info ]; then
/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || :
if [ -f %{_infodir}/%{name}.info.gz ]; then
/sbin/install-info %{_infodir}/%{name}.info.gz %{_infodir}/dir || :
fi
%files -f %{name}.lang
@ -329,6 +331,13 @@ fi
%{_libdir}/coreutils
%changelog
* Fri Oct 02 2009 Ondrej Vasik <ovasik@redhat.com> - 7.6-6
- ls -LR exits with status 2, not 0, when it encounters
a cycle(#525402)
- ls: print "?", not "0" as inode of dereferenced dangling
symlink(#525400)
- call the install-info on .gz info files
* Tue Sep 22 2009 Ondrej Vasik <ovasik@redhat.com> - 7.6-5
- improve and correct runuser documentation (#524805)