diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2007-02-03 18:45:46 +0100 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-02-03 18:45:46 +0100 |
commit | b28a8851ed22dbf0cd123974a0c97ae0b82bec2b (patch) | |
tree | 2ee82ce576b7026f2b99268044e627daf203fb81 /tests/cp | |
parent | 1c73876f5f7973ca41caaf0ce326254b1081713a (diff) | |
download | coreutils-b28a8851ed22dbf0cd123974a0c97ae0b82bec2b.tar.xz |
* NEWS: Document fix for cp --preserve=mode.
* src/copy.c (copy_internal): Omit the group- or other-writeable
permissions when creating a directory, to avoid a race condition
if the special mode bits aren't right just after the directory is
created.
* src/cp.c (make_dir_parents_private): Likewise.
* tests/cp/parent-perm-race: Test for the "cp --preserve=mode"
race fix in copy.c.
Diffstat (limited to 'tests/cp')
-rwxr-xr-x | tests/cp/parent-perm-race | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/tests/cp/parent-perm-race b/tests/cp/parent-perm-race index 80c95a69b..d2870bcea 100755 --- a/tests/cp/parent-perm-race +++ b/tests/cp/parent-perm-race @@ -1,7 +1,7 @@ #!/bin/sh # Make sure cp -pR --parents isn't too generous with parent permissions. -# Copyright (C) 2006 Free Software Foundation, Inc. +# Copyright (C) 2006, 2007 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 @@ -32,37 +32,47 @@ framework_failure=0 mkdir -p $tmp || framework_failure=1 cd $tmp || framework_failure=1 -umask 022 -mkdir -p a d || framework_failure=1 -mkfifo a/fifo || { - echo "$0: fifos not supported; skipping this test." 1>&2 - (exit 77); exit 77 -} - -# Copy a fifo's contents. That way, we can examine d/a's -# state while cp is running. -cp -p -R --copy-contents --parents a d & -cp_pid=$! - -( - # Now 'cp' is reading the fifo. - # Check the permissions of the temporary destination - # directory that 'cp' has made. - ls -ld d/a >d/ls.out - - # Close the fifo so that "cp" can continue. But output first, - # before exiting, otherwise some shells would optimize away the file - # descriptor that holds the fifo open. - echo foo -) >a/fifo - -case `cat d/ls.out` in -d???--[-S]--[-S]*) - fail=0;; -*) - fail=1;; -esac - -wait $cp_pid || fail=1 +umask 002 +mkdir mode ownership d || framework_failure=1 +chmod g+s d 2>/dev/null # The cp test is valid either way. + +fail=0 + +for attr in mode ownership +do + mkfifo $attr/fifo || { + echo "$0: fifos not supported; skipping this test." 1>&2 + (exit 77); exit 77 + } + + # Copy a fifo's contents. That way, we can examine d/$attr's + # state while cp is running. + cp --preserve=$attr -R --copy-contents --parents $attr d & + cp_pid=$! + + ( + # Now 'cp' is reading the fifo. + # Check the permissions of the temporary destination + # directory that 'cp' has made. + ls -ld d/$attr >d/$attr.ls + + # Close the fifo so that "cp" can continue. But output first, + # before exiting, otherwise some shells would optimize away the file + # descriptor that holds the fifo open. + echo foo + ) >$attr/fifo + + ls_output=`cat d/$attr.ls` || fail=1 + case $attr,$ls_output in + ownership,d???--[-S]--[-S]* | \ + mode,d????-??-?* | \ + mode,d??[-x]?w[-x]?-[-x]* ) + ;; + *) + fail=1;; + esac + + wait $cp_pid || fail=1 +done (exit $fail); exit $fail |