touch(1)ing a directory and failing yields return code 0
Jan Schaumann
jschauma at netmeister.org
Sat Apr 28 19:45:06 UTC 2007
When using touch(1) on a directory that I can't update the timestamp on
(say, if the filesystem is mounted read-only), it will return 0 as the
return value, even though it failed.
The reason this happens is in touch.c#225:
/* Try reading/writing. */
if (!S_ISLNK(sb.st_mode) && !S_ISDIR(sb.st_mode) &&
rw(*argv, &sb, fflag))
rval = 1;
else
warn("%s", *argv);
At this point, it tries to update the timestamp using utimes(2), which
failed, so it would continue to try to update it by reading and writing
the file.
However, since the file in question is a directory, it doesn't try this
and simply warns instead of setting the return value to 1.
$ mkdir foo
$ touch foo/bar
$ mount -u -o ro /
$ touch foo/bar
touch: foo/bar: Read-only file system
$ echo $?
1
$ touch foo
touch: foo: Read-only file system
$ echo $?
0
$
See NetBSD's touch(1):
/* Try reading/writing. */
if (!S_ISLNK(sb.st_mode) && rw(*argv, &sb, fflag))
rval = 1;
This still is slightly suboptimal, since the error message will be
$ touch foo
touch: foo: Is a directory
$ echo $?
1
$
But that's better than returning 0.
--
Probability factor of one to one. We have normality. I repeat, we have
normality. Anything you still can't cope with is therefore your own lookout.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-bugbusters/attachments/20070428/286352bd/attachment.pgp
More information about the freebsd-bugbusters
mailing list