Commit Graph

3064 Commits

Author SHA1 Message Date
Paul Eggert
cdec7e6e93 Correct cp's handling of destination symlinks in some cases.
* NEWS: "cp" no longer considers a destination symlink to be the
same as the referenced file when copying links or making backups.
* src/copy.c (copy_reg): When following a symlink, use the
followed name in later chown etc. requests, so that the created
file is affected, rather than the symlink.  Use O_NOFOLLOW on
source when not dereferencing symlinks; this avoids a race.
Preserve errno correctly when doing multiple open attempts on the
destination.
(copy_internal): Follow destination symlinks only when copying a
regular file and only when we don't intend to remove or rename the
destination first, regardless of whether following source
symlinks; this is because since POSIX and tradition (e.g.,
FreeBSD) say we should ordinarily follow destination symlinks if
the system calls would ordinarily do so.
* src/copy.h (struct cp_options): Add comment that 'dereference'
is only for source files.
* src/cp.c (usage): Note that --derereference etc. are only for
source files.
(make_dir_parents_private): Follow symlinks, regardless of whether
--dereference is specified, because these are destination symlinks.
* tests/cp/same-file: Adjust tests to match revised behavior.
Filter out perror output since it might vary from host to host.
Use sed alone instead of also using echo.

* doc/coreutils.texi (cp invocation): Document the behavior better when
the destination is a symlink.  Clarify source versus destination
symlinks.  Describe the new behavior for destination symlinks.

2007-06-15  Jim Meyering  <jim@meyering.net>

* src/copy.c: Include "canonicalize.h".
(copy_reg): Use canonicalize_filename_mode to follow the symlink,
so that we can always open with O_EXCL and avoid a race.
2007-06-15 22:47:16 +02:00
Jim Meyering
b1b0f5c556 bug-fix: cp would fail to write through a dangling symlink
* NEWS: Mention the bug fix.
* src/copy.c (copy_reg): When open fails with EEXIST, the destination
is lstat'able, and a symlink, call open again, but now without O_EXCL.
* tests/cp/thru-dangling: New file, to test for the above fix.
* tests/cp/Makefile.am (TESTS): Add thru-dangling.
* THANKS: Add Michael McLagan.
Bug report from Michael McLagan in <http://bugzilla.redhat.com/243588>.
2007-06-10 15:01:18 +02:00
Jim Meyering
a6a447fc58 cut: diagnose a range starting with 0 (-f 0-2) as invalid, and
give a better diagnostic for a field-number/offset of 0.
* NEWS: Mention the fix.
* src/cut.c (ADD_RANGE_PAIR): Add an explicit check for 0.
Based on a patch from James Youngman.
* tests/misc/cut: Add tests for the above.
2007-05-22 18:47:17 +02:00
Jim Meyering
ae5717158f "cut -f 2-0" now fails; before, it was equivalent to "cut -f 2-"
Also, diagnose the '-' in "cut -f -" as an invalid range, rather
than interpreting it as the unlimited range, "1-".
* NEWS: Mention these changes.
* src/cut.c (set_fields): Don't interpret an accumulator "value"
of 0 as an unspecified range endpoint.
Give better diagnostics.
Adjust a comment so that it is true also for 64-bit size_t.
* tests/cut/Test.pm: Add tests for the above.
2007-05-22 13:56:34 +02:00
Jim Meyering
02599650b1 stty: diagnose an invalid hex value in 35-colon commmand-line argument
* NEWS: Mention this.
* src/stty.c (strtoul_tcflag_t, strtoul_cc_t): New functions.
(recover_mode): Use those functions (not sscanf), to parse the
string robustly.
* tests/stty/invalid: New file.  Test for the above.
* tests/stty/Makefile.am (TESTS): Add invalid.
* .x-sc_prohibit_atoi_atof: Don't exempt stty.c from this check.
Add tests/stty/invalid so we don't have to obfuscate the comment
about sscanf therein.
* Makefile.maint (sc_prohibit_atoi_atof): Mention sscanf in the
diagnostic, too.
2007-05-22 07:55:40 +02:00
Jim Meyering
893ac688cc Remove the generated tests/*/Makefile.am files from version control.
* tests/cut/Makefile.am: git-remove this generated file.
* tests/head/Makefile.am: Likewise.
* tests/join/Makefile.am: Likewise.
* tests/pr/Makefile.am: Likewise.
* tests/sort/Makefile.am: Likewise.
* tests/tac/Makefile.am: Likewise.
* tests/tail/Makefile.am: Likewise.
* tests/test/Makefile.am: Likewise.
* tests/tr/Makefile.am: Likewise.
* tests/uniq/Makefile.am: Likewise.
* tests/wc/Makefile.am: Likewise.
* .cvsignore, .gitignore: Ignore these generated files.

* src/.cvsignore, src/.gitignore: Add chcon here, ...
* .cvsignore, .gitignore: ... not here.
2007-05-13 18:23:41 +02:00
Jim Meyering
16385191ce Test uniq's new --zero-terminated (-z) option.
* tests/uniq/Test.pm: When possible, create a "-z"-testing variant
of each existing test.
(2z, 3z, 4z, 5z, 20z, 122, 123): New tests from James Youngman.
2007-05-13 11:29:54 +02:00
Jim Meyering
283dadf095 Avoid test failure when run with an unusual umask.
* tests/ls/color-dtype-dir: Set umask to 022.
Suggestion from AIDA Shinra.
2007-05-04 13:32:46 +02:00
Jim Meyering
3affac54ed Avoid failure of root-only test when run with a restrictive umask.
* tests/rm/no-give-up: Ensure that non-root can access "d/" through
root-owned ".".  Reported by AIDA Shinra.
2007-05-04 12:01:43 +02:00
Jim Meyering
ab402c29f9 tr -c: don't abort when translating with S2 larger than complement of S1
* src/tr.c (main): Remove invalid assertion triggered by e.g.,
tr -c a '[b*256]'.  There's nothing wrong with having Set2 larger
than Set1.  Reported by Guntram Blohm.
* tests/tr/Test.pm (no-abort-1): Test for the above.
* NEWS: Mention this bug fix.
* THANKS: Add Guntram Blohm.
2007-05-04 10:03:01 +02:00
Jim Meyering
bf8cfacd24 Avoid test failure when run with a permissive umask.
* tests/rm/no-give-up: Set permissions of test directory properly,
i.e., not depending on umask prohibiting go=w.
Reported by AIDA Shinra.
2007-05-03 19:36:34 +02:00
Jim Meyering
aa3f52d17b Invoke rm via 'setuidgid ... env PATH="$PATH" ...', as in fail-eperm.
* tests/rm/fail-2eperm: Patch from AIDA Shinra.
Reported by Peter Dyballa.
* THANKS: Add AIDA Shinra and Peter Dyballa.
2007-05-02 23:34:33 +02:00
Jim Meyering
383713e030 * THANKS: Add Andreas Frische.
* NEWS: Mention today's ls --color fix.
* tests/ls-2/tests (sl-dangle): Add a test for today's fix.
2007-04-24 09:20:52 +02:00
Paul Eggert
395fcee97a split --line-bytes=N (-C N): don't create an empty file.
* src/split.c (line_bytes_split): Don't create an empty line
afterwards if the last buffer happens to be exactly full.
* tests/misc/split-fail: Add a test case for this.
* NEWS: mention this.
2007-04-12 00:21:25 +02:00
Jim Meyering
4d484fe09f Add a test for, and document, today's fix.
* NEWS: Mention today's ls --color fix.
* tests/ls-2/tests (sl-target): Add a test for today's fix.
* THANKS: Add Kirk Kelsey.
2007-04-07 20:51:13 +02:00
Paul Eggert
a3b65a63a0 * src/ls.c (print_horizontal): Fix bug reported by Mike Frysinger:
ls -x DIR would sometimes output the wrong string in place of the
first entry.
* NEWS: Mention the bug fix.
* tests/ls/x-option: New file.
* tests/ls/Makefile.am (TESTS): Add x-option.
2007-04-02 18:29:41 +02:00
Jim Meyering
848bd19d21 * src/runcon.c (main): Don't reorder arguments. Reported by
Ulrich Drepper in <http://bugzilla.redhat.com/232652>.
* tests/misc/runcon-no-reorder: New file.  Test for the above.
* tests/misc/Makefile.am (TESTS): Add runcon-no-reorder.
2007-03-29 21:37:06 +02:00
Jim Meyering
add8b36148 Arrange for "make check-root" to run the new root-only test.
* tests/Makefile.am (t9): New target, to run tests/cp/cp-a-selinux.
(all_t): Add t9.

Use a directory on a loopback device mounted with -o context=...
* tests/cp/cp-a-selinux: Since this test now runs mount and umount,
it is a root-only one.
2007-03-29 21:37:06 +02:00
Jim Meyering
c6922b6f7e * src/runcon.c: New program.
* src/Makefile.am (bin_PROGRAMS): Add runcon.
(runcon_LDADD): Define.
* README: Add runcon to the list of programs.
* AUTHORS: Add this: runcon: Russell Coker
* tests/help-version: Add runcon as an exception.
* man/Makefile.am (dist_man_MANS): Add runcon.1.
(runcon.1): New dependency.
* po/POTFILES.in: Add src/runcon.c.
2007-03-29 21:37:06 +02:00
Jim Meyering
8a86223d45 * tests/cp/cp-a-selinux: New file. Test for the bug reported in
* tests/cp/Makefile.am (TESTS): Add cp-a-selinux.

* tests/selinux: New file.
* tests/Makefile.am (EXTRA_DIST): Add selinux.
* tests/misc/selinux: Source the new script, rather than open coding it.

Change how "cp -a" and "cp --preserve=context" work with SELinux.
Now, cp -a attempts to preserve context, but failure to do so does
not change cp's exit status.  However "cp --preserve=context" is
similar, but failure *does* cause cp to exit with nonzero status.
* src/copy.h (struct cp_options) [require_preserve_context]: New member.
* src/copy.c (copy_reg, copy_internal): Implement the above.
* src/mv.c (cp_option_init): Initialize the new member.
* src/install.c (cp_option_init): Likewise.
* src/cp.c (cp_option_init): Likewise.
(decode_preserve_arg): Set it or reset it.

FIXME: add an on-writable-NFS-only test
2007-03-29 21:37:06 +02:00
Jim Meyering
5a7fe9c0f8 * tests/misc/selinux [VERBOSE]: Print version info for each
of the tested tools, not just ls.
2007-03-29 21:37:06 +02:00
Jim Meyering
3ea540c757 ls: Add support for SELinux and a slightly modified -Z option.
I started with the patches from Red Hat.
The entries below tell how the code evolved.

* src/ls.c (print_long_format, print_file_name_and_frills): When
there is no security context (due to getfilecon/lgetfilecon failing
with e.g. ENOTSUP), print it as "?", not "".
* src/ls.c (print_file_name_and_frills): Make -Z work without -l.
(length_of_file_name_and_frills): Likewise.

* src/ls.c: Remove the --lcontext and --scontext options.
Change the way -Z, --context work so that it no longer implies -l.
Thus, -Z -l will work like -lcontext and -Z without -l will work
like --scontext.

Adjust tests to reflect new 'ls -l' syntax -- affects only
systems with SELinux when operating on a file with no ACL.
These tests assumed that everything before the first space on
each line is the 10-byte mode string.  But there may also be a "+"
in the 11th column, just before the space.  However, note that this
is not new.  The same thing would have happened even without the
change below, when listing a file with an ACL.
* tests/chmod/equals, tests/cp/cp-parents, tests/cp/fail-perm:
* tests/cp/link-preserve, tests/install/basic-1, tests/misc/mknod:
* tests/mkdir/parents, tests/mkdir/special-1, tests/mv/partition-perm:

Don't make compilation depend on USE_ACL.  An SELinux security
context counts as an "alternate access control method", so ls
must output a "+" for each file with a security context.
* src/ls.c [struct fileinfo] (have_acl): Declare unconditionally.
(FILE_HAS_ACL): Remove macro definition.  Use f->have_acl directly.
(gobble_file): Record whether a file has a security context, and
update the condition used to determine whether to print the "+".
(gobble_file): Call getfilecon/lgetfilecon also when
format == long_format, so that we get the "+".

* src/ls.c (gobble_file): Add a comment explaining why (with a
security context option) ls doesn't exit nonzero due to e.g.,
getfilecon failing with errno == ENOTSUP.

* src/ls.c (gobble_file): Ignore failure of getfilecon if it's due
to ENOTSUP.

* src/ls.c (gobble_file): Factor out three small blocks using
getfilecon and lgetfilecon.
Don't ignore return value from getfilecon and lgetfilecon.

* src/ls.c (print_long_format): Don't use ?: (empty 2nd arg with C
ternary operator).
(print_scontext_format): Likewise.
(print_scontext): Declare to be "bool", not int.  Adjust uses.

* src/Makefile.am (dir_LDADD, ls_LDADD, vdir_LDADD): Add $(LIB_SELINUX).

* tests/misc/chcon: New file.
* tests/misc/chcon-fail: New file.
* tests/Makefile.am (check-root): Run new, root-only misc/chcon test.
* tests/misc/Makefile.am (TESTS): Add chcon and chcon-fail.

* tests/misc/Makefile.am (TESTS): Add selinux.
* tests/misc/selinux: New file.
* tests/help-version: Skip chcon.
2007-03-29 21:37:05 +02:00
Jim Meyering
de73024977 If strace malfunctions, skip the test rather than failing it.
* tests/mv/atomic: Required on a mips-unknown-linux-gnu system
running the aging linux-2.4.27-mipscvs-20040814.
2007-03-24 11:25:15 +01:00
Jim Meyering
25cdc8248d * tests/mv/hard-3: Correct the preceding change: $3 -> $2. 2007-03-22 22:11:03 +01:00
Paul Eggert
59e889f0f3 Improve a test script.
* tests/mv/hard-3: Check for 'ls' failure, too.
Generate more-useful debugging output when 'ls' fails.
2007-03-22 21:29:30 +01:00
Jim Meyering
3440b65ecf Fix a test script not to claim an ext2 file system is of type xfs.
* tests/du/slink: When using df --local and df --type=TYPE,
test only the exit code.  Don't bother with stdout.
Prompted by a report by Thomas Schwinge of an inaccurate diagnostic.
2007-03-21 17:19:30 +01:00
Jim Meyering
c63f4506cc Skip part of this test when "." is not a local file system.
* tests/mkdir/p-3: Likewise.
2007-03-20 16:47:36 +01:00
Jim Meyering
de540a76eb Skip part of this test when "." is not a local file system.
* tests/install/basic-1: Otherwise, it would fail on some NFS
file systems.
2007-03-20 13:26:28 +01:00
Jim Meyering
5bc4b89be8 Fix a generic NFS-related test failure.
* tests/mkdir/p-3: When setting up an unreadable "." in an
inaccessible parent, make the parent inaccessible *after* making "."
unreadable.  Otherwise, running "chmod a-r ." in an already-
inaccessible parent would fail on NFS with "Stale NFS file handle".

Signed-off-by: Jim Meyering <jim@meyering.net>
2007-03-18 22:37:54 +01:00
Jim Meyering
553d347d3e Fix a bug in how pr -m -s works.
* NEWS: Describe how the fix affects pr.
* src/pr.c (init_parameters): The --merge (-m) option does
not imply --expand-tabs (-e), so don't set "untabify_input".
Reported by Wis Macomson.
* tests/misc/pr: New file.  Test for the above fix.
* tests/misc/Makefile.am (TESTS): Add pr.
* THANKS: Update.
2007-03-18 16:21:26 +01:00
Jim Meyering
5b3313c120 * tests/misc/tty-eof: Add shuf to the list of tested commands. 2007-03-17 12:23:14 +01:00
Jim Meyering
0edae5eee6 Avoid test failure on NFS-mounted Solaris ZFS file system.
* tests/du/basic: Skip a test if "." is on a non-local file system.
2007-03-17 11:44:42 +01:00
Paul Eggert
369aaf7e5d * src/copy.c: Include filemode.h.
(overwrite_prompt): Say "try to overwrite", not "overwrite", to
make it clearer that the attempt may fail.  Problem reported by
Dan Jacobson in:
http://lists.gnu.org/archive/html/bug-coreutils/2007-03/msg00130.html
Output symbolic mode as well as numeric.
* tests/mv/i-2 (fail): Adjust to new prompt format.
2007-03-16 21:41:50 +01:00
Jim Meyering
24045feb85 Work around a failing test due to an NFS-based race condition.
* tests/cp/sparse: Accept a report that the copy is *smaller*.
2007-03-13 19:51:47 +01:00
Jim Meyering
04131454e3 The preceding change solved part of the problem. Now ginstall fails.
* tests/install/basic-1: Temporarily, don't redirect ginstall's
stderr to /dev/null, so I can see why the NFS autobuilder's NFS test
is failing.
2007-03-10 10:36:25 +01:00
Jim Meyering
bc86cb44e3 * tests/install/basic-1: When setting up an unreadable "." in an
inaccessible parent, make the parent inaccessible *after* making "."
unreadable.  Otherwise, running "chmod a-r ." in an already-
inaccessible parent would fail on NFS with "Stale NFS file handle".
Reported by Bob Proulx.
2007-03-10 09:53:49 +01:00
Jim Meyering
fe3fbf2f54 * tests/chgrp/basic: Also avoid test failures on Darwin 8.8.x (MacOS X 10.4). 2007-03-09 20:09:46 +01:00
Jim Meyering
222b7c46bd Avoid test failures on Darwin 7.9.0 (MacOS X 10.3.9)
* tests/chgrp/basic: Don't let failure by chgrp to set the
group of a symlink make this test fail.  Do give a diagnostic.
In the chgrp-no-change-ctime test, add darwin7.9.0 as another
known-failing system.
When failing on some other system, print $host_triplet, too.
Reported by Peter Fales.
2007-03-09 08:47:33 +01:00
Jim Meyering
f0537a71f1 pwd-unreadable-parent: Skip test on ia64/Linux, too.
* tests/misc/pwd-unreadable-parent: Also skip when $REPLACE_GETCWD.
Reported by Bob Proulx.
2007-03-03 21:38:16 +01:00
Jim Meyering
fe4f1227a5 pwd-unreadable-parent: Skip test on non-Linux/GNU systems.
* tests/misc/pwd-unreadable-parent: Rather than trying to decide
whether this test has a chance of succeeding, run it only when
$(host_os) is linux-gnu.  It was failing on powerpc-apple-darwin8.8.0
* tests/misc/Makefile.am (TESTS_ENVIRONMENT): Add host_os=$(host_os).
2007-03-02 14:25:48 +01:00
Jim Meyering
13a4b23e79 * tests/misc/pwd-long: Also allow "+" in $PWD. 2007-03-02 13:18:43 +01:00
Jim Meyering
55bc95b4d3 * tests/misc/df-P: This script *is* executable. 2007-02-28 08:11:41 +01:00
Jim Meyering
d480544281 Add a test for today's df -P fix.
* tests/misc/df-P: New file.
* tests/misc/Makefile.am (TESTS): Add df-P.
2007-02-27 19:35:27 +01:00
Jim Meyering
471eca0dd6 Don't skip this test on new-enough Linux/GNU systems.
* tests/misc/pwd-unreadable-parent: Test $REPLACE_GETCWD = 0,
rather than for __GETCWD_PREFIX in config.h (the latter is no
longer defined, ever, due to gnulib changes).
* tests/misc/Makefile.am (TESTS_ENVIRONMENT): Define REPLACE_GETCWD.
2007-02-24 20:57:14 +01:00
Jim Meyering
e98137ddd4 Remove the "gnits" option; it prohibits my using "+" as a version
string suffix, and all it does (beyond the default "gnu" option)
is to _require_ the THANKS file.
* configure.ac (AM_INIT_AUTOMAKE): Remove it.

Remove all AUTOMAKE_OPTIONS settings in Makefile.am files.
* tests/chgrp/Makefile.am, tests/chmod/Makefile.am:
* tests/chown/Makefile.am, tests/cp/Makefile.am:
* tests/du/Makefile.am, tests/expr/Makefile.am:
* tests/factor/Makefile.am, tests/general/Makefile.am:
* tests/install/Makefile.am, tests/ln/Makefile.am:
* tests/ls/Makefile.am, tests/mkdir/Makefile.am:
* tests/mv/Makefile.am, tests/readlink/Makefile.am:
* tests/rm/Makefile.am, tests/rmdir/Makefile.am:
* tests/seq/Makefile.am, tests/stty/Makefile.am:
* tests/tee/Makefile.am, tests/touch/Makefile.am:
2007-02-24 13:57:51 +01:00
Paul Eggert
3ea177e3fa * NEWS: sort no longer compresses temporaries by default.
* bootstrap.conf: Remove findprog.
* doc/coreutils.texi (sort invocation): The default is to not
compress.  Don't treat "" specially.
* src/sort.c: Don't include findprog.h.
(create_temp): Compress only if the user specified --compress-program.
* tests/misc/sort-compress: Adjusts tests to match new behavior.
2007-02-24 12:24:27 +01:00
Bruno Haible
2e140cfb42 * tests/readlink/can-e: Put the closing double-quote at the end of a
backquoted word, not in the middle. Works around a bug in sh on
OSF/1 4.0d.
* tests/readlink/can-f: Likewise.
* tests/readlink/can-m: Likewise.
2007-02-24 08:22:08 +01:00
Bruno Haible
33176a7269 * tests/du/slink: Skip the test if executing on an nfsv3 file system.
This avoids a test failure at least on OSF/1 4.0d.
2007-02-24 08:20:37 +01:00
Jim Meyering
cb121d8f36 With -Dlint, make shuf free all heap-allocated storage.
* src/shuf.c (main): Move declaration of input_lines to
function scope, and initialize to NULL, so we can free it.
[lint]: Free all malloc'd memory.
* tests/misc/shuf: Also test shuf's -e and -i options.
2007-02-23 15:18:16 +01:00
Paul Eggert
4e73fea3e3 Honor dd's noatime flag if possible, even if not supported on build fs
* doc/coreutils.texi (dd invocation): Warn that noatime might not be
reliable.
* src/dd.c (flags, usage): Look at O_NOATIME, not
HAVE_WORKING_O_NOATIME, to decide whether to support the noatime
flag, so that dd attempts O_NOATIME even if the build file system
does not support it.  Problem reported by Jim Meyering today in
bug-coreutils.
* tests/dd/misc: Generate a warning, not a failure, if noatime
exists but fails.
2007-02-22 19:09:35 +01:00