Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Jun 2008 15:40:03 GMT
From:      Jaakko Heinonen <jh@saunalahti.fi>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/112213: touch(1)ing a directory and failing yields return code 0
Message-ID:  <200806101540.m5AFe3fl071230@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/112213; it has been noted by GNATS.

From: Jaakko Heinonen <jh@saunalahti.fi>
To: bug-followup@FreeBSD.org, jschauma@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);
  }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806101540.m5AFe3fl071230>