summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--generic/tclPipe.c10
-rw-r--r--tests/exec.test30
-rw-r--r--unix/tclUnixPipe.c4
-rw-r--r--win/tclWinPipe.c4
5 files changed, 50 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 0efc97f..7d5a0f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-07-28 Donal K. Fellows <dkf@users.sf.net>
+
+ * generic/tclPipe.c (TclCreatePipeline): Arrange for POSIX systems to
+ * unix/tclUnixPipe.c (TclpOpenFile): use the O_APPEND flag for
+ * tests/exec.test (exec-19.1): files opened in a pipeline
+ like ">>this". Note that Windows cannot support such access; there is
+ no equivalent flag on the handle that can be set at the kernel-call
+ level. The test is unix-specific in every way. [Bug 1245953]
+
2005-07-26 Mo DeJong <mdejong@users.sourceforge.net>
* unix/configure: Regen.
diff --git a/generic/tclPipe.c b/generic/tclPipe.c
index 7339926..fc0e6c0 100644
--- a/generic/tclPipe.c
+++ b/generic/tclPipe.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclPipe.c,v 1.7.2.1 2004/07/02 23:37:31 hobbs Exp $
+ * RCS: @(#) $Id: tclPipe.c,v 1.7.2.2 2005/07/28 15:27:58 dkf Exp $
*/
#include "tclInt.h"
@@ -605,7 +605,13 @@ TclCreatePipeline(interp, argc, argv, pidArrayPtr, inPipePtr,
if (*p == '>') {
p++;
atOK = 0;
- flags = O_WRONLY | O_CREAT;
+
+ /*
+ * Note that the O_APPEND flag only has an effect on POSIX
+ * platforms. On Windows, we just have to carry on regardless.
+ */
+
+ flags = O_WRONLY | O_CREAT | O_APPEND;
}
if (*p == '&') {
if (errorClose != 0) {
diff --git a/tests/exec.test b/tests/exec.test
index 3613cba..bb6ecd4 100644
--- a/tests/exec.test
+++ b/tests/exec.test
@@ -11,7 +11,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: exec.test,v 1.16.2.4 2004/10/28 00:01:06 dgp Exp $
+# RCS: @(#) $Id: exec.test,v 1.16.2.5 2005/07/28 15:27:59 dkf Exp $
package require tcltest 2
namespace import -force ::tcltest::*
@@ -600,6 +600,34 @@ test exec-18.1 { exec cat deals with weird file names} {exec tempNotWin} {
set res
} {0 contents}
+# Note that this test cannot be adapted to work on Windows; that platform has
+# no kernel support for an analog of O_APPEND.
+test exec-19.1 {exec >> uses O_APPEND} {
+ -constraints {exec unix}
+ -setup {
+ set tmpfile [makeFile {0} tmpfile.exec-19.1]
+ }
+ -body {
+ # Note that we have to allow for the current contents of the
+ # temporary file, which is why the result is 14 and not 12
+ exec /bin/sh -c \
+ {for a in 1 2 3; do sleep 1; echo $a; done} >>$tmpfile &
+ exec /bin/sh -c \
+ {for a in a b c; do sleep 1; echo $a; done} >>$tmpfile &
+ # The above two shell invokations take about 3 seconds to
+ # finish, so allow 5s (in case the machine is busy)
+ after 5000
+ # Check that no bytes have got lost through mixups with
+ # overlapping appends, which is only guaranteed to work when
+ # we set O_APPEND on the file descriptor in the [exec >>...]
+ file size $tmpfile
+ }
+ -cleanup {
+ removeFile $tmpfile
+ }
+ -result 14
+}
+
# cleanup
foreach file {script gorp.file gorp.file2 echo cat wc sh sleep exit err} {
diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c
index dd9bc1c..0d3bd0b 100644
--- a/unix/tclUnixPipe.c
+++ b/unix/tclUnixPipe.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixPipe.c,v 1.23.2.4 2005/06/22 19:36:35 kennykb Exp $
+ * RCS: @(#) $Id: tclUnixPipe.c,v 1.23.2.5 2005/07/28 15:27:59 dkf Exp $
*/
#include "tclInt.h"
@@ -156,7 +156,7 @@ TclpOpenFile(fname, mode)
* so we can append to any data already in the file.
*/
- if (mode & O_WRONLY) {
+ if ((mode & O_WRONLY) && !(mode & O_APPEND)) {
TclOSseek(fd, (Tcl_SeekOffset) 0, SEEK_END);
}
diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c
index 323302a..dc9a917 100644
--- a/win/tclWinPipe.c
+++ b/win/tclWinPipe.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinPipe.c,v 1.33.2.13 2005/06/22 21:30:20 kennykb Exp $
+ * RCS: @(#) $Id: tclWinPipe.c,v 1.33.2.14 2005/07/28 15:27:59 dkf Exp $
*/
#include "tclWinInt.h"
@@ -670,7 +670,7 @@ TclpOpenFile(path, mode)
* Seek to the end of file if we are writing.
*/
- if (mode & O_WRONLY) {
+ if (mode & (O_WRONLY|O_APPEND)) {
SetFilePointer(handle, 0, NULL, FILE_END);
}