Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Feb 2012 10:46:03 +0300
From:      Sergey Kandaurov <pluknet@freebsd.org>
To:        Jaakko Heinonen <jh@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r230979 - head/usr.bin/touch
Message-ID:  <CAE-mSOLcOo3zzKxRJvkW%2BOe_-cPBoPXGGMKmNByvtSRggLJHig@mail.gmail.com>
In-Reply-To: <201202041337.q14DbVTn037485@svn.freebsd.org>
References:  <201202041337.q14DbVTn037485@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 4 February 2012 17:37, Jaakko Heinonen <jh@freebsd.org> wrote:
> Author: jh
> Date: Sat Feb =A04 13:37:31 2012
> New Revision: 230979
> URL: http://svn.freebsd.org/changeset/base/230979
>
> Log:
> =A0Remove useless and potentially dangerous rw() function which tries to
> =A0update access and modification times by reading and writing the file.
> =A0chmod(2) in rw() doesn't help because utimes(2) allow owner and the
> =A0super-user to change times. Using just utimes(2) should be sufficient.
>
> =A0The -f option becomes no-op.
>
> =A0Reviewed by: =A0jilles
>
> Modified:
> =A0head/usr.bin/touch/touch.1
> =A0head/usr.bin/touch/touch.c

Thank you.
FYI, this code was written before utimes(2) was born (yes, before 4.2BSD),
so it was technically correct to remove it for more than 20 years ago.

>
> Modified: head/usr.bin/touch/touch.1
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/usr.bin/touch/touch.1 =A0Sat Feb =A04 13:12:52 2012 =A0 =A0 =A0 =
=A0(r230978)
> +++ head/usr.bin/touch/touch.1 =A0Sat Feb =A04 13:37:31 2012 =A0 =A0 =A0 =
=A0(r230979)
> @@ -31,7 +31,7 @@
> =A0.\" =A0 =A0 @(#)touch.1 =A0 =A08.3 (Berkeley) 4/28/95
> =A0.\" $FreeBSD$
> =A0.\"
> -.Dd April 28, 1995
> +.Dd February 4, 2012
> =A0.Dt TOUCH 1
> =A0.Os
> =A0.Sh NAME
> @@ -40,7 +40,7 @@
> =A0.Sh SYNOPSIS
> =A0.Nm
> =A0.Op Fl A Ar [-][[hh]mm]SS
> -.Op Fl acfhm
> +.Op Fl achm
> =A0.Op Fl r Ar file
> =A0.Op Fl t Ar [[CC]YY]MMDDhhmm[.SS]
> =A0.Ar
> @@ -109,9 +109,6 @@ The
> =A0.Nm
> =A0utility does not treat this as an error.
> =A0No error messages are displayed and the exit value is not affected.
> -.It Fl f
> -Attempt to force the update, even if the file permissions do not
> -currently permit it.
> =A0.It Fl h
> =A0If the file is a symbolic link, change the times of the link
> =A0itself rather than the file that the link points to.
>
> Modified: head/usr.bin/touch/touch.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> --- head/usr.bin/touch/touch.c =A0Sat Feb =A04 13:12:52 2012 =A0 =A0 =A0 =
=A0(r230978)
> +++ head/usr.bin/touch/touch.c =A0Sat Feb =A04 13:37:31 2012 =A0 =A0 =A0 =
=A0(r230979)
> @@ -55,7 +55,6 @@ static const char sccsid[] =3D "@(#)touch.
> =A0#include <time.h>
> =A0#include <unistd.h>
>
> -int =A0 =A0rw(char *, struct stat *, int);
> =A0void =A0 stime_arg1(char *, struct timeval *);
> =A0void =A0 stime_arg2(char *, int, struct timeval *);
> =A0void =A0 stime_file(char *, struct timeval *);
> @@ -69,12 +68,12 @@ main(int argc, char *argv[])
> =A0 =A0 =A0 =A0struct timeval tv[2];
> =A0 =A0 =A0 =A0int (*stat_f)(const char *, struct stat *);
> =A0 =A0 =A0 =A0int (*utimes_f)(const char *, const struct timeval *);
> - =A0 =A0 =A0 int Aflag, aflag, cflag, fflag, mflag, ch, fd, len, rval, t=
imeset;
> + =A0 =A0 =A0 int Aflag, aflag, cflag, mflag, ch, fd, len, rval, timeset;
> =A0 =A0 =A0 =A0char *p;
> =A0 =A0 =A0 =A0char *myname;
>
> =A0 =A0 =A0 =A0myname =3D basename(argv[0]);
> - =A0 =A0 =A0 Aflag =3D aflag =3D cflag =3D fflag =3D mflag =3D timeset =
=3D 0;
> + =A0 =A0 =A0 Aflag =3D aflag =3D cflag =3D mflag =3D timeset =3D 0;
> =A0 =A0 =A0 =A0stat_f =3D stat;
> =A0 =A0 =A0 =A0utimes_f =3D utimes;
> =A0 =A0 =A0 =A0if (gettimeofday(&tv[0], NULL))
> @@ -92,7 +91,7 @@ main(int argc, char *argv[])
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cflag =3D 1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0case 'f':
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fflag =3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* No-op for compatibility.=
 */
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0case 'h':
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cflag =3D 1;
> @@ -222,14 +221,8 @@ main(int argc, char *argv[])
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!utimes_f(*argv, NULL))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue;
>
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Try reading/writing. */
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!S_ISLNK(sb.st_mode) && !S_ISDIR(sb.st_=
mode)) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rw(*argv, &sb, fflag))
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rval =3D 1;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rval =3D 1;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn("%s", *argv);
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rval =3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn("%s", *argv);
> =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0exit(rval);
> =A0}
> @@ -368,59 +361,10 @@ stime_file(char *fname, struct timeval *
> =A0 =A0 =A0 =A0TIMESPEC_TO_TIMEVAL(tvp + 1, &sb.st_mtim);
> =A0}
>
> -int
> -rw(char *fname, struct stat *sbp, int force)
> -{
> - =A0 =A0 =A0 int fd, needed_chmod, rval;
> - =A0 =A0 =A0 u_char byte;
> -
> - =A0 =A0 =A0 /* Try regular files. */
> - =A0 =A0 =A0 if (!S_ISREG(sbp->st_mode)) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 warnx("%s: %s", fname, strerror(EFTYPE));
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (1);
> - =A0 =A0 =A0 }
> -
> - =A0 =A0 =A0 needed_chmod =3D rval =3D 0;
> - =A0 =A0 =A0 if ((fd =3D open(fname, O_RDWR, 0)) =3D=3D -1) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!force || chmod(fname, DEFFILEMODE))
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ((fd =3D open(fname, O_RDWR, 0)) =3D=3D =
-1)
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 needed_chmod =3D 1;
> - =A0 =A0 =A0 }
> -
> - =A0 =A0 =A0 if (sbp->st_size !=3D 0) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (read(fd, &byte, sizeof(byte)) !=3D size=
of(byte))
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (lseek(fd, (off_t)0, SEEK_SET) =3D=3D -1=
)
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (write(fd, &byte, sizeof(byte)) !=3D siz=
eof(byte))
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err;
> - =A0 =A0 =A0 } else {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (write(fd, &byte, sizeof(byte)) !=3D siz=
eof(byte)) {
> -err: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rval =3D 1;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn("%s", fname);
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else if (ftruncate(fd, (off_t)0)) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rval =3D 1;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn("%s: file modified", f=
name);
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> - =A0 =A0 =A0 }
> -
> - =A0 =A0 =A0 if (close(fd) && rval !=3D 1) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 rval =3D 1;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn("%s", fname);
> - =A0 =A0 =A0 }
> - =A0 =A0 =A0 if (needed_chmod && chmod(fname, sbp->st_mode) && rval !=3D=
 1) {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 rval =3D 1;
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 warn("%s: permissions modified", fname);
> - =A0 =A0 =A0 }
> - =A0 =A0 =A0 return (rval);
> -}
> -
> =A0void
> =A0usage(char *myname)
> =A0{
> - =A0 =A0 =A0 fprintf(stderr, "usage:\n" "%s [-A [-][[hh]mm]SS] [-acfhm] =
[-r file] "
> + =A0 =A0 =A0 fprintf(stderr, "usage:\n" "%s [-A [-][[hh]mm]SS] [-achm] [=
-r file] "
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"[-t [[CC]YY]MMDDhhmm[.SS]] file ...\n", m=
yname);
> =A0 =A0 =A0 =A0exit(1);
> =A0}



--=20
wbr,
pluknet



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAE-mSOLcOo3zzKxRJvkW%2BOe_-cPBoPXGGMKmNByvtSRggLJHig>