Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Apr 2007 12:15:25 -0700
From:      Jan Schaumann <jschauma@netmeister.org>
To:        bugbusters@freebsd.org
Subject:   touch(1)ing a directory and failing yields return code 0
Message-ID:  <20070428191525.GB25064@netmeister.org>

next in thread | raw e-mail | index | archive | help

--UugvWAfsgieZRqgk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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 =3D 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 =3D 1;


This still is slightly suboptimal, since the error message will be

$ touch foo
touch: foo: Is a directory
$ echo $?
1
$=20

But that's better than returning 0.

--=20
Probability factor of one to one. We have normality. I repeat, we have=20
normality. Anything you still can't cope with is therefore your own lookout.

--UugvWAfsgieZRqgk
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (NetBSD)

iD8DBQFGM51NfFtkr68iakwRAv12AKDx50xVD9WjKzuBYs1ZrOKT54urNwCdFQnP
2+ZB1wezbGtRAOQAgIAWPdw=
=KYYY
-----END PGP SIGNATURE-----

--UugvWAfsgieZRqgk--



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