Compare commits

...

13 Commits
v8.18 ... v8.19

Author SHA1 Message Date
Jim Meyering
76ea9b1ada version 8.19
* NEWS: Record release date.
2012-08-20 08:13:02 +02:00
Paul Eggert
aa1ec87f52 tests: port df/no-mtab-status to Solaris
* tests/df/no-mtab-status: Include <mntent.h> in test program, so
that the getmntent hack compilation fails on Solaris, as it
should, since it's not compatible with Solaris.  Reported by
Stefano Lattarini in <http://bugs.gnu.org/12225>.
2012-08-19 22:31:39 +02:00
Jim Meyering
e44943a25e tests: avoid split/filter test failure on very low-mem system
* tests/split/filter: Use xz -1 when compressing, to minimize
memory usage.  Otherwise, xz could fail due to insufficient
virtual memory on a system with very little free memory.
2012-08-19 17:34:04 +02:00
Jim Meyering
46444af9e4 tests: trigger the sort -u free-memory-read bug
* tests/misc/sort-u-FMR: New file.
* tests/Makefile.am (TESTS): Add it.
* tests/misc/sort: Add the test here, too.
* NEWS (Bug fixes): Mention it.
2012-08-18 08:03:55 +02:00
Jim Meyering
b8104e47ca tests: wrap the valgrind-requiring assertion in a function
* tests/init.cfg (require_valgrind_): New function...
* tests/misc/sort-stale-thread-mem: ...extracted from here.
2012-08-18 07:39:49 +02:00
Paul Eggert
574b7c7dbe sort: simpler fix for sort -u data-loss bug, and for a FMR bug
This also fixes a free-memory-read (FMR) bug: when fillbuf's realloc
of buf->buf frees the buffer into which saved_line.text points,
the processing of that just-read longer line includes comparison
against the saved line in freed memory.
* src/sort.c (overlap): Remove.
(fillbuf): Do not try to copy saved lines, as that is too risky
in the presence of parallelism, reallocated buffers, etc.
(sort): Invalidate any saved line before sorting a new batch.
2012-08-18 07:39:29 +02:00
Jim Meyering
eb3f5b3b3d sort: sort --unique (-u) could cause data loss
sort -u could omit one or more lines of expected output.
This bug arose because sort recorded the most recently printed line via
reference, and if you were unlucky, the storage for that line would be
reused (overwritten) as additional input was read into memory.  If you
were doubly unlucky, the new value of the "saved" line would not only
match the very next line, but if that next line were also the first in
a series of identical, not-yet-printed lines, then the corrupted "saved"
line value would result in the omission of all matching lines.

* src/sort.c (saved_line): New static/global, renamed and moved from...
(write_unique): ...here.  Old name was "saved", which was too generic
for its new role as file-scoped global.
(fillbuf): With --unique, when we're about to read into a buffer that
overlaps the saved "preceding" line (saved_line), copy the line's .text
member to a realloc'd-as-needed temporary buffer and adjust the line's
key-defining members if they're set.
(overlap): New function.
* tests/misc/sort: New tests.
* NEWS (Bug fixes): Mention it.
* THANKS.in: Update.
Bug introduced via commit v8.5-89-g9face83.
Reported by Rasmus Borup Hansen in
http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/23173/focus=24647
2012-08-17 09:52:19 +02:00
Jim Meyering
0c98bfa359 tests: reverse args in Coreutils.pm-invoked diff, for consistency
* tests/Coreutils.pm (_compare_files): Reverse diff arguments so
that we invoke diff -c $expected $actual, which is consistent with
how init.sh-using tests invoke "compare exp out".
2012-08-16 20:14:03 +02:00
Jim Meyering
1e987a9966 maint: correct a stale comment in sort.c
* src/sort.c (fillbuf): Fix comment typo.  x2nrealloc no longer
doubles the size of its input buffer.
2012-08-16 20:13:59 +02:00
Jim Meyering
f1a03de07f maint: fix comment grammar to placate make syntax-check
* src/remove.c (rm_fts): s/can not/cannot/
2012-08-16 19:25:40 +02:00
Krzysztof Goj
fdc2da7165 rm: new option --dir (-d) to remove empty directories
Add new option to rm (-d/--dir), which allows removal of
empty directories, while still safely disallowing removal
of non-empty ones.

This improves compatibility with Mac OS X and BSD systems,
which honor the -d option.

* src/remove.c (rm_fts): Remove empty directories when requested.
* src/remove.h (rm_options) [remove_empty_directories]: New member.
* src/rm.c (long_opts, usage, main): Update usage and option parsing.
(rm_option_init): Initialize the new member.
* src/mv.c (rm_option_init): Initialize the new member.
* tests/rm/d-1: New test case - successfully delete empty dir.
* tests/rm/d-2: New test case - refuse to delete nonempty dir.
* tests/Makefile.am (TESTS): Add them.
2012-08-14 18:54:16 +02:00
Bernhard Voelker
46afefaaa8 df: fail when the mount list is required but cannot be read
* src/df.c (main): Add conditions to fail when the mount list cannot
be read: this includes the cases when a file name argument is given
and any of -a, -l, -t or -x is used.
* doc/coreutils.texi: Document the additional error conditions.
* tests/df/no-mtab-status: Add a new test.
* tests/Makefile.am: Reference the new test.
* NEWS: Mention the fix.
2012-08-14 11:34:54 +02:00
Jim Meyering
a07dfa9064 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2012-08-12 10:07:32 +02:00
22 changed files with 292 additions and 21 deletions

View File

@@ -1 +1 @@
8.17
8.18

27
NEWS
View File

@@ -1,5 +1,32 @@
GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release 8.19 (2012-08-20) [stable]
** Bug fixes
df now fails when the list of mounted file systems (/etc/mtab) cannot
be read, yet the file system type information is needed to process
certain options like -a, -l, -t and -x.
[This bug was present in "the beginning".]
sort -u could fail to output one or more result lines.
For example, this command would fail to print "1":
(yes 7 | head -11; echo 1) | sort --p=1 -S32b -u
[bug introduced in coreutils-8.6]
sort -u could read freed memory.
For example, this evokes a read from freed memory:
perl -le 'print "a\n"."0"x900'|valgrind sort --p=1 -S32b -u>/dev/null
[bug introduced in coreutils-8.6]
** New features
rm now accepts the --dir (-d) option which makes it remove empty directories.
Since removing empty directories is relatively safe, this option can be
used as a part of the alias rm='rm --dir'. This improves compatibility
with Mac OS X and BSD systems which also honor the -d option.
* Noteworthy changes in release 8.18 (2012-08-12) [stable]
** Bug fixes

View File

@@ -508,6 +508,7 @@ Primoz PETERLIN primozz.peterlin@gmail.com
Rainer Orth ro@TechFak.Uni-Bielefeld.DE
Ralf W. Stephan stephan@tmt.de
Ralph Loader loader@maths.ox.ac.uk
Rasmus Borup Hansen rbh@intomics.com
Raul Miller moth@magenta.com
Raúl Núñez de Arenas Coronado raul@pleyades.net
Richard A Downing richard.downing@bcs.org.uk

2
cfg.mk
View File

@@ -45,7 +45,7 @@ export VERBOSE = yes
# 4914152 9e
export XZ_OPT = -8e
old_NEWS_hash = 38cad4d11c6ce866fc52213e3a4dc437
old_NEWS_hash = b081ffe4128201150126951b1d8263e1
# Add an exemption for sc_makefile_at_at_check.
_makefile_at_at_check_exceptions = ' && !/^cu_install_program =/'

View File

@@ -8807,6 +8807,13 @@ The program accepts the following options. Also see @ref{Common options}.
@table @samp
@item -d
@itemx --dir
@opindex -d
@opindex --dir
@cindex directories, removing
Remove the listed directories if they are empty.
@item -f
@itemx --force
@opindex -f
@@ -10754,6 +10761,11 @@ inspect the exit status of a command like @samp{df -t ext3 -t reiserfs
@var{dir}} to test whether @var{dir} is on a file system of type
@samp{ext3} or @samp{reiserfs}.
Since the list of file systems (@var{mtab}) is needed to determine the
file system type, failure includes the cases when that list cannot
be read and one or more of the options @option{-a}, @option{-l}, @option{-t}
or @option{-x} is used together with a file name argument.
@node du invocation
@section @command{du}: Estimate file space usage

2
gnulib

Submodule gnulib updated: 39cedf6f42...bc33a8a0c7

View File

@@ -1100,10 +1100,19 @@ main (int argc, char **argv)
if (mount_list == NULL)
{
/* Couldn't read the table of mounted file systems.
Fail if df was invoked with no file name arguments;
Otherwise, merely give a warning and proceed. */
int status = (optind < argc ? 0 : EXIT_FAILURE);
const char *warning = (optind < argc ? _("Warning: ") : "");
Fail if df was invoked with no file name arguments,
or when either of -a, -l, -t or -x is used with file name
arguments. Otherwise, merely give a warning and proceed. */
int status = 0;
if ( ! (optind < argc)
|| (show_all_fs
|| show_local_fs
|| fs_select_list != NULL
|| fs_exclude_list != NULL))
{
status = EXIT_FAILURE;
}
const char *warning = (status == 0 ? _("Warning: ") : "");
error (status, errno, "%s%s", warning,
_("cannot read table of mounted file systems"));
}

View File

@@ -73,6 +73,7 @@ static void
rm_option_init (struct rm_options *x)
{
x->ignore_missing_files = false;
x->remove_empty_directories = true;
x->recursive = true;
x->one_file_system = false;

View File

@@ -414,11 +414,15 @@ rm_fts (FTS *fts, FTSENT *ent, struct rm_options const *x)
switch (ent->fts_info)
{
case FTS_D: /* preorder directory */
if (! x->recursive)
if (! x->recursive
&& !(x->remove_empty_directories
&& is_empty_dir (fts->fts_cwd_fd, ent->fts_accpath)))
{
/* This is the first (pre-order) encounter with a directory.
/* This is the first (pre-order) encounter with a directory
that we cannot delete.
Not recursive, so arrange to skip contents. */
error (0, EISDIR, _("cannot remove %s"), quote (ent->fts_path));
int err = x->remove_empty_directories ? ENOTEMPTY : EISDIR;
error (0, err, _("cannot remove %s"), quote (ent->fts_path));
mark_ancestor_dirs (ent);
fts_skip_tree (fts, ent);
return RM_ERROR;

View File

@@ -49,6 +49,9 @@ struct rm_options
/* If true, recursively remove directories. */
bool recursive;
/* If true, remove empty directories. */
bool remove_empty_directories;
/* Pointer to the device and inode numbers of '/', when --recursive
and preserving '/'. Otherwise NULL. */
struct dev_ino *root_dev_ino;

View File

@@ -77,6 +77,7 @@ static struct option const long_opts[] =
{"-presume-input-tty", no_argument, NULL, PRESUME_INPUT_TTY_OPTION},
{"recursive", no_argument, NULL, 'r'},
{"dir", no_argument, NULL, 'd'},
{"verbose", no_argument, NULL, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
@@ -154,6 +155,7 @@ Remove (unlink) the FILE(s).\n\
--no-preserve-root do not treat '/' specially\n\
--preserve-root do not remove '/' (default)\n\
-r, -R, --recursive remove directories and their contents recursively\n\
-d, --dir remove empty directories\n\
-v, --verbose explain what is being done\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -189,6 +191,7 @@ rm_option_init (struct rm_options *x)
x->ignore_missing_files = false;
x->interactive = RMI_SOMETIMES;
x->one_file_system = false;
x->remove_empty_directories = false;
x->recursive = false;
x->root_dev_ino = NULL;
x->stdin_tty = isatty (STDIN_FILENO);
@@ -220,10 +223,14 @@ main (int argc, char **argv)
/* Try to disable the ability to unlink a directory. */
priv_set_remove_linkdir ();
while ((c = getopt_long (argc, argv, "firvIR", long_opts, NULL)) != -1)
while ((c = getopt_long (argc, argv, "dfirvIR", long_opts, NULL)) != -1)
{
switch (c)
{
case 'd':
x.remove_empty_directories = true;
break;
case 'f':
x.interactive = RMI_NEVER;
x.ignore_missing_files = true;

View File

@@ -262,6 +262,9 @@ struct merge_node_queue
when popping. */
};
/* Used to implement --unique (-u). */
static struct line saved_line;
/* FIXME: None of these tables work with multibyte character sets.
Also, there are many other bugs when handling multibyte characters.
One way to fix this is to rewrite 'sort' to use wide characters
@@ -1813,7 +1816,7 @@ fillbuf (struct buffer *buf, FILE *fp, char const *file)
{
/* The current input line is too long to fit in the buffer.
Double the buffer size and try again, keeping it properly
Increase the buffer size and try again, keeping it properly
aligned. */
size_t line_alloc = buf->alloc / sizeof (struct line);
buf->buf = x2nrealloc (buf->buf, &line_alloc, sizeof (struct line));
@@ -3348,13 +3351,11 @@ queue_pop (struct merge_node_queue *queue)
static void
write_unique (struct line const *line, FILE *tfp, char const *temp_output)
{
static struct line saved;
if (unique)
{
if (saved.text && ! compare (line, &saved))
if (saved_line.text && ! compare (line, &saved_line))
return;
saved = *line;
saved_line = *line;
}
write_line (line, tfp, temp_output);
@@ -3892,6 +3893,7 @@ sort (char *const *files, size_t nfiles, char const *output_file,
break;
}
saved_line.text = NULL;
line = buffer_linelim (&buf);
if (buf.eof && !nfiles && !ntemps && !buf.left)
{

View File

@@ -130,14 +130,14 @@ sub _compare_files ($$$$$)
{
my ($program_name, $test_name, $in_or_out, $actual, $expected) = @_;
my $differ = compare ($expected, $actual);
my $differ = compare ($actual, $expected);
if ($differ)
{
my $info = (defined $in_or_out ? "std$in_or_out " : '');
warn "$program_name: test $test_name: ${info}mismatch, comparing "
. "$actual (actual) and $expected (expected)\n";
. "$expected (expected) and $actual (actual)\n";
# Ignore any failure, discard stderr.
system "diff -c $actual $expected 2>/dev/null";
system "diff -c $expected $actual 2>/dev/null";
}
return $differ;

View File

@@ -98,6 +98,8 @@ TESTS = \
chgrp/basic \
rm/dangling-symlink \
misc/ls-time \
rm/d-1 \
rm/d-2 \
rm/deep-1 \
rm/deep-2 \
rm/dir-no-w \
@@ -258,6 +260,7 @@ TESTS = \
misc/sort-unique-segv \
misc/sort-version \
misc/sort-NaN-infloop \
misc/sort-u-FMR \
split/filter \
split/suffix-auto-length \
split/suffix-length \
@@ -376,6 +379,7 @@ TESTS = \
df/df-P \
df/unreadable \
df/total-unprocessed \
df/no-mtab-status \
dd/direct \
dd/misc \
dd/nocache \

80
tests/df/no-mtab-status Executable file
View File

@@ -0,0 +1,80 @@
#!/bin/sh
# Test df's behaviour when the mount list cannot be read.
# This test is skipped on systems that lack LD_PRELOAD support; that's fine.
# Copyright (C) 2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. "${srcdir=.}/init.sh"; path_prepend_ ../src
print_ver_ df
df || skip_ "df fails"
# Simulate "mtab" failure.
cat > k.c <<'EOF' || framework_failure_
#include <stdio.h>
#include <errno.h>
#include <mntent.h>
struct mntent *getmntent (FILE *fp)
{
/* Prove that LD_PRELOAD works. */
static int done = 0;
if (!done)
{
fclose (fopen ("x", "w"));
++done;
}
/* Now simulate the failure. */
errno = ENOENT;
return NULL;
}
EOF
# Then compile/link it:
$CC -shared -fPIC -ldl -O2 k.c -o k.so \
|| skip_ "getmntent hack does not work on this platform"
# Test if LD_PRELOAD works:
LD_PRELOAD=./k.so df
test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?"
# These tests are supposed to succeed:
LD_PRELOAD=./k.so df '.' || fail=1
LD_PRELOAD=./k.so df -i '.' || fail=1
LD_PRELOAD=./k.so df -T '.' || fail=1
LD_PRELOAD=./k.so df -Ti '.' || fail=1
LD_PRELOAD=./k.so df --total '.' || fail=1
# These tests are supposed to fail:
LD_PRELOAD=./k.so df && fail=1
LD_PRELOAD=./k.so df -i && fail=1
LD_PRELOAD=./k.so df -T && fail=1
LD_PRELOAD=./k.so df -Ti && fail=1
LD_PRELOAD=./k.so df --total && fail=1
LD_PRELOAD=./k.so df -a && fail=1
LD_PRELOAD=./k.so df -a '.' && fail=1
LD_PRELOAD=./k.so df -l && fail=1
LD_PRELOAD=./k.so df -l '.' && fail=1
LD_PRELOAD=./k.so df -t hello && fail=1
LD_PRELOAD=./k.so df -t hello '.' && fail=1
LD_PRELOAD=./k.so df -x hello && fail=1
LD_PRELOAD=./k.so df -x hello '.' && fail=1
Exit $fail

View File

@@ -160,6 +160,12 @@ require_strace_()
fi
}
# Skip the current test if valgrind doesn't work.
require_valgrind_()
{
valgrind --help >/dev/null || skip_ "requires valgrind"
}
require_setfacl_()
{
setfacl -m user::rwx . \

View File

@@ -227,6 +227,21 @@ my @Tests =
["15d", '-i -u', {IN=>"\1a\na\n"}, {OUT=>"\1a\n"}],
["15e", '-i -u', {IN=>"a\n\1\1\1\1\1a\1\1\1\1\n"}, {OUT=>"a\n"}],
# This would fail (printing only the 7) for 8.6..8.18.
# Use --parallel=1 for reproducibility, and a small buffer size
# to let us trigger the problem with a smaller input.
["unique-1", '--p=1 -S32b -u', {IN=>"7\n"x11 . "1\n"}, {OUT=>"1\n7\n"}],
# Demonstrate that 8.19's key-spec-adjusting code is required.
# These are more finicky in that they are arch-dependent.
["unique-key-i686", '-u -k2,2 --p=1 -S32b',
{IN=>"a 7\n"x10 . "b 1\n"}, {OUT=>"b 1\na 7\n"}],
["unique-key-x86_64", '-u -k2,2 --p=1 -S32b',
{IN=>"a 7\n"x11 . "b 1\n"}, {OUT=>"b 1\na 7\n"}],
# Before 8.19, this would trigger a free-memory read.
["unique-free-mem-read", '-u --p=1 -S32b',
{IN=>"a\n"."b"x900 ."\n"},
{OUT=>"a\n"."b"x900 ."\n"}],
# From Erick Branderhorst -- fixed around 1.19e
["16a", '-f',
{IN=>"éminence\nüberhaupt\n's-Gravenhage\naëroclub\nAag\naagtappels\n"},

View File

@@ -22,8 +22,8 @@
print_ver_ sort
very_expensive_
require_valgrind_
valgrind --help >/dev/null || skip_ "requires valgrind"
grep '^#define HAVE_PTHREAD_T 1' "$CONFIG_HEADER" > /dev/null ||
skip_ 'requires pthreads'

29
tests/misc/sort-u-FMR Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/sh
# Before 8.19, this would trigger a free-memory read.
# Copyright (C) 2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. "${srcdir=.}/init.sh"; path_prepend_ ../src
print_ver_ sort
require_valgrind_
{ echo 0; printf '%0900d\n' 1; } > in || framework_failure_
valgrind --error-exitcode=1 sort --p=1 -S32b -u in > out || fail=1
compare in out || fail=1
Exit $fail

38
tests/rm/d-1 Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/sh
# Test "rm --dir --verbose".
# Copyright (C) 2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. "${srcdir=.}/init.sh"; path_prepend_ ../src
print_ver_ rm
mkdir a || framework_failure_
> b || framework_failure_
rm --verbose --dir a b > out || fail=1
cat <<\EOF > exp || framework_failure_
removed directory: 'a'
removed 'b'
EOF
test -e a && fail=1
test -e b && fail=1
# Compare expected and actual output.
compare exp out || fail=1
Exit $fail

33
tests/rm/d-2 Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/sh
# Ensure that 'rm -d dir' (i.e., without --recursive) gives a reasonable
# diagnostic when failing.
# Copyright (C) 2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. "${srcdir=.}/init.sh"; path_prepend_ ../src
print_ver_ rm
mkdir d || framework_failure_
> d/a || framework_failure_
rm -d d 2> out && fail=1
printf "%s\n" \
"rm: cannot remove 'd': Directory not empty" \
> exp || framework_failure_
compare exp out || fail=1
Exit $fail

View File

@@ -29,7 +29,7 @@ for total_n_lines in 5 3000 20000; do
# and would provide little added benefit.
case $i:$total_n_lines in 2:5);; *) continue;; esac
split -l$i --filter='xz > $FILE.xz' in out- || fail=1
split -l$i --filter='xz -1 > $FILE.xz' in out- || fail=1
xz -dc out-* > out || fail=1
compare in out || fail=1
rm -f out*