From owner-svn-src-all@FreeBSD.ORG Sun Feb 5 07:46:06 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2897A106564A; Sun, 5 Feb 2012 07:46:06 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: from mail-lpp01m010-f54.google.com (mail-lpp01m010-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id ACB6E8FC08; Sun, 5 Feb 2012 07:46:04 +0000 (UTC) Received: by lagz14 with SMTP id z14so3245496lag.13 for ; Sat, 04 Feb 2012 23:46:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Zf+m5iA6U1+uSGhj63F3T+U7rlxNRsGekZU67WV+c6s=; b=E4yRLzbWJHVFvOZhwpU8870t8JFeSU6jbuAOIeYW5D7H9g4eIQmQBQ43jfb2Pc1z+/ vly6yPB6H3R/6gTQh5kntl+ElJdbLQqxMXYi1OKKpTPqAwagKkmL7k3ee9kDn96E/GGc 5tyU3zEPsQKHq5vifvy7p6uA4Ym+wi52tThJs= MIME-Version: 1.0 Received: by 10.152.133.229 with SMTP id pf5mr6968614lab.18.1328427963547; Sat, 04 Feb 2012 23:46:03 -0800 (PST) Sender: pluknet@gmail.com Received: by 10.152.2.138 with HTTP; Sat, 4 Feb 2012 23:46:03 -0800 (PST) In-Reply-To: <201202041337.q14DbVTn037485@svn.freebsd.org> References: <201202041337.q14DbVTn037485@svn.freebsd.org> Date: Sun, 5 Feb 2012 10:46:03 +0300 X-Google-Sender-Auth: oCFXi5SYP0KzdDT7RF0RXgSS_Mg Message-ID: From: Sergey Kandaurov To: Jaakko Heinonen Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r230979 - head/usr.bin/touch X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Feb 2012 07:46:06 -0000 On 4 February 2012 17:37, Jaakko Heinonen 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 > =A0#include > > -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