summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2014-04-29ptx: fix whitespace trimming with multiple filesPádraig Brady
This issue was identified by running the test suite with http://code.google.com/p/address-sanitizer/ which is included in GCC 4.8 and enabled with -fsanitize=address This was checked on Fedora 20 with GCC 4.8 as follows: $ yum install libasan # http://bugzilla.redhat.com/991003 $ rm -f src/ptx.o $ make check AM_CFLAGS='-fsanitize=address' SUBDIRS=. VERBOSE=yes $ failure identified in tests/test-suite.log To see this particular failure triggered with multiple files: $ src/ptx <(echo a) <(echo a) 2>&1 | asan_symbolize.py -d ================================================================= ==32178==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000e74f at pc 0x435442 bp 0x7fffe8a1b290 sp 0x7fffe8a1b288 READ of size 1 at 0x60200000e74f thread T0 #0 0x435441 in define_all_fields coreutils/src/ptx.c:1425 #1 0x7fa206d31d64 in __libc_start_main ??:? #2 0x42f77c in _start ??:? 0x60200000e74f is located 1 bytes to the left of 3-byte region [0x60200000e750,0x60200000e753) allocated by thread T0 here: #0 0x421809 in realloc ??:? #1 0x439b4e in fread_file coreutils/lib/read-file.c:97 Shadow bytes around the buggy address: 0x0c047fff9c90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff9ca0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff9cb0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff9cc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff9cd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fd fd =>0x0c047fff9ce0: fa fa 03 fa fa fa fd fd fa[fa]03 fa fa fa 00 00 0x0c047fff9cf0: fa fa 04 fa fa fa 04 fa fa fa fd fa fa fa fd fa 0x0c047fff9d00: fa fa 00 fa fa fa fd fa fa fa 00 fa fa fa 00 fa 0x0c047fff9d10: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa 0x0c047fff9d20: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa 0x0c047fff9d30: fa fa fd fa fa fa 00 fa fa fa 00 fa fa fa 00 fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Heap right redzone: fb Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack partial redzone: f4 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 ASan internal: fe ==32178==ABORTING The initial report and high level analysis were from Jim Meyering... "The underlying problem is that swallow_file_in_memory() is setting the contents of the global text_buffer for the first file, then updating it (clobbering old value) for the second file. Yet, some pointers to the initial buffer have been squirreled away and later, one of them (keyafter) is presumed to point into the new "text_buffer", which it does not. The subsequent SKIP_WHITE_BACKWARDS use backs up "cursor" and goes out of bounds." * src/ptx.c (text_buffers): Maintain references for the limits of each buffer corresponding to each file, rather than just the last processed. (struct OCCURS): Add a member to map back to the corresponding file. Note normally this could be computed from the "reference" member rather than needing the extra storage, however this is not possible when in --references mode. (find_occurs_in_text): Reference the array rather than a single entry. (define_all_fields): Likewise. Also avoid computing the file index since this is now stored directly. (main): Update text_buffers[] array rather than a single text_buffer. * tests/misc/ptx-overrun.sh: Even though this issue is already triggered with AddressSanitizer, add a new case to demonstrate the whitespace trimming issue, and to trigger without AddressSanitizer. Fixes https://bugs.gnu.org/16171
2014-04-18tests: make ls tests independent of COLORTERM envPádraig Brady
Since the recent commit v8.22-68-g08783f1, ls coloring is now dependent on the COLORTERM environment variable. * tests/envvar-check: Unset COLORTERM from test environment. * tests/ls/color-dtype-dir.sh: Ensure coloring is used. * tests/misc/ls-misc.pl: Likewise. Prompted by the continuous integration build failure at: http://hydra.nixos.org/build/10397646
2014-04-17ls: don't output colors with unknown TERM env variableGuilherme de Almeida Suckevicz
--colors controls whether to output colors depending on whether we're connected to a terminal or not, while this change gives control over which terminals we output colors to. * NEWS: Mention the change in behavior. * src/ls.c (known_term_type): A new function to search the static list from dircolors.h (parse_ls_colors): Honor the TERM when both LS_COLORS and COLORTERM are non empty. * tests/ls/color-term.sh: A new test. * tests/local.mk: Reference the new test. Fixes http://bugs.gnu.org/15992
2014-04-11tests: fix false dd conv=sparse failure on newer XFSPádraig Brady
* tests/dd/sparse.sh: When testing that a hole is created, use an existing sparse destination file, so that we're not write extending the file size, and thus avoiding speculative preallocation which can result in smaller holes than requested. Workaround suggested by Brian Foster
2014-04-05maint: various cleanupsPádraig Brady
* tests/misc/numfmt.pl: Fix comment misspelling. * src/cut.c: Likewise. * src/tsort.c (detect_loop): Replace an fprintf() with error().
2014-04-05shred: overwrite inode storage used by some file systemsPádraig Brady
* doc/coreutils.texi (shred invocation): Mention some reasons why clearing slack space might be useful. * src/shred.c (do_wipefd): Add initial writes for each pass for small regular files in case the storage for those is in the inode, and thus a larger write up to a block size would bypass that. Move the direct I/O control to... (dopass): ... here so we can avoid enabling it for these small initial writes. It's better to retry direct I/O for each pass anyway to handle the case where direct I/O is disabled for only the last portion of a file when the size is not a multiple of the block size. Note we don't avoid the sync for the initial write as it will be small but more importantly could be on a different part of the disk and so worth doing independently to ensure the write is not discarded. * tests/misc/shred-exact.sh: Check some more direct I/O cases. * NEWS: Mention the improvements. The inode storage issue was mentioned by Paul Eggert.
2014-04-04shred: avoid a data pass on empty filesPádraig Brady
* src/shred.c (do_wipefd): Don't increase the size written for an empty file up to a full block. Also increase the size to OFF_T_MAX in the edge case where we do overflow. * NEWS: Mention the shred improvements from recent changes. * tests/misc/shred-passes.sh: Adjust as we no longer write a BLKSIZE of data for empty files.
2014-03-31head: fix bug with head -c-N when stdin is not at startPaul Eggert
* src/head.c (elide_tail_bytes_file): Fix typo in lseek invocation. * tests/misc/head-c.sh: Add test for this bug. * NEWS: Document this.
2014-03-26mv: fix issues with previous prompt adjustmentsPádraig Brady
* src/copy.c (overwrite_ok): Fix the gettext calls so that the second string is tagged for translation. Display the correct "replace ..." prompt when in move_mode. * tests/mv/i-3.sh: Display the output on failure to ease debugging.
2014-03-26ptx: avoid --format long option falling through into --helpBernhard Voelker
* src/ptx.c (main): Add a 'break' after the --format handling case. Otherwise it would fall through into the usage case. * tests/misc/ptx.pl: Add test cases for --format=tex and --format=roff. * NEWS (Bug fixes): Mention the fix. Bug introduced in 1999-04-04 commit, SH-UTILS-1_16f-269-gd815c15. Spotted by coverity (MISSING_BREAK).
2014-03-24cp: improve quality of overwrite promptPaul Eggert
* src/copy.c (overwrite_prompt): New arg X. All callers changed. Use X to improve the quality of the prompt (Bug#17087). * tests/mv/i-2.sh, tests/mv/i-3.sh: Change test to match new prompt.
2014-03-19chmod: fix erroneous warnings with -R --changesDylan Simon
For files with "special" bits set, we would stat the relative file name in the wrong directory, giving an erroneous ENOENT diagnostic. This issue was introduced with commit v5.92-653-gc1994c1 which changed fts to not change directory on traversal. * src/chmod.c (mode_changed): Use fts->fts_cwd_fd with fstatat rather than stat. All callers changed. * tests/chmod/c-option.sh: Add a test case. * NEWS: Mention the fix. Fixes http://bugs.gnu.org/17035
2014-03-13ln: with -sr, don't segfault for a TARGET of ''Jim Meyering
Prior to this change, "ln -sr '' F" would segfault, attempting to read path2[1] in relpath.c's path_common_prefix function. This problem arises whenever canonicalize_filename_mode returns NULL. * src/ln.c (convert_abs_rel): Call relpath only when both canonicalize_filename_mode calls return non-NULL. * tests/ln/relative.sh: Add a test to trigger this failure. * THANKS.in: List reporter's name/address. * NEWS (Bug fixes): Mention it. Reported by Erik Bernstein in 739752@bugs.debian.org. Fixes http://bugs.gnu.org/17010.
2014-03-13chroot: improve --userspec and --groups look-upPádraig Brady
- Support arbitrary numbers in --groups, consistent with what is already done for --userspec - Avoid look-ups entirely for --groups items with a leading '+' - Support names that are actually numbers in --groups - Ignore an empty --groups="" option for consistency with --userspec - Look up both inside and outside the chroot with inside taking precedence. The look-up outside may load required libraries to complete the look-up inside the chroot. This can happen for example with a 32 bit chroot on a 64 bit system, where the 32 bit NSS plugins within the chroot fail to load. * src/chroot.c (parse_additional_groups): A new function refactored from set_addition_groups(), to just do the parsing. The actual setgroups() call is separated out for calling from the chroot later. (main): Call parse_user_spec() and parse_additional_groups() both outside and inside the chroot for the reasons outlined above. * tests/misc/chroot-credentials.sh: Ensure arbitrary numeric IDs can be specified without causing look-up errors. * NEWS: Mention the improvements. * THANKS.in: Add Norihiro Kamae who initially reported the issue with a proposed patch. Also thanks to Dmitry V. Levin for his diagnosis and sample patch.
2014-03-05tests: avoid the :> construct which can hide errorsPádraig Brady
On most shells `:>file || framework_failure_` will not evaluate the framework_failure_ even if there was an error writing the file. shells which do evaluate the failure are ksh 93u+ and bash 4.2, while shells wich don't include bash 4.3, solaris, freebsd, dash. Furthermore this construct is problematic on Solaris 10 sh, which will try to optimize away a `:' command in a loop after the first iteration, even if it is redirected. * tests/cp/link-deref.sh: Remove the leading colon on redirections. * tests/cp/reflink-perm.sh: Likewise. * tests/id/zero.sh: Likewise. * tests/install/install-C.sh: Likewise. * tests/misc/env.sh: Likewise. * tests/misc/md5sum-bsd.sh: Likewise. * tests/misc/runcon-no-reorder.sh: Likewise. * tests/mv/partition-perm.sh: Likewise. * tests/rm/r-root.sh: Likewise. * tests/split/l-chunk.sh: Likewise. * tests/split/line-bytes.sh: Likewise. * tests/tail-2/inotify-rotate.sh: Likewise. * tests/tail-2/retry.sh: Likewise. * tests/tail-2/symlink.sh: Likewise. * tests/tail-2/wait.sh: Likewise. * tests/touch/read-only.sh: Likewise. + cfg.mk (sc_prohibit_colon_redirection): A new syntax check to avoid further instances of this creeping in.
2014-03-05tests: fix false failure in nohup.sh in non tty buildsPádraig Brady
* tests/misc/nohup.sh: When running tests without a controlling tty, an exec failure is triggered in a subshell, which causes POSIX shells to immediately exit the subshell. This was brought to notice by the newly conforming bash 4.3. Fixes http:/bugs.gnu.org/16940
2014-02-27date: fix crash or infinite loop when parsing a malformed TZ=""Pádraig Brady
* NEWS: Mention the fix. * gnulib: Update to incorporate the fix. This is the only change in this gnulib update. * tests/misc/date.pl: Add a test for this case. Fixes http://bugs.gnu.org/16872
2014-02-23shuf: with -r, don't dump core if the input is emptyPaul Eggert
Problem reported by valiant xiao in <http://bugs.gnu.org/16855>. * NEWS: Document this. * src/shuf.c (main): With -r, report an error if the input is empty. * tests/misc/shuf.sh: Test for the bug.
2014-02-10cp: with --link always use linkat() if availablePádraig Brady
* src/copy.c (copy_reg): If linkat() is available it doesn't matter about the gnulib emulation provided, and thus the LINK_FOLLOWS_SYMLINKS should not have significance here. This was noticed on FreeBSD and the consequence is that cp --link will create hardlinks to symlinks there, rather than emulating with symlinks to symlinks. * tests/cp/link-deref.sh: Adjust the checks to cater for all cases where hardlinks to symlinks are supported.
2014-02-09head,tail: consistently diagnose write errorsPádraig Brady
If we can't output more data, we should immediately diagnose the issue and exit rather than consuming all of input (in some cases). * src/tail.c (xwrite_stdout): Also diagnose the case where only some data is written. Also clearerr() to avoid the redundant less specific error from atexit (close_stdout); * src/head.c (xwrite_stdout): Copy this new function from tail, and use it to write all output. * tests/misc/head-write-error.sh: A new test to ensure we exit immediately on write error. * tests/local.mk: Reference the new test.
2014-02-09head: fix --lines=-0 outputting nothing if no newline at EOFАлексей Шилин
* src/head.c (elide_tail_lines_pipe): Just output all input in this case to avoid the issue and also avoid redundant '\n' processing. (elide_tail_lines_seekable): Likewise. * tests/misc/head-elide-tail.pl: Add tests for no '\n' at EOF. * NEWS: Mention the fix. Fixes http://bugs.gnu.org/16329
2014-02-09od: add an --endian option to control byte swappingNiels Möller
* src/od.c (main): Handle the new --endian option, taking "little" and "big" as parameters. (usage): Describe the new option. (PRINT_FIELDS): Adjust to swap bytes if required. * tests/misc/od-endian.sh: A new test to verify the byte swapping operations for hex (ints) and floats for all sizes between 1 and 16 inclusive. * test/local.mk: Reference the new test. * doc/coreutils.texi (od invocation): Describe the new option. * NEWS: Mention the new feature.
2014-01-24tests: skip chown/separator with conflicting group IDsAssaf Gordon
* tests/chown/separator.sh: skip test if the user's group has multiple entries. Fixes http://bugs.gnu.org/16532
2014-01-17ln: fix replacing symbolic links whose targets can't existPádraig Brady
* src/ln.c (errno_nonexisting): A new function to determine if the errno implies that a file doesn't or can't (currently) exist. (target_directory_operand): Use the new function to expand the set of errors we handle. * tests/ln/sf-1.sh: Add test cases for the newly handled errors. * THANKS.in: Mention the reporter. * NEWS: Mention the bug fix.
2014-01-14tests: restrict a recent SELinux test to SELinux systemsPádraig Brady
* tests/cp/no-ctx.sh: Since the test diagnoses whether the intercepted lgetfilecon() calls are actually called or not, restrict the test to systems where that occurs. The test cases are minimal on non SELinux systems and should be well covered by other tests. Reported-by: Bernhard Voelker
2014-01-13copy: fix a segfault in SELinux context copying codeNicolas Iooss
* src/selinux.c (restorecon_private): On ArchLinux the `fakeroot cp -a file1 file2` command segfaulted due to getfscreatecon() returning a NULL context. So map this to the sometimes ignored ENODATA error, rather than crashing. * tests/cp/no-ctx.sh: Add a new test case. * tests/local.mk: Reference the new test. * NEWS: Mention the fix. Fixes http://bugs.gnu.org/16335
2014-01-13maint: tests: refactor gcc commands for building shared libPádraig Brady
* init.cfg (gcc_shared_): A new function refactored from tests. (require_gcc_shared_): Adjust to call gcc_shared_() to build the test library, and remove that library before the function returns. * tests/cp/nfs-removal-race.sh: Call the new gcc_shared_(). * tests/df/no-mtab-status.sh: Likewise. * tests/df/skip-duplicates.sh: Likewise. * tests/ls/getxattr-speedup.sh: Likewise. * tests/rm/r-root.sh: Likewise.
2014-01-13copy: fix SELinux context preservation for existing directoriesPádraig Brady
* src/copy.c (copy_internal): Use the global process context to set the context of existing directories before they're populated. This is more consistent with the new directory case, and fixes a bug for existing directories where we erroneously set the context to the last copied descendent, rather than to that of the source directory itself. * tests/cp/cp-a-selinux.sh: Add a test for this case. * NEWS: Mention the fix. * THANKS.in: Add reporter Michal Trunecka.
2014-01-09tests: avoid FP failure when cp fails for /proc/cpuinfoBernhard Voelker
On emulated aarch64 systems like in the qemu-based OpenBuildService of openSUSE, cp fails to copy /proc/cpuinfo because the inode number changes between the initial stat() call and copying the file: $ cp /proc/cpuinfo exp cp: skipping file '/proc/cpuinfo', as it was \ replaced while being copied * tests/cp/proc-zero-len.sh: When cp fails, check on the above error message to skip the test.
2014-01-02maint: update all copyright year number rangesBernhard Voelker
Run "make update-copyright", but then also run this, perl -pi -e 's/2\d\d\d-//' tests/sample-test to make that one script use the single most recent year number.
2014-01-02build: update gnulib submodule, bootstrap and tests/init.sh to latestBernhard Voelker
* gnulib: Update to latest. * bootstrap: Update from gnulib. * tests/init.sh: Likewise.
2013-12-13tests: avoid unlikely deadlock in dd/no-allocate on some shellsPádraig Brady
* test/dd/no-allocate.sh: Use 'wait' to ensure we don't have multiple writers to the fifo, which was seen to trigger a very hard to reproduce deadlock with make -j20 on solaris. Also avoid writing to the fifo with the shell; instead using dd. (check_dd_seek_alloc): A new function refactored from the various cases, which are now constructed from function parameters.
2013-12-13tests: restrict cp --link inode comparisons to compatible systemsPádraig Brady
* tests/cp/link-deref.sh: On systems were cp can't determine if gnulib linkat() emulation might create a symlink instead of a hardlink to a symlink, copy.c will create a symlink to the symlink so that it has more control over its metadata. Also even if the system supports this operation, the particular file system under test may not. So avoid the hardlinked symlink verification in these cases. This fixes a false failure on aix, solaris and freebsd.
2013-12-11tests: df/total-unprocessed: fix false failure with lofsPádraig Brady
* tests/df/total-unprocessed.sh: Skip the test when we can't determine the file system type as the exclusion filter is not applied in that case. "lofs" being ignored is effectively an unknown file system type.
2013-12-11tests: avoid warnings due to new filefrag -v formatPádraig Brady
* tests/cp/sparse-fiemap.sh: Newer versions of filefrag output more fields, in different orders, so handle that to avoid warnings.
2013-12-09tests: fix false failure due to xargs usagePádraig Brady
* tests/readlink/multi.sh: Ensure there is a trailing delimeter or xargs may (on AIX 7 at least) suppress the last argument.
2013-12-09tests: fix false failure on systems without /dev/stdinPádraig Brady
* tests/rm/interactive-once.sh: Ensure the expected output matches with the output on systems without /dev/stdin (like AIX 7). Also change some fail=1 to a more appropriate framework_failure_.
2013-12-09tests: fix false failure due to gdb inline function handlingPádraig Brady
Inline functions are awkward to breakpoint as mentioned at: https://sourceware.org/bugzilla/show_bug.cgi?id=10738 The normal case here was for the breakpoint on the inline function to fail, resulting in a 10s delay before skipping the test. However on GCC 4.7.2 on ppc64 at least it was seen that the test failed erroneously due to the breakpoint being successfully set on an "out of line" function, but an inline function was actually being called. * tests/tail-2/inotify-race.sh: Switch to a line based breakpoint, rather than a symbol base one, which avoids issues with breakpoints on inline functions. Also skip_ on the initial breakpoint check in case the breakpoint is not traversed which would be the case on remote file systems for example.
2013-12-09tail: use consistent diagnostics with and without inotifyPádraig Brady
* src/tail.c: With inotify, when a file is initially absent, we fstat(-1) for that file spec, thus recording an errnum of EBADF, which caused the "has become accessible" diagnostic to be issued, when the file first appears. Instead we avoid the fstat(-1) and thus emit the more natural and consistent "has appeared" diagnostic. * tests/tail-2/retry.sh: Use the new diagnostic which also causes this test to pass on systems without inotify.
2013-12-09tests: avoid false df failure with nfs and lofsBernhard Voelker
* tests/df/total-unprocessed.sh: -t nfs and --local are _not_ mutually exclusive on solaris, with lofs mounts.
2013-12-07tests: avoid problematic $(< file) shell constructPádraig Brady
* tests/cp/link-deref.sh: This was seen to cause an issue with dash v0.5.6 at least, so change to a simpler expression.
2013-12-07tests: fix false failure on platforms using newfstatatPádraig Brady
* tests/ls/stat-free-color.sh: Add newfstatat to the list of syscalls to trace. Also add all "stat" syscalls to the list of syscalls that we verify that strace supports. Also only create a single dangling symlink to check, since we already only check for a single "stat" call. Fixes http://bugs.gnu.org/16075 seen on AArch64
2013-12-07tests: avoid a false memory leak test failurePádraig Brady
* tests/misc/shuf-reservoir.sh: Restrict the valgrind "exit on leak" behavior to developer environments where specific "lint" code is enabled to avoid inconsequential leaks.
2013-12-06tests: fix shuf test verifying that -i and -e can not be combinedBernhard Voelker
Previously, the test triggered another error diagnostic: shuf: invalid input range ‘-e’ and therefore eclipsed the expected one: shuf: cannot combine -e and -i options While at it, reindent a line with more than 80 characters, present since the previous commit to silence sc_long_lines. * tests/misc/shuf.sh: Pass a valid range to the -i option.
2013-12-06shuf: --repeat, not --repetitions; default --head-count is infinityPaul Eggert
Original problem reported by Philipp Thomas in <http://bugs.gnu.org/16061>. * NEWS: shuf --repeat, not shuf --repetitions. * doc/coreutils.texi (shuf invocation): * src/shuf.c (usage, long_opts, main): * tests/misc/shuf.sh: Likewise. Also, the default head-count is infinity.
2013-12-05selinux: fix --context=CTX for cp and diagnose defaultcon() errorsPádraig Brady
* src/selinux.h (ignorable_ctx_err): A new function used to determine if a warning should be given after a call to defaultcon() or restorecon(). * src/cp.c (main): Fix the setfscreatecon() call to use the argument passed by the user. * src/mkdir.c (make_ancestor): Show all but "ignoreable" errors from defaultcon() and restorecon(). * tests/misc/selinux.sh: Add a test run as root in selinux enforcing mode, to ensure cp --context=invalid is honored and fails immediately.
2013-12-04df: dereference symlinks to disk device nodesPádraig Brady
This is so the matching for the device is done on the canonical name of the disk node, rather than on the path of the symlink. In any case the user will generally want to use the symlink target. * src/df.c (get_disk): Canonicalize the passed file, before matching against the list of mounted file system devices. Note we pass the original symlink name to the "file" output field, as the symlink target is usually available through the "source" field. * tests/df/df-symlink.sh: Test the dereferencing operation. * tests/local.mk: Mention the new test. * NEWS: Mention the fix. Reported by Ondrej Oprala
2013-11-29tests: add a test for rm -r "/"Bernhard Voelker
* tests/rm/r-root.sh: Add a non-root test. * tests/local.mk (all_tests): Mention the test.
2013-11-27selinux: adjust utils to run restorecon with -ZPádraig Brady
cp, mv, install, mkdir, mkfifo, mknod are adjusted so that: -Z no longer accepts an argument. -Z or --context without an argument do not warn without SELinux. --context with an argument will warn without SELinux. * src/local.mk: Reference the new selinux module where required. * src/system.h: Make the argument to --context optional. * src/mkdir.c: Likewise. Also handle the SMACK case for --context. Note we currently silently ignore -Z with SMACK. * src/mkfifo.c: Likewise. * src/mknod.c: Likewise. * src/install.c: Likewise. Note install(1) by default already set the context for target files to their system default, albeit with an older method. Use the -Z option to select between the old and new context restoration behavior, and document the differences and details for how context restoration is done in new and old methods, with a view disabling the old method entirely in future. * src/cp.c: Make the argument to --context optional. Note -Z implies --no-preserve=context. I.E. -Z overrides that aspect of -a no matter what order specified. (struct cp_options): Document the context handling options. (main): Check/adjust option combinations after all options are processed, to both simplify processing and to make handling independent of order of options on the command line. Also improve the diagnostics from a failed call to setfscreatecon(). (set_process_security_ctx): A new function, refactored to set the default context from the source file, or with the type adjusted as per the system default for the destination path. (set_file_security_ctx): A new function refactored to set the security context of an existing file, either based on the process context or the default system context for a path. (copy_internal): Use the refactored functions to simplify error handling and consistently fail or warn as needed. (copy_reg): Likewise. (copy_internal): With --preserve=context, also copy context from non regular files. Note for directories this may impact the copying of subsequent files to that directory? (copy_attr): If we're handling SELinux explicitly, then exclude to avoid the redudant copy with --preserve=context, and the problematic copy with -Z. Note SELinux attribute exclusion also now honors cp -a --no-preserve=context. Note there was a very small window over 10 years ago, where attr_copy_file was available, while attr_copy_check_permissions was not, so we don't bother adding an explicit m4 check for the latter function. * src/mv.c: Support --context, but don't allow specifying an argument. * src/chcon.c: Adjust a comment to be specific to SELinux. * src/runcon.c: Likewise. * src/copy.c: Honor the context settings to "restorecon" as appropriate. * src/copy.h: Add a new setting to select "restorecon" functionality. * tests/mkdir/selinux.sh: s/-Z/--context=/ * tests/cp/cp-a-selinux.sh: Augment this test with cases testing basic -Z functionality, and also test the various invalid option combinations and option precedence. * tests/mkdir/restorecon.sh: Add a new test for the more involved mkdir -Z handling, since the directory changing and non existent directories need to be specially handled. Also check the similar but simpler handling of -Z by mk{nod,fifo}. * tests/local.mk: Reference the new test. * doc/coreutils.texi (cp invocation): Update as per interface changes. (mv invocation): Likewise. (install invocation): Likewise. (mkfifo invocation): Likewise. (mknod invocation): Likewise. (mkdir invocation): Likewise. * NEWS: Mention the new feature and change in behavior.
2013-11-27shred: provide --remove methods to avoid excessive syncingPádraig Brady
A sync operation is very often expensive. For illustration I timed the following python script which indicated that each ext4 dir sync was taking about 2ms and 12ms, on an SSD and traditional disk respectively. import os d=os.open(".", os.O_DIRECTORY|os.O_RDONLY) for i in range(1000): os.fdatasync(d) So syncing for each character for each file can result in significant delays. Often this overhead is redundant, as only the data is sensitive and not the file name. Even if the names are sensitive, your file system may employ synchronous metadata updates, which also makes explicit syncing redundant. * tests/misc/shred-remove.sh: Ensure all the new parameters actually unlink the file. * doc/coreutils.texi (shred invocation): Describe the new parameters to the --remove option. * src/shred.c (Usage): Likewise. (main): Parse the new options. (wipename): Inspect the new enum to see which of the now optional tasks to perform. * NEWS: Mention the new feature. * THANKS.in: Add reporter Joseph D. Wagner