file copy -force does an invalid call to open
Opencdd157d4849df09ab1d594938aa0d2f4694d643fCreated 10 years agoUpdated 10 years ago
Descriptionplain2016-07-18 14:52:40
The following TCL command:
file copy -force in.txt out.txt
will produce this call to "open" syscall:
open("out.txt", O_WRONLY|O_CREAT|O_TRUNC, 0100664) = 6
We can see that beside the mode ("664") there is the S_IFREG flag (0100000, regular flag) which is set. According to open man page, there shouldn't be any other bit in "mode" than the permission bits (see http://man7.org/linux/man-pages/man2/open.2.html "According to POSIX, the effect when other bits are set in mode is unspecified...")
I found that some filesystem doesn't like this bit to be set.
I see that "file copy -force" do a stat on the file before doing the open and I suspect TCL to blindly reuse the flag gained by the stat command but it should only use the lower bits.
aspectplain2016-07-19 03:58:01
> I suspect TCL to blindly reuse the flag gained by the stat command but it should only use the lower bits. This appears to be the case: http://core.tcl.tk/tcl/artifact/1b60acbf412a1ef8?ln=574 This looks like the right place to mask the permissions parameter, but we should be careful. To quote more fully from the Linux manual: > According to POSIX, the effect when other bits (than 0777) are set in > mode is unspecified. On Linux, the following bits are also honored in > mode: (refers to mode & 07000 - setu/gid and sticky bits). Should [file copy] on Linux also copy these bits? What about other unixes? This smells like one of those dusty under-specified corners of POSIX where the right thing for all platforms is not always going to be obvious.
Tomoplain2016-07-21 14:50:41
I would say that we can keep all bits in the 07777 mask. Upper bits are informative bits for stat command. It shouldn't break anything. What do you think ?
dkfhtml2016-07-24 12:52:53
We certainly shouldn't be setting the file type descriptor bits. There's literally no reason at all for handing those over.
Log in (anonymous is fine) to add a comment.