bin/112213: touch(1)ing a directory and failing yields return
code 0
Jaakko Heinonen
jh at saunalahti.fi
Tue Jun 10 15:40:04 UTC 2008
The following reply was made to PR bin/112213; it has been noted by GNATS.
From: Jaakko Heinonen <jh at saunalahti.fi>
To: bug-followup at FreeBSD.org, jschauma at netmeister.org
Cc:
Subject: Re: bin/112213: touch(1)ing a directory and failing yields return
code 0
Date: Tue, 10 Jun 2008 18:38:30 +0300
The if statement you are referring to seems to be incorrect.
202 /* Try reading/writing. */
203 if (!S_ISLNK(sb.st_mode) && !S_ISDIR(sb.st_mode) &&
204 rw(*argv, &sb, fflag))
205 rval = 1;
206 else
207 warn("%s", *argv);
rval is correctly set to 1 if rw() fails but if rw() succeeds a bogus
warning is printed. Secondly rval is not set at all when *argv is a
symbolic link or directory. (It should be set because earlier attempts
to set times failed.)
I think that the following patch fixes the bug and it definitely fixes
the case you gave:
$ touch foo/bar ; echo $?
touch: foo/bar: Read-only file system
1
$ touch foo ; echo $?
touch: foo: Read-only file system
1
Index: usr.bin/touch/touch.c
===================================================================
--- usr.bin/touch/touch.c (revision 179703)
+++ usr.bin/touch/touch.c (working copy)
@@ -222,11 +222,13 @@
continue;
/* Try reading/writing. */
- if (!S_ISLNK(sb.st_mode) && !S_ISDIR(sb.st_mode) &&
- rw(*argv, &sb, fflag))
+ if (!S_ISLNK(sb.st_mode) && !S_ISDIR(sb.st_mode)) {
+ if (rw(*argv, &sb, fflag))
+ rval = 1;
+ } else {
rval = 1;
- else
warn("%s", *argv);
+ }
}
exit(rval);
}
More information about the freebsd-bugs
mailing list