Hi all!
The touch(1) program which comes with plan9/plan9port fails when called on a
file which does not exist:
$ ls
$ 9 touch a
touch: a: cannot create: Invalid argument
$
What fails is a call to the create() function from lib9 (also part of
plan9port: src/lib9/create.c) which wraps open(2). create() calls open(2) with
flags O_CREAT and O_TRUNC, along with one of O_RDONLY, O_WRONLY and O_RDWR as
provided by the caller.
touch(1) calls create() with OREAD (which translates to O_RDONLY) on line 57 of
src/cmd/touch.c. The caveats section of open(2) manual page mentions this is not
a valid combination.
The documentation of GNU libc also mentions that O_RDONLY + O_TRUNC is
unspecified [1], although in practice, the file is created on a GNU/Linux
system.
The following patch fixes the issue:
--- src/cmd/touch.c.orig Fri Jun 28 18:19:08 2013
+++ src/cmd/touch.c Fri Jun 28 18:19:19 2013
@@ -54,7 +54,7 @@
fprint(2, "touch: %s: cannot wstat: %r\n", name);
return 1;
}
- if((fd = create(name, OREAD, 0666)) < 0) {
+ if((fd = create(name, OWRITE, 0666)) < 0) {
fprint(2, "touch: %s: cannot create: %r\n", name);
return 1;
}
If others in this list agree that this is indeed a bug, I will report it
upstream.
Cheers,
Alexis
[1]:
http://www.gnu.org/software/libc/manual/html_node/Open_002dtime-Flags.html#Open_002dtime-Flags