From owner-freebsd-bugs@FreeBSD.ORG Sat Apr 28 19:20:05 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5830016A408 for ; Sat, 28 Apr 2007 19:20:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 1E06E13C45B for ; Sat, 28 Apr 2007 19:20:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l3SJK4Rp050771 for ; Sat, 28 Apr 2007 19:20:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l3SJK4oL050751; Sat, 28 Apr 2007 19:20:04 GMT (envelope-from gnats) Resent-Date: Sat, 28 Apr 2007 19:20:04 GMT Resent-Message-Id: <200704281920.l3SJK4oL050751@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jan Schaumann Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3407F16A402 for ; Sat, 28 Apr 2007 19:16:53 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [69.147.83.33]) by mx1.freebsd.org (Postfix) with ESMTP id 21C8C13C468 for ; Sat, 28 Apr 2007 19:16:53 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l3SJGrbR048870 for ; Sat, 28 Apr 2007 19:16:53 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id l3SJBoLT048085; Sat, 28 Apr 2007 19:11:50 GMT (envelope-from nobody) Message-Id: <200704281911.l3SJBoLT048085@www.freebsd.org> Date: Sat, 28 Apr 2007 19:11:50 GMT From: Jan Schaumann To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: misc/112212: touch(1)ing a directory and failing yields return code 0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Apr 2007 19:20:05 -0000 >Number: 112212 >Category: misc >Synopsis: touch(1)ing a directory and failing yields return code 0 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Apr 28 19:20:04 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Jan Schaumann >Release: >Organization: >Environment: >Description: 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. >How-To-Repeat: $ 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 $ >Fix: 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. >Release-Note: >Audit-Trail: >Unformatted: